When creating a transparent or semi-transparent object, we might want to see its internal faces. However, by default, Unity transparent shaders make them invisible. In this recipe, we will edit one of Unity's built-in transparent shaders in order to make those faces visible to the user.
In order to follow this recipe, you will need to download the source code to Unity's built-in shaders from http://unity3d.com/unity/download/archive. You will also need a texture with a transparency channel. We have provided one, named grid.tga
, in the 0423_03_10
folder.
To disable culling for a material, follow these steps:
AlphaTest-BumpSpec.shader
, available within the DefaultResources
folder, onto your desktop.AlphaTest-BumpSpec.shader
copy to AlphaTest-DoubleSided.shader
. Then, open it in your code editor.Shader "Transparent/Cutout/DoubleSided" {
.SubShader { Tags {"Queue"="AlphaTest" "IgnoreProjector"="True" "RenderType"="TransparentCutout"} LOD 400 // Line of code to be added: Cull Off // End of code to be added.
grid.tga
texture.Grid
.Grid
material and, in the Inspector view, change its shader to Transparent/Cutout/DoubleSided
.grid.tga
texture as the Base texture for the Grid
material. Your double-sided transparent material is ready for use. It can even cast shadows!The Cull Off
command makes Unity render both front and back faces of the object. Although it works fine for our Cutout shader, using it with other types of transparent shaders might lead to unexpected results.
Here are some additional resources and solutions:
Unity's documentation includes several articles on shader programming. You can check them out at http://docs.unity3d.com/Documentation/Components/SL-Reference.html.
3.147.77.208