I have geometry that is overlapping with other geometry (the floor). So, I used a shader to bring my desired mesh to the top. However, a new problem arose: the shader was rendering not only on top of the floor but also on top of other objects. To address this issue, I utilized the render queue and set it to Geometry mode, assigning a specific number.
My question is: Is there any other efficient way to handle this? I mean, if two objects are experiencing z-fighting, can we resolve only those conflicts without affecting other objects?

Shader:
Shader "Custom/DepthBiasShader"
{
Properties
{
_DepthBias ("Depth Bias", Range(0.0, 0.01)) = 0.005
_Color ("Main Color", Color) = (1,1,1,1) // Default white color
}
SubShader
{
Tags { "RenderType"="Opaque" }
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc"
struct appdata
{
float4 vertex : POSITION;
float2 uv : TEXCOORD0;
};
struct v2f
{
float2 uv : TEXCOORD0;
UNITY_FOG_COORDS(1)
float4 vertex : SV_POSITION;
};
float _DepthBias;
fixed4 _Color;
v2f vert(appdata v)
{
v2f o;
o.vertex = UnityObjectToClipPos(v.vertex);
o.uv = v.uv;
UNITY_TRANSFER_FOG(o,o.vertex);
return o;
}
half4 frag(v2f i) : SV_Target
{
// Apply color property
half4 col = _Color;
// Apply depth bias
float depth = LinearEyeDepth(i.vertex.z / i.vertex.w); // Calculate depth in view space
float bias = _DepthBias * depth;
clip(i.vertex.z - bias);
return col;
}
ENDCG
}
}
FallBack "Diffuse"
}