I am using Unity but this question might not be proper to this engine.

I have projected the shadow map onto this sphere but there are grazing shadows. Is it possible to avoid it or to correct it as I am using the raw depth data of the texture.

enter image description here

Here is the pseudo-shader code.

uniform sampler2D _ShadowMap;
float4 shadowCoord : TEXCOORD1;

// vertex shader
o.shadowCoord = mul(unity_World2Shadow[0], mul(_Object2World, v.vertex));

// fragment shader
color.rgb = tex2D(_ShadowMap, i.shadowCoord);
return color;
  • 1
    $\begingroup$ Hello, it could be a particular issue so, can you edit your post and add your GPU code (vertex/fragment shaders) as well as your specific CPU's code on which you are dispatching your shadow map to GPU? this is in order to do a fast debug. $\endgroup$
    – czapata91
    Jan 15, 2016 at 4:07
  • $\begingroup$ I added the code but as you can see, there's nothing really advanced here. I also precise that I am using Unity. $\endgroup$
    – MaT
    Jan 15, 2016 at 7:27
  • $\begingroup$ This should be the same issue as in stackoverflow.com/questions/1513383/texturing-error-on-a-sphere $\endgroup$ Jan 16, 2016 at 13:53

1 Answer 1


One of the downsides to shadowmapping is that you need to offset, or bias, the point used for shadowmap-lookups. This is done in a variety of ways - typically by a constant (shadowmap-depth) distance or based on the slope of the casting triangle. Both of these tend to be done during the shadowmap-rendering pass.

I think what you need to solve your sphere-problem, is to offset the point you are shading a bit along its surface normal, before doing the shadowmap-lookup. This happens during shading, when sampling the shadowmap, not during shadowmap-rendering. Incidentally it is also part of the Unity standard rendering pipeline, so you can steal it from the shader include-files.

ref http://www.dissidentlogic.com/old/images/NormalOffsetShadows/GDC_Poster_NormalOffset.png ref http://www.digitalrune.com/Blog/Post/1765/Shadow-Acne


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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