有两种,第一种是CG,第二种是HLSL
第一种:
Pass{
Tags{"LightMode"= "ShadowCaster"}//***************
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile_shadowcaster//***************
#include "UnityCG.cginc"
sampler2D _SpecTex;
float4 _SpecTex_ST;
struct MeshData {
float4 vertex : POSITION;
float3 normal :NORMAL;
float2 uv : TEXCOORD0;
};
struct Interpolars {
float4 uvSpec : TEXCOORD0;
V2F_SHADOW_CASTER;//***************
};
Interpolars vert(MeshData v){
Interpolars o;
TRANSFER_SHADOW_CASTER_NORMALOFFSET(o);//***************
return o;
}
float4 frag(Interpolars i): SV_Target{
SHADOW_CASTER_FRAGMENT(i)//***************
}
ENDCG
}
第二种:
pass {
Tags{ "LightMode" = "ShadowCaster" }//************
HLSLPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "Packages/com.unity.render-pipelines.universal/ShaderLibrary/Core.hlsl"//*******
struct appdata
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : SV_POSITION;//************
};
sampler2D _MainTex;
float4 _MainTex_ST;
v2f vert(appdata v)
{
v2f o;
o.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return o;
}
float4 frag(v2f i) : SV_Target
{
float4 color;
color.xyz = float3(0.0, 0.0, 0.0);
return color;
}
ENDHLSL
}