- Home /
Camera OnPostRenderer on iPhone/iPad sometimes paints all the GL.Lines Black.
Hi I am using the following code to render a number of marks without inducing too much rendering overhead. It takes only one draw call. It works fine in the editor but at certain camera angles/positions on the iphone and ipad the drawn lines are drawn black instead of the desired colour.
var drawLines = true; private var lineMaterial : Material; private var stateLink : StateController;
function Awake () { lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" + "SubShader { Tags { \"Queue\" = \"Transparent+2\" \"RenderType\"=\"Transparent\"}" + "Pass {" + " BindChannels { Bind \"Color\",color }" + " Blend SrcAlpha OneMinusSrcAlpha" + " ZWrite Off Cull Off Fog { Mode Off }" + "} } }"); lineMaterial.hideFlags = HideFlags.HideAndDontSave; lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; stateLink = GameObject.FindWithTag ("Engine").GetComponent(StateController); }
function OnPostRender () { if(drawLines) { lineMaterial.SetPass(0); GL.Begin(GL.LINES); stateLink.drawTrajMarks(); GL.End(); } }
function OnApplicationQuit () { DestroyImmediate(lineMaterial); }
@script RequireComponent(Camera)
The line stateLink.drawTrajMarks();
calls functions which draw lines by calling positions from an number of different objects.
eg.
function drawTrajMarks()
{
...
GL.Color(colour);
for (var q = 0; q < circle2.length-1; q++)
{
GL.Vertex(circle2[q]+posnPnt );
GL.Vertex(circle2[q+1]+posnPnt );
}
...
}
I have tried a number of things to determine why the color goes black only at certain camera angles. I thought initially it was a z buffer order problem. But even if I change to ZTest always, at some camera angles the lines become black. I would be very interested in any pointers of where I should look next.
I am also seeing this behavior in my project. Have you had any success in solving it?
I've discovered that the lines seem to draw more consistently with color if at least one particle from a particle system is visible on screen, but this doesn't work 100% of the time.
This post talks about the same issue: http://answers.unity3d.com/questions/254732/gllines-are-black-on-ipad-when-mesh-are-on-screen.html
Answer by Petr Benysek · Jan 20, 2014 at 03:55 PM
I've had the same problem on Android (in Win Editor colors were working fine)... After several hours of experimenting, I've found that mesh instantiation as well as some other mesh operations can get OpenGL into a weird state where it stops listening to GL.Color command.
In my case, solution was quite easy (at last!): call GL.InvalidateState(); before other GL commands.
Hope that helps. :)
Your answer
Follow this Question
Related Questions
Use Gl.Lines to connect Vector3 points in world space 1 Answer
Drawing semi-transparent objects with GL.Begin(GL.QUADS) 3 Answers
GL - Shader not working in Android 1 Answer
GL.Quads not correctly displaying color. It's all black 0 Answers
OpenGL function don't work well on Unity 2017.2.0f3, But worked well on Unity 2017.1.1f1 0 Answers