实验目的:在Deferred渲染路径下ForwardBass是否会被执行?
Shader "Custom/noDeferredSurf_1" { Properties { _MainTex ("Base (RGB)", 2D) = "white" {} } SubShader { Tags { "RenderType"="Opaque" } LOD 200 //.1 Pass { Tags {"LightMode"="ForwardBase"} 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 } //.2 Blend One One CGPROGRAM //exclude_path:prepass参数告诉Unity不要为Deferred渲染路径产生Shader #pragma surface surf Lambert exclude_path:prepass #pragma debug sampler2D _MainTex; struct Input { float2 uv_MainTex; }; void surf (Input IN, inout SurfaceOutput o) { half4 c = tex2D (_MainTex, IN.uv_MainTex); o.Albedo = c.rgb; o.Alpha = c.a; } ENDCG } FallBack Off }
效果
结论:
在Deferred渲染路径下,没有适合于Deferred模式的Pass,Unity会执行适合于Forward模式的Pass