categories of shader:shader by pipeline classification is generally divided into fixed rendering pipeline and programmable rendering pipeline(1) Fixed rendering pipeline-this is the standard Geometry & Illumination (transforming&lighting) pipeline, the function is fixed, it controls the world, vision, projection transformation and fixed lighting control and texture mixing. T&l pipelines can be rendered with state control, matrix, illumination and mining parameters. Features are relatively limited. All of the basic graphics cards are functional. (2) programmable rendering pipeline--programming the vertex and pixel operations in the rendering pipeline separately without having to apply fixed functions like fixed rendering pipelines, instead of setting parameters to control the pipeline. Three kinds of shader of Unity3d
Unity's shader is divided into three types:(1) The fixed function shader belongs to the stationary rendering pipeline shader, which is basically used for advanced shader fallback when the old video card cannot be displayed (detailed later). Using the Shaderlab language, the syntax is similar to Microsoft's FX files or Nvidia's CGFX. (2) Vertex and Fragment Shader the most powerful Shader type, which belongs to the programmable rendering pipeline. The CG/HLSL syntax is used. (3) Surface Shader Unity3d respected Shader type, using Unity's pre-fabricated lighting model for lighting operations. The CG/HLSL syntax is also used. Unity3d Three shader comparison
Three kinds shader common:
(1) All must start from the only root shader
(2) Properties parameter section, The function and syntax are exactly the same.
(3) Specific functions are in Subshader ( subshader: Sub-Shader,shader will run from top to bottom, the first hardware can support Subshader, the main role is to support the use of hardware. )
(4) can be labeled, such as tags {"rendertype" = "Opaque"} lod and lighting on etc
(5) can be fallback
(6) to handle basic functions such as light diffuse (diffuse) and specular reflection (specular). but vertex and fragment and surface can implement advanced features that cannot be achieved by the Fixed function, For example, based on the effects of UV computing and so on.
Three shader different points:
(1) Fixed function shader and vertex and Fragment shader and Subshader under pass{}, But surface Shader, because has already packed the concrete content in the illumination model, cannot add pass{}, adds the error.
(2) Fixed function Shader There is no semicolon after each line of code '; ' but v&f shader and Surface shader Each code must be semicolon '; '
(3) The core structure is different:
The core of the Fixed function shader is
material{} and settexture[_maintex]{}
Vertex and The core of Fragment shader is
- Cgprogram
- #pragma vertex vert
- #pragma fragment Frag
- #include "Unitycg.cginc"
- Endcg
The core of Surface shader is
(1) This applies to unity3d with light model Lambert, and do not do vertex processing, then only one surface processing function surf can be
Cgprogram
#pragma surface surf Lambert
Endcg
or (2) This set represents the use of a light model of their own writingLsylightmodel, and a vertex processing function is used vert
Cgprogram
Surface finish function Lighting model function vertex processing: function
#pragma surface surf Lsylightmodel vertex:vert
//Perform order vertex processing functions, surface processing functions, lighting model functions, color values
ENDCG
[Unity Shader] Shader classification