Author Topic: Shadow maping in 4k under linux. [ now with binaries ]  (Read 26217 times)

0 Members and 1 Guest are viewing this topic.

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Hi!
as some might remember i was trying to create a 4k demo on linux. i failed ;P, but meanwhile i created this, a quite small implementation of shadowmaping using multiple lights with GLSL. the whole code compiled & compressed is a little less that 4k ( and could be less ). Mabye it is not so impressive as creations of others( the colours are horrible ;d ), but i hope someone will find this implementation handy. I tried to explain as much of code as i could but i am not good at explaining things.
If you have problems with seeing the shadows uncomment a part of fragment shader ( colour[1]*shadow(...) ).

The code is almost platform independant, for non-linux os'es, you need to change the asm code in terrain.c to seed = time( 0 );.
( code uses GL/GLU/SDL libraries )

Could someone test it? It works ok on my comp, but always someone has a comp on which my programs fail ;).

The code is avaible here:
students.mimuw.edu.pl/~mp248778/4k.tar.gz

Ps. On 64-bit os'es the file will be much bigger ( ~600-700 bytes ).
Ps2. it could be much smaller ( ~600b ) if ATI drivers had no problems when i don't load stdlib. is there a walkaround?


edit:
Windows binaries ( not striped, packed, anything ) Pressing q exits. Download nof.exe if you see only white terrain.
http://students.mimuw.edu.pl/~mp248778/1light.exe
http://students.mimuw.edu.pl/~mp248778/2lights.exe
students.mimuw.edu.pl/~mp248778/nof.exe
students.mimuw.edu.pl/~mp248778/SDL.dll
« Last Edit: November 29, 2007 by frea »
Nananan.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Shadow maping in 4k under linux.
« Reply #1 on: November 27, 2007 »
I don't have linux installed here, but looking at your code it looks a very nice job :)
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux.
« Reply #2 on: November 27, 2007 »
Same as Rbraz, I have no Linux so cant run it but it looks interesting.
Why do you say ATi drivers have a problem when there is no stdlib? Is this a linux only issue. What happens?

The shaders can be smaller but they are very cool as an example, can you maybe upload an image of the result for thos without Linux but who would like to understand the code more?

Taj...
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux.
« Reply #3 on: November 27, 2007 »
ATI's fglrx calls varius functions like sprintf/strlen/etc. If i compile with gcc -c (files) (flags ), and then link with ld -dynamic-linker /usr/lib64/linux-x86-64.so ( gl/sdl libraries ) ( .o files ), the program crashes  when fglrx tries to call any stdlib function, which are not linked by my program.

taj : could you give ma a hint how to make these shaders smaller?

And about linux, i said that the code should be platform independant ( except that small thing in terrain.c, which is explained how to fix ).

I'll try to compile it on windows ( although i'll not try to make it 4k ;p ) and link the executable.

edit: the links to executables are in the first post.
« Last Edit: November 27, 2007 by frea »
Nananan.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux.
« Reply #4 on: November 27, 2007 »

taj : could you give ma a hint how to make these shaders smaller?


Try reducing all variable names to one letter. Reduce 0.5 to .5 and similar for 1.0 etc. Depending on your packer you may find it shorter to have a for loop with inline code than a function call (which has loads of overhead string-wise). I have no linux size compression experience except a really dumb self written unpacker using gzip once so I cant say for sure, but if you are using gzip to compress, it uses a dictionary so the above advice will hold true.

Hmmm the windows exes just draw a white surface (ie no shader running) under XP SP2, ATi x600...my guess is the shader at this line:

Code: [Select]
if(abs(shCo.s)<abs(shCo.q)&&\
abs(shCo.t)<abs(shCo.q)&&\
shCo.p>0)\

should be

Code: [Select]
if(abs(shCo.s)<abs(shCo.q)&&\
abs(shCo.t)<abs(shCo.q)&&\
shCo.p>0.)\

Also:
Code: [Select]
shCo=shCo*0.5f+0.5f;\
Should have no 'f's. Similar with return 1.0f;


Infact I'm confused how this works for you! Maybe "f" has crept into the standard without me noticing!

Taj
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #5 on: November 27, 2007 »
and karma++ for code...
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #6 on: November 27, 2007 »
When i reduced the variable names the size  increased by 1-2 bytes.
About the f from 1.0f, the glsl specification that i have expicitly says that a float function must return a float ( no casting is allowed ), and 1.0 is a double.

If this exe wont work for you i'll just create this exe with shaders beeing loaded from file and errors written to a file, so any corrections could be much easier :).
students.mimuw.edu.pl/~mp248778/nof.exe
I hope it will work ;). It is hard to debug through a forum :P.
( surprisingly the nof version works also for me, i must have an old glsl specification ).


edit: btw under linux compile without the --short-doubles.
« Last Edit: November 27, 2007 by frea »
Nananan.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #7 on: November 27, 2007 »
The new exe works...what did you do, make the changes I suggested?
Looks cool BTW. Very nice effect. I can see why you like it.

When i reduced the variable names the size  increased by 1-2 bytes.
About the f from 1.0f, the glsl specification that i have expicitly says that a float function must return a float ( no casting is allowed ), and 1.0 is a double.

Its not a double. There are no doubles in glsl. Are you confusing with C notation? This isnt C : its glsl.
Floats are written 1.0, 0.5 .5 etc. No "f". That your ATi compiler breaks the spec and allows "f" under linux does not mean it will work everywhere. That your spec says a float function must return a float has no bearing on how a float is written in glsl.

The slight increase in size is baffling...this certainly wouldnt work like that under crinkler but I guess crinkler must be more sensitive to variable size. I'd still advise trying getting rid of your function.
« Last Edit: November 27, 2007 by taj »
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #8 on: November 27, 2007 »
Yes i made the changes you suggested.
you are right about these floats/doubles :). Thanks.

it is nothing new, that ATI drivers under linux work weridly :).
Is anyone now experiencing any problems with the exe's?
Nananan.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #9 on: November 27, 2007 »
Hmmm the more I dig the more I think the code is interesting. This is a great first post, I hope you stick around. Also thanks for crediting me in the code ! I thought nobody did that anymore :-). I shall be sure to greet you when I use this stuff because I will if I can. I need to convert to VC++ and get rid of sdl first but I might even try that tonight. Good work.

(lets see if we can get it below 2k...)

Hmmm. and interesting. You are using GCC. I notice you dont use wglGetProcAddress anywhere for the extensions. Did you cross-compile under Linux for windows? Or how else did you compile. If it seems like a dumb question, its not. If I have to use
wglGetProcAddress for all those extensions you use, the exe will be much bigger. If GCC avoids this ... hmmm then maybe switching to GCC for 4ks would actually save some bytes for extension heavy code.
 
Taj
« Last Edit: November 27, 2007 by taj »
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #10 on: November 28, 2007 »
To compile it under windows i used nothing fancy, just downloaded GLee and included it into the project. That is why it is so huge btw.

gcc under linux links me to some 'advanced' ogl functions cheaply, allowing me not to use linux equivalent of wglgetprocaddress ( i forgot how is that function called ). The only problem is to find equivalents of missing functions ( like glCreateProgram(), which is glCreateProgramObjectARB() ), but it is just matter of googling / looking into libGL.so.

It might be that only my drivers give me such posibility, but i don't have any other card to test it ( anyone with nVidia card is willing to test it under linux? ). xorg-x11 drivers allow this compilation but they are not supporting shaders.

i would really like to see it fitting 2k, especialy under linux where you cannot use crinkler :).
« Last Edit: November 29, 2007 by frea »
Nananan.

Offline Rbz

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 2757
  • Karma: 493
    • View Profile
    • https://www.rbraz.com/
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #11 on: November 29, 2007 »
...
Is anyone now experiencing any problems with the exe's?
Hmm, your windows binaries isn't working here, I got only a white rotating thing and a black background  :(


gfx card: GeForce 6600GT
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #12 on: November 29, 2007 »
all three of them? even the nof.exe?
Nananan.

Offline Jim

  • Founder Member
  • DBF Aficionado
  • ********
  • Posts: 5301
  • Karma: 402
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #13 on: November 29, 2007 »
All 3 work here 8600GT/Vista.
It's a lovely demo, and I think I can see the effect, but I don't think you've chosen the best model to demonstrate it.  Is it possible to put some monoliths casting shadows on there or something?

Jim
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #14 on: November 29, 2007 »
To add anything i would need some more space, but codewise there is no problem with that. So if taj will succed with making it smaller that will be possible. For now i am a little tired with that program, and my studies are taking more and more of my time :), so i'll try later optimizing this code.
Nananan.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #15 on: November 29, 2007 »
To compile it under windows i used nothing fancy, just downloaded GLee and included it into the project. That is why it is so huge btw.

i would really like to see it fitting 2k, especialy under linux where you cannot use crinkler :).

Hmm well GLEE cant be used under windows as you know, so thats going to be tough to load all those extensions - there are so many. However, its such a cool piece of code I think I'll give it a go.

Taj
Challenge Trophies Won:

Offline Paul

  • Pentium
  • *****
  • Posts: 1490
  • Karma: 47
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #16 on: November 29, 2007 »
All three give me a blue screen. "2 lights" worked yestarday(28/11).
8800gts/vista
« Last Edit: November 29, 2007 by Paul »
I will bite you - http://s5.bitefight.se/c.php?uid=31059
Challenge Trophies Won:

Offline frea

  • C= 64
  • **
  • Posts: 61
  • Karma: 2
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #17 on: November 29, 2007 »
This is weird, especialy 2lights which worked yesterday and are not working today. I don't know what might be causing a blue screen, i am not using windows too much. I could understand a crash of the program, but a blue screen? I don't do any lowlvl stuff in that program, i just call gl functions.
Nananan.

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #18 on: November 29, 2007 »
Frea,

I converted the code from GLEE+SDL to a pure windows version. Using exactly your code plus crinkler using stupid flags) its 2492. I had no idea GZIP was so much worse than crinkler. For you and anyone interested in compiling and playing under windows using VC++ I'm putting the archive here. There is also an exe which may work better than the GLEE/SDL one or not...dont know. I have no idea why Pauls PC would Blue Screen!

Theres quite a few bytes can be saved but I dont know if I can be bothered, mainly I'm just interested in understanding this code. We'll see.

WARNING: due to size limitations I was unable to include crinkler in this distribution so it wont work "out of the bag". Crinkler is in the next post. Drop it into the directory with all the code.

Taj
« Last Edit: November 29, 2007 by taj »
Challenge Trophies Won:

Offline taj

  • Bytes hurt
  • DBF Aficionado
  • ******
  • Posts: 4810
  • Karma: 189
  • Scene there, done that.
    • View Profile
Re: Shadow maping in 4k under linux. [ now with binaries ]
« Reply #19 on: November 29, 2007 »
and crinkler (called link.exe - dont worry thats how it should be called...)

Challenge Trophies Won: