• Advertisement
Sign in to follow this  

resolved: trying to fix translucency / light distance problem

This topic is 2092 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:
http://http.develope...ugems_ch16.html
http://takinginitiat...shadow-mapping/

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

translucentShadowMaps.png

I calculate the object thickness, s, using
[source lang="cpp"]
//shadowMapPS
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;

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

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

[/source]


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
Advertisement
In case anyone else runs into this problem, I think I've figured it out. I was using point lighting for illumination:

translucentShadowMaps-1.png
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):
translucentShadowMapWithDirectionalLight.png

Share this post


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

  • Advertisement