title: How do you calculate the angle between two normals in glsl?
body: <p>How do you calculate the angle between two normals in glsl? I am trying to add the fresnel effect to the outer edges of an object (combining that effect with phong shading), and I think that the angle is the only thing I am missing.</p>
  
  <p>Fragment Shader:</p>
  
  <pre><code>varying vec3 N;
  varying vec3 v;
  
  void main(void) {
    v = vec3(gl_ModelViewMatrix * gl_Vertex);
    N = normalize(gl_NormalMatrix * gl_Normal);
    gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
  }
  </code></pre>
  
  <p>Vertex Shader:</p>
  
  <pre><code>varying vec3 N;
  varying vec3 v;
  
  void main(void) {
    vec3 L = normalize(gl_LightSource[0].position.xyz - v);
    vec3 E = normalize(-v);
    vec3 R = normalize(-reflect(L,N));
  
    vec4 Iamb = gl_FrontLightProduct[0].ambient
    vec4 Idiff = gl_FrontLightProduct[0].diffuse * max(dot(N,L), 0.0);
    vec4 Ispec = gl_FrontLightProduct[0].specular * pow(max(dot(R,E),0.0), gl_FrontMaterial.shininess);
    vec4 Itot = gl_FrontLightModelProduct.sceneColor + Iamb + Idiff + Ispec;
  
    vec3 A = //calculate the angle between the lighting direction and the normal//
    float F = 0.33 + 0.67*(1-cos(A))*(1-cos(A))*(1-cos(A))*(1-cos(A))*(1-cos(A));
    vec4 white = {1.0, 1.0, 1.0, 1.0};
  
    gl_FragColor = F*white + (1.0-F)*Itot;
  }
  </code></pre>
  
  <p>varying vec3</p>