此代码如何从球形地图中采样?

How does this code sample from a spherical map?

阅读本教程来自: https://learnopengl.com/PBR/IBL/Diffuse-irradiance

我遇到了这段代码:

const vec2 invAtan = vec2(0.1591, 0.3183);
vec2 SampleSphericalMap(vec3 direction)
{
    vec2 uv = vec2(atan(direction.z, direction.x), asin(direction.y));
    uv *= invAtan;
    uv += 0.5;
    return uv;
}

要对如下所示的图像进行采样:

我的问题是这个和神奇的 "invAtan" 常量是从哪里来的?

您发布的图片是 equirectangular projection of a 360 degree photograph taken next to the Colosseum in Rome, Italy

invAtan常数是2PIPIreciprocal(or multiplicative inverse)

0.1591 = 1/6.28319(=>2PI) = 360 度弧度

0.3183 = 1/3.14159(=>PI) = 180 度弧度

所以你从 cartesian coordinates to polar angles to uvs, see this great resource(headline: Direct Polar). In more practical terms, assuming that given direction is normalized(hence mapped to the unit-sphere) 乘以 invAtan 将值转换为 [-.5,.5] 范围,添加 .5 导致 uv 查找坐标在 [0,1].