- Home /
using openGL to render simple line
i have this script, and works great except i want solid white line material. i tried to use it without the material but i get strange results, grid lines in the editor view start changing?
how to get solid white line is the question, and is it reliable to use this method?
static var lineMaterial : Material; static function CreateLineMaterial() { if( !lineMaterial ) { lineMaterial = new Material( "Shader \"Lines/Colored Blended\" {" + "SubShader { Pass { " + " Blend SrcAlpha OneMinusSrcAlpha " + " ZWrite Off Cull Off Fog { Mode Off } " + " BindChannels {" + " Bind \"vertex\", vertex Bind \"color\", color }" + "} } }" ); lineMaterial.hideFlags = HideFlags.HideAndDontSave; lineMaterial.shader.hideFlags = HideFlags.HideAndDontSave; } }
function OnPostRender() { CreateLineMaterial(); lineMaterial.SetPass( 0 ); GL.Begin( GL.LINES ); GL.Color( Color(1,1,1,0.5) ); GL.Vertex3( 0, 0, 0 ); GL.Vertex3( 1, 0, 0 ); GL.Vertex3( 0, 1, 0 ); GL.Vertex3( 1, 1, 0 ); GL.Color( Color(0,0,0,0.5) ); GL.Vertex3( 0, 0, 0 ); GL.Vertex3( 0, 1, 0 ); GL.Vertex3( 1, 0, 0 ); GL.Vertex3( 1, 1, 0 ); GL.End(); }
Answer by Tetrad · Jun 24, 2010 at 09:17 PM
1) Why not use Line Renderer.
2) If you want solid lines, perhaps change the shader to get rid of blending? You say "solid white line" but your post render code seems to want to go from white 50% alpha to black 50% alpha.