- Home /
Question by
nekropantz · Nov 07, 2021 at 09:28 PM ·
shaderspritespriterendererdepth-buffer
How do I write a cutout sprite shader to depth depthtexture ?
Hi!
Tearing my hair out while trying to write only the nontransparent pixels to the depth buffer. I think the issue is that it is using "Legacy Shaders/VertexLit/SHADOWCASTER" for the depth pass but I cannot find a fragment equivalent.
The issue:
My Shader
// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'
Shader "Sprites/DefaultWithDepth"
{
Properties
{
[PerRendererData] _MainTex ("Sprite Texture", 2D) = "white" {}
_Color ("Tint", Color) = (1,1,1,1)
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
}
SubShader
{
Tags
{
"Queue"="AlphaTest"
"IgnoreProjector"="True"
"RenderType"="TransparentCutout"
"PreviewType"="Plane"
"CanUseSpriteAtlas"="True"
}
Cull Off
Lighting Off
Blend One OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma multi_compile _ PIXELSNAP_ON
#include "UnityCG.cginc"
struct appdata_t
{
float4 vertex : POSITION;
float4 color : COLOR;
float2 texcoord : TEXCOORD0;
};
struct v2f
{
float4 vertex : SV_POSITION;
fixed4 color : COLOR;
half2 texcoord : TEXCOORD0;
};
fixed4 _Color;
v2f vert(appdata_t IN)
{
v2f OUT;
OUT.vertex = UnityObjectToClipPos(IN.vertex);
OUT.texcoord = IN.texcoord;
OUT.color = IN.color * _Color;
#ifdef PIXELSNAP_ON
OUT.vertex = UnityPixelSnap (OUT.vertex);
#endif
return OUT;
}
sampler2D _MainTex;
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = tex2D(_MainTex, IN.texcoord) * IN.color;
c.rgb *= c.a;
clip(c.a - 0.5);
return c;
}
ENDCG
}
UsePass "Legacy Shaders/VertexLit/SHADOWCASTER"
}
}
capture.png
(370.6 kB)
Comment
Your answer
Follow this Question
Related Questions
Outline set of tiled sprites 0 Answers
How do I achieve a field of vision effect with sprites? 0 Answers
Getting the correct object level depth in shader 1 Answer
Cheapest way of rendering 2000 sprites? 1 Answer
Distort shader not showing sprites 2 Answers