Display complex object when it is behind the wall

In my project a player character can stand behind the wall. I want to draw it in front of all objects. An outline or solid color is good for me. I've found a similar topic(How to make an outline of an object behind a wall?) and implemented a simple shader that displays sphere in different colors when it is behind another object. Sphere Visible through wall

Shader "SolidColorWithZTest" 
{
    Properties 
    {
        _Color1 ("Color1", Color) = (1,1,1,1)
        _Color2 ("Color2", Color) = (1,1,1,1)
    }
    SubShader 
    {
        Tags { "Queue" = "Geometry+1" }
        Pass 
        { 
            ZTest Greater
            Color [_Color1]
        }
        Pass 
        { 
            ZTest Less
            Color [_Color2] 
        }
    }
}

I tried this approach on complex model such as player character, and got an issue. A solid color "pops-up" from back of model. Player Character With Artifacts I'm using character from Third Person Shooter Demo, and here is shader I'm using:

Shader "Texture With ZTest" 
{
    Properties 
    {
        _Color ("Main Color", Color) = (1,1,1,1)
        _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    }

    Category 
    {
        SubShader 
        { 
            Tags { "Queue"="Overlay+1" }

            UsePass "Specular/BASE"
            Pass 
            {
                ZTest Less          
                SetTexture [_MainTex] {combine texture}
            }

            Pass
            {
                ZTest Greater
                Lighting Off
                Color [_Color]
            }
        }
    }

    FallBack "Specular", 1
}

What can be done to hide this white artifacts? Any suggestions are acceptable, including non-shader approach.

Just put the ZTest Greater pass before the ZTest Less pass.

I tested the shader and it almost worked, what was missing was to avoid writing to the depth buffer in the greater pass:

Shader “Texture With ZTest”{

Properties 
{
    _Color ("Main Color", Color) = (1,1,1,1)
    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
}

Category 
{
    SubShader 
    { 
        Tags { "Queue"="Overlay+1" }

        Pass
        {
            ZWrite Off
            ZTest Greater
            Lighting Off
            Color [_Color]
        }

        Pass 
        {
            ZTest Less          
            SetTexture [_MainTex] {combine texture}
        }
    }
}

FallBack "Specular", 1

}

I tested the shader myself and I found that everything worked except it did not support any sort of alpha channel transparency so I fiddled with it and came up with this.

Shader "Custom/NewShader" {
    Properties
    {
	    _Color ("Main Color", Color) = (1,1,1,1)
	    _MainTex ("Base (RGB) Gloss (A)", 2D) = "white" {}
    }
     
    Category
    {
    	SubShader
    	{
   			Tags { "Queue"="Overlay+1"
   			 "RenderType"="Transparent"}
     
		    Pass
		    {
		    	Blend SrcAlpha OneMinusSrcAlpha
			    ZWrite Off
			    ZTest Greater
			    Lighting Off
			    SetTexture [_MainTex] {combine texture}
		    }
     
   			 Pass
    		{
    			Blend SrcAlpha OneMinusSrcAlpha
    			ZTest Less
    			SetTexture [_MainTex] {combine texture}
    		}
    
    	}
    }
     
    FallBack "Diffuse"
}

Hey, the Main Color don’t change the color of the texture, so I have a Text Mesh with this material, but the text appear black, I want it white and that don’t work, how can I make Main Color work or download the font texture to change it color on photoshop ? thx

I dont know whatyou are going to do.
I am hacking Unity Games for a while now and i am using a different way!

#region Create Material
void CreateWallhackMaterial()
{
if (!WallhackMaterial)
{
WallhackMaterial = new Material(“Shader "Custom/Cham"{ SubShader { Pass { ZTest Less ZWrite On Color (1, 0.92, 0.016, 1) } Pass { ZTest Greater ZWrite Off Color (1,0,0,1) } }}”);
WallhackMaterial.hideFlags = HideFlags.HideAndDontSave;
WallhackMaterial.hideFlags = HideFlags.HideAndDontSave;
WallMats= new Material
{
WallhackMaterial
WallhackMaterial
WallhackMaterial
WallhackMaterial
WallhackMaterial
WallhackMaterial,
WallhackMaterial,
WallhackMaterial,
WallhackMaterial,
WallhackMaterial,
WallhackMaterial
};
}
}
#endregion
i call this void every frame (OnGUI()) and loop through the enemys!
if u wanna see how that looks


I dont know if that helped but this is working for me :wink: