surface shader是一种对vertex and fragment shader的一种包装,不能加pass通道,加pass会编译报错
#pragma surface surf standard fullforwardshadows
pragma :表示是一条编译指令
surface :表示这个Shader是一个表面着色器
surf :函数名,在之后的代码块中,必能找到同名的函数,是最核心的算法
standard :LightModel --> 光照模型,standard是标准光照模型
最后的是[optionalparams],表示可能会有其他的选项
前四个模块必须要有
光照函数 :
当我们自己在编写光照函数的时候,函数名必须要加上lighting,但是使用光照函数的时候,只使用lighting后面的有效部分即可。
例 :我们编写光照函数,起名为lightingStandard,当调用这个函数的时候,使用Standard即可。
#pragma target 3.0
这句指令代表使用shader model 3.0,不加这条指令,默认使用shader model 2.0;使用shader model 3.0会得到一个更好的光照效果
在CG PROGRAM中,必须对应properties中的所有的属性再重新声明一次
Properties CG
Color fixed4(四阶向量)
float(Range) half
2D sampler2D
struct Input {
float2 uv_MainTex; } // 输入结构体,用于藐视纹理坐标的结构体,必须要以uv开头
透明化 :
在pragma编译指令处,加上alpha,再在标签中加一个渲染队列 { "Queue" = "Transparent" },即可实现透明化
阴影效果 :
假如在编译指令中,没有得到一个阴影通道,在 FallBack "Diffuse"会默认产生一个阴影通道。如果想要产生一个阴影通道,可以在编译指令中加上"addshadow"