Rendering 15——Deferred Lights

https://catlikecoding.com/unity/tutorials/rendering/part-15/

2.7 fading shadows
the shadow map is finite. it can not cover the entire world.
the larger an area it covers, the lower the resolution of the shadows.
uniy has a maximum distance up to which shadows are drawn. beyond that, there are no real-time shadows.
this distance can be adjust via Edit/Project Settings/Quality.

在这里插入图片描述
when shadows approach this distance, the fade out.
To fade the shadows, we must first know the distance at which they should be completely gone. This distance depends on how the directional shadows are projected. In Stable Fit mode the fading is spherical, centered on the middle of the map. In Close Fit mode it’s based on the view depth.

The UnityComputeShadowFadeDistance function can figure out the correct metric for us. It has the world position and view depth as parameters. It will either return the distance from the shadow center, or the unmodified view depth.

the shadows should begin to fade as they approach the fade distance, completely disappearing once they reach it.
the UnityComputeShadowFade function calculates the appropriate fade factor.

float shadowFadeDistance =
			UnityComputeShadowFadeDistance(worldPos, viewZ);
		float shadowFade = UnityComputeShadowFade(shadowFadeDistance);

What do these functions look like?
They are defined in UnityShadowLibrary. The unity_ShadowFadeCenterAndType variable contains the shadow center and the shadow type. The _LightShadowData variable’s Z and W components contain the scale and offset used for fading.

float UnityComputeShadowFadeDistance (float3 wpos, float z) {
    float sphereDist = distance(wpos, unity_ShadowFadeCenterAndType.xyz);
    return lerp(z, sphereDist, unity_ShadowFadeCenterAndType.w);
}

half UnityComputeShadowFade(float fadeDist) {
    return saturate(fadeDist * _LightShadowData.z + _LightShadowData.w);
}

the shadow factor is a value from 0 to 1, which indicates how much the shadows should fade away.
the actual fading can be done by simpling adding this value to the shadow attenuation, and clamping to 0~1.

float shadowFade = UnityComputeShadowFade(shadowFadeDistance);
shadowAttenuation = saturate(shadowAttenuation + shadowFade);
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值