问题描述
我正在> https://learnopengl.com/PBR/IBL/Diffuse-辐照度.
本教程通过创建6个视图将等角矩形转换为立方体贴图.
The tutorial convert a equirectangular to a cubemap by creating 6 views.
视图是以下代码:
glm::mat4 captureViews[] =
{
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(-1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, -1.0f, 0.0f), glm::vec3(0.0f, 0.0f, -1.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 0.0f, 1.0f), glm::vec3(0.0f, -1.0f, 0.0f)),
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3( 0.0f, 0.0f, -1.0f), glm::vec3(0.0f, -1.0f, 0.0f))
};
我不理解glm::lookAt
的第三个参数.
I don't understand the third parameter of glm::lookAt
.
glm::lookAt
的第三个参数是up
向量.我认为captureViews
应该是:
glm::lookAt
's third parameter is the up
vector. I think the captureViews
should be:
// zero is [0, 0, 0]
// right is [1, 0, 0]
// left is [-1, 0, 0]
// up is [0, 1, 0]
// down is [0, -1, 0]
// back is [0, 0, 1]
// forward is [0, 0, -1]
glm::mat4 captureViews[] =
{
glm::lookAt(zero, right, up),
glm::lookAt(zero, left, up),
glm::lookAt(zero, up, back),
glm::lookAt(zero, down, forward),
glm::lookAt(zero, back, up),
glm::lookAt(zero, forward, up)
};
但是我完全错了.我不了解本教程的up
向量中的魔术.
But I totally wrong. I don't understand the magic in the tutorial's up
vector.
有人可以帮我解释一下吗?
Can anyone explain it for me?
推荐答案
使用立方体贴图纹理时,必须将3维方向矢量转换为相对于地图一侧的2维纹理坐标.
When a cubemap texture is used, then a 3 dimensional direction vector has to be transformed, to 2 dimensional texture coordinate relative to one side of the map.
此转换规范的相关部分为 OpenGL 4.6 API核心配置文件规范,8.13多维数据集贴图纹理选择,第253页:
The relevant part of the specification for this transformtion is OpenGL 4.6 API Core Profile Specification, 8.13 Cube Map Texture Selection, page 253:
s = 1/2 * (s_c / |m_a| + 1)
t = 1/2 * (t_c / |m_a| + 1)
Major Axis Direction| Target |sc |tc |ma |
--------------------+---------------------------+---+---+---+
+rx |TEXTURE_CUBE_MAP_POSITIVE_X|−rz|−ry| rx|
−rx |TEXTURE_CUBE_MAP_NEGATIVE_X| rz|−ry| rx|
+ry |TEXTURE_CUBE_MAP_POSITIVE_Y| rx| rz| ry|
−ry |TEXTURE_CUBE_MAP_NEGATIVE_Y| rx|−rz| ry|
+rz |TEXTURE_CUBE_MAP_POSITIVE_Z| rx|−ry| rz|
−rz |TEXTURE_CUBE_MAP_NEGATIVE_Z|−rx|−ry| rz|
--------------------+---------------------------+---+---+---+
sc
对应于u coordiante,而tc
对应于v
cooridate.因此,tc
必须沿视图空间向上的方向
sc
cooresponds the u coordiante and tc
to the v
cooridnate. So tc
has to be in the direction of the view space up vector
查看表格的第一行:
+rx | TEXTURE_CUBE_MAP_POSITIVE_X | −rz | −ry | rx
这意味着,对于立方体贴图的X +侧(右侧),对应于切线和双法线的方向为
This means, for the X+ side (right side) of the cube map, the directions which correspond to the tangent and binormal are
sc = (0, 0, -1)
tc = (0, -1, 0)
这与表glm::mat4 captureViews[]
的第一行完全匹配:
This perfectly matches the 1st row of the table glm::mat4 captureViews[]
:
glm::lookAt(glm::vec3(0.0f, 0.0f, 0.0f), glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, -1.0f, 0.0f))
因为主要方向是由视线给出的,所以视线就是从视线到目标位置(los = target - eye
)的方向,所以(1,0,0).
向上向量(或ts
)为(0,-1,0).sc
由视线和向上矢量(0,0,-1)的叉积给出.
because the major direction is given by the line of sight, which is the directon form the eye position to the target (los = target - eye
) and so (1, 0, 0).
The up vector (or ts
) is (0, -1, 0).sc
is given by the cross product of the line of sight and the up vector (0, 0, -1).
这篇关于不了解Learnopengl.com中的漫射辐射教程中的captureViews的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!