Search Unity

openGL depth

Discussion in 'Scripting' started by Dazzid, Sep 18, 2014.

  1. Dazzid

    Dazzid

    Joined:
    Apr 15, 2014
    Posts:
    61
    HI All,
    I have a question related to OpenGL in unity. I need to paint in 3D and right now it is painting all the triangles superimposed mixing 3D position with 2D rendering. How can I paint in 3D using this unity openGL technique?
    Here the code:
    Code (CSharp):
    1. public class CameraPostRender : MonoBehaviour
    2. {
    3.  
    4.         private static Material m;
    5.         private GameObject g;
    6.         GraphModel gm;
    7.         private float myConnectionThreshold;
    8.  
    9.         void Start ()
    10.         {
    11.                 gm = (GameObject.Find ("ConnectomeRoot").GetComponent<Connectome> ()).gm;
    12.                 m = new Material (Shader.Find ("Particles/Alpha Blended"));
    13.                 g = new GameObject ("g");
    14.                 myConnectionThreshold = 1.51f;
    15.         }
    16.  
    17.         void Update ()
    18.         {
    19.    
    20.         }
    21.  
    22.         void OnPostRender ()
    23.         {
    24.                 m.SetPass (0);
    25.                 GL.PushMatrix ();
    26.                 GL.MultMatrix (g.transform.transform.localToWorldMatrix);
    27.                 GL.Begin (GL.TRIANGLES);
    28.  
    29.                 for (int i = 1; i <= gm.nodeCount; i++) {
    30.                         if (gm.Nodes [i].weight_node > myConnectionThreshold) {
    31.                                 foreach (int n in gm.Nodes [i].EdgesFrom) {
    32.                                         int particle_from = gm.Edges [n].NodeFrom;
    33.                                         int particle_to = gm.Edges [n].NodeTo;
    34.                                         float lineSize = Mathf.Clamp (gm.Edges [n].Weight * 5.5f, 0.09f, 1.0f);
    35.                                         GL.Color (new Color (gm.Nodes [particle_from].myColor.r, gm.Nodes [particle_from].myColor.g, gm.Nodes [particle_from].myColor.b, 0.05f));
    36.                                         GL.Vertex3 (gm.Nodes [particle_from].newPosition.x, gm.Nodes [particle_from].newPosition.y, gm.Nodes [particle_from].newPosition.z);
    37.                                         GL.Vertex3 (gm.Nodes [particle_to].newPosition.x, gm.Nodes [particle_to].newPosition.y, gm.Nodes [particle_to].newPosition.z);
    38.                                 }
    39.                         }
    40.                 }
    41.        
    42.                 GL.End ();
    43.                 GL.PopMatrix ();
    44.         }
    45. }
     
  2. hpjohn

    hpjohn

    Joined:
    Aug 14, 2012
    Posts:
    2,190
    Well, you've put all your code into POST RENDER, so the GL stuff is drawn over the top of everything else.