View Full Version : Deferred spotlight shadowmapping, weird artifacts.

11-29-2015, 11:21 PM
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: http://pastebin.com/1M6VSHLT
/* '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.xyz /= 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)
EDIT: BETTER VIDEO HERE: https://www.youtube.com/watch?v=ZtUMR5xXOK0
More descriptive with annotations, a visible spotlight frustum, and lower shadowmap resolution for clearer results.

Old video: https://www.youtube.com/watch?v=6tzDSY1NSGE

Any help, tips and/or recommendations are highly appreciated!