Hi everyone,
I don’t know anything about shaders and I don’t really have time to learn (next thing on my list) right now.
I’m currently in a game jam (1 month) and I’m facing a problem.
My artist drew me a rat, here’s the sprite:
I have a floor that don’t have any rotation or anything. And my rat has a rotation of 50 degrees on the x axis.
The problem is that its tail isn’t visible as it is under the floor.
I’m sure there is a way to render it on top of it with a shader but I don’t know how to do that.

I’d like it to get rendered on top of the floor only (it would be convenient to have a “z-index” or “z-order” property and the bigger ones are rendered in front of the others).
I would also need the sprite to cast and receive shadows.
So if someone has the knowledge I’d be very grateful for your help.
Thank you very much in advance.
After asking ChatGPT again and again it gave me a shader that works as intended. There it is:
Shader "Sprites/Custom/SpriteShadow"
{
Properties
{
[PerRendererData] _MainTex("Sprite Texture", 2D) = "white" {}
_Color("Tint", Color) = (1,1,1,1)
_ExtraBrightness("Brightness", Range(0,1)) = 0.5
[MaterialToggle] PixelSnap("Pixel snap", Float) = 0
[HideInInspector] _RendererColor("RendererColor", Color) = (1,1,1,1)
[HideInInspector] _Flip("Flip", Vector) = (1,1,1,1)
[PerRendererData] _AlphaTex("External Alpha", 2D) = "white" {}
[PerRendererData] _EnableExternalAlpha("Enable External Alpha", Float) = 0
_Cutoff("Alpha Cutoff", Range(0,1)) = 0.5
}
SubShader
{
Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
"PreviewType" = "Plane"
"CanUseSpriteAtlas" = "True"
"DepthTest" = "True"
}
Cull Off
Lighting Off
ZWrite Off
Blend One OneMinusSrcAlpha
ZTest Less
CGPROGRAM
#pragma surface surf Lambert vertex:vert alphatest:_Cutoff addshadow nofog nolightmap nodynlightmap keepalpha noinstancing
#pragma multi_compile_local _ PIXELSNAP_ON
#pragma multi_compile _ ETC1_EXTERNAL_ALPHA
#include "UnitySprites.cginc"
float _ExtraBrightness;
struct Input
{
float2 uv_MainTex;
fixed4 color;
};
void vert(inout appdata_full v, out Input o)
{
v.vertex = UnityFlipSprite(v.vertex, _Flip);
#if defined(PIXELSNAP_ON)
v.vertex = UnityPixelSnap(v.vertex);
#endif
UNITY_INITIALIZE_OUTPUT(Input, o);
o.color = v.color * _Color * _RendererColor;
o.color.rgb += _ExtraBrightness;
}
void surf(Input IN, inout SurfaceOutput o)
{
fixed4 c = SampleSpriteTexture(IN.uv_MainTex) * IN.color;
o.Albedo = c.rgb * c.a;
o.Alpha = c.a;
}
ENDCG
}
Fallback "Transparent/VertexLit"
}
Here’s the result:
https://i.imgur.com/BFdeebx.gif
At the moment I don’t know if it’ll cause me any issue.
If someone with the necessary knowledge can explain to me what it does I’d be very curious.
And if you have a better solution I’d still be very grateful.
Thank you very much!
I realized that I’ve also applied the same shader by error on the ground and without it, it doesn’t work. But as the lighting was off I searched what specific part made it work and I made a standard surface shader for the ground and set ZWrite to Off and ZTest to Less and it works.
Still don’t know why tbh haha.
That works because without ZWrite on, the shaders aren’t writing any values to the depth buffer… Which means that objects rendered below the ground for example can’t get clipped away by it. Which could be a really bad thing. Another issue you’ll run into is that the objects are going to renderer based on pivot distance from camera, so you may end up with transparent sprites rendering behind the ground unless you force the ground to an earlier queue.
You can use this kind of code in the vert() program of a regular sprite shader to offset the sprite towards the camera, preventing it from clipping but allowing it to still look like it’s in the correct spot: 'Pull to Camera' shader?
The other option would be to open the import settings of your sprite, go to Sprite Editor, and move the Pivot to be at the bottom of the tail. That way the mouse doesn’t penetrate the ground when placed at the same level.
Or, if you do ZTest Always
(and ZWrite off
so it doesn’t clip other sprites) in your mouse’s shader, it won’t get clipped by depth values. This may be fine for you if the stuff above ground is all going to be using transparent shaders.
Thank you very much for your answer, it helps a lot!