今天在研究Diffuse的时候发现了一个问题就是
代码中 出现了下面的代码,在Unity面板中调节发现不起变化。下面是自己研究的一些新的
o.Alpha = c.a;
最终的解决方案其实就相当于选用了Legacy Shaders->Transparent->Diffuse的着色器,在此仅是做一个发现问题=>解决问题的一个个人记录
创建一个Cube,新建个Material选用Legacy Shaders->Diffuse。调节Main Color中的Alpha没有效果,好奇的打开对应的shader代码,产生疑问为什么Alpha赋值了却没有生效?
解决过程:
Blend SrcAlpha OneMinusSrcAlhpa
//这行代码将传入的值强制设置成了1
//#define UNITY_OPAQUE_ALPHA(outputAlpha) outputAlpha = 1.0
UNITY_OPAQUE_ALPHA(c.a)
上代码:
//不透明
Shader "Legacy Shaders/Transparent/Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Opaque" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Legacy Shaders/Transparent/VertexLit"
}
//透明
Shader "Legacy Shaders/Transparent/Diffuse" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
}
SubShader {
Tags {"Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent"}
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha:fade //区别在这里
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Legacy Shaders/Transparent/VertexLit"
}