Browse Source

Reorganized the model rendering loop to reduce duplicate calculations and condition checks.

master
Nico de Poel 3 years ago
parent
commit
8af98229f5
  1. 31
      main.c

31
main.c

@ -293,9 +293,18 @@ static int fakeLight(const int *norm)
void drawModel(ps1mdl_t *model, TIM_IMAGE *frontTex, TIM_IMAGE *backTex, int xOffset, int frameCounter)
{
TIM_IMAGE *tex;
short u0, u1, u2, uoffs, voffs;
int frameNum = frameCounter % model->header->frameCount;
int vertOffs = frameNum * model->header->vertexCount;
unsigned short halfSkinWidth = model->header->skinWidth >> 1;
short frontUOffs = (frontTex->prect->x % 64) << (2 - (frontTex->mode & 0x3));
short frontVOffs = (frontTex->prect->y & 0xFF);
short backUOffs = (backTex->prect->x % 64) << (2 - (backTex->mode & 0x3));
short backVOffs = (backTex->prect->y & 0xFF);
for (int triIdx = 0; triIdx < model->header->triangleCount; ++triIdx)
{
ps1mdl_triangle_t *tri = &model->triangles[triIdx];
@ -318,15 +327,19 @@ void drawModel(ps1mdl_t *model, TIM_IMAGE *frontTex, TIM_IMAGE *backTex, int xOf
int lit1 = fakeLight(anorms[v1->normalIndex]);
int lit2 = fakeLight(anorms[v2->normalIndex]);
// Since we have the texture split into two parts, we need to correct the UVs that are *not* on the seam, instead of the other way round
short u0 = !tri->frontFace && !tc0->onSeam ? tc0->u - (model->header->skinWidth >> 1) : tc0->u;
short u1 = !tri->frontFace && !tc1->onSeam ? tc1->u - (model->header->skinWidth >> 1) : tc1->u;
short u2 = !tri->frontFace && !tc2->onSeam ? tc2->u - (model->header->skinWidth >> 1) : tc2->u;
TIM_IMAGE *tex = tri->frontFace ? frontTex : backTex;
short uoffs = (tex->prect->x % 64) << (2 - (tex->mode & 0x3));
short voffs = (tex->prect->y & 0xFF);
if (tri->frontFace)
{
u0 = tc0->u, u1 = tc1->u, u2 = tc2->u;
tex = frontTex, uoffs = frontUOffs, voffs = frontVOffs;
}
else
{
// Since we have the texture split into two parts, we need to correct the UVs that are *not* on the seam, instead of the other way round
u0 = tc0->onSeam ? tc0->u : tc0->u - halfSkinWidth;
u1 = tc1->onSeam ? tc1->u : tc1->u - halfSkinWidth;
u2 = tc2->onSeam ? tc2->u : tc2->u - halfSkinWidth;
tex = backTex, uoffs = backUOffs, voffs = backVOffs;
}
POLY_GT3 *poly = (POLY_GT3*)nextpri;
setPolyGT3(poly);

Loading…
Cancel
Save