I have a situation which is quite hard to explain. Firstly I have a scene which consist of a Screen Space -Camera canvas set at plane distance = 10. Attached to the canvas is a UGUI Raw Image element which is displaying a render target, and a Pie Chart which is a filled-circle created using procedural mesh. Each object are position of top of each other but with different Z-order.(ie textui is place in front of the circle which is place in front of the rawimage). The hierarchy of the objects are as follow:
- ScreenSpaceCanvas
++ RawImage
++ Panel
+++ PieChart(emptyObject)
++++ TextLabel
++++ ProceduralCircleMesh
The camera is at world position (0,1, -10) with lookAt in the direction of (0,0,1).
The local position of each of the element are as follow:
- ScreenSpaceCanvas
++ RawImage = (0,0,10)
++ Panel = (0,0, -1)
+++ PieChart = (0,0,-1)
++++ TextLabel = (0,0,-2)
++++ ProceduralCircleMesh = (0,0,0)
So this is the problem I am facing, when the RawImage is active, the UIText in TextLabel does not draw(or maybe is drawn behind the piechart), but then I disabled the rawImage, the text object rendered correctly in front of the circle.
To help isolating the problem, the ProceduralCircleMesh has a custom shader attached to it
Shader "Custom/PieChart" {
Properties {
_Color ("Color", Color) = (1,1,1,1)
}
SubShader
{
Tags { "Queue"="Transparent" "IgnoreProjector"="True" "RenderType"="Transparent" }
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
Cull off
Zwrite off
CGPROGRAM
#include "UnityCG.cginc"
#pragma target 4.0
#pragma vertex vert
#pragma fragment frag
half4 _Color;
struct VertIn
{
float4 vertex : POSITION;
};
struct v2f
{
float4 pos : SV_POSITION;
};
v2f vert(VertIn v)
{
v2f OUT;
OUT.pos = mul(UNITY_MATRIX_MVP, v.vertex);
return OUT;
}
half4 frag(v2f i) : SV_TARGET
{
return _Color;
}
ENDCG
}
}
FallBack "Diffuse"
}
When i change the shader to a opaque shader by modifying the shader to
Tags { "RenderType"="Opaque" }
Pass
{
Cull off
Zwrite On
.
.
.
The text is rendered correctly in front of the circle.
Hence i suspect that the problem is caused by the conflicting draw order of the circle with the rest of the transparent UI element, but i have no idea how to resolve this.
Sorry for the long post, hope you guys can point me to the right direction