title: GLSL : Passing whole mesh to Geometry Shader
body: <p>I've been searching the net for an answer without success... So i turn to you.</p>
  
  <p>I'm trying to implement a shader that could give me the thickness of a mesh through a color map (or at least a two state color : over or under threshold) with GLSL.
  I' would need to perform hittest from a vertex, with its reversed normal as vector. And get the distance to the closest hit point on the mesh.</p>
  
  <p>I've already done the hittest function but i can't wrap my head around parsing the whole mesh in geometry shader.</p>
  
  <p>Here is a simplified version of the geometry shader:</p>
  
  <pre><code>        in VS_GS_VERTEX
          {
              vec3 normal;
          } vertex_in[];
  
          out GS_FS_VERTEX
          {
              vec3 color;
          } vertex_out;
  
  
          layout (triangles) in;
          layout (line_strip, max_vertices = 3) out;
  
          uniform mat4 projectionMatrix;
          uniform mat4 viewMatrix;
          uniform mat4 modelMatrix;
  
  
  
      void main(void)
      {
          float negate = -1.0f;
          for (int i = 0; i &lt; gl_in.length(); i += 3)
          {
              vec4 position1 = gl_in[i].gl_Position;
              vec4 position2 = gl_in[i + 1].gl_Position;
              vec4 position3 = gl_in[i + 2].gl_Position;
              vec3 target1 = vec3(position1.xyz + normalize(vertex_in[i].normal) * negate);
              vec3 target2 = vec3(position2.xyz + normalize(vertex_in[i + 1].normal) * negate);
              vec3 target3 = vec3(position3.xyz + normalize(vertex_in[i + 2].normal) * negate);
              for (int j = 0; j &lt; gl_in.length(); j++)
              {
                  vec4 positiontest = gl_in[j].gl_Position;
                  if (position1 != positiontest)
                  {
                      vec3 pointTouche;
                      if (hit(position1.xyz, target1, positiontest.x, positiontest.y, positiontest.z, out pointTouche))
                      {
                          float distance = length(position1 - pointTouche);
                          if (distance &lt; 10)
                          {
                              vec3 PointerColor = vec3(1, 0, 0);
                              vertex_out.color = PointerColor;
                              gl_Position = projectionMatrix * viewMatrix * modelMatrix * position1;
                              EmitVertex();
                          }
                          else
                          {
                              vec3 PointerColor = vec3(0, 0, 1);
                              vertex_out.color = PointerColor;
                              gl_Position = projectionMatrix * viewMatrix * modelMatrix * position1;
                              EmitVertex();
                          }
                      }
                  }
  
  
                  if (position2 != positiontest)
                  {
                      vec3 pointTouche;
                      if (hit(position2.xyz, target2, positiontest.x, positiontest.y, positiontest.z, out pointTouche))
                      {
                          float distance = length(position2 - pointTouche);
                          if (distance &lt; 10)
                          {
                              vec3 PointerColor = vec3(1, 0, 0);
                              vertex_out.color = PointerColor;
                              gl_Position = projectionMatrix * viewMatrix * modelMatrix * position2;
                              EmitVertex();
                          }
                          else
                          {
                              vec3 PointerColor = vec3(0, 0, 1);
                              vertex_out.color = PointerColor;
                              gl_Position = projectionMatrix * viewMatrix * modelMatrix * position2;
                              EmitVertex();
                          }
                      }
                  }
  
  
                  if (position3 != positiontest)
                  {
                      vec3 pointTouche;
                      if (hit(position3.xyz, target3, positiontest.x, positiontest.y, positiontest.z, out pointTouche))
                      {
                          float distance = length(position3 - pointTouche);
                          if (distance &lt; 10)
                          {
                              vec3 PointerColor = vec3(1, 0, 0);
                              vertex_out.color = PointerColor;
                              gl_Position = projectionMatrix * viewMatrix * modelMatrix * position3;
                              EmitVertex();
                          }
                          else
                          {
                              vec3 PointerColor = vec3(0, 0, 1);
                              vertex_out.color = PointerColor;
                              gl_Position = projectionMatrix * viewMatrix * modelMatrix * position3;
                              EmitVertex();
                          }
                      }
                  }
              }
              EndPrimitive();
          }
      }";
  </code></pre>
  
  <p>If somebody has any idea, it would be much appreciated.
  Thanks all.</p>