Shader-数据类型
变量除了在 代码段中申明外 还 必须在Properties中 声明后才能正确使用(和能在inspector视图显示)
Properties中格式为:变量名字(inspector中显示的名字,类型)=默认值
其中类型有(类型=举例—————对应CG语言中类型)
Range(min,max)=0—————float ,half , fixed
Float=0.0 ——————————float,half,fixed
Int=1————————————–int
Color=(1,1,1,1) 或(1,1,1)———–float4 ,float3,half4 ,fixed4
vector=(1,1,1,1) 或 (1,1,1)———-float4 ,float3,half4 ,fixed4
2D=”white”{} ————————sampler2D
3D=”white”{} ————————sampler3D
Cube==”white”{} ————————samplerCUBE
数据类型说明:
float是32位浮点数
half是16位浮点数
fixed是12位定点数
float
s23e8 (“fp32”) IEEE single precision floating point
half
s10e5 (“fp16”) floating point w/ IEEE semantics
fixed
S1.10 fixed point, clamping to [-2, 2)
double
s52e11 (“fp64”) IEEE double precision floating point
常量后缀:
- d for
double - f for
float - h for
half - i for
int - l for
long - s for
short - t for
char - u for
unsigned, which may also be followed by s, t, i, or l - x for
fixed
Shader "Custom/NewShader" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
_color("color",Color)=(1,1,1)
}
SubShader {
Tags { "RenderType"="Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
float3 _color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
half4 c = tex2D (_MainTex, IN.uv_MainTex);
c.rgb=_color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}