【问题标题】:bias matrix in shadow mapping阴影映射中的偏置矩阵
【发布时间】:2010-03-07 12:12:26
【问题描述】:

我正在研究 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, ...?

谢谢!

【问题讨论】:

    标签: opengl


    【解决方案1】:

    当您使用标准模型视图/投影矩阵变换截锥体内的顶点时,您得到的结果是一个顶点,一旦 w-divide 完成,它位于 [-1:1]x[-1:1] x[-1:1] 立方体。您希望纹理坐标在 [0:1]x[0:1] 范围内,因此重新映射 x 和 y。假设您的 DepthRange 是 [0:1],Z 也是同样的事情。

    【讨论】:

      猜你喜欢
      • 2013-01-13
      • 1970-01-01
      • 1970-01-01
      • 2015-02-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-16
      相关资源
      最近更新 更多