Unity3d制作双面材质:
Shader中Cull指令的使用:
通过Cull指令来控制需要剔除那个面的渲染图元。Cull指令的语法如下:
Cull Back | Front | Off
设置为Back,背对摄像机的渲染图源就不会被渲染,设置为Front,朝向摄像机的渲染图元就不会被渲染。
设置为Off就会关闭剔除功能,即所有图元都会被渲染。
步骤:
1.在项目面板中创建plane作为演示。
2.导入两张图片作为贴图演示。
3.在项目面板中创建DoubleSurface shader
4.打开创建的shader进行编辑:
Shader "Custom/DoubleSurface" {
Properties{
_Color("Main Color" , Color) = (1 ,1 ,1 ,1 )
_MainTex("Base (RGB)" , 2 D) = "white" {}
_MainTex_2("Base (RGB)" , 2 D) = "white" {}
}
SubShader{
Tags{ "RenderType" = "Opaque" }
LOD 100
Pass{
Cull Front
Lighting Off
SetTexture[_MainTex]{ combine texture }
SetTexture[_MainTex]
{
ConstantColor[_Color]
Combine Previous * Constant
}
}
Pass
{
Cull Back
Lighting Off
SetTexture[_MainTex_2]{ combine texture }
SetTexture[_MainTex_2]
{
ConstantColor[_Color]
Combine Previous * Constant
}
}
}
}
5.创建好之后把DoubleSurface shader附给plane的材质
6.选则导入的图片,如下图所示:
参考:
《Shader入门精要》,冯乐乐