Asked • 06/19/19

How do you calculate the angle between two normals in glsl?

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. Fragment Shader: 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; } Vertex Shader: 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; } varying vec3

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.