http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2 zeigt:Computing Halb Vektor auf WebGL
H = Eye - L
habe ich folgendes auf meinem WebGL Vertexshader die Halbvektor zu berechnen:
vec4 ecPosition = u_mvMatrix * vec4(a_position.xyz, 1.0); // Get the eye coordinate position
vec3 eyeDirection = normalize(-ecPosition.xyz); // Get the eye direction
v_halfVector = normalize(eyeDirection + lightDirection); // Compute and normalize the half-vector
Aber ich bin mir nicht sicher, ob die obigen Codeschnipsel korrekt sind.
Jeder Zeiger/Hilfe wird geschätzt. Vielen Dank im Voraus für Ihre Hilfe.
EDIT: Es scheint der richtige Code sollten Sie versuchen, den Durchschnitt der Auge und Lichtvektoren zu erhalten, sollte nicht die letzte Zeile sein „normalisieren (eyeDirection + lightDirection)
vec4 ecPosition = u_mvMatrix * vec4(a_position.xyz, 1.0); // Position in the eye coordinate position
vec3 ecLightPosition = (u_mvMatrix * lightPosition).xyz; // Light position in the eye coordinate
vec3 lightDirection = ecLightPosition - ecPosition.xyz // Light direction
vec3 eyeDirection = (-ecPosition.xyz); // Eye direction
v_halfVector = normalize(eyeDirection + lightDirection); // Compute and normalize the half-vector