I want to understand how parts of surface shader corresponds to different parts of light pre-pass shader.
Light Pre-Pass (Unity3's Deferred Shading) consists of 3 parts,
1. G-Buffer Pass,
2. Lighting Pre-Pass,
3. Shading Pass.
So things like parallax, which is done per-object to UV should be done in pass #1 (G-Buffer) for correct normal, and pass #3 for correct Specular/Albedo Color. Part #2 (Lit Pre-Pass) is done per light, which means it needs to be located in surface shader so I can apply different lighting model, And Part #3 (Shading) needs to be located in a surface shader so I can apply processes to final color for one-time, per-pixel effect, such as damage blinking, and emmisive glow color.
I know that per-light pre-pass is done with custom lighting models, but So would somebody please help me to locate/modify in this surface shader where per-object G-Buffer pass is accumulated, and where per-pixel shading pass is located in a Unity 3 surface shader?
I am also confused by why the surf() outputs a normal, if it is the last part of rendering pipeline..
Thanks for any help!
Shader "test"
{
Properties
{
_Color("_Color", Color) = (1,0,0,1)
}
SubShader
{
Tags
{
"Queue"="Geometry+0"
"IgnoreProjector"="False"
"RenderType"="Opaque"
}
Cull Back
ZWrite On
ZTest LEqual
CGPROGRAM
#pragma surface surf BlinnPhongEditor vertex:vert
#pragma target 2.0
struct EditorSurfaceOutput {
half3 Albedo;
half3 Normal;
half3 Emission;
half3 Gloss;
half Specular;
half Alpha;
};
inline half4 LightingBlinnPhongEditor (EditorSurfaceOutput s, half3 lightDir, half3 viewDir, half atten)
{
#ifndef USING_DIRECTIONAL_LIGHT
lightDir = normalize(lightDir);
#endif
viewDir = normalize(viewDir);
half3 h = normalize (lightDir + viewDir);
half diff = max (0, dot (s.Normal, lightDir));
float nh = max (0, dot (s.Normal, h));
float3 spec = pow (nh, s.Specular*128.0) * s.Gloss;
half4 c;
c.rgb = (s.Albedo * _LightColor0.rgb * diff + _LightColor0.rgb * spec) * (atten * 2);
c.a = s.Alpha + _LightColor0.a * Luminance(spec) * atten;
return c;
}
inline half4 LightingBlinnPhongEditor_PrePass (EditorSurfaceOutput s, half4 light)
{
half3 spec = light.a * s.Gloss;
half4 c;
c.rgb = (s.Albedo * light.rgb + light.rgb * spec);
c.a = s.Alpha + Luminance(spec);
return c;
}
struct Input {
float3 viewDir;
};
void vert (inout appdata_full v, out Input o) {
}
float4 _Color;
float _SpecPower;
float4 _RimColor;
float _RimPower;
void surf (Input IN, inout EditorSurfaceOutput o) {
o.Albedo = 0.0;
o.Normal = float3(0.0,0.0,1.0);
o.Emission = 0.0;
o.Gloss = 0.0;
o.Specular = 0.0;
o.Alpha = 1.0;
o.Albedo = _Color;
o.Normal = float3( 0.0, 0.0, 1.0);
o.Specular = _SpecPower.xxxx;
o.Gloss = Multiply0;
o.Alpha = 1.0;
}
ENDCG
}
Fallback "Diffuse"
}