Jump to content
  • Advertisement
Sign in to follow this  

OpenGL Spotlight and shadowmapping issues

This topic is 2107 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm having issues with making shadowmapping for spotlights work as intended for an OpenGL 4.3 deferred renderer. The problem is described further below.


Here is the scene with the "shadowFactor" commented-out in the shader, so the scene is fully lit.




Here is the depth texture, from the lights POV:




Here is the pictures that show the problem, when the shadowFactor is Not commented-out. Note the white-spots on the edge of the ground plane; distant in the first picture, up-close in the second.






Here is the actual fragment shader for the lighting pass for spot lights:

    #version 430      
    layout(std140) uniform; 
    uniform UnifDirLight  
        mat4 mWVPMatrix;     // camera world-view-projection matrix
        mat4 mVPMatrix;      // the spotlights view-projection matrix
        vec4 mLightColor; 
        vec4 mLightDir;   
        vec4 mGamma;     
        vec2 mScreenSize;  
    } UnifDirLightPass;  
    layout (binding = 2) uniform sampler2D unifPositionTexture; 
    layout (binding = 3) uniform sampler2D unifNormalTexture;   
    layout (binding = 4) uniform sampler2D unifDiffuseTexture;  
    layout (binding = 5) uniform sampler2D unifShadowTexture; 
    out vec4 fragColor;                                       
    void main()    
        vec2 texcoord = gl_FragCoord.xy / UnifDirLightPass.mScreenSize;
        vec3 worldPos = texture(unifPositionTexture, texcoord).xyz;    
        vec3 normal   = normalize(texture(unifNormalTexture, texcoord).xyz); 
        vec3 diffuse  = texture(unifDiffuseTexture, texcoord).xyz;     
        vec4 lightClipPos = UnifDirLightPass.mVPMatrix * vec4(worldPos, 1.0);
        vec3 projCoords   = lightClipPos.xyz / lightClipPos.w;              
        projCoords.x = 0.5 * projCoords.x + 0.5;                         
        projCoords.y = 0.5 * projCoords.y + 0.5;       
        projCoords.z = 0.5 * projCoords.z + 0.5;       
        float depthValue   = texture(unifShadowTexture, projCoords.xy).x;  
        float shadowFactor = 0.0;                                         
        if (depthValue >= (projCoords.z + 0.0001))               
             shadowFactor = 1.0;  
        float angleNormal = clamp(dot(normal, UnifDirLightPass.mLightDir.xyz), 0, 1);
        fragColor = vec4(diffuse, 1.0) * shadowFactor * angleNormal * 

I can't see what really is the issue at hand. Any pointers?

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!