Surface Shader Pipeline execution order

Hello,

I am working on creating a custom lighting model for a Surface Shader. I have several questions that are related to the order in which Surface Shaders are “executed”, as in when in the pipeline specific functions are called.

I understand that Unity 3.0 has deferred lighting (and to a lesser extent how it actually works), but is it always used?

For example, say I have a surface shader that has both forward and deferred lighting functions, are they both called for every light? Is only one called for each light (either deferred or forward)? Do they only get called if a light is light is actually lighting a particular pixel? Is this something that is determined or can be set dynamically, or is it more of a compile-time thing?

Next, where in the pipeline is the surf() function called for a surface shader (assuming it is called surf(), of course)? Is it after the forward lighting, but before deferred lighting?

I think what I am really looking for is a visual explanation/flow chart of the surface shader pipeline, so if anyone knows a good one and wouldn’t mind sharing it, I would appreciate it!

Bump…

Say I have a surface shader function called surf() that uses a custom lighting model called myLightingModel(), that uses only forward rendering.

Is surf() called before myLightingModel()? Does that even make sense, or does it not even work like that (e.g. the surf() function is essentially “compiled out”/ combined with the lighting model)?

Only the lighting function for the active light model is used.

If the light is forward it will use forward, if the light is deferred it will use deferred, if it is auto, it will use what you configured in the player settings.
if the mode is vertex only or if they are set to be used for bake only, they will use neither.