Writing Surface Shaders
Surface shaders in Unity is a gcode generation approach that makes it much easier to write shaders using low level vertex/pixel shader programs. The code just generates all the repetitive code that it would have to be written by hand.
(can be written in CG/HLSL)
Here is how it works
1) Define a surface function that takes in any UVs or data you need as input and fills in output structure SurfaceOutput. SurfaceOutput basically describes properties of the surface. (can be written in CG/HLSL) The shaders compiler then figures out what inputs are needed, what outputs are filled, then generates actual vertex&pixel shaders, as well as rendering passes to handle forward and deferrend rendering.
Here is how it works
1) Define a surface function that takes in any UVs or data you need as input and fills in output structure SurfaceOutput. SurfaceOutput basically describes properties of the surface. (can be written in CG/HLSL) The shaders compiler then figures out what inputs are needed, what outputs are filled, then generates actual vertex&pixel shaders, as well as rendering passes to handle forward and deferrend rendering.
Standard output structure of surface shaders is this:
struct SurfaceOutput
{
struct SurfaceOutput
{
half3 Albedo;
half3 Albedo;
half3 Emission;
half Specular;
half Gloss;
half Alpha;
}
Surface shader compile directives should be placed in between
CGPROGRAM
Surface shader compile directives should be placed in between
CGPROGRAM
No comments:
Post a Comment