问题描述
我正在研究OpenGL中的阴影映射.
I'm looking at shadow mapping in OpenGL.
我看到如下代码:
// This is matrix transform every coordinate x,y,z
// x = x* 0.5 + 0.5
// y = y* 0.5 + 0.5
// z = z* 0.5 + 0.5
// Moving from unit cube [-1,1] to [0,1]
const GLdouble bias[16] = {
0.5, 0.0, 0.0, 0.0,
0.0, 0.5, 0.0, 0.0,
0.0, 0.0, 0.5, 0.0,
0.5, 0.5, 0.5, 1.0};
// Grab modelview and transformation matrices
glGetDoublev(GL_MODELVIEW_MATRIX, modelView);
glGetDoublev(GL_PROJECTION_MATRIX, projection);
glMatrixMode(GL_TEXTURE);
glActiveTextureARB(GL_TEXTURE7);
glLoadIdentity();
glLoadMatrixd(bias);
// concatating all matrice into one.
glMultMatrixd (projection);
glMultMatrixd (modelView);
// Go back to normal matrix mode
glMatrixMode(GL_MODELVIEW);
现在,如果我剔除偏见矩阵.该代码不起作用.搜索其他阴影映射代码,我看到了相同的偏差矩阵,没有任何解释.为什么要让这种偏见将x,y,z映射到0.5 * x + 0.5、0.5 * y + y,...?
Now, if I rip out the bias matrix. The code does not work. Searching other shadow mapping code, I see the same bias matrix, without any explaination. Why do I want this bias to map x, y, z to 0.5 * x + 0.5, 0.5 * y + y, ... ?
谢谢!
推荐答案
当您使用标准的modelview/projection矩阵在视锥内部转换顶点时,得到的结果是一个顶点,一旦完成w-divide,就可以[-1:1] x [-1:1] x [-1:1]立方体.您希望纹理坐标在[0:1] x [0:1]范围内,因此需要重新映射x和y.假设您的 DepthRange 是[0:1],这是默认设置.
when you transform vertices inside the frustum with a standard modelview/projection matrix, the result you get is a vertex that, once w-divide is done, is in the [-1:1]x[-1:1]x[-1:1] cube. you want your texture coordinates to be in the [0:1]x[0:1] range, hence the remapping for x and y. It's the same kind of thing for Z, assuming your DepthRange is [0:1], which is the default.
这篇关于阴影映射中的偏差矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!