Skip to content

Commit

Permalink
engine: use VectorNormalizeFast() when the return value isn't used
Browse files Browse the repository at this point in the history
  • Loading branch information
illwieckz committed Dec 9, 2024
1 parent 9a8dbdb commit 1fc022f
Show file tree
Hide file tree
Showing 14 changed files with 53 additions and 53 deletions.
26 changes: 13 additions & 13 deletions src/engine/qcommon/q_math.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ void MakeNormalVectors( const vec3_t forward, vec3_t right, vec3_t up )

d = DotProduct( right, forward );
VectorMA( right, -d, forward, right );
VectorNormalize( right );
VectorNormalizeFast( right );
CrossProduct( right, forward, up );
}

Expand Down Expand Up @@ -1082,7 +1082,7 @@ void PerpendicularVector( vec3_t dst, const vec3_t src )
/*
* * normalize the result
*/
VectorNormalize( dst );
VectorNormalizeFast( dst );
}

// Ridah
Expand All @@ -1099,13 +1099,13 @@ void GetPerpendicularViewVector( const vec3_t point, const vec3_t p1, const vec3
vec3_t v1, v2;

VectorSubtract( point, p1, v1 );
VectorNormalize( v1 );
VectorNormalizeFast( v1 );

VectorSubtract( point, p2, v2 );
VectorNormalize( v2 );
VectorNormalizeFast( v2 );

CrossProduct( v1, v2, up );
VectorNormalize( up );
VectorNormalizeFast( up );
}

/*
Expand All @@ -1119,7 +1119,7 @@ void ProjectPointOntoVector( const vec3_t point, const vec3_t vStart, const vec3

VectorSubtract( point, vStart, pVec );
VectorSubtract( vEnd, vStart, vec );
VectorNormalize( vec );
VectorNormalizeFast( vec );
// project onto the directional vector for this segment
VectorMA( vStart, DotProduct( pVec, vec ), vec, vProj );
}
Expand Down Expand Up @@ -1255,7 +1255,7 @@ void ProjectPointOntoVectorBounded( const vec3_t point, const vec3_t vStart, con

VectorSubtract( point, vStart, pVec );
VectorSubtract( vEnd, vStart, vec );
VectorNormalize( vec );
VectorNormalizeFast( vec );
// project onto the directional vector for this segment
VectorMA( vStart, DotProduct( pVec, vec ), vec, vProj );

Expand Down Expand Up @@ -2684,16 +2684,16 @@ void MatrixLookAtLH( matrix_t m, const vec3_t eye, const vec3_t dir, const vec3_

#if 1
CrossProduct( up, dir, sideN );
VectorNormalize( sideN );
VectorNormalizeFast( sideN );

CrossProduct( dir, sideN, upN );
VectorNormalize( upN );
VectorNormalizeFast( upN );
#else
CrossProduct( dir, up, sideN );
VectorNormalize( sideN );
VectorNormalizeFast( sideN );
CrossProduct( sideN, dir, upN );
VectorNormalize( upN );
VectorNormalizeFast( upN );
#endif

VectorNormalize2( dir, dirN );
Expand Down Expand Up @@ -2723,10 +2723,10 @@ void MatrixLookAtRH( matrix_t m, const vec3_t eye, const vec3_t dir, const vec3_
vec3_t sideN;

CrossProduct( dir, up, sideN );
VectorNormalize( sideN );
VectorNormalizeFast( sideN );

CrossProduct( sideN, dir, upN );
VectorNormalize( upN );
VectorNormalizeFast( upN );

VectorNormalize2( dir, dirN );

Expand Down
10 changes: 5 additions & 5 deletions src/engine/renderer/tr_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1608,18 +1608,18 @@ static void RB_SetupLightForShadowing( trRefLight_t *light, int index,
{
// original light direction is from surface to light
VectorInverse( lightDirection );
VectorNormalize( lightDirection );
VectorNormalizeFast( lightDirection );

VectorCopy( backEnd.viewParms.orientation.origin, viewOrigin );
VectorCopy( backEnd.viewParms.orientation.axis[ 0 ], viewDirection );
VectorNormalize( viewDirection );
VectorNormalizeFast( viewDirection );

// calculate new up dir
CrossProduct( lightDirection, viewDirection, side );
VectorNormalize( side );
VectorNormalizeFast( side );

CrossProduct( side, lightDirection, up );
VectorNormalize( up );
VectorNormalizeFast( up );

vectoangles( lightDirection, angles );
MatrixFromAngles( rotationMatrix, angles[ PITCH ], angles[ YAW ], angles[ ROLL ] );
Expand Down Expand Up @@ -2736,7 +2736,7 @@ void RB_RunVisTests( )
Tess_MapVBOs( false );
VectorSubtract( backEnd.orientation.viewOrigin,
test->position, diff );
VectorNormalize( diff );
VectorNormalizeFast( diff );
VectorMA( test->position, test->depthAdjust, diff, center );

VectorScale( backEnd.viewParms.orientation.axis[ 1 ],
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_bsp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5042,7 +5042,7 @@ void RE_LoadWorldMap( const char *name )
tr.sunDirection[ 1 ] = 0.3f;
tr.sunDirection[ 2 ] = 0.9f;

VectorNormalize( tr.sunDirection );
VectorNormalizeFast( tr.sunDirection );

// set default ambient color
tr.worldEntity.ambientLight[ 0 ] = r_forceAmbient->value;
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_curve.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ srfGridMesh_t *R_SubdividePatchToGrid( int width, int height, srfVert_t points[
// dist-from-midpoint
VectorSubtract( midxyz, gridctrl[ i ][ j ].xyz, midxyz );
VectorSubtract( gridctrl[ i ][ j + 2 ].xyz, gridctrl[ i ][ j ].xyz, direction );
VectorNormalize( direction );
VectorNormalizeFast( direction );

d = DotProduct( midxyz, direction );
VectorScale( direction, d, projected );
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_flares.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ void RB_AddFlare( void *surface, int fogNum, vec3_t point, vec3_t color, vec3_t
if ( normal )
{
VectorSubtract( backEnd.viewParms.orientation.origin, point, local );
VectorNormalize( local );
VectorNormalizeFast( local );
d1 = DotProduct( local, normal );
d1 *= ( 1.0 - distLerp );
d1 += d2;
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/tr_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1121,7 +1121,7 @@ void R_UploadImage( const char *name, const byte **dataArray, int numLayers, int
n[ 1 ] = Tex_ByteToFloat( scaledBuffer[ j * 4 + 1 ] );
n[ 2 ] = Tex_ByteToFloat( scaledBuffer[ j * 4 + 2 ] );

VectorNormalize( n );
VectorNormalizeFast( n );

scaledBuffer[ j * 4 + 0 ] = Tex_FloatToByte( n[ 0 ] );
scaledBuffer[ j * 4 + 1 ] = Tex_FloatToByte( n[ 1 ] );
Expand Down Expand Up @@ -2497,7 +2497,7 @@ static void R_CreateRandomNormalsImage()
angle = 2.0f * M_PI * r; // / 360.0f;

VectorSet( n, cosf( angle ), sinf( angle ), r );
VectorNormalize( n );
VectorNormalizeFast( n );

ptr[ 0 ] = ( byte )( 128 + 127 * n[ 0 ] );
ptr[ 1 ] = ( byte )( 128 + 127 * n[ 1 ] );
Expand Down
14 changes: 7 additions & 7 deletions src/engine/renderer/tr_light.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ int R_LightForPoint( vec3_t point, vec3_t ambientLight, vec3_t directedLight, ve
lightDir[ 1 ] = copysignf( 1.0f - fabsf( X ), Y );
}

VectorNormalize( lightDir );
VectorNormalizeFast( lightDir );

if ( ambientLight[ 0 ] < r_forceAmbient->value &&
ambientLight[ 1 ] < r_forceAmbient->value &&
Expand Down Expand Up @@ -335,7 +335,7 @@ void R_SetupEntityLighting( const trRefdef_t *refdef, trRefEntity_t *ent, vec3_t
ent->directedLight[ 2 ] = 224.0f / 255.0f;

VectorSet( ent->lightDir, -1, 1, 1.25 );
VectorNormalize( ent->lightDir );
VectorNormalizeFast( ent->lightDir );
}

if ( ( ent->e.renderfx & RF_MINLIGHT ) ) // && VectorLength(ent->ambientLight) <= 0)
Expand Down Expand Up @@ -368,7 +368,7 @@ void R_SetupLightOrigin( trRefLight_t *light )
{
MatrixTransformPoint( light->transformMatrix, light->l.center, transformed );
VectorSubtract( transformed, light->l.origin, light->direction );
VectorNormalize( light->direction );
VectorNormalizeFast( light->direction );

VectorMA( light->l.origin, 10000, light->direction, light->origin );
}
Expand All @@ -378,7 +378,7 @@ void R_SetupLightOrigin( trRefLight_t *light )

MatrixTransformPoint( light->transformMatrix, down, transformed );
VectorSubtract( transformed, light->l.origin, light->direction );
VectorNormalize( light->direction );
VectorNormalizeFast( light->direction );

VectorMA( light->l.origin, 10000, light->direction, light->origin );

Expand Down Expand Up @@ -614,7 +614,7 @@ void R_SetupLightFrustum( trRefLight_t *light )
{
VectorMA( light->l.origin, light->l.radius, axis[ i ], planeOrigin );
VectorNegate( axis[ i ], planeNormal );
VectorNormalize( planeNormal );
VectorNormalizeFast( planeNormal );

VectorCopy( planeNormal, light->frustum[ i ].normal );
light->frustum[ i ].dist = DotProduct( planeOrigin, planeNormal );
Expand All @@ -624,7 +624,7 @@ void R_SetupLightFrustum( trRefLight_t *light )
{
VectorMA( light->l.origin, -light->l.radius, axis[ i ], planeOrigin );
VectorCopy( axis[ i ], planeNormal );
VectorNormalize( planeNormal );
VectorNormalizeFast( planeNormal );

VectorCopy( planeNormal, light->frustum[ i + 3 ].normal );
light->frustum[ i + 3 ].dist = DotProduct( planeOrigin, planeNormal );
Expand Down Expand Up @@ -714,7 +714,7 @@ void R_SetupLightProjection( trRefLight_t *light )
float uLen = VectorNormalize2( light->l.projUp, up );

CrossProduct( up, right, normal );
VectorNormalize( normal );
VectorNormalizeFast( normal );

vec_t dist = DotProduct( light->l.projTarget, normal );

Expand Down
14 changes: 7 additions & 7 deletions src/engine/renderer/tr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void R_CalcFaceNormal( vec3_t normal,
VectorSubtract( v1, v0, v );
CrossProduct( u, v, normal );

VectorNormalize( normal );
VectorNormalizeFast( normal );
}


Expand Down Expand Up @@ -97,8 +97,8 @@ void R_CalcTangents( vec3_t tangent, vec3_t binormal,
binormal[1] = dtx[0] * dpy[1] - dpx[1] * dty[0];
binormal[2] = dtx[0] * dpy[2] - dpx[2] * dty[0];

VectorNormalize( tangent );
VectorNormalize( binormal );
VectorNormalizeFast( tangent );
VectorNormalizeFast( binormal );
}

void R_CalcTangents( vec3_t tangent, vec3_t binormal,
Expand Down Expand Up @@ -138,8 +138,8 @@ void R_CalcTangents( vec3_t tangent, vec3_t binormal,
binormal[1] = dtx[0] * dpy[1] - dpx[1] * dty[0];
binormal[2] = dtx[0] * dpy[2] - dpx[2] * dty[0];

VectorNormalize( tangent );
VectorNormalize( binormal );
VectorNormalizeFast( tangent );
VectorNormalizeFast( binormal );
}


Expand Down Expand Up @@ -1660,7 +1660,7 @@ static void R_SetupPortalFrustum( const viewParms_t& oldParms, const orientation

for (int i = 0; i < 4; i++)
{
VectorNormalize(frustum[i].normal);
VectorNormalizeFast(frustum[i].normal);
SetPlaneSignbits(&frustum[i]);
frustum[i].dist = 0; // all side planes intersect the view origin
frustum[i].type = PLANE_NON_AXIAL;
Expand Down Expand Up @@ -2271,7 +2271,7 @@ void R_TransformShadowLight( trRefLight_t *light ) {

light->l.rlType = refLightType_t::RL_PROJ;
VectorSubtract( mids, light->l.origin, forward );
VectorNormalize( forward );
VectorNormalizeFast( forward );
PerpendicularVector( right, forward );
CrossProduct( forward, right, up );

Expand Down
12 changes: 6 additions & 6 deletions src/engine/renderer/tr_model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,9 +469,9 @@ int RE_LerpTagET( orientation_t *tag, const refEntity_t *refent, const char *tag
VectorCopy( tag->axis[ 1 ], tag->axis[ 2 ] );
VectorCopy( tag->axis[ 0 ], tag->axis[ 1 ] );
VectorCopy( tmp, tag->axis[ 0 ] );
VectorNormalize( tag->axis[ 0 ] );
VectorNormalize( tag->axis[ 1 ] );
VectorNormalize( tag->axis[ 2 ] );
VectorNormalizeFast( tag->axis[ 0 ] );
VectorNormalizeFast( tag->axis[ 1 ] );
VectorNormalizeFast( tag->axis[ 2 ] );
return retval;
}
else if ( model->type == modtype_t::MOD_MESH )
Expand All @@ -496,9 +496,9 @@ int RE_LerpTagET( orientation_t *tag, const refEntity_t *refent, const char *tag
tag->axis[ 2 ][ i ] = start->axis[ 2 ][ i ] * backLerp + end->axis[ 2 ][ i ] * frontLerp;
}

VectorNormalize( tag->axis[ 0 ] );
VectorNormalize( tag->axis[ 1 ] );
VectorNormalize( tag->axis[ 2 ] );
VectorNormalizeFast( tag->axis[ 0 ] );
VectorNormalizeFast( tag->axis[ 1 ] );
VectorNormalizeFast( tag->axis[ 2 ] );

return retval;
}
Expand Down
4 changes: 2 additions & 2 deletions src/engine/renderer/tr_model_md3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,8 @@ bool R_LoadMD3( model_t *mod, int lod, const void *buffer, const char *modName )

for ( j = 0; j < surf->numVerts; j++ )
{
VectorNormalize( tangents[ j ] );
VectorNormalize( binormals[ j ] );
VectorNormalizeFast( tangents[ j ] );
VectorNormalizeFast( binormals[ j ] );
R_TBNtoQtangents(
tangents[ j ], binormals[ j ],
surf->normals[ f * surf->numVerts + j ].normal,
Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/tr_model_md5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ static void CalcTangentSpaces( md5Surface_t &surf, const vec2_t *texCoords )
v = surf.verts;
for ( unsigned j = 0; j < surf.numVerts; j++, v++ )
{
VectorNormalize( v->tangent );
VectorNormalizeFast( v->tangent );
v->tangent[ 3 ] = 0;
VectorNormalize( v->binormal );
VectorNormalizeFast( v->binormal );
v->binormal[ 3 ] = 0;
VectorNormalize( v->normal );
VectorNormalizeFast( v->normal );
v->normal[ 3 ] = 0;
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/engine/renderer/tr_shade_calc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,12 +597,12 @@ static void Autosprite2Deform( uint32_t numVertexes )
vec3_t quadCenter;
VectorMA( sides[ 2 ].firstVert, 0.5f, sides[ 2 ].vector, quadCenter );
VectorSubtract( quadCenter, backEnd.viewParms.orientation.origin, forward );
VectorNormalize( forward );
VectorNormalizeFast( forward );
}

vec3_t newMinorAxis;
CrossProduct( sides[ 1 ].vector, forward, newMinorAxis);
VectorNormalize( newMinorAxis );
VectorNormalizeFast( newMinorAxis );
plane_t projection;
VectorNormalize2( sides[ 0 ].vector, projection.normal );
projection.dist = DotProduct( sides[ 0 ].firstVert, projection.normal )
Expand All @@ -629,7 +629,7 @@ static void Autosprite2Deform( uint32_t numVertexes )
{
VectorNegate( normal, normal );
}
VectorNormalize( normal );
VectorNormalizeFast( normal );
// What the fuck are tangent and binormal even for?
// I'll just put in zeroes and let R_TBNtoQtangents make some up for me.
R_TBNtoQtangents( vec3_origin, vec3_origin, normal, qtangents );
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4099,7 +4099,7 @@ static bool ParseShader( const char *_text )

tr.sunLight[ 2 ] = atof( token );

VectorNormalize( tr.sunLight );
VectorNormalizeFast( tr.sunLight );

token = COM_ParseExt2( text, false );

Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1371,7 +1371,7 @@ static void Tess_SurfaceFlare( srfFlare_t *surf )

VectorMA( surf->origin, 2.0F, surf->normal, origin );
VectorSubtract( origin, backEnd.viewParms.orientation.origin, dir );
VectorNormalize( dir );
VectorNormalizeFast( dir );
d = -DotProduct( dir, surf->normal );
VectorMA( origin, r_ignore->value, dir, origin );

Expand Down

0 comments on commit 1fc022f

Please sign in to comment.