aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStapleButter <thetotalworm@gmail.com>2017-04-12 20:25:54 +0200
committerStapleButter <thetotalworm@gmail.com>2017-04-12 20:25:54 +0200
commitc62e160b269b3faeec303de8d593929efd66d107 (patch)
tree1298ce94ec37265206c24b94a7ef033ed6dd2798
parent54eeb38d3df54aef7211442d2355c822f093b56f (diff)
* decal texture blending
* start implementing toon shading * temp. revert the DMA fix, causes issues
-rw-r--r--src/GPU3D.cpp4
-rw-r--r--src/GPU3D.h2
-rw-r--r--src/GPU3D_Soft.cpp61
-rw-r--r--src/NDS.cpp4
4 files changed, 63 insertions, 8 deletions
diff --git a/src/GPU3D.cpp b/src/GPU3D.cpp
index e06ff90..378565a 100644
--- a/src/GPU3D.cpp
+++ b/src/GPU3D.cpp
@@ -717,8 +717,9 @@ void SubmitPolygon()
poly->FacingView = facingview;
u32 texfmt = (TexParam >> 26) & 0x7;
+ u32 blendmode = (CurPolygonAttr >> 4) & 0x3;
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)
{
@@ -1731,6 +1732,7 @@ void VBlank()
RenderPolygonRAM = CurPolygonRAM;
RenderNumPolygons = NumPolygons;
+ // TODO: find out which other registers are latched for rendering
RenderClearAttr1 = ClearAttr1;
RenderClearAttr2 = ClearAttr2;
diff --git a/src/GPU3D.h b/src/GPU3D.h
index 5c29b76..0b07442 100644
--- a/src/GPU3D.h
+++ b/src/GPU3D.h
@@ -61,6 +61,8 @@ extern u32 AlphaRef;
extern s32 Viewport[4];
extern u32 RenderClearAttr1, RenderClearAttr2;
+extern u16 ToonTable[32];
+
bool Init();
void DeInit();
void Reset();
diff --git a/src/GPU3D_Soft.cpp b/src/GPU3D_Soft.cpp
index dc94130..4f67255 100644
--- a/src/GPU3D_Soft.cpp
+++ b/src/GPU3D_Soft.cpp
@@ -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;
u8 r, g, b, a;
+ u32 blendmode = (polygon->Attr >> 4) & 0x3;
u32 polyalpha = (polygon->Attr >> 16) & 0x1F;
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))
{
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++;
tb = (tcolor >> 9) & 0x3E; if (tb) tb++;
- // TODO: other blending modes
- 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;
+ if (blendmode == 1)
+ {
+ // decal
+
+ 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
{
@@ -328,6 +367,18 @@ u32 RenderPixel(Polygon* polygon, s32 x, s32 y, s32 z, u8 vr, u8 vg, u8 vb, s16
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;
return r | (g << 8) | (b << 16) | (a << 24);
diff --git a/src/NDS.cpp b/src/NDS.cpp
index 98eda41..ac28f74 100644
--- a/src/NDS.cpp
+++ b/src/NDS.cpp
@@ -561,12 +561,12 @@ void StopCPU(u32 cpu, u32 mask)
if (cpu)
{
CPUStop |= (mask << 16);
- ARM7->Halt(2);
+ //ARM7->Halt(2);
}
else
{
CPUStop |= mask;
- ARM9->Halt(2);
+ //ARM9->Halt(2);
}
}