- Home /
Transparency Shader that Allows Shadows
I'm trying to "hide" walls behind the player by setting their transparency down a bit. I don't want them to cast or receive shadows any differently than if they were opaque, just make them slightly transparent so the player is never hidden. Seems like most of what I'm finding is for people who want to allow transparent objects to cast shadows based on transparency, so I'm hoping there is a multi-pass system that might allow shadows to ignore the alpha channel of the object, but still make the object alpha-y? Could I maybe just modify the diffuse channel's alpha?
In a related note, I've found reference to the Visibility Bubble system implemented in a few games, but very little in regards to how to implement it. Any thoughts?
Answer by ScroodgeM · Jul 17, 2012 at 06:45 PM
try this one
Shader "Transparent/Diffuse with Shadow" { 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 Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM #pragma surface surf Lambert addshadow
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 "Transparent/VertexLit" }
This is really close! The only issue is with objects in this pass ignoring shadows from other objects in the pass. If there is any fix, that would be awesome. Otherwise I might be able to make this work by having only the objects that need to be transparent having this shader and then toggling back to the default diffuse geometry shader.
this shader is more expensive then diffuse shader (cause no zbuffer writes and it is everything below this geometry renders even if it is hided totally). so you shouldn't use it for all walls - just for ones that have at least some transparency
PS a shadow-receiving for transparency objects is not so easy due to shadow rendering mechanism
Gotcha. That should be fine. I'll just toggle the shader on for objects I need it. It's only for objects blocking the view of the player, so they'll be out of focal point anyways. Thanks so much!