[renderer] Move a couple functions to using vec4f_t

Makes for a few less FIXMEs and better consistency with vectors.
This commit is contained in:
Bill Currie 2022-03-30 23:50:12 +09:00
parent da42aaf423
commit a6df8ab995
13 changed files with 54 additions and 64 deletions

View file

@ -62,7 +62,7 @@ void R_LoadSkys (const char *);
void R_ClearEfrags (void);
void R_FindNearLights (const vec3_t pos, int count, dlight_t **lights);
void R_FindNearLights (vec4f_t pos, int count, dlight_t **lights);
dlight_t *R_AllocDlight (int key);
void R_DecayLights (double frametime);
void R_ClearDlights (void);
@ -78,8 +78,9 @@ void R_MarkLeaves (void);
void GL_SetPalette (void *data, const byte *palette);
void GLSL_SetPalette (void *data, const byte *palette);
int R_BillboardFrame (struct entity_s *ent, int orientation, const vec3_t cameravec,
vec3_t bbup, vec3_t bbright, vec3_t bbfwd);
int R_BillboardFrame (struct entity_s *ent, int orientation,
vec4f_t cameravec,
vec4f_t *bbup, vec4f_t *bbright, vec4f_t *bbfwd);
mspriteframe_t *R_GetSpriteFrame (const msprite_t *sprite,
const struct animation_s *animation);

View file

@ -119,7 +119,7 @@ void R_DrawEntitiesOnList (struct entqueue_s *queue);
extern plane_t screenedge[4];
extern vec3_t r_entorigin;
extern vec4f_t r_entorigin;
extern int r_visframecount;
@ -307,7 +307,7 @@ void R_TimeRefresh_f (void);
void R_PrintAliasStats (void);
void R_PrintTimes (void);
void R_AnimateLight (void);
int R_LightPoint (mod_brush_t *brush, const vec3_t p);
int R_LightPoint (mod_brush_t *brush, vec4f_t p);
void R_SetupFrame (void);
void R_cshift_f (void);
void R_EmitEdge (mvertex_t *pv0, mvertex_t *pv1);

View file

@ -434,7 +434,7 @@ gl_R_DrawAliasModel (entity_t *e)
if (scale[0] != 1.0) {
radius *= scale[0];
}
if (R_CullSphere (r_refdef.frustum, &origin[0], radius)) {//FIXME
if (R_CullSphere (r_refdef.frustum, (vec_t*)&origin, radius)) {//FIXME
return;
}
@ -449,7 +449,7 @@ gl_R_DrawAliasModel (entity_t *e)
float lightadj;
// get lighting information
R_LightPoint (&r_refdef.worldmodel->brush, &origin[0]);//FIXME
R_LightPoint (&r_refdef.worldmodel->brush, origin);//FIXME
lightadj = (ambientcolor[0] + ambientcolor[1] + ambientcolor[2]) / 765.0;

View file

@ -71,8 +71,7 @@ R_DrawSpriteModel_f (entity_t *e)
// don't bother culling, it's just a single polygon without a surface cache
frame = R_GetSpriteFrame (sprite, &e->animation);
if (!R_BillboardFrame (e, sprite->type, &cameravec[0],
&up[0], &right[0], &pn[0])) {
if (!R_BillboardFrame (e, sprite->type, cameravec, &up, &right, &pn)) {
// the orientation is undefined so can't draw the sprite
return;
}

View file

@ -161,7 +161,7 @@ calc_lighting (entity_t *ent, float *ambient, float *shadelight,
entorigin = Transform_GetWorldPosition (ent->transform);
VectorSet ( -1, 0, 0, lightvec); //FIXME
light = R_LightPoint (&r_refdef.worldmodel->brush, &entorigin[0]);
light = R_LightPoint (&r_refdef.worldmodel->brush, entorigin);
*ambient = max (light, max (ent->renderer.model->min_light,
ent->renderer.min_light) * 128);
*shadelight = *ambient;

View file

@ -225,9 +225,9 @@ glsl_R_DrawIQM (entity_t *ent)
entorigin = mat[3];
mmulf (mvp_mat, iqm_vp, mat);
R_LightPoint (&r_refdef.worldmodel->brush, &entorigin[0]);//FIXME min_light?
R_LightPoint (&r_refdef.worldmodel->brush, entorigin);//FIXME min_light?
VectorScale (ambientcolor, 1/255.0, ambientcolor);
R_FindNearLights (&entorigin[0], MAX_IQM_LIGHTS, lights);//FIXME
R_FindNearLights (entorigin, MAX_IQM_LIGHTS, lights);
blend = R_IQMGetLerpedFrames (ent, iqm);
frame = R_IQMBlendFrames (iqm, ent->animation.pose1, ent->animation.pose2,

View file

@ -227,8 +227,7 @@ glsl_R_DrawSprite (entity_t *ent)
vec4f_t origin = Transform_GetWorldPosition (ent->transform);
cameravec = r_refdef.frame.position - origin;
if (!R_BillboardFrame (ent, sprite->type, &cameravec[0],
&sup[0], &sright[0], &spn[0])) {
if (!R_BillboardFrame (ent, sprite->type, cameravec, &sup, &sright, &spn)) {
// the orientation is undefined so can't draw the sprite
return;
}

View file

@ -46,10 +46,10 @@
int
R_BillboardFrame (entity_t *ent, int orientation, const vec3_t cameravec,
vec3_t bbup, vec3_t bbright, vec3_t bbfwd)
R_BillboardFrame (entity_t *ent, int orientation, vec4f_t cameravec,
vec4f_t *bbup, vec4f_t *bbright, vec4f_t *bbfwd)
{
vec3_t tvec;
vec4f_t tvec;
float dot;
switch (orientation) {
@ -57,23 +57,21 @@ R_BillboardFrame (entity_t *ent, int orientation, const vec3_t cameravec,
// the billboard has its up vector parallel with world up, and
// its right vector perpendicular to cameravec.
// Undefined if the camera is too close to the entity.
VectorNegate (cameravec, tvec);
VectorNormalize (tvec);
tvec = -normalf (cameravec);
dot = tvec[2]; // DotProduct (tvec, world up)
if ((dot > 0.999848) || (dot < -0.999848)) // cos(1 degree)
return 0;
VectorSet (0, 0, 1, bbup);
*bbup = (vec4f_t) { 0, 0, 1, 0 };
//CrossProduct(bbup, -cameravec, bbright)
VectorSet (tvec[1], -tvec[0], 0, bbright);
VectorNormalize (bbright);
*bbright = normalf ((vec4f_t) { tvec[1], -tvec[0], 0, 0 });
//CrossProduct (bbright, bbup, bbfwd)
VectorSet (-bbright[1], bbright[0], 0, bbfwd);
*bbfwd = (vec4f_t) { -(*bbright)[1], (*bbright)[0], 0, 0};
break;
case SPR_VP_PARALLEL:
// the billboard always has the same orientation as the camera
VectorCopy (r_refdef.frame.up, bbup);
VectorCopy (r_refdef.frame.right, bbright);
VectorCopy (r_refdef.frame.forward, bbfwd);
*bbup = r_refdef.frame.up;
*bbright = r_refdef.frame.right;
*bbfwd = r_refdef.frame.forward;
break;
case SPR_VP_PARALLEL_UPRIGHT:
// the billboar has its up vector parallel with world up, and
@ -82,10 +80,10 @@ R_BillboardFrame (entity_t *ent, int orientation, const vec3_t cameravec,
dot = r_refdef.frame.forward[2];
if ((dot > 0.999848) || (dot < -0.999848)) // cos(1 degree)
return 0;
VectorSet (0, 0, 1, bbup);
VectorSet (r_refdef.frame.forward[1], -r_refdef.frame.forward[0], 0, bbright);
VectorNormalize (bbright);
VectorSet (-bbright[1], bbright[0], 0, bbfwd);
*bbup = (vec4f_t) { 0, 0, 1, 0 };
*bbright = normalf ((vec4f_t) {r_refdef.frame.forward[1],
-r_refdef.frame.forward[0], 0, 0 });
*bbfwd = (vec4f_t) { -(*bbright)[1], (*bbright)[0], 0, 0};
break;
case SPR_ORIENTED:
{
@ -93,9 +91,9 @@ R_BillboardFrame (entity_t *ent, int orientation, const vec3_t cameravec,
// entity's orientation.
mat4f_t mat;
Transform_GetWorldMatrix (ent->transform, mat);
VectorCopy (mat[0], bbfwd);
VectorNegate (mat[1], bbright);
VectorCopy (mat[2], bbup);
*bbfwd = mat[0];
*bbright = mat[1];
*bbup = mat[2];
}
break;
case SPR_VP_PARALLEL_ORIENTED:
@ -108,9 +106,9 @@ R_BillboardFrame (entity_t *ent, int orientation, const vec3_t cameravec,
// FIXME needs proper testing (need to find, make, or fake a
// parallel oriented sprite)
mmulf (spmat, r_refdef.camera, entmat);
VectorCopy (spmat[0], bbfwd);
VectorNegate (spmat[1], bbright);
VectorCopy (spmat[1], bbup);
*bbfwd = spmat[0];
*bbright = spmat[1];
*bbup = spmat[2];
}
break;
default:

View file

@ -52,7 +52,7 @@ vec3_t ambientcolor;
unsigned int r_maxdlights;
void
R_FindNearLights (const vec3_t pos, int count, dlight_t **lights)
R_FindNearLights (vec4f_t pos, int count, dlight_t **lights)
{
float *scores = alloca (count * sizeof (float));
float score;
@ -399,8 +399,8 @@ calc_lighting_3 (msurface_t *surf, int ds, int dt)
}
static int
RecursiveLightPoint (mod_brush_t *brush, mnode_t *node, const vec3_t start,
const vec3_t end)
RecursiveLightPoint (mod_brush_t *brush, mnode_t *node, vec4f_t start,
vec4f_t end)
{
unsigned i;
int r, s, t, ds, dt, side;
@ -408,7 +408,6 @@ RecursiveLightPoint (mod_brush_t *brush, mnode_t *node, const vec3_t start,
plane_t *plane;
msurface_t *surf;
mtexinfo_t *tex;
vec3_t mid;
loop:
if (node->contents < 0)
return -1; // didn't hit anything
@ -425,9 +424,7 @@ loop:
}
frac = front / (front - back);
mid[0] = start[0] + (end[0] - start[0]) * frac;
mid[1] = start[1] + (end[1] - start[1]) * frac;
mid[2] = start[2] + (end[2] - start[2]) * frac;
vec4f_t mid = start + (end - start) * frac;
// go down front side
r = RecursiveLightPoint (brush, node->children[side], start, mid);
@ -476,22 +473,16 @@ loop:
}
int
R_LightPoint (mod_brush_t *brush, const vec3_t p)
R_LightPoint (mod_brush_t *brush, vec4f_t p)
{
vec3_t end;
int r;
if (!brush->lightdata) {
// allow dlights to have some effect, so don't go /quite/ fullbright
ambientcolor[2] = ambientcolor[1] = ambientcolor[0] = 200;
return 200;
}
end[0] = p[0];
end[1] = p[1];
end[2] = p[2] - 2048;
r = RecursiveLightPoint (brush, brush->nodes, p, end);
vec4f_t end = p - (vec4f_t) { 0, 0, 2048, 0 };
int r = RecursiveLightPoint (brush, brush->nodes, p, end);
if (r == -1)
r = 0;

View file

@ -62,7 +62,7 @@ int r_framecount = 1; // so frame counts initialized to 0 don't match
vec3_t modelorg; // modelorg is the viewpoint relative to
// the currently rendering entity
vec3_t base_modelorg;
vec3_t r_entorigin; // the currently rendering entity in world
vec4f_t r_entorigin; // the currently rendering entity in world
// coordinates
// screen size info
refdef_t r_refdef;

View file

@ -52,7 +52,7 @@ spritedesc_t r_spritedesc;
static void
R_RotateSprite (const vec3_t relvieworg, float beamlength, vec3_t org)
R_RotateSprite (vec4f_t relvieworg, float beamlength, vec3_t org)
{
vec3_t vec;
@ -244,25 +244,27 @@ void
R_DrawSprite (entity_t *ent)
{
msprite_t *sprite = ent->renderer.model->cache.data;
vec3_t relvieworg;
VectorSubtract (r_refdef.frame.position, r_entorigin, relvieworg);
vec4f_t cameravec = r_refdef.frame.position - r_entorigin;
r_spritedesc.pspriteframe = R_GetSpriteFrame (sprite, &ent->animation);
sprite_width = r_spritedesc.pspriteframe->width;
sprite_height = r_spritedesc.pspriteframe->height;
if (!R_BillboardFrame (ent, sprite->type, relvieworg,
r_spritedesc.vup,
r_spritedesc.vright,
r_spritedesc.vfwd)) {
vec4f_t up = {};
vec4f_t right = {};
vec4f_t fwd = {};
if (!R_BillboardFrame (ent, sprite->type, cameravec, &up, &right, &fwd)) {
// the orientation is undefined so can't draw the sprite
return;
}
VectorCopy (up, r_spritedesc.vup);//FIXME
VectorCopy (right, r_spritedesc.vright);
VectorCopy (fwd, r_spritedesc.vfwd);
vec3_t org;
R_RotateSprite (relvieworg, sprite->beamlength, org);
R_RotateSprite (cameravec, sprite->beamlength, org);
R_SetupAndDrawSprite (org);
}

View file

@ -160,7 +160,7 @@ update_lights (vulkan_ctx_t *ctx)
light_data->distFactor2 = 1 / 16384.0;
light_data->lightCount = 0;
R_FindNearLights (&r_refdef.frame.position[0], MaxLights - 1, lights);
R_FindNearLights (r_refdef.frame.position, MaxLights - 1, lights);
for (int i = 0; i < MaxLights - 1; i++) {
if (!lights[i]) {
break;

View file

@ -120,8 +120,8 @@ Vulkan_DrawSprite (entity_t *ent, qfv_renderframe_t *rFrame)
mat[3] = Transform_GetWorldPosition (ent->transform);
vec4f_t cameravec = r_refdef.frame.position - mat[3];
R_BillboardFrame (ent, sprite->type, &cameravec[0],
&mat[2][0], &mat[1][0], &mat[0][0]);
R_BillboardFrame (ent, sprite->type, cameravec,
&mat[2], &mat[1], &mat[0]);
mat[0] = -mat[0];
emit_commands (sframe->cmdSet.a[QFV_spriteDepth],