When doing projective textureing, we need to remap X, Y and Z form [-1,1] to [0,1]. This is clear for X and Y coordinates to me, but not enough clear for Z coordinate. It’s because in my OGL renderer I actually use D3D projection matrix:
xScale 0 0 0
0 yScale 0 0
0 0 zf/(zf-zn) 1
0 0 -zn*zf/(zf-zn) 0
where:
yScale = cot(fovY/2)
xScale = yScale / aspect ratio
And this matrix maps Z to range [0,1]. But such tex proj remapping matrix:
projTexCoordTransform = CMatrix
(
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 1.0f, 0.0f,
0.5f, 0.5f, 0.0f, 1.0f
);
simply doesn’t work. I need to use:
projTexCoordTransform = CMatrix
(
0.5f, 0.0f, 0.0f, 0.0f,
0.0f, 0.5f, 0.0f, 0.0f,
0.0f, 0.0f, 0.5f, 0.0f,
0.5f, 0.5f, 0.5f, 1.0f
);
which makes remapping [-1,1] -> [0,1]. The question is: why? Does OGL make some additional internal scaling and forces Z values to be in range [-1,1] or what?