I am trying to get some characters rendering correctly while moving in front of and behind eachother.
This is how the character should look normally:
This is how they look with overlap:
Currently, the red character on the right is closer to the camera and the body is correctly rendering on top of the orange body, but the mouth of the orange character shows through which is the problem.
The distance from the camera for the orange one is 200 with its eyes and mouth at 195.
The distance from the camera for the red one is 170 with eyes and mouth at 165
I would like all of the the composed orange character to show behind the red character.
I have also tried the shader below with ZWrite On but that causes the entire eyes/mouth not to render at all when the other alien is on top.
Any help would be greatly appreciated!
Here is the shader I am using currently using:
Code:
Shader "CustomGradientShader"
{
Properties
{
_MainTex( "Particle Texture", 2D ) = "white" {}
}
SubShader
{
Tags { "RenderType"="Transparent"}
Tags { "Queue" = "Transparent+1" }
Blend SrcAlpha OneMinusSrcAlpha
AlphaTest Off
ColorMask RGB
Cull Off
Lighting Off
ZWrite Off
Fog {Mode Off}
pass
{
CGPROGRAM
#pragma vertex wfiVertCol
#pragma fragment passThrough
#include "UnityCG.cginc"
sampler2D _MainTex;
struct VertOut
{
float4 position : POSITION;
float2 uv : TEXCOORD0;
float4 color : COLOR;
};
struct VertIn
{
float4 vertex : POSITION;
float4 color : COLOR;
float4 texcoord : TEXCOORD0;
};
float4 _MainTex_ST;
VertOut wfiVertCol(VertIn input, float3 normal : NORMAL)
{
VertOut output;
output.position = mul(UNITY_MATRIX_MVP,input.vertex);
output.color = input.color;
output.uv = TRANSFORM_TEX (input.texcoord, _MainTex);
return output;
}
struct FragOut
{
float4 color : COLOR;
};
FragOut passThrough(VertOut vertexOut)
{
FragOut output;
float4 texColor = tex2D(_MainTex, vertexOut.uv);
float r = texColor[0]+(1-(texColor[0]/1))*vertexOut.color[0];
float g = texColor[1]+(1-(texColor[1]/1))*vertexOut.color[1];
float b = texColor[2]+(1-(texColor[2]/1))*vertexOut.color[2];
output.color = float4(r,g,b,texColor[3]);
return output;
}
ENDCG
}
}
FallBack "Diffuse"
}