5.2.4 如何使用属性
Shader "Custom/Chap5.2.4/Simpler Shader"
{
Properties {
_Color ("Color Tint", Color) = (1.0,1.0,1.0,1.0)
}
SubShader {
pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
fixed4 _Color;
struct a2v {
float4 vertex: POSITION;
float3 normal: NORMAL;
float4 texcoord: TEXCOORD0;
};
struct v2f {
float4 pos: SV_POSITION;
fixed3 color: COLOR0;
};
v2f vert(a2v v) {
v2f o;
o.pos = UnityObjectToClipPos(v.vertex);
o.color = v.normal * 0.5 + fixed3(0.5, 0.5, 0.5);
return o;
}
fixed4 frag(v2f i): SV_Target {
fixed3 c = i.color;
c *= _Color.rgb;
return fixed4(c, 1.0);
}
ENDCG
}
}
}
- 属性的使用注意两点。
- 属性定义在 Properties 内
- 定义的属性如果要使用的话需要在 pass 中定义对应的变量来接收供 frag 和 vert 使用。