I’ve been wrestling with the issue of transparency and depth of field. I need lit solid FX that also have a glow.
- If I use cutout, I can’t have partial opacity for the glow.
- If I use fade, I get the glow, but the shader does not write to the depth buffer and Depth of Field blurs out the pixels that don’t have objects in focus behind them.
- I can achieve a close-enough look by stacking a card with a cutout on top of another card with a fade, but stacking cards on top of each other is not really a great solution for vfx .
Ultimately I’d like to set this up in a multi-pass shader where it chooses between the two based on the texture alpha. How would I go about setting up a multi pass shader to have lit, shadow casting solid for where the texture alpha is above the cutoff and transparent, no shadow casting where the alpha is below the cutoff? Is that even possible?
I’m using Built-in RP.
I’ve got the multiple passes working. One with clipping, one with transparency. But as soon as I add the transparent portion, the opaque section loses its depth.
Shader "Custom/LitTransparentMultiPass"
{
Properties
{
_Color("Color", Color) = (1,1,1,1)
_MainTex("Albedo (RGB)", 2D) = "white" {}
}
SubShader
{
Tags { "Queue" = "Geometry" "RenderType" = "Opaque" }
LOD 200
Cull Off
ZWrite On
ZTest Always
CGPROGRAM
// Physically based Standard lighting model, and enable shadows on all light types
#pragma surface surf Standard fullforwardshadows addshadow
// Use shader model 3.0 target, to get nicer looking lighting
#pragma target 3.0
sampler2D _MainTex;
struct Input
{
float2 uv_MainTex;
};
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
// Albedo comes from a texture tinted by color
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
o.Albedo = c.rgb;
o.Alpha = 0;
clip(c.a - 0.9);
}
ENDCG
// TRANSPARENT PORTION
Tags{ "Queue" = "Transparent" "RenderType" = "Transparent" }
LOD 200
Cull Off
ZWrite Off
CGPROGRAM
#pragma surface surf Standard alpha:fade
#pragma target 3.0
sampler2D _MainTex;
struct Input {
float2 uv_MainTex;
};
fixed4 _Color;
void surf(Input IN, inout SurfaceOutputStandard o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex + 0.1) * _Color; //offset UVs slightly just to ensure that both are rendering
o.Albedo = c.rgb;
o.Alpha = c.a;
}
ENDCG
}
FallBack "Diffuse"
}