http://www.lighthouse3d.com/opengl/glsl/index.php?ogldir2显示以下内容:
H = 眼睛 - L
我在我的 WebGL 顶点着色器上执行了以下操作来计算半向量:
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
但我不确定上面的代码片段是否正确。
任何指针/帮助表示赞赏。在此先感谢您的帮助。
编辑:似乎正确的代码应该是
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