不了解Learnopengl.com中的漫射辐射教程中的captureViews [英] Do not understand captureViews in Diffuse-irradiance tutorial in learnopengl.com
问题描述
我正在> 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.
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 t r)
纹理坐标 从立方体的中心发出的方向向量(rx ry rz)
.q
坐标将被忽略.在纹理应用时,内插的每个片段方向向量会根据最大量值坐标方向(长轴方向)选择立方体贴图的二维图像之一.如果两个或多个坐标具有相同的幅度,则实现可以定义规则以消除这种情况的歧义.该规则必须是确定性的,并且仅取决于(rx ry rz)
.表8.19中的目标列说明了主轴方向如何映射到特定立方体贴图目标的二维图像. 使用表8.19中指定的主轴方向确定的sc
,tc
和ma
,更新了(s t)
计算如下:
When a cube map texture is sampled, the
(s t r)
texture coordinates are treated as a direction vector(rx ry rz)
emanating from the center of a cube. Theq
coordinate is ignored. At texture application time, the interpolated per-fragment direction vector selects one of the cube map face’s two-dimensional images based on the largest magnitude coordinate direction (the major axis direction). If two or more coordinates have the identical magnitude, the implementation may define the rule to disambiguate this situation. The rule must be deterministic and depend only on(rx ry rz)
. The target column in table 8.19 explains how the major axis direction maps to the two-dimensional image of a particular cube map target. Using thesc
,tc
, andma
determined by the major axis direction as specified in table 8.19, an updated(s t)
is calculated as follows:
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!