# What is this artifact in my shadow map?

This topic is 792 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm implementing a simple shadow map hlsl shader. Everything was just fine but something odd is happening to my shadow map.

Here is the screenshot -

I don't know what is this artifact called. Maybe Shadow Acne. I'm not so sure. I'm already using normal offset bias in my vertex shader.

Here is my current pixel shader implemention of shadow map. I'm using the tex2Dproj function to get a free hardware PCF filter -

float4 pixelMain
(
float4 SMPos : TEXCOORD0,
float2 texCoords : TEXCOORD2,
float3 vWorldNormal : TEXCOORD3

) : COLOR0
{
float4 mapColor = tex2D(gColorMap, texCoords);

float shadow = tex2Dproj(gDepthMap, SMPos);

float cDiffuse = dot(vWorldNormal, normalize(gLightDir));

float4 totalDiffuse = (cDiffuse * gLightDiffuse) * shadow;

// Compose the final color:
float4 finalCol = (gLightAmbient + totalDiffuse) * mapColor;

return finalCol;
}


The gDepthMap is a depth surface and contains only depth information.

If I remove the ambient term from the final color calculation -

// Compose the final color:
float4 finalCol = totalDiffuse * mapColor;
return finalCol;


The result looks like following -

Acceptable but the shadow is too dark. Is there any way to lighten the shadow?

So I have no idea what to do now and what the big mistake I did in my pixel shader. Is my final color calculation wrong?

##### Share on other sites

" I'm using the tex2Dproj function to get a free hardware PCF filter"

I don't think that is exactly how it works. Besides, anything you do in a shader program is on the hardware, and it sure isn't free.

I am not that great or learned when it comes to graphics programming and HLSL, but I implement a manual PCF blur to smooth my shadow map. I don't access to my implementation at the moment otherwise I would post it.

Edited by ExErvus

##### Share on other sites

Have you tried clamping (saturate) the dot product?

##### Share on other sites

" I'm using the tex2Dproj function to get a free hardware PCF filter"

I don't think that is exactly how it works. Besides, anything you do in a shader program is on the hardware, and it sure isn't free.

It does work like that (it's a D3D9 extension that every card supports nowadays), and the term is correct as the filtering is performed by the hardware and not by calculations in the shader (software).

##### Share on other sites

Have you tried clamping (saturate) the dot product?

Well, This is a good solution. But... actually the back side of the teapot looks very flat.

Thanks.

Edited by MD Forhad Reja

##### Share on other sites

Two thoughts come to mind.

Have you tried playing around with the bias? Tweaking it until the issue is not visible on the geometry?

Also, are you using a nullified Sampler State, or did you specify a clamped sampler?

Marcus Hansen

##### Share on other sites

Two thoughts come to mind.

Have you tried playing around with the bias? Tweaking it until the issue is not visible on the geometry?

Also, are you using a nullified Sampler State, or did you specify a clamped sampler?

Marcus Hansen

OK, I will change the bias value and see what happen. And yes, I'm using D3DTADDRESS_CLAMP for D3DSAMP_ADDRESSU and D3DSAMP_ADDRESSV.

Never mind, what is nullified Sampler State?

##### Share on other sites

Have you tried clamping (saturate) the dot product?

Well, This is a good solution. But... actually the back side of the teapot looks very flat.

Thanks.

Yes, but remember that you are using a "flat" color as your ambient term.

You could use "half Lambert" for the diffuse term (instead of clamping, multiply by 0.5 and add 0.5), this will remap the [-1,1] range to [0, 1] giving you that backside gradient you are looking for.

Anyway... Its not really related to your shadow issue.

##### Share on other sites

The ground looks fine, is it being rendered differently?

##### Share on other sites

Have you tried clamping (saturate) the dot product?

Well, This is a good solution. But... actually the back side of the teapot looks very flat.

Thanks.

Yes, but remember that you are using a "flat" color as your ambient term.

You could use "half Lambert" for the diffuse term (instead of clamping, multiply by 0.5 and add 0.5), this will remap the [-1,1] range to [0, 1] giving you that backside gradient you are looking for.

Anyway... Its not really related to your shadow issue.

Thanks. I really like the idea of "half Lambert".  Let me check it out...

1. 1
2. 2
Rutin
25
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• ### Forum Statistics

• Total Topics
631764
• Total Posts
3002210
×