Game Development Reference
In-Depth Information
Backface Culling
As discovered earlier, Unity does not show the reverse side of surfaces. This is
called backface culling and is a common technique in computer graphics for
not drawing the reverse side of a polygon. In some cases, however, as with the
curtain in the warehouse example, it may be necessary to draw both sides.
In the hands-on session we used two cloths, one for either side. This is an
inefficient way as it immediately doubles the number of polygons used
for the curtain. A better way is to turn backface culling off.
To do this in Unity requires the writing of a shader . A shader is a piece of
code the game engine interprets as a texturing treatment for the surface
of a polygon. When you set a material to Diffuse or Transparent/Specular ,
you are using a prewritten shader.
To write your own shader requires extensive knowledge of the shader
language and complex computer graphics principles; however, numerous
shaders are available on the Unity Web site for you to try, so here are
the steps required to add a custom shader.
Unity Hands On
Loading a Custom Shader
Step 1. Open Unity and create a simple scene with plane or other
object to test the shader. If you prefer, you could add this to the
curtain in the warehouse application.
Step 2. In the Project select Create > Shader. A new shader file will
appear in the Project. Rename to backfaceOn. Double-click to open
this file. Replace the existing code with that in Listing 2.19 . This
custom shader has been taken from http://unity3d.com/support/
documentation/Components/SL-CullAndDepth.html .
Listing 2.19 A Custom Unity Shader to Remove Backface Culling
Shader "Backface On" {
Properties {
_Color ("Main Color", Color) = (1,1,1,0)
_SpecColor ("Spec Color", Color) = (1,1,1,1)
_Emission ("Emmisive Color", Color) = (0,0,0,0)
_Shininess ("Shininess", Range (0.01, 1)) = 0.7
_MainTex ("Base (RGB)", 2D) = "white" { }
}
SubShader {
Material {
Diffuse [_Color]
Ambient [_Color]
Shininess [_Shininess]
Specular [_SpecColor]
Emission [_Emission]
}
Search Nedrilad ::




Custom Search