Skip to content

Commit

Permalink
Make sprite mosaic (more) accurate (melonDS-emu#1687)
Browse files Browse the repository at this point in the history
* Make horizontal sprite mosaic (more) accurate

* Vertical sprite mosaic should not extend the sprite's bounding area

* Vertical sprite mosaic should not extend the sprite's bounding area (2)

* OBJIndex is no longer needed
  • Loading branch information
fleroviux authored Aug 27, 2023
1 parent d69745b commit a571fe1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 41 deletions.
53 changes: 13 additions & 40 deletions src/GPU2D_Soft.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1561,22 +1561,17 @@ void SoftRenderer::ApplySpriteMosaicX()
if (CurUnit->OBJMosaicSize[0] == 0) return;

u32* objLine = OBJLine[CurUnit->Num];
u8* objIndex = OBJIndex[CurUnit->Num];

u8* curOBJXMosaicTable = MosaicTable[CurUnit->OBJMosaicSize[1]];

u32 lastcolor = objLine[0];

for (u32 i = 1; i < 256; i++)
{
if (!(objLine[i] & 0x100000))
{
// not a mosaic'd sprite pixel
continue;
}
u32 currentcolor = objLine[i];

if ((objIndex[i] != objIndex[i-1]) || (curOBJXMosaicTable[i] == 0))
lastcolor = objLine[i];
if (!(lastcolor & currentcolor & 0x100000) || curOBJXMosaicTable[i] == 0)
lastcolor = currentcolor;
else
objLine[i] = lastcolor;
}
Expand Down Expand Up @@ -1674,8 +1669,6 @@ void SoftRenderer::DrawSprites(u32 line, Unit* unit)
memset(OBJWindow[CurUnit->Num], 0, 256);
if (!(CurUnit->DispCnt & 0x1000)) return;

memset(OBJIndex, 0xFF, 256);

u16* oam = (u16*)&GPU::OAM[CurUnit->Num ? 0x400 : 0];

const s32 spritewidth[16] =
Expand Down Expand Up @@ -1728,9 +1721,9 @@ void SoftRenderer::DrawSprites(u32 line, Unit* unit)
}

u32 ypos = attrib[0] & 0xFF;
ypos = (sprline - ypos) & 0xFF;
if (ypos >= (u32)boundheight)
if (((line - ypos) & 0xFF) >= (u32)boundheight)
continue;
ypos = (sprline - ypos) & 0xFF;

s32 xpos = (s32)(attrib[1] << 23) >> 23;
if (xpos <= -boundwidth)
Expand All @@ -1752,9 +1745,9 @@ void SoftRenderer::DrawSprites(u32 line, Unit* unit)
s32 height = spriteheight[sizeparam];

u32 ypos = attrib[0] & 0xFF;
ypos = (sprline - ypos) & 0xFF;
if (ypos >= (u32)height)
if (((line - ypos) & 0xFF) >= (u32)height)
continue;
ypos = (sprline - ypos) & 0xFF;

s32 xpos = (s32)(attrib[1] << 23) >> 23;
if (xpos <= -width)
Expand Down Expand Up @@ -1786,7 +1779,6 @@ void SoftRenderer::DrawSprite_Rotscale(u32 num, u32 boundwidth, u32 boundheight,
CurUnit->GetOBJVRAM(objvram, objvrammask);

u32* objLine = OBJLine[CurUnit->Num];
u8* objIndex = OBJIndex[CurUnit->Num];
u8* objWindow = OBJWindow[CurUnit->Num];

s32 centerX = boundwidth >> 1;
Expand Down Expand Up @@ -1871,15 +1863,12 @@ void SoftRenderer::DrawSprite_Rotscale(u32 num, u32 boundwidth, u32 boundheight,
if (color & 0x8000)
{
if (window) objWindow[xpos] = 1;
else { objLine[xpos] = color | pixelattr; objIndex[xpos] = num; }
else objLine[xpos] = color | pixelattr;
}
else if (!window)
{
if (objLine[xpos] == 0)
{
objLine[xpos] = pixelattr & 0x180000;
objIndex[xpos] = num;
}
}
}

Expand Down Expand Up @@ -1929,15 +1918,12 @@ void SoftRenderer::DrawSprite_Rotscale(u32 num, u32 boundwidth, u32 boundheight,
if (color)
{
if (window) objWindow[xpos] = 1;
else { objLine[xpos] = color | pixelattr; objIndex[xpos] = num; }
else objLine[xpos] = color | pixelattr;
}
else if (!window)
{
if (objLine[xpos] == 0)
{
objLine[xpos] = pixelattr & 0x180000;
objIndex[xpos] = num;
}
}
}

Expand Down Expand Up @@ -1969,15 +1955,12 @@ void SoftRenderer::DrawSprite_Rotscale(u32 num, u32 boundwidth, u32 boundheight,
if (color)
{
if (window) objWindow[xpos] = 1;
else { objLine[xpos] = color | pixelattr; objIndex[xpos] = num; }
else objLine[xpos] = color | pixelattr;
}
else if (!window)
{
if (objLine[xpos] == 0)
{
objLine[xpos] = pixelattr & 0x180000;
objIndex[xpos] = num;
}
}
}

Expand Down Expand Up @@ -2013,7 +1996,6 @@ void SoftRenderer::DrawSprite_Normal(u32 num, u32 width, u32 height, s32 xpos, s
CurUnit->GetOBJVRAM(objvram, objvrammask);

u32* objLine = OBJLine[CurUnit->Num];
u8* objIndex = OBJIndex[CurUnit->Num];
u8* objWindow = OBJWindow[CurUnit->Num];

// yflip
Expand Down Expand Up @@ -2099,15 +2081,12 @@ void SoftRenderer::DrawSprite_Normal(u32 num, u32 width, u32 height, s32 xpos, s
if (color & 0x8000)
{
if (window) objWindow[xpos] = 1;
else { objLine[xpos] = color | pixelattr; objIndex[xpos] = num; }
else objLine[xpos] = color | pixelattr;
}
else if (!window)
{
if (objLine[xpos] == 0)
{
objLine[xpos] = pixelattr & 0x180000;
objIndex[xpos] = num;
}
}

xoff++;
Expand Down Expand Up @@ -2169,15 +2148,12 @@ void SoftRenderer::DrawSprite_Normal(u32 num, u32 width, u32 height, s32 xpos, s
if (color)
{
if (window) objWindow[xpos] = 1;
else { objLine[xpos] = color | pixelattr; objIndex[xpos] = num; }
else objLine[xpos] = color | pixelattr;
}
else if (!window)
{
if (objLine[xpos] == 0)
{
objLine[xpos] = pixelattr & 0x180000;
objIndex[xpos] = num;
}
}

xoff++;
Expand Down Expand Up @@ -2232,15 +2208,12 @@ void SoftRenderer::DrawSprite_Normal(u32 num, u32 width, u32 height, s32 xpos, s
if (color)
{
if (window) objWindow[xpos] = 1;
else { objLine[xpos] = color | pixelattr; objIndex[xpos] = num; }
else objLine[xpos] = color | pixelattr;
}
else if (!window)
{
if (objLine[xpos] == 0)
{
objLine[xpos] = pixelattr & 0x180000;
objIndex[xpos] = num;
}
}

xoff++;
Expand Down
1 change: 0 additions & 1 deletion src/GPU2D_Soft.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ class SoftRenderer : public Renderer2D
alignas(8) u8 WindowMask[256];

alignas(8) u32 OBJLine[2][256];
alignas(8) u8 OBJIndex[2][256];
alignas(8) u8 OBJWindow[2][256];

u32 NumSprites[2];
Expand Down

0 comments on commit a571fe1

Please sign in to comment.