7

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;
MaT
  • 1,229
  • 10
  • 21
  • 1
    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. – czapata91 Jan 15 '16 at 04:07
  • I added the code but as you can see, there's nothing really advanced here. I also precise that I am using Unity. – MaT Jan 15 '16 at 07:27
  • This should be the same issue as in http://stackoverflow.com/questions/1513383/texturing-error-on-a-sphere – NeinDochOah Jan 16 '16 at 13:53

1 Answers1

2

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

Mikkel Gjoel
  • 471
  • 2
  • 4