mirror of
https://github.com/melonDS-emu/melonDS.git
synced 2025-07-23 14:19:55 -06:00
* decal texture blending
* start implementing toon shading * temp. revert the DMA fix, causes issues
This commit is contained in:
@ -717,8 +717,9 @@ void SubmitPolygon()
|
|||||||
poly->FacingView = facingview;
|
poly->FacingView = facingview;
|
||||||
|
|
||||||
u32 texfmt = (TexParam >> 26) & 0x7;
|
u32 texfmt = (TexParam >> 26) & 0x7;
|
||||||
|
u32 blendmode = (CurPolygonAttr >> 4) & 0x3;
|
||||||
u32 polyalpha = (CurPolygonAttr >> 16) & 0x1F;
|
u32 polyalpha = (CurPolygonAttr >> 16) & 0x1F;
|
||||||
poly->Translucent = (texfmt == 1 || texfmt == 6 || (polyalpha > 0 && polyalpha < 31));
|
poly->Translucent = ((texfmt == 1 || texfmt == 6) && (blendmode != 1)) || (polyalpha > 0 && polyalpha < 31);
|
||||||
|
|
||||||
if (LastStripPolygon && clipstart > 0)
|
if (LastStripPolygon && clipstart > 0)
|
||||||
{
|
{
|
||||||
@ -1731,6 +1732,7 @@ void VBlank()
|
|||||||
RenderPolygonRAM = CurPolygonRAM;
|
RenderPolygonRAM = CurPolygonRAM;
|
||||||
RenderNumPolygons = NumPolygons;
|
RenderNumPolygons = NumPolygons;
|
||||||
|
|
||||||
|
// TODO: find out which other registers are latched for rendering
|
||||||
RenderClearAttr1 = ClearAttr1;
|
RenderClearAttr1 = ClearAttr1;
|
||||||
RenderClearAttr2 = ClearAttr2;
|
RenderClearAttr2 = ClearAttr2;
|
||||||
|
|
||||||
|
@ -61,6 +61,8 @@ extern u32 AlphaRef;
|
|||||||
extern s32 Viewport[4];
|
extern s32 Viewport[4];
|
||||||
extern u32 RenderClearAttr1, RenderClearAttr2;
|
extern u32 RenderClearAttr1, RenderClearAttr2;
|
||||||
|
|
||||||
|
extern u16 ToonTable[32];
|
||||||
|
|
||||||
bool Init();
|
bool Init();
|
||||||
void DeInit();
|
void DeInit();
|
||||||
void Reset();
|
void Reset();
|
||||||
|
@ -300,9 +300,19 @@ u32 RenderPixel(Polygon* polygon, s32 x, s32 y, s32 z, u8 vr, u8 vg, u8 vb, s16
|
|||||||
u32 attr = polygon->Attr;
|
u32 attr = polygon->Attr;
|
||||||
u8 r, g, b, a;
|
u8 r, g, b, a;
|
||||||
|
|
||||||
|
u32 blendmode = (polygon->Attr >> 4) & 0x3;
|
||||||
u32 polyalpha = (polygon->Attr >> 16) & 0x1F;
|
u32 polyalpha = (polygon->Attr >> 16) & 0x1F;
|
||||||
bool wireframe = (polyalpha == 0);
|
bool wireframe = (polyalpha == 0);
|
||||||
|
|
||||||
|
if (blendmode == 2)
|
||||||
|
{
|
||||||
|
u16 tooncolor = ToonTable[vr >> 1];
|
||||||
|
|
||||||
|
vr = (tooncolor << 1) & 0x3E; if (vr) vr++;
|
||||||
|
vg = (tooncolor >> 4) & 0x3E; if (vg) vg++;
|
||||||
|
vb = (tooncolor >> 9) & 0x3E; if (vb) vb++;
|
||||||
|
}
|
||||||
|
|
||||||
if ((DispCnt & (1<<0)) && (((polygon->TexParam >> 26) & 0x7) != 0))
|
if ((DispCnt & (1<<0)) && (((polygon->TexParam >> 26) & 0x7) != 0))
|
||||||
{
|
{
|
||||||
u8 tr, tg, tb;
|
u8 tr, tg, tb;
|
||||||
@ -314,11 +324,40 @@ u32 RenderPixel(Polygon* polygon, s32 x, s32 y, s32 z, u8 vr, u8 vg, u8 vb, s16
|
|||||||
tg = (tcolor >> 4) & 0x3E; if (tg) tg++;
|
tg = (tcolor >> 4) & 0x3E; if (tg) tg++;
|
||||||
tb = (tcolor >> 9) & 0x3E; if (tb) tb++;
|
tb = (tcolor >> 9) & 0x3E; if (tb) tb++;
|
||||||
|
|
||||||
// TODO: other blending modes
|
if (blendmode == 1)
|
||||||
r = ((tr+1) * (vr+1) - 1) >> 6;
|
{
|
||||||
g = ((tg+1) * (vg+1) - 1) >> 6;
|
// decal
|
||||||
b = ((tb+1) * (vb+1) - 1) >> 6;
|
|
||||||
a = ((talpha+1) * (polyalpha+1) - 1) >> 5;
|
if (talpha == 0)
|
||||||
|
{
|
||||||
|
r = vr;
|
||||||
|
g = vg;
|
||||||
|
b = vb;
|
||||||
|
}
|
||||||
|
else if (talpha == 31)
|
||||||
|
{
|
||||||
|
r = tr;
|
||||||
|
g = tg;
|
||||||
|
b = tb;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
r = ((tr * talpha) + (vr * (31-talpha))) >> 5;
|
||||||
|
g = ((tg * talpha) + (vg * (31-talpha))) >> 5;
|
||||||
|
b = ((tb * talpha) + (vb * (31-talpha))) >> 5;
|
||||||
|
}
|
||||||
|
a = polyalpha;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// modulate
|
||||||
|
// TODO: check that it works the same for shadows
|
||||||
|
|
||||||
|
r = ((tr+1) * (vr+1) - 1) >> 6;
|
||||||
|
g = ((tg+1) * (vg+1) - 1) >> 6;
|
||||||
|
b = ((tb+1) * (vb+1) - 1) >> 6;
|
||||||
|
a = ((talpha+1) * (polyalpha+1) - 1) >> 5;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -328,6 +367,18 @@ u32 RenderPixel(Polygon* polygon, s32 x, s32 y, s32 z, u8 vr, u8 vg, u8 vb, s16
|
|||||||
a = polyalpha;
|
a = polyalpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*if ((blendmode == 2) && (DispCnt & (1<<1)))
|
||||||
|
{
|
||||||
|
r += vr;
|
||||||
|
g += vg;
|
||||||
|
b += vb;
|
||||||
|
|
||||||
|
if (r > 63) r = 63;
|
||||||
|
if (g > 63) g = 63;
|
||||||
|
if (b > 63) b = 63;
|
||||||
|
}*/
|
||||||
|
|
||||||
|
// checkme: can wireframe polygons use texture alpha?
|
||||||
if (wireframe) a = 31;
|
if (wireframe) a = 31;
|
||||||
|
|
||||||
return r | (g << 8) | (b << 16) | (a << 24);
|
return r | (g << 8) | (b << 16) | (a << 24);
|
||||||
|
@ -561,12 +561,12 @@ void StopCPU(u32 cpu, u32 mask)
|
|||||||
if (cpu)
|
if (cpu)
|
||||||
{
|
{
|
||||||
CPUStop |= (mask << 16);
|
CPUStop |= (mask << 16);
|
||||||
ARM7->Halt(2);
|
//ARM7->Halt(2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
CPUStop |= mask;
|
CPUStop |= mask;
|
||||||
ARM9->Halt(2);
|
//ARM9->Halt(2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user