Sign in to follow this  
maogenc

resolved: trying to fix translucency / light distance problem

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:
[url="http://http.developer.nvidia.com/GPUGems/gpugems_ch16.html"]http://http.develope...ugems_ch16.html[/url]
[url="http://takinginitiative.net/2011/05/15/directx10-tutorial-10-shadow-mapping/"]http://takinginitiat...shadow-mapping/[/url]

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

[img]http://i1023.photobucket.com/albums/af358/maogenc/3d%20graphics/translucentShadowMaps.png[/img]

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

[img]http://i1023.photobucket.com/albums/af358/maogenc/3d%20graphics/translucentShadowMaps-1.png[/img]
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):
[img]http://i1023.photobucket.com/albums/af358/maogenc/3d%20graphics/translucentShadowMapWithDirectionalLight.png[/img]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this