PDA

View Full Version : depth peeling program


abc9804
03-14-2008, 07:09 AM
Hello,everyone
I get the depth peeling code from NV demos (C. Everitt).I'm not familier with shader programming. Can you please try to interpret this fragment code?

char _fp_peel[] =
"!!ARBfp1.0\n"
"OPTION ARB_fragment_program_shadow;\n"
"TEMP R0;\n"
"TEX R0.x, fragment.position, texture[0], SHADOWRECT;\n"
"ADD R0.x, R0.x, -0.5;\n"
"KIL R0.x;\n"
"MOV result.color, fragment.color;\n"
"END\n";

Also,I have three problem:how to understand TEX sentence? if fragment.position changes into fragment.texcoord[0],is there any differences? The last one,why R0.x need subtract 0.5?
Many thanks,

Reedbeta
03-14-2008, 09:32 AM
fragment.position is a built-in variable that represents the fragment's x, y coordinates on the screen. fragment.texcoord[0] isn't necessarily the same although you could set up your geometry with appropriate texcoords so that it would be the same.

As for the subtraction of 0.5, look at the next line: KIL R0.x. This instruction discards (kills) the fragment if R0.x is less than zero. So the subtraction right before means that the fragment gets killed if the returned value from the texture is less than 0.5, i.e. if the fragment is more than 50% shadowed.