定制函数 函数的传参 函数的前向声明
1.函数必须要在用之前声明
void Func( ) { } void frag (inout float4 col:COLOR) { Func( ); }
2.如果想把函数放在后面 需要提前声明
void Func (); void frag (inout float4 col:COLOR) { Func( ); } void Func( ) { }
3.函数运用 :out关键语不能缺,如果无out 只能是值拷贝,无法输出
void Func (out float4 c); void frag (inout float4 col:COLOR) { Func(col); } void Func( out float4 c) { c = float4(0,1,0,1); }
4.数组函数申明运用
//函数传递数组 float Func2(float arr[2]) //带返回值 数组里面的数字是不能省略的 必须明确数组长度 也是值拷贝 { float sum = 0; for (int i = 0;i<arr.Length; i++) { sum += arr[i]; } return sum; //带返回值 } void frag (inout float4 col:COLOR) { //Func(col); float arr[] ={0.5,0.5}; col.x = Func2(arr); }
5.Cg include
新建一个shader ,将后缀改成cginc