addShadow
This commit is contained in:
1 parent
c2a9014239
commit
b9129b0d47
8 files changed
+332
-19
No files matched your search
+59
-1
@@ -183,6 +183,64 @@ Shader "BSDF/StandardURPDouble"
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
|
||||
Pass{
|
||||
Name "ShadowCaster"
|
||||
Tags {
|
||||
"LightMode" = "ShadowCaster"//阴影投射
|
||||
}
|
||||
ZWrite On
|
||||
ZTest LEqual
|
||||
ColorMask 0
|
||||
Cull Off
|
||||
HLSLPROGRAM //着色器
|
||||
#pragma multi_compile instancing
|
||||
#pragma multi_compile DOTS INSTANCING ON
|
||||
#pragma multi_compile CASTING PUNCTUAL LIGHT SHADOW
|
||||
|
||||
#pragma vertex ShadowVS
|
||||
#pragma fragment ShadowFS
|
||||
|
||||
float3 _LightDirection;
|
||||
float3 _LightPosition;
|
||||
|
||||
struct Attributes
|
||||
{
|
||||
float4 positionOS : POSITION;
|
||||
float3 normalOS : NORMAL;
|
||||
};
|
||||
|
||||
struct Varyings
|
||||
{
|
||||
float4 positionCS : SV_POSITION;
|
||||
};
|
||||
//将阴影的世界空间顶点位置转换为适合阴影投射的裁剪空间位置
|
||||
float4 GetShadowPositionHClip(Attributes input){
|
||||
float3 positionWS = TransformObjectToWorld(input.positionOS.xyz);
|
||||
float3 normalWS = TransformObjectToWorldDir(input.normalOS);
|
||||
#if _CASTING_PUNCTUAL_LIGHT_SHADOW
|
||||
float3 lightDirectionWS = normalize(_LightPosition - positionWS);
|
||||
#else
|
||||
float3 lightDirectionWS = _LightDirection;
|
||||
#endif
|
||||
|
||||
float4 positionCS = TransformWorldToHClip(ApplyShadowBias(positionWS, normalWS, lightDirectionWS));
|
||||
|
||||
#if UNITY_REVERSED_Z
|
||||
positionCS.z = min(positionCS.z, UNITY_NEAR_CLIP_VALUE);
|
||||
#else
|
||||
positionCS.z = max(positionCS.z, UNITY_NEAR_CLIP_VALUE);
|
||||
#endif
|
||||
return positionCS;
|
||||
}
|
||||
Varyings ShadowVS(Attributes input){
|
||||
Varyings output;
|
||||
output.positionCS = GetShadowPositionHClip(input);
|
||||
return output;
|
||||
}
|
||||
half4 ShadowFS(Varyings input):SV_TARGET{
|
||||
return 0;
|
||||
}
|
||||
ENDHLSL
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user