Shadow problem

Started by jakethesnake, May 07, 2015, 06:24:46

Previous topic - Next topic

jakethesnake

In my fragment shader I'm iterating through all the lights and applying lightning effects to each pixel. Prior to any gl rendering I draw all shadows to a separate texture, using a red sprite.

In my shader I then sample that texture. If red > 0, then I subtract the "lightning effect" with "lightning effect"*"value of red".

+ "if (shadowColor.x > 0.0)" + "\n"
							+ "tempColor-= tempColor*shadowColor.x;" + "\n"
						+ "finalColor += texColor.xyz * tempColor.xyz;" + "\n"


This is all very good, but I want each shadow to be bound to a specific light. I tried doing it by drawing a value of specific value of green on top of the red in my shadow-texture. Then, for light nr 1 I did:

+ "if (shadowColor.y == 0.1)" + "\n"
							+ "tempColor-= tempColor*shadowColor.x;" + "\n"
						+ "finalColor += texColor.xyz * tempColor.xyz;" + "\n"


For 2:

+ "if (shadowColor.y == 0.2)" + "\n"
							+ "tempColor-= tempColor*shadowColor.x;" + "\n"
						+ "finalColor += texColor.xyz * tempColor.xyz;" + "\n"


However, if shadows 1 and 2 overlap, then I get the Green value 0.1+0.2 = 0.3, which corresponds to none of the shadows when It should correspond to both.

On top of that, the "==" never yields true, since the 2Dsampler gives me a float. For the first light I have to do:

+ "if (shadowColor.y > 0.9 && shadowColor.y < 1.9 )" + "\n"
							+ "tempColor-= tempColor*shadowColor.x;" + "\n"
						+ "finalColor += texColor.xyz * tempColor.xyz;" + "\n"


But it still doesn't work though...

I could solve this easily if I only could draw to and then access some integer-buffer. Then the LSB would be light 1, then 2, 3...

Then, the fragment could consult this buffer and apply shadows where it should.

LIGHT INTEGER = |Nth Light|...|light 5|light4|light3|light2|light1|

if (light Integer & 4 == 1)
   Apply shadow 4

Any ideas on how to do this, or solve it in another way?

abcdef

You might find more luck at opengl.org forums, they have forums better suited to these questions. You might find people here who can help too (there are some very knowledgable people) but the numbers of people will be much higher at opengl.org

jakethesnake

Quote from: abcdef on May 07, 2015, 08:27:12
You might find more luck at opengl.org forums, they have forums better suited to these questions. You might find people here who can help too (there are some very knowledgable people) but the numbers of people will be much higher at opengl.org

I will look into that!

Kai

You can certainly render to and sample an integer format texture: https://www.opengl.org/wiki/GL_EXT_texture_integer
Starting with GLSL 3.30 you also have full integer arithmetics support in shaders, including bitwise and shifting operations.

jakethesnake

Perfect, I'll look into that. I suppose I have to make a new shader-program that writes ints as colors instead of floats.