變量除了在 代碼段中申明外 還 必須在Properties中 聲明後才能正確使用(和能在inspector視圖顯示)code
Properties中格式爲:變量名字(inspector中顯示的名字,類型)=默認值ci
其中類型有(類型=舉例---------------對應CG語言中類型)it
Range(min,max)=0---------------float ,half , fixedio
Float=0.0 ------------------------------float,half,fixed變量
Int=1--------------------------------------int數據類型
Color=(1,1,1,1) 或(1,1,1)-----------float4 ,float3,half4 ,fixed4float
vector=(1,1,1,1) 或 (1,1,1)----------float4 ,float3,half4 ,fixed4lamp
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" }