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.
asked
Apr 29 '11 at 04:03 AM
cncguy
1k
●
21
●
25
●
36
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
worked for me!