Fix (and document) depth linearization

master
Webster Sheets 2021-03-27 00:32:41 -04:00
parent aeb5d906bb
commit 37deea46c5
2 changed files with 3 additions and 1 deletions

View File

@ -582,7 +582,7 @@ static vector3d projectToScreenSpace(const vector3d &pos, RefCountedPtr<CameraCo
float znear;
float zfar;
Pi::renderer->GetNearFarRange(znear, zfar);
proj.z = -((zfar * znear) / (proj.z * (zfar - znear) + znear));
proj.z = -znear / proj.z;
// set z to -1 if in front of camera, 1 else
if (adjustZ)

View File

@ -82,6 +82,8 @@ namespace Graphics {
const vector3d vVP = {
vNDC.x * 0.5 + 0.5,
vNDC.y * 0.5 + 0.5,
// FIXME: this isn't a proper linearization into viewspace (needs -znear / zNDC)
// but it accomplishes the goal of positions behind the camera having z > 0.
-vNDC.z // undo reverse-Z coordinate flip
};