#pragma surface surfaceFunction lightMode [optionalparams]
:#pragma surface 用于指明该编译指令是用于定义表面着色器的,后面需要指明表面函数(surfaceFunction)和光照模型( lightMode),以及一些可选的参数
surfaceFunction 用于定义对象的表面属性(反射率、光滑度、透明度等),通常是名为 surf 的函数(名字可以任意),格式是固定的
void surf(Input IN, inout SurfaceOutput o) void surf(Input IN, inout SurfaceOutputStandard o) void surf(Input IN, inout SurfaceOutputStandardSpecular o)
使用表面函数中设置的各种表面属性,来应用某些光照模型。Unity内置了基于物理的光照模型函数 Standard 和 StandardSpecular( UnityPBSLighting.cginc),以及简单的非基于物理的光照模型函数 Lambert 和 Blinn-Phong(Lighting.cginc)
half4 Lighting (SurfaceOutput s, half3 lightDir, half atten); half4 Lighting (SurfaceOutput s, half3 lightDir, half3 viewDir, half atten);
还支持自定义变量,采样坐标必须以uv为前缀,比如 uv_MainTex
SurfaceOutput、SurfaceOutputStandard、SurfaceOutputStandardSpecular 会作为表面函数的输出,光照函数的输入来进行光照计算
struct SurfaceOutput{ fixed3 Albedo; fixed3 Normal; fixed3 Emission; half Specular; fixed Gloss; fixed Alpha; };
struct SurfaceOutputStandard{ fixed3 Albedo; fixed3 Normal; //tangent space normal half3 Emission; half Metallic; //0=non-metal,1=metal half Smoothness; //0=rough,1=smooth half Occlusion; fixed Alpha; }; struct SurfaceOutputStandardSpecular{ fixed3 Albedo; fixed3 Specular; fixed3 Normal; //tangent space normal half3 Emission; half Smoothness; //0=rough,1=smooth half Occlusion; fixed Alpha; };
Unity背后会为表面着色器生成真正的一个包含多个Pass(针对不同渲染路径的)的顶点/片元着色器。会为前向渲染路径生成LightMode为ForwardBase和ForwardAdd的Pass;为延迟渲染路径生成LightMode为Deferred的Pass;为了给光照映射和动态全局光照提取表面信息,Unity会生成LightMode为Meta的Pass
上一篇:oppoa59s系统什么时候更新
下一篇:韩版S8更新系统了