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!
So the story with pre-pass is that whatever you write in surf() will be used both to output to the g-buffer and will also be used to calculate final color in the final pass (a.k.a. forward pass, a.k.a. shading pass).
So if you write something into o.Normal and o.Specular, these values will actually be used to render the g-buffer.
Other values will be consumed by your lighting function (custom or not), which happens after the basic lighting was calculated and is available in the _LightBuffer.
If you're interested in digging into this more, you can add "#pragma debug" to your shader, then select the shader in the Project window and click "Open compiled shader" in the Inpsector. This will allow you the see the Cg code that gets generated from the surface shader code. For comparison you can also do it for the built-in shaders.
answered Oct 26 '10 at 10:09 AM