- Home /
How to draw GL Lines over GameObjects/Images?
I am drawing lines between GameObjects to show their connection (showing a graph) using GL Lines and it always worked fine until I created a background Image using a Sprite. GameObjects are always hiding the Lines and because of the Background Image I can't see the lines anymore. Someone else had the reverse problem here: http://answers.unity3d.com/questions/434827/gllines-over-game-objects.html and I tried to use this shader but it doesn't work for me.
The code I have under OnPostRender() looks like this:
Shader shader = Shader.Find("Lines/Colored Blended");
Material lineMat = new Material(shader);
GL.PushMatrix();
lineMat.SetPass(0);
GL.LoadOrtho();
for (int i = 0; i < drawingGraph.edges.Count; i++)
{
Vector3 start = startObj.transform.position;
Vector3 end = endObj.transform.position;
GL.Begin(GL.LINES);
GL.Vertex3(start.x / Screen.width, start.y / Screen.height, start.z);
GL.Vertex3(end.x / Screen.width, end.y / Screen.height, end.z);
GL.End();
}
GL.PopMatrix();
The shader I'm using is this from the other post:
Shader "Lines/Colored Blended" {
SubShader{
Tags { "RenderType" = "Overdraw" }
Pass {
ZWrite Off
ZTest Always
Cull Off
Fog { Mode Off }
BindChannels {
Bind "vertex", vertex Bind "color", color
}
}
}
}
And that's how it looks without the background GameObject: And here with the background:
Can you guys tell me what I'm doing wrong? Thanks!
Answer by Southgarden116 · Nov 22, 2016 at 08:25 PM
I solved it! In case anyone else has that problem: The canvas render mode was set to "Screen Space - Overlay". I switched to "Screen Space - Camera" and it worked.
Your answer
Follow this Question
Related Questions
GL - Shader not working in Android 1 Answer
Shader Graph | How to create gradient from scratch 1 Answer
Shader graph shader won't pick up lighting 0 Answers
Material doesn't have a color property '_Color' 4 Answers
Shader Graph transparency issue 0 Answers