In the form of Unity Shader

   (1) a surface shader

    Unity colored surface is itself a shader code type. It requires very little amounts of code, Unity behind a lot of work to do, but the cost of rendering relatively large. Unity but still behind the surface shader into corresponding vertex / fragment shader. Unity to be surface shader vertex / fragment shader higher level of abstraction. Its value lies in the existence, Unity for us to deal with a lot of light details, we do not need to worry about.

Shader "Custom/Simple Surface Shader" {
    Subshader {
        Tags { "RenderType" = "Opaque" }
        CGPROGRAM
        #pragma surface surf Lambert
        struct Input {
            float4 color : COLOR;
        };
        void surf (Input IN, inout SurfaceOutput o) {
            o.Albedo = 1;
        }
        ENDCG
    }
    Fallback "Diffuse"
}

    As can be seen from the above procedure, the surface of the shader is defined between the semantic SubShader blocks (blocks not Pass semantics) and the CGPROGRAM ENDCG. The reason is that the surface shader developers do not need to be concerned about how many Pass use, how each Pass rendering issues, Unity will do these things for us in the back. We have to do is tell it: use these textures to the fill color, use a texture to fill the normals normals, using Lambert lighting model ....

   

  (2) the vertex / fragment shader

Shader "Custom/Simple VertexFragment Shader" {
    SubShader {
        Pass {
            CGPROGRAM

            #pragma vertex vert
            #pragma fragment frag
            
            float4 vert (float4 v : POSITON) : SV_POSITON {
                return mul (UNITY_MATRIX_MVP, v);
            }

            fixed4 frag() : SV_Target {
                return fixed4(1.0, 0.0, 0.0, 1.0);
            }

            ENDCG
        }
    }
}

    And a surface different shader is a vertex / fragment shader is written in a semantic Pass block, rather than the SubShader. The reason is that we need to define Shader code for each Pass need to use their own. Although more complicated, but the benefits are very high flexibility. More importantly, we can control the rendering of the implementation details.

   

   (3) a fixed function shader

    Only old equipment need them.

 

    In the new version of Unity, the surface of the colored and fixed functions are converted into the vertex shader / fragment shader.

Guess you like

Origin www.cnblogs.com/chia-liblog/p/11074974.html