我正在浏览OpenGL Superbible book的球形环境映射片段着色器。它如下:
#version 420 code
layout (binding = 0) uniform sampled2d tex_envmap;
in VS_OUT
{
vec3 normal;
vec3 view;
} fs_in;
out vec4 color;
void main(void)
{
// u will be our normalized view vector
vec3 u = normalize(fs_in.view);
// reflect u about the plane defined by the normal at the fragment
vec3 r = reflect(u, normalize(fs_in.normal));
// computer scal factor
r.z += 1.0f;
float m = 0.5 * inversesqrt(dor(r, r));
// sample from scaled and biased texture coordinate
color = texture(tex_envmap, r.xy * m + vec2(0.5f));
}
我不明白为什么r的z分量加到1.0然后再除以矢量的大小。我知道值在(-1,1)之间。所以,首先我们将它们分成2,然后用0.5添加它们,但我不知道为什么我们要改变z分量。谁能帮帮我吗?