Skip to content

Commit

Permalink
Avoid half float round trips on skeletal model TCs
Browse files Browse the repository at this point in the history
  • Loading branch information
slipher committed Oct 9, 2024
1 parent af3e93f commit 4b8566e
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/engine/renderer/tr_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -2107,8 +2107,7 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED };
vec4_t binormal;
vec4_t normal;

f16vec2_t texCoords;
char _pad[ 4 ];
vec2_t texCoords;
uint32_t firstWeight;
uint32_t numWeights;

Expand Down Expand Up @@ -2241,7 +2240,7 @@ enum class realtimeLightingRenderer_t { LEGACY, TILED };
float *normals;
float *tangents;
float *bitangents;
f16_t *texcoords;
float *texcoords;
byte *blendIndexes;
byte *blendWeights;
byte *colors;
Expand Down
8 changes: 4 additions & 4 deletions src/engine/renderer/tr_model_iqm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
size += header->num_vertexes * 3 * sizeof(float); // normals
size += header->num_vertexes * 3 * sizeof(float); // tangents
size += header->num_vertexes * 3 * sizeof(float); // bitangents
size += header->num_vertexes * 2 * sizeof(f16_t); // texcoords
size += header->num_vertexes * 2 * sizeof(float); // texcoords
size += header->num_vertexes * 4 * sizeof(byte); // blendIndexes
size += header->num_vertexes * 4 * sizeof(byte); // blendWeights
size += header->num_vertexes * 4 * sizeof(byte); // colors
Expand Down Expand Up @@ -541,7 +541,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
IQModel->bitangents = (float *)ptr;
ptr = IQModel->bitangents + 3 * header->num_vertexes;

IQModel->texcoords = (f16_t *)ptr;
IQModel->texcoords = (float *)ptr;
ptr = IQModel->texcoords + 2 * header->num_vertexes;

IQModel->blendIndexes = (byte *)ptr;
Expand Down Expand Up @@ -725,7 +725,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
break;
case IQM_TEXCOORD:
for( int j = 0; j < n; j++ ) {
IQModel->texcoords[ j ] = floatToHalf( ((float *)IQMPtr( header, vertexarray->offset ))[ j ] );
IQModel->texcoords[ j ] = ((float *)IQMPtr( header, vertexarray->offset ))[ j ];
}
break;
case IQM_BLENDINDEXES:
Expand Down Expand Up @@ -793,7 +793,7 @@ bool R_LoadIQModel( model_t *mod, const void *buffer, int filesize,
{ ATTR_INDEX_BONE_FACTORS, GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT, boneFactorBuf, 4, sizeof( u16vec4_t ), 0 },
{ ATTR_INDEX_POSITION, GL_FLOAT, GL_SHORT, IQModel->positions, 3, sizeof( float[ 3 ] ), ATTR_OPTION_NORMALIZE },
{ ATTR_INDEX_QTANGENT, GL_SHORT, GL_SHORT, qtangentbuf, 4, sizeof( i16vec4_t ), ATTR_OPTION_NORMALIZE, },
{ ATTR_INDEX_TEXCOORD, GL_HALF_FLOAT, GL_HALF_FLOAT, IQModel->texcoords, 2, sizeof( f16_t[ 2 ] ), 0 },
{ ATTR_INDEX_TEXCOORD, GL_FLOAT, GL_HALF_FLOAT, IQModel->texcoords, 2, sizeof( float[ 2 ] ), 0 },
{ ATTR_INDEX_COLOR, GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE, IQModel->colors, 4, sizeof( u8vec4_t ), ATTR_OPTION_NORMALIZE },
};

Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_model_md5.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ bool R_LoadMD5( model_t *mod, const char *buffer, const char *modName )
{
token = COM_ParseExt2( &buf_p, false );
texCoords[ j ][ k ] = atof( token );
v->texCoords[ k ] = floatToHalf( texCoords[ j ][ k ] );
v->texCoords[ k ] = texCoords[ j ][ k ];
}

// skip )
Expand Down
2 changes: 1 addition & 1 deletion src/engine/renderer/tr_model_skel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ srfVBOMD5Mesh_t *R_GenerateMD5VBOSurface(
{ ATTR_INDEX_BONE_FACTORS, GL_UNSIGNED_SHORT, GL_UNSIGNED_SHORT, boneFactors, 4, sizeof(u16vec4_t), 0 },
{ ATTR_INDEX_POSITION, GL_FLOAT, GL_SHORT, &surf->verts[ 0 ].position, 3, sizeof(md5Vertex_t), ATTR_OPTION_NORMALIZE },
{ ATTR_INDEX_QTANGENT, GL_SHORT, GL_SHORT, qtangents, 4, sizeof(i16vec4_t), ATTR_OPTION_NORMALIZE },
{ ATTR_INDEX_TEXCOORD, GL_HALF_FLOAT, GL_HALF_FLOAT, &surf->verts[ 0 ].texCoords, 2, sizeof(md5Vertex_t), 0 },
{ ATTR_INDEX_TEXCOORD, GL_FLOAT, GL_HALF_FLOAT, &surf->verts[ 0 ].texCoords, 2, sizeof(md5Vertex_t), 0 },
{ ATTR_INDEX_COLOR, GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE, dummyColor, 4, 0, ATTR_OPTION_NORMALIZE },
};

Expand Down
19 changes: 6 additions & 13 deletions src/engine/renderer/tr_surface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1055,9 +1055,7 @@ static void Tess_SurfaceMD5( md5Surface_t *srf )

VectorCopy( position, tessVertex->xyz );

// FIXME: don't store data as half float?
tessVertex->texCoords[ 0 ] = halfToFloat( surfaceVertex->texCoords[ 0 ] );
tessVertex->texCoords[ 1 ] = halfToFloat( surfaceVertex->texCoords[ 1 ] );
Vector2Copy( surfaceVertex->texCoords, tessVertex->texCoords );
}
}
else
Expand Down Expand Up @@ -1100,8 +1098,7 @@ static void Tess_SurfaceMD5( md5Surface_t *srf )

R_TBNtoQtangents( tangent, binormal, normal, tessVertex->qtangents );

tessVertex->texCoords[ 0 ] = halfToFloat( surfaceVertex->texCoords[ 0 ] );
tessVertex->texCoords[ 1 ] = halfToFloat( surfaceVertex->texCoords[ 1 ] );
Vector2Copy( surfaceVertex->texCoords, tessVertex->texCoords );
}
}

Expand Down Expand Up @@ -1218,7 +1215,7 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {
float *modelNormal = model->normals + 3 * firstVertex;
float *modelTangent = model->tangents + 3 * firstVertex;
float *modelBitangent = model->bitangents + 3 * firstVertex;
f16_t *modelTexcoord = model->texcoords + 2 * firstVertex;
float *modelTexcoord = model->texcoords + 2 * firstVertex;
shaderVertex_t *tessVertex = tess.verts + tess.numVertexes;
shaderVertex_t *lastVertex = tessVertex + surf->num_vertexes;

Expand Down Expand Up @@ -1258,9 +1255,7 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {

VectorCopy( position, tessVertex->xyz );

// FIXME: don't store data as half floats?
tessVertex->texCoords[ 0 ] = halfToFloat( modelTexcoord[ 0 ] );
tessVertex->texCoords[ 1 ] = halfToFloat( modelTexcoord[ 1 ] );
Vector2Copy( modelTexcoord, tessVertex->texCoords );
}
}
else
Expand Down Expand Up @@ -1308,8 +1303,7 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {

R_TBNtoQtangents( tangent, binormal, normal, tessVertex->qtangents );

tessVertex->texCoords[ 0 ] = halfToFloat( modelTexcoord[ 0 ] );
tessVertex->texCoords[ 1 ] = halfToFloat( modelTexcoord[ 1 ] );
Vector2Copy( modelTexcoord, tessVertex->texCoords );
}
}
}
Expand All @@ -1326,8 +1320,7 @@ void Tess_SurfaceIQM( srfIQModel_t *surf ) {

R_TBNtoQtangents( modelTangent, modelBitangent, modelNormal, tessVertex->qtangents );

tessVertex->texCoords[ 0 ] = halfToFloat( modelTexcoord[ 0 ] );
tessVertex->texCoords[ 1 ] = halfToFloat( modelTexcoord[ 1 ] );
Vector2Copy( modelTexcoord, tessVertex->texCoords );
}
}

Expand Down

0 comments on commit 4b8566e

Please sign in to comment.