What is this artifact in my shadow map?

Started by
21 comments, last by MD Forhad Reja 7 years, 11 months ago

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 -

[attachment=31895:shadow_map_art.png]

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 -

[attachment=31896:shadow_map_art_2.png]

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?

Please help!

Advertisement

" 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.

Have you tried clamping (saturate) the dot product?

" 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).

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.

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

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?

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.

The ground looks fine, is it being rendered differently?

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

This topic is closed to new replies.

Advertisement