0
\$\begingroup\$

When I move the light, the shadows will fall apart as if their occluders aren't occluding them in certain areas.

For example, in the following scene, I move a pointlight 400 units down the Z axis, I get a scene like this, where somehow occluded fragments are passing the shadow test:

Scene from distance Single shadow

The shadowmap texture appears fine to me. Since I'm working with a pointlight, I need a cubemap, so here are the relevant portions of its texture:

Cubemap


I'm fairly certain my issue has to be somewhere in one of my shaders.

My point light's shadowing logic subtracts the lights' position from the fragment's world position, takes the length of that vec3 and outputs that as the FragColor.

#version 330

in vec3 WorldPos; // aka ViewMatrix*ModelMatrix*Vertex

layout (location = 0) out float FragColor;

uniform vec3 LightPos;

void main()
{   
    vec3 LightToVertex = WorldPos - LightPos;
    float LightToPixelDistance = length(LightToVertex);

    FragColor = LightToPixelDistance;
}

And then within the actual lighting logic, I do this to calculate a shadow factor (where 1.0 == full illumination, and 0.0 == full darkness)

uniform samplerCubeShadow ShadowMap;
in vec3 WorldPos;

float CalcShadowFactor()                                                  
{       
    vec3 LightDirection = WorldPos - pointLight.position; 
    float Distance = length(LightDirection);        
    vec3 Direction = normalize(LightDirection);

    float Factor = 0.2;         
    vec4 UVC = vec4(Direction, (Distance + EPSILON));
    Factor += texture(ShadowMap, UVC) +0.05;

    return Factor;
}
\$\endgroup\$
  • \$\begingroup\$ Also, I'll gladly add any extra information if anyone needs it \$\endgroup\$ – Yattabyte Dec 25 '15 at 0:16
  • 1
    \$\begingroup\$ I don't know what your "ViewMatrix * ModelMatrix * Vertex" is but it should be in world space (maybe leave out the ViewMatrix?). \$\endgroup\$ – Byron Dec 25 '15 at 1:47
1
\$\begingroup\$

Byron's comment was right. I thought I needed to use the camera's view matrix (from the light's position), but alas it wasn't needed. Removing it solved the problem

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.