• Create Account

Banner advertising on our site currently available from just \$5!

# Deferred Rendering - Shadow Mapping Artifacts

1 reply to this topic

### #1Tobias Pott  Members   -  Reputation: 101

Like
0Likes
Like

Posted Today, 08:41 AM

Hello everyone,

I'm twisting my mind around some artifacts I get when using a Shadow Maps in my deferred rendering pipeline.

First of all an image of my scene rendered in deferred mode with shadow map applied to visualize what I'm going to talk about.

To explain the scene:

I've got a plane and a torus both rendered at 0,0,0 world space.

The light is above and slightly in front of the camera casting down to the origin (0,0,0)

The Shadow mapping itself looks quite okay, as you can see on the ground area (shadow arc below the half torus). What is busting my balls is are the artifacts occurring on the inner side of the torus. In some way they are jagged due to a lower resolution of the shadow map but there are unshaded parts in between dark areas I can't pinpoint the cause for.


void main()
{
if(Light.Enabled)
{
vec2 ScreenTexCoord = CalcTexCoord();
vec4 Pos = texture(PositionMap, fTexCoord);
vec4 WorldPos = texture(PositionWorldMap, fTexCoord); // world space coordinate of the fragment
vec3 Normal = normalize(texture(NormalMap, fTexCoord).xyz);

// calc some basic shading (is reduced to output diffuse intensity only)
vec4 DirLight = CalcDirectionalLight(WorldPos.xyz, Normal);

FragColor = Color * DirLight;
{
// convert from camera view space to the lights screen space
vec4 lsPos = (Light.ShadowMatrix * CameraToWorld) * WorldPos;
lsPos.xyz /= lsPos.w;
float depth = texture(ShadowMap, lsPos.xy).x;

// check against the z value and set the shadow factor either 0 or 1 (shadowed or not)
float k = lsPos.z < depth ? 1.0 : 0.0;

FragColor *= k;
}
}
else
}



This is my light pass fragment code. I have the ShadowMap, Position (Modelspace), Position (Camera view), Normal, Texcoord, Color and Depth Textures from my MRT. The data from my GBuffer looks fine to me thus I don't think it might be a problem with that.

            float k = lsPos.z < depth ? 1.0 : 0.0;

I'm not sure if I'm doing a correct test on the depth. My previous Shadow mapping approach was working on Forward rendering and was coming along without such a check (I picked the code from a thread on the net).

My problem is I don't understand exactly why this check is done against the z value and I'm wondering if I should do a check against some value from my GBuffer DepthMap, and if so which values I should check against.

My Brain is now just over flood and I lost a bit of my orientation hoping someone around here can give me a little push in a direction to get this thing fixed.

Kind Regards

Tobias

### #2Hodgman  Moderators   -  Reputation: 40238

Like
1Likes
Like

Posted Today, 08:55 AM

Ignoring the shadowing for a moment -- it doesn't look like your directional light is working.

The areas containing the artifacts are facing away from the light, so they should be black... and if they were black, you wouldn't even notice this shadow artifact... so it's not a problem

As for the shadow artifact, it looks like regular shadow acne, caused by lack of precision. You can fight it with depth bias rasterizer state when rendering the shadowmap, using a normal offset when sampling the shadow map, or using a statistical technique such as VSM.

PARTNERS