we will see how to define a legacy deferred lighting model.
first step paste the shader code:
Shader "Course/Deferred" {
Properties {
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
Blend One One
CGPROGRAM
#pragma surface surf XXXDeferred
half4 LightingXXXDeferred_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=tex2D(_MainTex,IN.uv_MainTex).rgb;
}
ENDCG
}
}
in unity, we have to create a cube, a camera whose render path is set to legacy deferred.
like this:
then you will see the object is rendered if the rendering path of the camera is equal to Legacy Deferred(light prepass). attention please, if you set the rendering path to Deferred. the object will not be rendered.
from the above shader code, the legacy deferred lighting should be observe the the following rule:
LightingXXXDeferred_PrePass
this format should be limit your lighting function.
last, if you set the camera’s rendering path to other mode, like forward or vertex lit the object which used the legacy deferred shader will not be rendered.
this is first shader i have learnt.