第一个被执行的Pass
5.2 3个渲染路径之外
5.2.1 LightMode的其他值Shader "Tut/Lighting/FirstLight/Lab_1/Always" { SubShader { pass{ Tags{ "LightMode"="Always"} Blend One One CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "Lighting.cginc" struct vertOut{ float4 pos:SV_POSITION; float4 color:COLOR; }; vertOut vert(appdata_base v) { vertOut o; o.pos=mul(UNITY_MATRIX_MVP,v.vertex); o.color=float4(0,1,0,1); return o; } float4 frag(vertOut i):COLOR { return i.color; } ENDCG }//end pass } }然后是Deferred_Always.1.shader,有一个针对Deferred渲染路径的Surface Shader,其次是一个Always Pass,其混合模式为Blend One Zero,也就是说,如果Always在Surface Shader之后执行,就会只显示自己输出的绿色,反之会输出一个混合之后的黄色。其代码如下:
Shader "Tut/Lighting/FirstLight/Lab_2/Deferred_Always.1" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } Blend One One CGPROGRAM #pragma surface surf MyDeferred half4 LightingMyDeferred_PrePass (SurfaceOutput s, half4 light) { half4 c; c.rgb = s.Albedo; c.a = s.Alpha; return c; } struct Input { float2 uv_MainTex; }; sampler2D _MainTex; void surf (Input IN, inout SurfaceOutput o) { o.Albedo=float3(1,0,0); } ENDCG pass{ Tags{ "LightMode"="Always"} Blend One Zero CGPROGRAM #pragma vertex vert #pragma fragment frag #include "UnityCG.cginc" #include "Lighting.cginc" struct vertOut{ float4 pos:SV_POSITION; float4 color:COLOR; }; vertOut vert(appdata_base v) { vertOut o; o.pos=mul(UNITY_MATRIX_MVP,v.vertex); o.color=float4(0,1,0,1); return o; } float4 frag(vertOut i):COLOR { return i.color; } ENDCG }//end pass } }还有Deferred_Always.2.shader,它和Deferred_Always.l.shader的不同之处在于Always的Pass在代码中被放置到了针对Deferred而写的Surface Shader之前。