- Home /
Question by
schlenger · Jul 08, 2016 at 10:15 AM ·
shaderunity5transparencyshadow
Combine Basic Shadow Shader and Transparency Shader in Unity
I got some two shaders: One shader can receive shadows and another shader can display transparent material. When I try to combine them, the mesh is not displayed anymore and I'm not sure, where the error is exactly.
The shadow shader code:
Shader "Custom/basicShadow" {
Properties {
_Color ("Main Color", Color) = (1,1,1,1)
_MainTex ("Base (RGB)", 2D) = "white" {}
}
SubShader {
Tags { "RenderType"="Opaque" }
CGPROGRAM
#pragma surface surf Lambert
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Albedo *= IN.color.rgb;
o.Alpha = c.a;
}
ENDCG
}
Fallback "VertexLit"
}
The transparency shader code:
Shader "Custom/transparentShadow" {
Properties {
_MainTex ("Color (RGB) Alpha (A)", 2D) = "white" {}
_Color ("Main Color", Color) = (1,1,1,1)
}
SubShader {
Tags { "Queue"="Transparent" "RenderType"="Transparent" }
LOD 200
CGPROGRAM
#pragma surface surf Lambert alpha
#pragma target 3.0
sampler2D _MainTex;
fixed4 _Color;
struct Input {
float2 uv_MainTex;
float4 color : COLOR;
};
void surf (Input IN, inout SurfaceOutput o) {
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Albedo *= IN.color.rgb;
o.Alpha = tex2D (_MainTex, IN.uv_MainTex).a *0.9;
}
ENDCG
}
Fallback "Diffuse"
}
When adding the alpha
tag to shadow tag, the mesh is not displayed anymore. Changing the tags of the shadow shader to Tags { "Queue"="Transparent" "RenderType"="Transparent" }
however works, but doesn't result in a different outcome.
Comment