Shader (Shader)

Source: Internet
Author: User

Shader (Shader)
    • Vertex shader (Vertex shader)
    • Fragment shader (Fragment shader)
    • Geometry shader (Geometry Shader)
    • Shader with Universal computing power (Compute Shader)
Vertex shader (Vertex Shader)

Each vertex is executed once vertex Shader. Its function is to transform the three-dimensional coordinates of each vertex in the virtual space into two-dimensional coordinates that can be displayed on the screen, with depth information for z-buffer.
Operable Properties: position, color, texture coordinates, but cannot create new vertices.

The following tasks are mainly accomplished:

    • Position transformation of matrix multiplication based on point operation
    • Calculates the color value of each point according to the illumination formula
    • Generate or convert texture coordinates
Input to the vertex shader
    • Attribute
    • Uniform
    • Sampler
Attribute

Attribute can be understood as input data for each vertex, such as spatial position, normal vector, texture coordinates, and vertex color.
It is only in the vertex shader, there is no attribute in the fragment shader

Uniform

Uniform saving read-only constant data passed to the shader by the application
In a vertex shader, these data are usually transformation matrices, illumination parameters, colors, and so on.
A variable modified by the uniform modifier is a global variable that is visible to both the vertex shader and the fragment shader
If both shaders are connected to the same program Object, they share the same copy of the uniform global variable set
So if you declare a uniform variable with the same name in both shaders, make sure it's exactly the same as the same name: same name + same type, because they're actually the same variable
In addition, the uniform variable is stored in the constant storage area

Sampler

A special kind of uniform, which is optional in the vertex shader for rendering textures. The sampler can be used for vertex shaders and fragment shaders.

Vertex shader output
    • Varying
    • Built-in variables
Varying

The varying variable is used to store the output data of the vertex shader and, of course, the input data of the slice shader, and the varying variable will eventually be linearly interpolated during the rasterization process.
Vertex shader If you declare a varying variable, it must be passed to the slice shader to further pass to the next stage, so the varying variable declared in the vertex shader should re-declare the varying variable of the same type in the slice shader.

Built-in variables

such as: Gl_position, gl_frontfacing, gl_pointsize

Fragment shader (Fragment Shader)

It calculates the color and other properties of each pixel. It calculates the color of the pixel and outputs it by applying lighting values, bump maps, shadows, specular highlights, translucency, and so on. It can also change the depth of the pixel (z-buffering) or output multiple colors in a state where multiple render targets are activated. A pixel shader cannot produce complex effects because it operates on only one pixel without knowing the geometry of the scene.

Input data for fragment shaders
    • Varying
    • Uniform
    • Sampler
Varying

The varying variable for the output of the vertex shader stage is output to the slice shader as its input, including the gl_fragcoord,gl_frontfacing and Gl_pointcoord above, in the rasterization phase after being linearly interpolated.

Uniform

As already mentioned, here are constants for the element shader, such as atomization parameters, texture parameters, etc.

Sampler

A special uniform for rendering textures

There is only a unique varying output variable in the fragment shader stage-that is, the built-in variable: gl_fragcolor

Shader (Shader)

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.