v1.0
This commit is contained in:
commit
cebe21db2e
46 files changed
+10008
No files matched your search
+28
@@ -0,0 +1,28 @@
|
||||
#pragma multi_compile_instancing // 启用GPU实例化编译
|
||||
#pragma multi_compile _ DOTS_INSTANCING_ON // 启用DOTS实例化编译
|
||||
#pragma multi_compile_vertex _ _CASTING_PUNCTUAL_LIGHT_SHADOW // 启用点光源阴影
|
||||
|
||||
|
||||
// 将阴影的世界空间顶点位置转换为适合阴影投射的裁剪空间位置
|
||||
float4 GetShadowPositionHClip(Attributes input)
|
||||
{
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz); // 将本地空间顶点坐标转换为世界空间顶点坐标
|
||||
float3 normalWS = TransformObjectToWorldNormal(input.normalOS); // 将本地空间法线转换为世界空间法线
|
||||
|
||||
#if _CASTING_PUNCTUAL_LIGHT_SHADOW // 点光源
|
||||
float3 lightDirectionWS = normalize(_LightPosition - positionWS); // 计算光源方向
|
||||
#else // 平行光
|
||||
float3 lightDirectionWS = _LightDirection; // 使用预定义的光源方向
|
||||
#endif
|
||||
|
||||
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS)); // 应用阴影偏移
|
||||
|
||||
// 根据平台的Z缓冲区方向调整Z值
|
||||
#if UNITY_REVERSED_Z // 反转Z缓冲区
|
||||
positionCS.z = min(positionCS.z, UNITY_NEAR_CLIP_VALUE); // 限制Z值在近裁剪平面以下
|
||||
#else // 正向Z缓冲区
|
||||
positionCS.z = max(positionCS.z, UNITY_NEAR_CLIP_VALUE); // 限制Z值在远裁剪平面以上
|
||||
#endif
|
||||
|
||||
return positionCS; // 返回裁剪空间顶点坐标
|
||||
}
|
||||
Reference in new issue
Block a user