Part of the Khronos Group

The Industry's Foundation for High Performance Graphics

from games to virtual reality, mobile phones to supercomputers

Results 1 to 1 of 1

Thread: Deferred spotlight shadowmapping, weird artifacts.

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Junior Member Newbie
    Join Date
    Nov 2011

    Exclamation Deferred spotlight shadowmapping, weird artifacts.

    Been working on implementing simple shadowmaps, but I've came across some weird issues. I've been at this issue for almost a week now (a few hours here and there) and cant figure it out

    This is the relevant shader code:
    Code :
    /* 'viewPosition' is saved in GBuffer and written as ViewMatrix * ModelMatrix * VertexPosition
     * 'linearViewDepth' is saved in GBuffer and written as LinearizeDepth(gl_FragCoord.z, nearclip, farclip)
     * 'uniform_shadowmap' is a texturesampler for the shadow depth map
     * 'uniform_snearclip' and 'uniform_sfarclip' are the near and far clip planes for the shadowmaps projection
     * 'uniform_invViewMatrix' is the inverse of ViewMatrix
     * 'uniform_lightViewProjMatrix' is the viewprojection matrix for the spotlight "camera"
    float LinearizeDepth(float depth, float near, float far)
      float z = depth * 2.0 - 1.0;
      return (2.0 * near * far) / (far + near - z * (far - near));
    void checkShadow(vec3 viewPosition, float linearViewDepth)
      vec4 worldPosition = uniform_invViewMatrix * vec4(viewPosition, 1);
      vec4 lightPosition = uniform_lightViewProjMatrix * worldPosition; /= lightPosition.w;
      vec2 shadowUV = lightPosition.xy * vec2(0.5) + vec2(0.5);
      float linearShadowDepth = LinearizeDepth(texture(uniform_shadowmap, shadowUV).r, uniform_snearclip, uniform_sfarclip);
      if (linearShadowDepth < linearViewDepth)

    More descriptive with annotations, a visible spotlight frustum, and lower shadowmap resolution for clearer results.

    Old video:

    Any help, tips and/or recommendations are highly appreciated!
    Last edited by haikarainen; 11-30-2015 at 02:33 AM.

Tags for this Thread

Posting Permissions

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