Unity3d Tutorial Shader Chapter: The first shader General Chapter

Source: Internet
Author: User

original articles should be reproduced please specify: Reproduced from the Wind Yu Chong Unity3d Tutorial College


Introduction, in Unity3d, all graphics must be drawn through shader, the shader. The general use of the process, we are using unity comes with the shader, that is, build-in shader. After learning shader, the shader can make a lot of special effects you want, enhance the game's picture performance. such as the reflection of water. The logo flashes and so on.

categories of shader

shader by pipeline classification is generally divided into fixed rendering pipeline and programmable rendering pipeline1) Fixed rendering pipeline-this is the standard Geometry & Illumination (transforming&lighting) pipeline, which is fixed, which controls the world, vision, projection transformations, and fixed lighting control and texture blending. 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 kinds of shader contrast

three kinds of shader common:
(1) must start with the only root shader
(2) Properties parameter section, the function and syntax are exactly the same
(3) Specific functions are in the Subshader (Subshader: Sub-Shader,shader will run the first hardware to support the Subshader, the primary role is to support the use of hardware. )
(4) can be labeled, such as tags {"rendertype" = "Opaque"} LOD 200 and lighting on etc.
(5) can be fallback
(6) can handle basic functions such as light diffuse reflection (diffuse) and specular reflection (specular). but vertex and fragment andsurface can be achievedFixed function is not possibleadvanced features, such as effects based on UV calculations, and more.

Three different points of shader:
(1) The Fixed function Shader and vertex and Fragment Shader under Subshader and pass{}, but surface Shader, because the specific content has been packaged in the lighting model, can not add pass{}, Added will be an error.
(2)Fixed function Shader There is no semicolon after each line of code '; ' But v&f shader andSurface shader Each sentence must be followed by a semicolon '; '
(3) The core structure is different:
The core of the Fixed function shader is
material{} and settexture[_maintex]{}

the core of Vertex and Fragment shader is

    1. Cgprogram
    2. #pragma vertex vert
    3. #pragma fragment Frag
    4. #include "Unitycg.cginc"
    5. 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 of Lsylightmodel uses a light model that is written by itself and uses a vertex-processing function 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    

Unity3d Tutorial Shader Chapter: The first shader General Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.