Game Development Reference
In-Depth Information
be difficult to understand, as it showed how to create the shader without using any surface
shader and it used the old version of Unity): http://unity3d.com/unite/archive/2008 .
Let's get back to the diagram—we can see that the shader file that we are writing works on
both the vertex and pixel (fragment) levels. Then, it will show the result to the frame buf-
fer, but what are vertex and pixel shaders? These are the different types of processors in
the GPU. First, the vertex processor gets the vertex data, which contains the position and
color of each vertex in the 3D model; then, it draws a triangle from these vertices and
passes the data to the pixel processor. The pixel processor will get that value and translate
it to the per-pixel screen. It is similar to taking vector art from Illustrator or Flash and
translating it to pixel art in Photoshop. Then, it interpolates color data to each pixel, as
shown in the following diagram:
From the explanation, we know that we need to deal with the vertex and pixel shader pro-
gramming when we want to write a shader program. For example, if we want to create a
shader, we will need to get the vertex data from our geometry, calculate the data, and pass
it out to the pixel level. At the pixel level, we will calculate the color of the geometry,
light, and shadow, and then we will get the result.
However, this can be very complex and repetitive when we have to handle lighting manu-
ally. That's why Unity created surface shaders so that we don't have to deal with various
types of lightning, rendering, and so on.
If you check out the ShaderLab link in Unity, you will see that there are many things to
do, but don't be afraid because we don't need to understand everything that's there to cre-
Search WWH ::




Custom Search