Skip to content

Commit 5407497

Browse files
committed
renderer: introduce R_TBNtoQtangentsFast() and floatToSnorm16_fast()
1 parent 11e6b88 commit 5407497

2 files changed

Lines changed: 26 additions & 3 deletions

File tree

src/engine/renderer/tr_local.h

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,15 @@ static inline void floatToSnorm16( const vec4_t in, i16vec4_t out )
116116
out[ 3 ] = floatToSnorm16( in[ 3 ] );
117117
}
118118

119+
static inline void floatToSnorm16_fast( const vec4_t in, i16vec4_t out )
120+
{
121+
// Just truncate them all.
122+
out[ 0 ] = in[ 0 ] * 32767.0f;
123+
out[ 1 ] = in[ 1 ] * 32767.0f;
124+
out[ 2 ] = in[ 2 ] * 32767.0f;
125+
out[ 3 ] = in[ 3 ] * 32767.0f;
126+
}
127+
119128
static inline void snorm16ToFloat( const i16vec4_t in, vec4_t out )
120129
{
121130
out[ 0 ] = snorm16ToFloat( in[ 0 ] );
@@ -2868,7 +2877,13 @@ inline bool checkGLErrors()
28682877
* minimal error.
28692878
*/
28702879
void R_TBNtoQtangents( const vec3_t tangent, const vec3_t binormal,
2871-
const vec3_t normal, i16vec4_t qtangent );
2880+
const vec3_t normal, i16vec4_t qtangent, bool fast = false );
2881+
2882+
inline void R_TBNtoQtangentsFast( const vec3_t tangent, const vec3_t binormal,
2883+
const vec3_t normal, i16vec4_t qtangent )
2884+
{
2885+
R_TBNtoQtangents( tangent, binormal, normal, qtangent, true );
2886+
}
28722887

28732888
void R_QtangentsToTBN( const i16vec4_t qtangent, vec3_t tangent,
28742889
vec3_t binormal, vec3_t normal );

src/engine/renderer/tr_main.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ void R_QtangentsToNormal( const i16vec4_t qtangent, vec3_t normal )
168168
}
169169

170170
void R_TBNtoQtangents( const vec3_t tangent, const vec3_t binormal,
171-
const vec3_t normal, i16vec4_t qtangent )
171+
const vec3_t normal, i16vec4_t qtangent, bool fast )
172172
{
173173
vec3_t tangent2, binormal2, normal2;
174174
vec4_t q;
@@ -292,7 +292,15 @@ void R_TBNtoQtangents( const vec3_t tangent, const vec3_t binormal,
292292
}
293293

294294
i16vec4_t resqtangent;
295-
floatToSnorm16( q, resqtangent );
295+
296+
if ( fast )
297+
{
298+
floatToSnorm16_fast( q, resqtangent );
299+
}
300+
else
301+
{
302+
floatToSnorm16( q, resqtangent );
303+
}
296304

297305
if( resqtangent[ 3 ] == 0 )
298306
{

0 commit comments

Comments
 (0)