Jump to content
  • Advertisement
Sign in to follow this  
MD Forhad Reja

What is this artifact in my shadow map?

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

If you intended to correct an error in the post then please contact us.

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 - 

 

[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!

 

 

Share this post


Link to post
Share on other sites
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.

Edited by ExErvus

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
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...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!