How to avoid sprite clipping on the walls in 2.5D?
Ey, so here is the thing, i have sprites that act as a billboard on a 3d envionment, i worked on the shaders for the sprites earlier but I can't find a way to make it not clip into the wall when it collides with it, and making the collider bigger doesnt solve the problem as it would do the same with taller sprites and also not look like it is actually colliding, so to do that i need the sprite to be in front of the objects behind them but not in front of them, how can I render the sprite in front of the 3d objects that are behind them but not just part of the sprite?
This is the shader code:
Shader "Sprites/SpriteLightWithNormalsRIM"
{
Properties
{
_Color ("Main Color", Color) = (1,1,1,1)
[PerRendererData]_MainTex ("Base (RGB) Trans (A)", 2D) = "white" {}
[MaterialToggle] PixelSnap ("Pixel snap", Float) = 0
_Cutoff ("Alpha cutoff", Range(0,1)) = 0.5
_RimColor("Rim Color(RGB) Power(A)", Color) = (1,1,1,1)
_RimPower("Rim Power", Float) = 1
_Amount ("Offset", Float) = 1.0
}
SubShader
{
Tags {"Queue"="alphatest" "IgnoreProjector"="True" "RenderType"="TransparentCutOut" "CanUseSpriteAtlas"="True"}
LOD 200
//ZWrite On
//ZTest LEqual
Lighting On
CGPROGRAM
#pragma surface surf Lambert addshadow vertex:vert alphatest:_Cutoff
#pragma multi_compile DUMMY PIXELSNAP_ON
fixed4 _Color;
sampler2D _MainTex;
float4 _RimColor;
float _RimPower;
float _Amount;
struct Input
{
float2 uv_MainTex;
float3 nrmls;
float3 viewDir;
};
void vert(inout appdata_full v, out Input o)
{
v.normal = float3(0,0,-1); // 0,0,-1
v.tangent = float4 (0,0,0,0);
UNITY_INITIALIZE_OUTPUT(Input,o);
o.nrmls = v.normal;
}
void surf (Input IN, inout SurfaceOutput o)
{
fixed4 c = tex2D(_MainTex, IN.uv_MainTex) * _Color;
half rim = 1.0 - saturate(dot(normalize(IN.viewDir), o.Normal));
o.Albedo = c.rgb;
o.Alpha = c.a;
o.Normal = IN.nrmls;
o.Emission = (_RimColor.rgb * pow(rim, _RimColor.a)) * _RimPower;
}
ENDCG
}
Fallback "Legacy Shaders/Transparent/Cutout/Diffuse"
//Fallback "Shan/SurfaceRimLight"
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612131532im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to partially change texture? 0 Answers
Is it possible to create a texture that hides a specific texture? 0 Answers
How can I apply a 9-slice scaling to a mash object using a shader? 0 Answers
Get a Color from the Sprite Renderer in the Shader Graph using a Vector Sprite. Unity 2019.4.0f1. 1 Answer
Change sprite collection 1 Answer