【发布时间】:2010-12-28 21:04:05
【问题描述】:
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
但是我不确定上面的代码sn-ps是否正确。
感谢任何指针/帮助。提前感谢您的帮助。
编辑:似乎正确的代码应该是
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
【问题讨论】:
标签: webgl