srp——点光源阴影的一些坑总结

在这里插入图片描述
去除Pancaking
在这里插入图片描述
这个在shadowcaster的顶点着色器中注意到:

OutputProperty vert(InputProperty inputProperty)
{
	OutputProperty outputProperty;
	UNITY_SETUP_INSTANCE_ID(inputProperty);
	UNITY_TRANSFER_INSTANCE_ID(inputProperty, outputProperty);
	float3 positionWS = TransformObjectToWorld(inputProperty.positionOS);
	outputProperty.positionCS = TransformWorldToHClip(positionWS);

	#if UNITY_REVERSED_Z
		outputProperty.positionCS.z =
			min(outputProperty.positionCS.z, outputProperty.positionCS.w * UNITY_NEAR_CLIP_VALUE);
	#else
		outputProperty.positionCS.z =
			max(outputProperty.positionCS.z, outputProperty.positionCS.w * UNITY_NEAR_CLIP_VALUE);
	#endif
		outputProperty.baseUV = inputProperty.baseUV * _MainTex_ST.xy + _MainTex_ST.zw;
		return outputProperty;
}

我们将顶点无条件的压到到近平面之前。防止在近平面和灯光直接有物体。
在这里插入图片描述
我们将物体最少移动到近平面之前,否则如果物体在绿色的体中,则会产生阴影,形成pancaking。

这是对平行光来说,需要这样的处理。但是对于点光源和聚光灯来说,不需要,因为这个两种光源都有一个位置属性。那么是允许物体出现在光源之后的。同时,对于这两种光源来说,使用透视投影,而不是正交投影,如果把所有的点都集中到近平面之前,那么则会出现过度的扭曲现象。所以对于点光源和聚光灯来说,要关闭这个处理。
参考这句话:

In the case of spot lights—which do have a position—shadow casters can end up partially behind the light’s position. As we’re using a perspective projection in this case, clamping vertices to the near plane would severely distort such shadows. So we should turn off clamping when pancaking isn’t appropriate.

又是脏的感觉 ,下面加点bias。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值