Unity 中显示双面材质,新建一个 Shader,复制如下代码。再把模型材质的 Shader 改成刚刚保存的这个 DoubleSide 即可。
功能原理:
在 Pass()函数中,增加一行 Cull off 这条代码,其意义是显示模型所有的面。
相关的代码也有一下
Cull Back—— 不绘制背离观察者的几何面
Cull Front—— 不绘制面向观察者的几何面,用于由内自外的旋转对象
代码如下:
Shader “Unlit/DoubleSide”{
Properties
{
_Color (“Main Color”, Color) = (1,1,1,1)
_MainTex (“Base (RGB)”, 2D) = “white” {}
}
SubShader
{
Tags { “Queue” = “Transparent” }
Material
{
Diffuse [_Color]
Ambient (1,1,1,1)
}
Pass
{
Lighting On
Cull off
Blend SrcAlpha OneMinusSrcAlpha
SetTexture [_MainTex]
{
constantColor [_Color]
Combine texture * primary DOUBLE, texture * constant
}
}
}
FallBack “Diffuse”, 1
}