【发布时间】:2019-06-18 14:59:51
【问题描述】:
我有一个 .fbx 3D 网格,我已将它作为 Unity 中的游戏对象导入。它有顶点颜色。我试图让网格的某些部分呈现为透明,理想情况下,一旦用户选择了一个选项。
作为参考,这是我正在使用的网格的屏幕截图。
我在 Unity 中编写了一个着色器,它附加到这个游戏对象的材质上,它允许显示网格的顶点颜色。
Shader "Custom/VertexColor" {
// Where it will appear inside of the Shader Dropdown Menu of the Material / Name of the shader
SubShader{
Tags { "RenderType" = "Opaque" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert vertex:vert
#pragma target 3.0
struct Input {
float4 vertColor;
};
float _CutoutThresh;
void vert(inout appdata_full v, out Input o) {
UNITY_INITIALIZE_OUTPUT(Input, o);
o.vertColor = v.color;
}
void surf(Input IN, inout SurfaceOutput o) {
#include "UnityCG.cginc
o.Albedo = IN.vertColor.rgb;
clip(IN.vertColor.r = 0.5); // Discards any pixel whose interpolated vertex color in the red channel is less than 0.5
}
ENDCG
}
FallBack "Diffuse"
}
具体来说,这里的这一行: 剪辑(IN.vertColor.g = 0.5); // 丢弃绿色通道中插值顶点颜色小于 0.5 的任何像素
我希望这条线丢弃所有非绿色像素,但我的游戏对象看起来仍然一样。
【问题讨论】:
标签: unity3d colors shader mesh vertex-shader