title: GLSL geometry shader matrices
body: <p>I have the following vertex shader: </p>
  
  <pre><code>#version 150 core
  
  attribute vec4 vertex;
  varying vec3 vert;
  varying float zdepth;
  
  uniform mat4 projMatrix;
  uniform mat4 mvMatrix;
  
  void main() {
     vert = vertex.xyz;
     zdepth = -(mvMatrix * vertex).z;
     gl_Position = projMatrix * mvMatrix * vertex;
  }
  </code></pre>
  
  <p>and geometry shader:</p>
  
  <pre><code>#version 150 core
  
  
  uniform mat4 projMatrix;
  uniform mat4 mvMatrix;
  
  layout(lines_adjacency) in;
  layout(triangle_strip, max_vertices = 4) out;
  
  void main() {
  
  
  
      vec4 p0 = gl_in[0].gl_Position;
      vec4 p1 = gl_in[1].gl_Position;
      vec4 p2 = gl_in[2].gl_Position;
      vec4 p3 = gl_in[3].gl_Position;
  
      vec4 v0 = normalize(p1-p0);
      vec4 v1 = normalize(p2-p1);
      vec4 v2 = normalize(p3-p2);
  
      vec4 n11 = normalize(v1-v0);
      vec4 n12 = -n11;
  
      vec4 n21 = normalize(v2-v1);
      vec4 n22 = -n21;
  
      gl_Position = p1+n11*0.2;
      EmitVertex();
      gl_Position = p1+n12*0.2;
      EmitVertex();
      gl_Position = p2+n21*0.2;
      EmitVertex();
      gl_Position = p2+n22*0.2;
      EmitVertex();
  
      EndPrimitive();
  }
  </code></pre>
  
  <p>The task of the geometry shader is to convert a line strip into triangle strip.
  This is what I get for a line strip spiral:</p>
  
  <p><a href="https://i.stack.imgur.com/kkkSY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/kkkSY.png" alt="spiral triangle strip"></a></p>
  
  <p>I want to have the triangle strip normal always pointing in the viewer direction and get a even thickness. Of course it has to be less thick further away.</p>
  
  <p>I need to rotate the n11,n12,n21,n22 so they are parallel to the view plane:
  <a href="https://i.stack.imgur.com/GRIFl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GRIFl.png" alt="normals"></a></p>
  
  <p>I would probably need to manipulate v0,v1,v2 with projMatrix and mvMatrix?
  Thanks!</p>