Hi all,
So I’m writing a 2d debug primitives renderer for runtime debug viewing (Lines, circles, quads etc)
I can’t figure out for the life of me how to make it render on top of everything else in the scene.
I generate a mesh dynamically and create a material for it that uses a debug shader.
This is the rendering call:
Graphics.DrawMesh(ShapesMesh, Matrix4x4.identity, ShapesMaterial, layer: RENDER_LAYER);
I tried setting the “Queue” to “Overlay” in the shader, setting ZWrite ON and ZTest Always, etc. No matter what I do, there’s always things in the scene that render on top of my mesh. Those things are MeshRenderers that have a higher than “Default” sorting layer (Foreground) (generated from TilemapEditor plugin). I can’t see anyway to access sortingLayers from the Graphics.Draw* calls. Here’s my debug shader:
Shader "TinyTitanStudios/XDebugShader"
{
SubShader
{
Tags
{
"Queue"="Overlay"
}
Cull Off
Lighting Off
ZWrite ON
ZTest Always
Blend SrcAlpha OneMinusSrcAlpha
Pass
{
CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#pragma target 2.0
#include "UnityCG.cginc"
#include "UnityUI.cginc"
struct VertexInput
{
float4 Vertex : POSITION;
float4 Color : COLOR;
};
struct VertexOutput
{
float4 Vertex : SV_POSITION;
fixed4 Color : COLOR;
};
VertexOutput vert(VertexInput IN)
{
VertexOutput OUT;
OUT.Vertex = UnityObjectToClipPos(IN.Vertex);
OUT.Color = IN.Color;
return(OUT);
}
fixed4 frag(VertexOutput IN) : SV_Target
{
fixed4 OUT = IN.Color;
return(OUT);
}
ENDCG
}
}
}
In the mean time I can’t see any way to do this without creating a new GameObject with a MeshRenderer attached with its sortingLayer set to something higher than Foreground.
Attached image shows the debug lines rendering underneath the trees.
Thanks for any tips!
