Shader tutorial on Unity3d development (Shader language overview of GPU rendering)

Source: Internet
Author: User

Respect for the wisdom of others, welcome reprint, please indicate the author's heart if Transparent address http://www.cnblogs.com/ubanck/p/4110618.html

In the previous blog, roughly explained the principle of 3D rendering, that is, from a simple model to the process of rendering to the screen! It mentions the important coordinate transformation way, said not clear! Today to talk about the implementation of the shader language

Hardware, the GPU has a vertex shader and fragment shader, from the rendering pipeline, the vertex shader controls the coordinate conversion process of this vertex, the fragment shader controls the color calculation process of the pixel. The vertex shader completes the vertex transformation, enters into the fragment shader for processing (the fragment shader has the ability to retrieve texture information, the texture is equivalent to an array for the GPU, and the temporary vertex shader does not)

The vertex shader extracts the entity information from the register, so-called element information including (vertex position, normal vector, texture coordinates), which is from the application side, if there is DX or OpenGL programming experience, it should be well understood. After obtaining the element information, the vertex shader program completes the operation process of vertex coordinate space transformation, normal vector space transformation, illumination calculation and so on.

The previous article mentions that vertex coordinates start with the model space coordinate system, then to the World space coordinate system, and so on, and the illumination calculation is done at this stage, because the light is involved in the normal vector, so it needs to be handled in the World space coordinate system. After this, the data is transferred to the fragment shader, which contains texture coordinates and illumination information, and so on, after the fragment shader is taken, the color of each fragment is calculated, and finally the processed data is sent to the rasterization operation module, The operation of the so-called rasterization operation module is to assign the color to the corresponding pixel point, which is called Rasterization!

So we can say that the vertex shader program is mainly for geometric calculations, and the fragment is mainly for the final color calculation. Note: What is a fragment? Vertex good understanding, pixel understanding, then what is a fragment? The fragment is actually a data set after rasterization, which has not been compared with the depth value, and the pixels are compared.

After the GPU implementation process and basic principles, it is time to get to the point, we have to talk about our shader programming, as long as the programming, will mention the language, shader language is now said to be three DX of the HLSL (High Level shading language), OpenGL GLSL (OpenGL Shading language) also has NVIDIA CG (C for Graphics)!!! HLSL and GLSL are similar in nature, and CG language running in the upper level of DX and OpenGL, can be both very good support, and because I am currently using Unity3d development game, there is CG is very convenient to write, so the shader will be around CG! CG Grammar I will not explain in detail, this thing can refer to the official documents, and you can see the name will feel, must be similar to C. Related functions: http://http.developer.nvidia.com/Cg/index.html.

Here the basis of all the bedding, where the details of those changes need to participate in the mathematical formula deduction for the moment, the reader only need to know the formula is good, the derivation process can be see the "3D Mathematical basis: graphics and game development," a book, in this aspect of a more detailed explanation.

Next: Will formally explain unity Shader, of course, the period always involved in some other knowledge, we will expand to, explain, in the next Caishuxueqian, if there is any wrong place, please crossing treatise, welcome patronage, greatly honored!!!

Shader tutorial on Unity3d development (Shader language overview of GPU rendering)

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.