Game Development Reference
In-Depth Information
Chapter 3. Shade Your Hero/Heroine
In the last two projects, we learned how to create a UI using the GUI object as well as a 2D
platform game that used the 2D sprite texture to create our 2D character, and we also got to
know a bit about the 3D world in the first project. So, in this project, we will be using a full
3D character. We will take a close look at how to apply a material and shader to the model.
In Unity, there are three different types of shaders. First, surface shaders is the best option
if we want our shader to be affected by lights and shadows. Next, Vertex and Fragment
Shaders will be required when our shader doesn't need to interact with lighting or needs an
effect that surface shaders can't handle. Finally, ShaderLab and Fixed Function Shaders use
the old hardware that don't support programmable shaders (GLSL and HLSL/CG), which is
mostly used for fallback from a fancy shader. Each type has its advantages. However, we
will use surface shaders in this project, which is very convenient and easiest to use when
we want to deal with the lighting and shadow. (For more details, check out Appendix D ,
Shaders and CG/HLSL Programming. )
Note
Computer Graphics ( CG ) is a high-level shader language developed by NVIDIA in close
collaboration with Microsoft to programme the vertex and pixel shader. It is similar to
High Level Shader Language or High Level Shading Language ( HLSL ), which is a
proprietary shading language developed by Microsoft for use with the Microsoft Direct3D
API. These references are taken from http://http.developer.nvidia.com/CgTutorial/
cg_tutorial_chapter01.html and http://msdn.microsoft.com/en-us/library/
bb509635(v=VS.85).aspx .
We will also get an understanding of shader programming in Unity and create custom
shaders by using surface shaders. We can then use the Cg shading language or HLSL to
write vertex and fragment shaders.
Note
Surface shaders in Unity is basically the repetitive code that makes it easier to write the
shaders that interact with lighting than using low-level vertex/pixel shader programs (Ver-
tex and Fragment Shaders), such as lighting calculation. However, we still need to know
Cg/HLSL to write surface shaders. For more information, refer to http://docs.unity3d.com/
Documentation/Components/SL-SurfaceShaders.html .
Search WWH ::




Custom Search