Skip to content

Commit

Permalink
F3DEX3: fix ambient light support, adjust viewport for new Max Z
Browse files Browse the repository at this point in the history
  • Loading branch information
aglab2 authored and gonetz committed Jan 8, 2025
1 parent 4e2052e commit 1217256
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 23 deletions.
15 changes: 12 additions & 3 deletions src/gSP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,8 @@ void gSPDMAMatrix( u32 matrix, u8 index, u8 multiply )
mtx[3][0], mtx[3][1], mtx[3][2], mtx[3][3] );
}

#define G_F3DEX3_NEW_MAXZ 0x7FFF

void gSPViewport( u32 v )
{
u32 address = RSP_SegmentToPhysical( v );
Expand All @@ -267,8 +269,15 @@ void gSPViewport( u32 v )
gSP.viewport.vtrans[2] = _FIXED2FLOAT( *(s16*)&RDRAM[address + 14], 10 );// * 0.00097847357f;
gSP.viewport.vtrans[3] = *(s16*)&RDRAM[address + 12];

if (gSP.viewport.vscale[1] < 0.0f && !GBI.isNegativeY())
gSP.viewport.vscale[1] = -gSP.viewport.vscale[1];
if (gSP.viewport.vscale[1] < 0.0f) {
if (!GBI.isNegativeY()) {
gSP.viewport.vscale[1] = -gSP.viewport.vscale[1];
if (F3DEX3 == GBI.getMicrocodeType()) {
gSP.viewport.vscale[2] /= (G_F3DEX3_NEW_MAXZ / 2) / 511.f;
gSP.viewport.vtrans[2] /= (G_F3DEX3_NEW_MAXZ / 2) / 511.f;
}
}
}

gSP.viewport.x = gSP.viewport.vtrans[0] - gSP.viewport.vscale[0];
gSP.viewport.y = gSP.viewport.vtrans[1] - gSP.viewport.vscale[1];
Expand Down Expand Up @@ -314,7 +323,7 @@ void gSPLight( u32 l, s32 n )

Light *light = (Light*)&RDRAM[addrByte];

if (n < 9) {
if (n < 10) {
gSP.lights.rgb[n][R] = _FIXED2FLOATCOLOR(light->r,8);
gSP.lights.rgb[n][G] = _FIXED2FLOATCOLOR(light->g,8);
gSP.lights.rgb[n][B] = _FIXED2FLOATCOLOR(light->b,8);
Expand Down
22 changes: 2 additions & 20 deletions src/uCodes/F3DEX3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,7 @@

#define F3DEX3_G_MAX_LIGHTS 9

struct F3DEX3_Ambient
{
u8 pad0, b, g, r;
u8 pad1, b2, g2, r2;
};

struct F3DEX3_Light
{
u8 pad0, b, g, r;
u8 pad1, b2, g2, r2;
s8 pad2, z, y, x;
u8 size, pad3[3];
};

// Notice how it looks like F3DEX3_Light but the ending so there are 8 bytes of difference
// Notice how it looks like Light but the ending so there are 8 bytes of difference
struct F3DEX3_LookAt
{
s8 pad, z, y, x;
Expand Down Expand Up @@ -83,18 +69,14 @@ static void writeLight(int off, u32 w)
gSPLookAt(w - (sizeof(F3DEX3_LookAtOld) - sizeof(F3DEX3_LookAt)) + sizeof(F3DEX3_LookAt), 1);
}

for (u32 i = 1; i <= gSP.numLights; i++)
for (u32 i = 1; i <= gSP.numLights + 1; i++)
{
if (_LIGHT_TO_OFFSET(i) == off)
{
gSPLight(w, i);
}
}

if (_LIGHT_TO_OFFSET(gSP.numLights + 1) == off)
{
// TODO: Write ambient lights
}
if ((F3DEX3_G_MAX_LIGHTS * 0x10) + 0x18 == off)
{
// TODO: OcclusionPlane not supported
Expand Down

0 comments on commit 1217256

Please sign in to comment.