Best way to have a quad or plane hover just above another objects normal?

As the title says I am using a texture on a quad that is z-Fighting ‘stitching’ so I have to have it hover above the faces normal.
I tried with .forward but that wont work.

firstObj.transform.position = secondObj.transform.position + (-Vector3.forward * 0.1f)

I know it has something to do with the normal but I cant remember.

Thanks, any help will be appreciated!

1 Answer

1

You can use this shader which makes the object render slightly towards the camera so you don’t have to manually adjust the transform.position.

Shader "Custom/BlendedDecal"
{
	Properties
	{
		_Color ("Tint", Color) = (1,1,1,1)
		_MainTex ("Texture", 2D) = "white" {}
	}
	
	SubShader
	{
		Lighting Off
		ZTest LEqual
		ZWrite Off
		Tags {"Queue" = "Transparent"}
		Pass
		{
			Alphatest Greater 0
			Blend SrcAlpha OneMinusSrcAlpha
			Offset -1, -1
			SetTexture [_MainTex]
			{
				ConstantColor[_Color]
				Combine texture * constant
			}
		}
	}
}

Great answer, I had to change the 'Offset' to make it work: Properties { ... _Offset("Offset", Float) = -1 } Pass { ... Offset[_Offset],[_Offset] } but now I am running into another problem. Because I am using a alpha texture I am getting a black border around all my alphas and it's not rendering quite correctly. Do you know what can solve this? [74366-wat.png|74366]