Shadowing bug
A while back I implemented omnidirectional shadow maps, and thought that they worked.
They didn't! But they looked like they were working but in reality, there were some odd bugs resultant from my managing of near/far depth precision. And then I had to spend a month working double time for my job and sort of lost track of things.
Anyway, I think I have it worked out now, and shadowing seems quite robust, but for a small likely offset-related bug. Here are three screenshots in sequence. You'll see a cylinder in the foreground. Its shadow on the floor has a sort of half-moon area missing where the cylinder touches the floor. As the cylinder is raised, the half-moon fills in.
1:
![[Image: ShaderUnification-2010-01-31-00.png]](http://shamyl.zakariya.net/screenshots/ShaderUnification-2010-01-31-00.png)
2:
![[Image: ShaderUnification-2010-01-31-01.png]](http://shamyl.zakariya.net/screenshots/ShaderUnification-2010-01-31-01.png)
3:
![[Image: ShaderUnification-2010-01-31-02.png]](http://shamyl.zakariya.net/screenshots/ShaderUnification-2010-01-31-02.png)
I tried adding a bias to the depth sampling, but it didn't help, it just caused horrific self-shadowing acne.
Here's some example GLSL code. I'm showing only the single-tap version for clarity.
If I set BIAS to a small value > 0, the half-moon goes away, but the acne shows up.
Any thoughts? Should I just live with it?
They didn't! But they looked like they were working but in reality, there were some odd bugs resultant from my managing of near/far depth precision. And then I had to spend a month working double time for my job and sort of lost track of things.Anyway, I think I have it worked out now, and shadowing seems quite robust, but for a small likely offset-related bug. Here are three screenshots in sequence. You'll see a cylinder in the foreground. Its shadow on the floor has a sort of half-moon area missing where the cylinder touches the floor. As the cylinder is raised, the half-moon fills in.
1:
![[Image: ShaderUnification-2010-01-31-00.png]](http://shamyl.zakariya.net/screenshots/ShaderUnification-2010-01-31-00.png)
2:
![[Image: ShaderUnification-2010-01-31-01.png]](http://shamyl.zakariya.net/screenshots/ShaderUnification-2010-01-31-01.png)
3:
![[Image: ShaderUnification-2010-01-31-02.png]](http://shamyl.zakariya.net/screenshots/ShaderUnification-2010-01-31-02.png)
I tried adding a bias to the depth sampling, but it didn't help, it just caused horrific self-shadowing acne.
Here's some example GLSL code. I'm showing only the single-tap version for clarity.
Code:
#define BIAS 0.0
float positional_shadow_sample( in vec3 dir, in float fragDepth )
{
float shadowDepth = FixedToFloat( textureCube( ShadowMap, dir ));
return fragDepth < shadowDepth ? 1.0 : 0.0;
}
float shadow_coefficient_low( in vec3 ecPos )
{
#ifdef SHADOWED
float dist = length( LightDirWorld );
vec3 lightDir = LightDirWorld / dist;
float depth = ((dist - MinDepth) / DepthRange) + BIAS;
float shadow = positional_shadow_sample( lightDir, depth );
#ifdef SELF_SHADOW_FIX
vec3 ec_normal = normalize(cross(dFdx(ecPos), dFdy(ecPos)));
float lambertian = dot(ec_normal,normalize( gl_LightSource[0].position.xyz - ecPos ));
return step( 0.004, lambertian ) * shadow;
#else
return shadow;
#endif
#else
return 1.0;
#endif
}If I set BIAS to a small value > 0, the half-moon goes away, but the acne shows up.
Any thoughts? Should I just live with it?
I've usually seen this kind of artifact when you render only backfaces into the shadow map. This is because the triangles on the back of the cylinder are very close to the triangles on the ground, and the polygon offset pushes the triangles outside the threshold for shadowing. Assuming this is the case, you essentially have two options: one is to try to find a polygon offset that gives you an optimal balance between the artifacts of having too much or too little biasing, and the other is to render front faces into the shadow buffer. Rendering front faces will show more acne if your polygon offset isn't right, but it should get rid of these light seams. I would recommend going for the rendering front faces rout since no matter how much you tune it, gaps of light in your shadows are very noticeable.
That's pretty much what I was expecting, but I was under the impression that front-faced shadow rendering was almost impossible to tune effectively to prevent acne. Worth a looksy, though.
It's definitely not impossible, but it will probably take a bit longer to get a good set of values. Filtering can also help reduce any acne might pop up occasionally.
I don't quite think its just depth precision. After all, the shadows seem to work much better for the pig et al. It seems to me that you may have a large values set for the in glPolygonOffset()?
If you have a working binary, it might be interesting to see how it performs on other graphics hardware, too.
If you have a working binary, it might be interesting to see how it performs on other graphics hardware, too.
Actually, right now I'm not polygon-offsetting during shadow rendering at all.
EDIT: I've been thinking about this, and it really seems not to be a polygon offset issue. The distance I drag the cylinder up away from the floor to ge tthe shadow to render correctly is way too far for this to be a simple offset matter, even if I'm using back-facing polys. I have to assume I'm incorrectly computing the depth when writing to the depth buffer, or else I'm incorrectly comparing in the lit shadow sampling code.
EDIT: I've been thinking about this, and it really seems not to be a polygon offset issue. The distance I drag the cylinder up away from the floor to ge tthe shadow to render correctly is way too far for this to be a simple offset matter, even if I'm using back-facing polys. I have to assume I'm incorrectly computing the depth when writing to the depth buffer, or else I'm incorrectly comparing in the lit shadow sampling code.
The reason I thought polygon offset was wrong is because of the crescent shaped shadow. It seems that the slope of the polygon to the light rays affects the depth, eg the side walls, nearly tangential to the light, seem to produce a correct shadow, while the back wall, which is more perpendicular, seems to be offset too far back.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| iPhone 3GS Shadowing Bug | Bersaelor | 6 | 9,625 |
Dec 28, 2010 04:08 PM Last Post: jarodl |
|
| Shadow Mapping - Self-Shadowing Z-Fighting Artifacts | Bachus | 16 | 16,939 |
Feb 11, 2009 12:24 PM Last Post: arekkusu |
|
| 2D lighting/shadowing demo | Skorche | 7 | 5,776 |
Nov 22, 2004 09:53 AM Last Post: Skorche |
|
| Static Shadowing with shadow maps | NYGhost | 1 | 3,314 |
Jun 28, 2003 06:21 PM Last Post: Feanor |
|
| self shadowing | honkFactory | 9 | 4,234 |
Jan 9, 2003 10:54 PM Last Post: Mark Levin |
|

