Jump to content
  • Advertisement
Sign in to follow this  

resolved: trying to fix translucency / light distance problem

This topic is 2183 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 attempting to implement subsurface scattering with translucent shadow maps as described in GPU gems 1, using the shadow map code from the TakingInitiative blog:

Problem: objects become more transparent farther from the light source, but the transparency effect itself is correct for an individual object


I calculate the object thickness, s, using
[source lang="cpp"]
float shadowMapDepth = shadowMap.Sample(bilinearSampler, input.lpos.xy);
float s = input.lpos.z - shadowMapDepth;[/source]
I calculate the exponential decay using
[source lang="cpp"]exp(-s*900)*float4(1,.5,.5,0);[/source]
other lines of code relevant to the shadow map
[source lang="cpp"]//init
depthStencilDesc.DepthFunc = D3D10_COMPARISON_LESS;

pD3DDevice->ClearDepthStencilView( pShadowMapDepthView, D3D10_CLEAR_DEPTH, 1.0f, 0 );

output.pos = mul( input.pos, mul( world, lightViewProj ) );


input.lpos is the coordinate the camera sees (in light space) and the shadow map measures the distance from the light source to the surface of the object.

I get the object thickness just by subtracting these two values and plugging it into the decay function.

I thought I could fix this by reversing the depth test and initially clearing the shadow map to black but it didn't work. Edited by maogenc

Share this post

Link to post
Share on other sites
In case anyone else runs into this problem, I think I've figured it out. I was using point lighting for illumination:

Since the light rays extend out from a point, the length the light travels through the object is slightly greater than it would be if the light were directional. This difference is exaggerated by the exponential function and the result is that objects near the light source are rendered as if they were much thicker objects.

The difference can be seen in this image with directional lighting (artifacts occur near the edges due to distance inaccuracy in the shadow map):

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!