2

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
4

1 に答える 1

1

目と光のベクトルの平均を取得しようとしていると仮定すると、その最後の行は代わりに「normalize(eyeDirection + lightDirection)」にすべきではありませんか?また、光ベクトルは表面から出てくるので、目ではなく反転する方が理にかなっている場合があります。

私はここでは専門家ではないので、巨大な塩でアドバイスを受けてください。:)

于 2011-01-03T17:55:42.747 に答える