1.没有Pass:因为Render Path已经封装好了
Shader "Custom/Test"
{Properties{_Color ("Color", Color) = (1,1,1,1)_MainTex ("Albedo (RGB)", 2D) = "white" {}_Glossiness ("Smoothness", Range(0,1)) = 0.5_Metallic ("Metallic", Range(0,1)) = 0.0}SubShader{Tags { "RenderType"="Opaque" }LOD 200CGPROGRAM// Physically based Standard lighting model, and enable shadows on all light types定义入口函数 surf 因为RenderPath一般渲染两次,所以这里包括顶点着色器的入口函数,片段着色器的入口函数,灯光的入口函数,finalColor#pragma surface surf Standard fullforwardshadows// Use shader model 3.0 target, to get nicer looking lighting#pragma target 3.0sampler2D _MainTex;struct Input{float2 uv_MainTex;};half _Glossiness;half _Metallic;fixed4 _Color;// Add instancing support for this shader. You need to check 'Enable Instancing' on materials that use the shader.// See https://docs.unity3d.com/Manual/GPUInstancing.html for more information about instancing.// #pragma instancing_options assumeuniformscalingUNITY_INSTANCING_BUFFER_START(Props)// put more per-instance properties hereUNITY_INSTANCING_BUFFER_END(Props)void surf (Input IN, inout SurfaceOutputStandard o){// Albedo comes from a texture tinted by colorfixed4 c = tex2D (_MainTex, IN.uv_MainTex) * _Color;o.Albedo = c.rgb;// Metallic and smoothness come from slider variableso.Metallic = _Metallic;o.Smoothness = _Glossiness;o.Alpha = c.a;}ENDCG}FallBack "Diffuse"
}
2.封装好的光照模型:
struct SurfaceOutputStandard{fixed3 Albedo; // base (diffuse or specular) colorfixed3 Normal; // tangent space normal, if writtenhalf3 Emission;half Metallic; // 0=non-metal, 1=metalhalf Smoothness; // 0=rough, 1=smoothhalf Occlusion; // occlusion (default 1)fixed Alpha; // alpha for transparencies};//有高光的Specularstruct SurfaceOutputStandardSpecular{fixed3 Albedo; // diffuse colorfixed3 Specular; // specular colorfixed3 Normal; // tangent space normal, if writtenhalf3 Emission;half Smoothness; // 0=rough, 1=smoothhalf Occlusion; // occlusion (default 1)fixed Alpha; // alpha for transparencies};
3.Unity 5.0以前:自定义灯光效果
#pragma surface surf Lambert vertex:MyVertex finalcolor:MyColor
4.Unity5.0 以后:
#pragma surface surfaceFunction lightModel [optionalparams]
surfaceFunction : 顶点 surf 灯光 finalColor