- Home /
Order of functions in a shader?
I'm trying to learn more about shaders, and can't find any documentation or tutorials on what I would think would be a very basic concept: what order are shader functions executed, and how are variables passed between them?
The documentation is pretty clear with vertex/pixel shaders: vertex functions happen first and their results get passed on to pixel shaders. However, what about surface shaders with lighting functions and optional vertex functions?
Answer by Julien-Lynge · Jun 29, 2012 at 03:52 PM
After playing around for a while, this appears to be the order:
vert is called first with information from Unity (e.g. appdata_full) as input, and outputs an Input struct
then surf is called, with Input as input and EditorSurfaceOutput as output
then the lighting function is called with EditorSurfaceOutput as input and a color (of type half4) is output for each pixel
then the PrePass lighting function (if defined) is called from within the lighting function, passing EditorSurfaceOutput and the light information to it
BTW: If you want to include a vertex function in your surface shader, use the syntax
#pragma surface [surface function] [lighting function] vertex:[vertex function]