标准的输出结构:
struct SurfaceOutput { fixed3 Albedo; // diffuse color fixed3 Normal; // tangent space normal, if written fixed3 Emission; half Specular; // specular power in 0..1 range fixed Gloss; // specular intensity fixed Alpha; // alpha for transparencies };
基于物理的光照模型的内置标准输出:
struct SurfaceOutputStandard { fixed3 Albedo; // base (diffuse or specular) color fixed3 Normal; // tangent space normal, if written half3 Emission; half Metallic; // 0=non-metal, 1=metal half Smoothness; // 0=rough, 1=smooth half Occlusion; // occlusion (default 1) fixed Alpha; // alpha for transparencies };
内置的标准高光输出模型:
struct SurfaceOutputStandardSpecular { fixed3 Albedo; // diffuse color fixed3 Specular; // specular color fixed3 Normal; // tangent space normal, if written half3 Emission; half Smoothness; // 0=rough, 1=smooth half Occlusion; // occlusion (default 1) fixed Alpha; // alpha for transparencies };
Surface Shader编译指令:
语法:
SubShader { CGPROGRAM #pragma surface 方法名 光照模型 [可选参数] ENDCG }
必要参数
- 方法名
- 光照模型:内置的有基于物理的标准光照模型和标准高光模型,或者是没有物理的Lambert光照模型或者是BlinnPhong(高光)模型.
Standard
光照模型对应SurfaceOutputStandard
输出结构, 对应Unity中的 Standard (metallic workflow) shaderStandardSpecular
光照模型使用SurfaceOutputStandardSpecular输出结构,对应Standard (specular setup) shader
Lambert
andBlinnPhong
光照模型不是基于物理的,但是可以兼容老旧硬件并且渲染很快.
可选参数
Transparency and alpha testing 是通过alpha
和 alphatest
指令控制的.透明度有两种类型:传统的alpha混合以及更真实的"左乘混合".
- alpha | alpha:auto
- alpha:blend
- alpha:fade
- alpha:premul
- alphatest:VariableName
- keepalpha
- decal:add
- decal:blend
Custom modifier functions[自定义可变函数]
- vertex:VertexFunction
- finalcolor;ColorFunction
- finalgbuffer:ColorFunction
- finalprepass:ColorFunction
Shadows and Tessellation[曲面细分]
- addshadow
- fullforwardshadow
- tessellate:TessFunction
Code generation options
- exclude_path
- noshadow
- noambient
- novertexlights
- nolightmap
- noynlightmap
- nodirlightmap
- nofog
- nometa
- noforwardadd
- nolppv
- noshadowmask
Miscellaneous 选项
- softvegetation
- interpolateview
- halfasview
- approxview
- dualforward
- dithercrossfade
输入结构
输入结构中的texture必须以 uv 开头 。
- float3 viewDir
- float4 COLOR
- float4 screenPos
- float3 worldPos
- float3 worldRef1
- float3 worldNormal
- float3 worldRef1:INTERNAL_DATA
- float3 worlNormal:INTERNAL_DATA