【问题标题】:Computing half vector on WebGL在 WebGL 上计算半向量
【发布时间】: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


    【解决方案1】:

    假设您正在尝试获取眼睛和光线矢量的平均值,那么最后一行不应该是“normalize(eyeDirection + lightDirection)”吗?此外,由于它是从表面出来的,因此反转光矢量而不是眼睛可能更有意义。

    我不是这里的专家,所以请谨慎接受我的建议。 :)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-11-27
      • 2023-02-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-16
      • 2016-08-05
      相关资源
      最近更新 更多