Jump to content
  • Advertisement
Sign in to follow this  
xujiezhige

Soft blurry shadow in ParallaxOcclusionMapping

This topic is 2478 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

Greeting!

I am learning ParallaxOcclusionMapping recently, but i get in trouble now.
I can't comprehend the following codes well which are found in ParallaxOcclusionMapping sample in DX9.
Is there any theory or basis behind the codes, especially the number and weight, such as 0.88, 0.77, 0.66?


if ( g_bDisplayShadows == true )
{
float2 vLightRayTS = vLightTS.xy * g_fHeightMapScale;
// Compute the soft blurry shadows taking into account self-occlusion for
// features of the height field:
float sh0 = tex2Dgrad( tNormalHeightMap, texSampleBase, dx, dy ).a;
float shA = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.88, dx, dy ).a - sh0 - 0.88 ) * 1 * g_fShadowSoftening;
float sh9 = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.77, dx, dy ).a - sh0 - 0.77 ) * 2 * g_fShadowSoftening;
float sh8 = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.66, dx, dy ).a - sh0 - 0.66 ) * 4 * g_fShadowSoftening;
float sh7 = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.55, dx, dy ).a - sh0 - 0.55 ) * 6 * g_fShadowSoftening;
float sh6 = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.44, dx, dy ).a - sh0 - 0.44 ) * 8 * g_fShadowSoftening;
float sh5 = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.33, dx, dy ).a - sh0 - 0.33 ) * 10 * g_fShadowSoftening;
float sh4 = (tex2Dgrad( tNormalHeightMap, texSampleBase + vLightRayTS * 0.22, dx, dy ).a - sh0 - 0.22 ) * 12 * g_fShadowSoftening;
// Compute the actual shadow strength:
fOcclusionShadow = 1 - max( max( max( max( max( max( shA, sh9 ), sh8 ), sh7 ), sh6 ), sh5 ), sh4 );
// The previous computation overbrightens the image, let's adjust for that:
fOcclusionShadow = fOcclusionShadow * 0.6 + 0.4;
}

Share this post


Link to post
Share on other sites
Advertisement
If I understand it correct, the values are creating a height sampling line from the light direction in tangent space.

Share this post


Link to post
Share on other sites
Yes, you are right, Dawoodoz.

But what i want to know is why author use this method to calculate the soft shadow factor? Does he take some theories into the above formula?

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!