Part of the Khronos Group
OpenGL.org

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 10 of 16

Thread: Spotlight and shadowmapping issues

Threaded View

  1. #1
    Intern Newbie
    Join Date
    Jan 2014
    Posts
    33

    Spotlight and shadowmapping issues

    I'm trying to implement shadowmapping for spotlights in an OpenGL 4.3 deferred renderer. The problem is described below.

    Here is the scene from the cameras POV, with shadow calculations commented-out:



    Here is the depth texture generated during the shadow pass.



    The two images describe the problem: in the first image, you can see small spots of light along the edges of the ground plane, and second image shows this up-close.




    Here is the fragment shader for the spotlight lighting pass:

    Code :
        #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 * 
                UnifDirLightPass.mLightColor;
        }

    I don't see where the problem is, or what might be causing the strange white spots on the edges of the ground plane. Any pointers?
    Last edited by Dark Photon; 01-11-2014 at 12:44 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •