[glsl] Adjust view/projection matrices for consistency

The actual view and projection matrices are now consistent with vulkan,
with the vulkan-gl disparity moved into adjustment matrices. The goal is
to allow the same camera data and code to be used in all renderers. The
extra matrix multiplication shouldn't be too expensive as it occurs only
when the field of view (not often, under user control) or near and far
clip distances (very rarely) change.
This commit is contained in:
Bill Currie 2022-02-25 10:50:53 +09:00
parent 5ad7c0fbd6
commit e920abe142
1 changed files with 16 additions and 6 deletions

View File

@ -78,8 +78,17 @@ glsl_R_ViewChanged (void)
// NOTE columns! // NOTE columns!
proj[0] = (vec4f_t) { f / aspect, 0, 0, 0 }; proj[0] = (vec4f_t) { f / aspect, 0, 0, 0 };
proj[1] = (vec4f_t) { 0, f, 0, 0 }; proj[1] = (vec4f_t) { 0, f, 0, 0 };
proj[2] = (vec4f_t) { 0, 0, (fard + neard) / (neard - fard), -1 }; proj[2] = (vec4f_t) { 0, 0, (fard) / (fard - neard), 1 };
proj[3] = (vec4f_t) { 0, 0, (2 * fard * neard) / (neard - fard), 0 }; proj[3] = (vec4f_t) { 0, 0, (fard * neard) / (neard - fard), 0 };
// convert 0..1 depth buffer range to -1..1
static mat4f_t depth_range = {
{ 1, 0, 0, 0},
{ 0, 1, 0, 0},
{ 0, 0, 2, 0},
{ 0, 0,-1, 1},
};
mmulf (proj, depth_range, proj);
} }
void void
@ -90,9 +99,10 @@ glsl_R_SetupFrame (void)
r_framecount++; r_framecount++;
VectorCopy (r_refdef.viewposition, r_origin); VectorCopy (r_refdef.viewposition, r_origin);
VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 1, 0, 0, 0 }), vpn); vec4f_t rotation = r_refdef.viewrotation;
VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, -1, 0, 0 }), vright); VectorCopy (qvmulf (rotation, (vec4f_t) { 1, 0, 0, 0 }), vpn);
VectorCopy (qvmulf (r_refdef.viewrotation, (vec4f_t) { 0, 0, 1, 0 }), vup); VectorCopy (qvmulf (rotation, (vec4f_t) { 0,-1, 0, 0 }), vright);
VectorCopy (qvmulf (rotation, (vec4f_t) { 0, 0, 1, 0 }), vup);
R_SetFrustum (); R_SetFrustum ();
@ -105,7 +115,7 @@ R_SetupView (void)
{ {
float x, y, w, h; float x, y, w, h;
static mat4f_t z_up = { static mat4f_t z_up = {
{ 0, 0, -1, 0}, { 0, 0, 1, 0},
{-1, 0, 0, 0}, {-1, 0, 0, 0},
{ 0, 1, 0, 0}, { 0, 1, 0, 0},
{ 0, 0, 0, 1}, { 0, 0, 0, 1},