Shaderlab属性类型和CG变量类型的匹配关系
ShaderLab属性类型对应的CG属性类型
- Color,Vector - float4,half4,fixed4
- Range,Float - float,half,fixed
- 2D - sampler2D
- Cube - samplerCube
- 3D - * sampler3D*
Shader "Custom/UsePropertiesShader"{
Properties{
//声明一个Color 类型的属性
_Color("Color Tint",Color)=(1.0,1.0,1.0,1.0)
}
SubShader{
Pass{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
//在CG代码中,我们需要定义一个与属性名称和类型都匹配的变量
fixed4 _Color;
struct a2v{
float4 vertex:POSITION;
float3 normal:NORMAL;
float4 texcoord:TEXCOORD0;
};
struct v2f{
float4 pos:SV_POSITION;
float3 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
}
}
Fallback "VertexLit"
}
网友评论