From 04ba7243828378c9b3c50c5a243022cfcda40654 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 14 Mar 2022 11:56:10 +0900 Subject: [PATCH] [sw] Clean up alias and iqm matrix setup This removes some FIXMEs and might even speed things up ever so slightly. --- include/r_shared.h | 1 + libs/video/renderer/sw/sw_ralias.c | 49 ++++++++---------------------- libs/video/renderer/sw/sw_riqm.c | 13 +------- libs/video/renderer/sw/sw_rmain.c | 1 + libs/video/renderer/sw/sw_rmisc.c | 4 +++ 5 files changed, 19 insertions(+), 49 deletions(-) diff --git a/include/r_shared.h b/include/r_shared.h index e3e3c585f..d24632139 100644 --- a/include/r_shared.h +++ b/include/r_shared.h @@ -72,6 +72,7 @@ extern byte color_black[4]; extern vec3_t vup, base_vup; extern vec3_t vfwd, base_vfwd; extern vec3_t vright, base_vright; +extern float r_viewmatrix[3][4]; #define NUMSTACKEDGES 2400 //2000 #define MINEDGES NUMSTACKEDGES diff --git a/libs/video/renderer/sw/sw_ralias.c b/libs/video/renderer/sw/sw_ralias.c index d8c5dd2e4..f99b2712d 100644 --- a/libs/video/renderer/sw/sw_ralias.c +++ b/libs/video/renderer/sw/sw_ralias.c @@ -61,7 +61,7 @@ auxvert_t *pauxverts; float ziscale; static model_t *pmodel; -static vec3_t alias_forward, alias_right, alias_up; +static vec3_t alias_forward, alias_left, alias_up; static maliasskindesc_t *pskindesc; @@ -356,50 +356,25 @@ static void R_AliasSetUpTransform (entity_t *ent, int trivial_accept) { int i; - float rotationmatrix[3][4], t2matrix[3][4]; - static float tmatrix[3][4]; - static float viewmatrix[3][4]; + float rotationmatrix[3][4]; mat4f_t mat; Transform_GetWorldMatrix (ent->transform, mat); VectorCopy (mat[0], alias_forward); - VectorNegate (mat[1], alias_right); + VectorCopy (mat[1], alias_left); VectorCopy (mat[2], alias_up); - tmatrix[0][0] = pmdl->scale[0]; - tmatrix[1][1] = pmdl->scale[1]; - tmatrix[2][2] = pmdl->scale[2]; - - tmatrix[0][3] = pmdl->scale_origin[0]; - tmatrix[1][3] = pmdl->scale_origin[1]; - tmatrix[2][3] = pmdl->scale_origin[2]; - -// TODO: can do this with simple matrix rearrangement - for (i = 0; i < 3; i++) { - t2matrix[i][0] = alias_forward[i]; - t2matrix[i][1] = -alias_right[i]; - t2matrix[i][2] = alias_up[i]; + rotationmatrix[i][0] = pmdl->scale[0] * alias_forward[i]; + rotationmatrix[i][1] = pmdl->scale[1] * alias_left[i]; + rotationmatrix[i][2] = pmdl->scale[2] * alias_up[i]; + rotationmatrix[i][3] = pmdl->scale_origin[0] * alias_forward[i] + + pmdl->scale_origin[1] * alias_left[i] + + pmdl->scale_origin[2] * alias_up[i] + + r_entorigin[i] - r_refdef.frame.position[i]; } - t2matrix[0][3] = r_entorigin[0] - r_refdef.frame.position[0]; - t2matrix[1][3] = r_entorigin[1] - r_refdef.frame.position[1]; - t2matrix[2][3] = r_entorigin[2] - r_refdef.frame.position[2]; - -// FIXME: can do more efficiently than full concatenation - R_ConcatTransforms (t2matrix, tmatrix, rotationmatrix); - -// TODO: should be global, set when vright, etc., set - VectorCopy (vright, viewmatrix[0]); - VectorCopy (vup, viewmatrix[1]); - VectorNegate (viewmatrix[1], viewmatrix[1]); - VectorCopy (vfwd, viewmatrix[2]); - -// viewmatrix[0][3] = 0; -// viewmatrix[1][3] = 0; -// viewmatrix[2][3] = 0; - - R_ConcatTransforms (viewmatrix, rotationmatrix, aliastransform); + R_ConcatTransforms (r_viewmatrix, rotationmatrix, aliastransform); // do the scaling up of x and y to screen coordinates as part of the transform // for the unclipped case (it would mess up clipping in the clipped case). @@ -603,7 +578,7 @@ R_AliasSetupLighting (alight_t *plighting) // rotate the lighting vector into the model's frame of reference r_plightvec[0] = DotProduct (plighting->plightvec, alias_forward); - r_plightvec[1] = -DotProduct (plighting->plightvec, alias_right); + r_plightvec[1] = DotProduct (plighting->plightvec, alias_left); r_plightvec[2] = DotProduct (plighting->plightvec, alias_up); } diff --git a/libs/video/renderer/sw/sw_riqm.c b/libs/video/renderer/sw/sw_riqm.c index b81c0951e..b4851c991 100644 --- a/libs/video/renderer/sw/sw_riqm.c +++ b/libs/video/renderer/sw/sw_riqm.c @@ -246,7 +246,6 @@ R_IQMSetUpTransform (entity_t *ent, int trivial_accept) { int i; float rotationmatrix[3][4]; - static float viewmatrix[3][4]; vec3_t forward, left, up; mat4f_t mat; @@ -267,17 +266,7 @@ R_IQMSetUpTransform (entity_t *ent, int trivial_accept) rotationmatrix[1][3] = r_entorigin[1] - r_refdef.frame.position[1]; rotationmatrix[2][3] = r_entorigin[2] - r_refdef.frame.position[2]; -// TODO: should be global, set when vright, etc., set - VectorCopy (vright, viewmatrix[0]); - VectorCopy (vup, viewmatrix[1]); - VectorNegate (viewmatrix[1], viewmatrix[1]); - VectorCopy (vfwd, viewmatrix[2]); - -// viewmatrix[0][3] = 0; -// viewmatrix[1][3] = 0; -// viewmatrix[2][3] = 0; - - R_ConcatTransforms (viewmatrix, rotationmatrix, aliastransform); + R_ConcatTransforms (r_viewmatrix, rotationmatrix, aliastransform); // do the scaling up of x and y to screen coordinates as part of the transform // for the unclipped case (it would mess up clipping in the clipped case). diff --git a/libs/video/renderer/sw/sw_rmain.c b/libs/video/renderer/sw/sw_rmain.c index 1dd5ffe87..19be8c6e0 100644 --- a/libs/video/renderer/sw/sw_rmain.c +++ b/libs/video/renderer/sw/sw_rmain.c @@ -110,6 +110,7 @@ int r_frustum_indexes[4 * 6]; vec3_t vup, base_vup; vec3_t vfwd, base_vfwd; vec3_t vright, base_vright; +float r_viewmatrix[3][4]; float r_aliastransition, r_resfudge; diff --git a/libs/video/renderer/sw/sw_rmisc.c b/libs/video/renderer/sw/sw_rmisc.c index c3f95b084..ebc56a34d 100644 --- a/libs/video/renderer/sw/sw_rmisc.c +++ b/libs/video/renderer/sw/sw_rmisc.c @@ -252,6 +252,10 @@ R_SetupFrame (void) VectorCopy (vup, base_vup); VectorCopy (modelorg, base_modelorg); + VectorCopy (vright, r_viewmatrix[0]); + VectorNegate (vup, r_viewmatrix[1]); + VectorCopy (vfwd, r_viewmatrix[2]); + R_SetSkyFrame (); R_SetUpFrustumIndexes ();