<p>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.</p>

<p>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.</p>

<p>ref <a href="http://www.dissidentlogic.com/old/images/NormalOffsetShadows/GDC_Poster_NormalOffset.png" rel="nofollow">http://www.dissidentlogic.com/old/images/NormalOffsetShadows/GDC_Poster_NormalOffset.png</a>
ref <a href="http://www.digitalrune.com/Blog/Post/1765/Shadow-Acne" rel="nofollow">http://www.digitalrune.com/Blog/Post/1765/Shadow-Acne</a></p>

CC BY-SA 3.0
2016-01-18T13:40:31.857Z
2016-01-18T13:40:31.857Z
Mikkel Gjoel
<p>I am using Unity but this question might not be proper to this engine.</p>

<p>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.</p>

<p><a href="https://i.sstatic.net/sGOqR.jpg" rel="noreferrer"><img src="https://i.sstatic.net/sGOqR.jpg" alt="enter image description here"></a></p>

<p>Here is the pseudo-shader code.</p>

<pre><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;
</code></pre>

CC BY-SA 3.0
2016-01-15T04:07:54.017Z
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
CC BY-SA 3.0
2016-01-15T07:27:49.133Z
I added the code but as you can see, there's nothing really advanced here. I also precise that I am using Unity.
MaT
CC BY-SA 3.0
2016-01-16T13:53:15.863Z
This should be the same issue as in http://stackoverflow.com/questions/1513383/texturing-error-on-a-sphere
NeinDochOah
<opengl><algorithm><shader><glsl><shadow-mapping>
Shadow map projection issue
MaT
# Shadow map projection issue

(Asked by: username_0 on 2016-01-14)

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](https://i.sstatic.net/sGOqR.jpg)](https://i.sstatic.net/sGOqR.jpg)

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;

```

**Tags:** opengl, algorithm, shader, glsl, shadow-mapping

> **Comments:**
> **username_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.  
> **username_0**: I added the code but as you can see, there's nothing really advanced here. I also precise that I am using Unity.  
> **username_2**: This should be the same issue as in http://stackoverflow.com/questions/1513383/texturing-error-on-a-sphere  

---

## 1 answers

### Answer by username_3 on 2016-01-18. Score: 2 | Accepted answer

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>


---

