Phi*_*sen 8 shader unity-game-engine
在Unity中,如何在黑暗中阻止我的3D文本"发光"?
例如,我正在使用下面的着色器代码,但文本比其他东西更明亮/自发光.更改为"Lighting On"会消除光晕,但也会消除材质颜色,并变为黑色.
怎么解决这个?非常感谢!
Shader "GUI/3D Text Shader - Cull Back" {
Properties {
_MainTex ("Font Texture", 2D) = "white" {}
_Color ("Text Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Lighting Off Cull Back ZWrite Off Fog { Mode Off }
Blend SrcAlpha OneMinusSrcAlpha
Pass {
Color [_Color]
SetTexture [_MainTex] {
combine primary, texture * primary
}
}
}
Run Code Online (Sandbox Code Playgroud)
复制自评论,为上下文添加:
我怀疑发光的光芒只是材料的无光泽颜色与黑暗/可变光照的场景形成鲜明对比?点亮的着色器可以解决这个问题,但Unity的TextMesh组件似乎不会生成网格法线,因此着色器的光照计算将会损坏(如果完全编译).它解释了为什么Lighting On
输出黑色.无法访问TextMesh内部并且仅限于固定功能着色器的限制,自定义着色器可能是您唯一的选择.
以下是使用Lambert闪电模型的基本Surface Shader.在引擎盖下,它将编译为标准的顶点/片段着色器,Unity的照明计算自动注入.它是作为替代品编写的,因此只需将其添加到您的项目中并将其拖放到您的材料上:
Shader "GUI/3D Text Shader - Lit"
{
Properties
{
_Color ("Text Color", Color) = (1,1,1,1)
_MainTex ("Font Texture", 2D) = "white" {}
}
SubShader
{
Tags {"RenderType"="Transparent" "Queue"="Transparent"}
Cull Back
CGPROGRAM
#pragma surface SS_Main Lambert vertex:VS_Main alpha:blend
#pragma target 3.0
uniform fixed4 _Color;
uniform sampler2D _MainTex;
struct Output
{
float4 vertex : POSITION;
float3 normal : NORMAL;
float4 texcoord : TEXCOORD0;
float4 texcoord1 : TEXCOORD1;
float4 texcoord2 : TEXCOORD2;
};
struct Input
{
float2 uv_MainTex;
};
void VS_Main (inout Output o)
{
// Generate normals for lighting.
o.normal = float3(0, 0, -1);
}
void SS_Main (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D (_MainTex, IN.uv_MainTex);
o.Albedo = _Color.rgb;
o.Alpha = c.a;
}
ENDCG
}
}
Run Code Online (Sandbox Code Playgroud)