I'm trying to write the functionality for point-light shadowing. I got spotlight shadowing working first, but then when I switched to point light shadowing (by using a cube map, rendering depth from 6 POV's, etc...) I'm now getting a checkered pattern of light (with NO shadows). Does anyone have any intuition regarding why this might be?
Here's a screenshot:
(Note that if you look closely, you can clearly see that a cubemap is being rendered with the front face of the cube just to the right of the triangle)
And here's my render pass fragment shader glsl code (if you want to see the rest, I can post that as well, but figured this is the important bit)
Note: I'm using deferred lighting, so the vertex shader of this pass is just a quad, and the pos_tex, norm_tex, and col_tex are from the geometry buffer generated in a previous pass.
#version 330 core
in vec2 UV;
out vec3 color;
uniform vec3 lightPosVec; //Non rotation affine
uniform sampler2D pos_tex;
uniform sampler2D col_tex;
uniform sampler2D norm_tex;
uniform samplerCubeShadow shadow_tex;
uniform sampler2D accum_tex; //the tex being drawn to
void main()
{
vec3 lightToFragVec = texture(pos_tex, UV).xyz-lightPosVec;
vec3 l2fabs = abs(lightToFragVec);
float greatestMagnitudeOfLightToFragVec = max(l2fabs.x, max(l2fabs.y, l2fabs.z));
float lightToFragDepth = ((100.0+0.1) / (100.0-0.1) - (2*100.0*0.1)/(100.0-0.1)/greatestMagnitudeOfLightToFragVec + 1.0) * 0.5;
float shadowed = texture(shadow_tex, vec4(normalize(lightToFragVec),lightToFragDepth));
color =
texture(accum_tex, UV).xyz+ //current value
texture(col_tex, UV).xyz //frag color
*dot(lightPosVec-texture(pos_tex,UV).xyz,texture(norm_tex,UV).xyz) //dot product of angle of incidence of light to normal
*(4+15*shadowed) //shadow amplification
/max(0.000001,dot(lightToFragVec,lightToFragVec)); //distance cutoff
}
Thank you!
EDIT:
Ok, so I've been toying around with it, and now the texture seems to be random...
So this makes me think that the depth cube is just full of noise? But that seems unlikely, because for the texture() function with a samplerCubeShadow to return 1.0, the value at that point must be EXACTLY the value of the depth at that fragment... right? Also, I have it set up to control the position of the light with wasd+up+down, and the pattern moves with the movement of the light (when I back up, it gets bigger/dimmer). Which means that the values MUST be dynamically changing to match the actual distance? Oh man I'm confused...
EDIT 2 Ok, sorry, this question is out of control, but I figured I'd continue to document my progress for the sake of anyone in the future with similar problems.
Anyways, I've now figured out that I get the same exact result no matter what I put as the 4th component of the 4d vector passed to texture() with the shadowcubemap. Like, I can even put a constant, and I get the exact same result. How is that possible?
EDIT 3 Darn. Turns out the error had nothing to do with anything I've just said. See answer below for details :(