- Home /
Duplicate Question
GL.Lines Drawing over objects
Im facing a problem using Open GL. I have two images to show. What i want to achieve is in the first image which is made in Cocos2d. Second one i made with unity.
The Alpha shaded layer is made in GL. In cocos ihave the option to set Z. In unity when i Set/change the Z of the layer. It comes on top of everything. e.g a building z is 10 other is 5 and if i set the z of the layer to 6 i should come between but there are only two options either it appears on top of all or below which means we cant see it ..
any solution to this ??? My code for this is
static void 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;
}
}
public IsoShader (List<Vector2> p1, List<Vector2> p2, List<Vector2> p3, List<Vector2> p4)
{
boundaryPoint1 = new List<Vector2>(p1);
boundaryPoint2 = new List<Vector2>(p2);
boundaryPoint3 = new List<Vector2>(p3);
boundaryPoint4 = new List<Vector2>(p4);
}
void OnPostRender()
{
CreateLineMaterial();
lineMaterial.SetPass( 0 );
if(boundaryPoint1 != null)
{
GL.PushMatrix();
GL.Begin(GL.TRIANGLES);
GL.Color(color);
Draw();
GL.End();
GL.PopMatrix();
}
}
public float zIndex;
void Draw()
{
float scale = gState.world.isoView.transform.localScale.x;
for(int i=0; i<boundaryPoint1.Count; i++)
GL.Vertex3(scale * boundaryPoint1[i].x + gState.world.isoView.transform.position.x, scale * boundaryPoint1[i].y + gState.world.isoView.transform.position.y,zIndex);
for(int i=0; i<boundaryPoint2.Count; i++)
GL.Vertex3(scale * boundaryPoint2[i].x + gState.world.isoView.transform.position.x, scale * boundaryPoint2[i].y + gState.world.isoView.transform.position.y,zIndex);
for(int i=0; i<boundaryPoint3.Count; i++)
GL.Vertex3(scale * boundaryPoint3[i].x + gState.world.isoView.transform.position.x, scale * boundaryPoint3[i].y + gState.world.isoView.transform.position.y,zIndex);
for(int i=0; i<boundaryPoint4.Count; i++)
GL.Vertex3(scale * boundaryPoint4[i].x + gState.world.isoView.transform.position.x, scale * boundaryPoint4[i].y + gState.world.isoView.transform.position.y,zIndex);
}
I dont know how to do this with GL. For now im moving onto Graphics Library in Unity. Create a mesh programatically. Assing Material/ Transparent Shader and then do the required task. But i read some where that GL Library is faster than Graphics library is that so ?
Regards Usama
As you can see i am drawing a transparent shape. but the shader draws an opaque one. I changed the render type to transparent but still it draws a black opaque shape. How to make it draw alpha blended shape ? should i add color property in the shader or its fine using seperately ?
Answer by SaraCecilia · Dec 01, 2014 at 02:10 PM
http://answers.unity3d.com/questions/434827/gllines-over-game-objects.html