vertex colors, with Gouraud shading and all
has yet to be checked for whether it's accurate, optimized, etc...
This commit is contained in:
parent
050ba5dfbe
commit
15c8d59e2b
20
GPU3D.cpp
20
GPU3D.cpp
|
@ -157,6 +157,7 @@ void UpdateClipMatrix();
|
||||||
|
|
||||||
u32 PolygonMode;
|
u32 PolygonMode;
|
||||||
s16 CurVertex[3];
|
s16 CurVertex[3];
|
||||||
|
u8 VertexColor[3];
|
||||||
|
|
||||||
Vertex TempVertexBuffer[4];
|
Vertex TempVertexBuffer[4];
|
||||||
u32 VertexNum;
|
u32 VertexNum;
|
||||||
|
@ -690,10 +691,9 @@ void SubmitVertex()
|
||||||
vertextrans->Position[1] = (vertextrans->Position[1] * w_inv) >> 12;
|
vertextrans->Position[1] = (vertextrans->Position[1] * w_inv) >> 12;
|
||||||
vertextrans->Position[2] = (vertextrans->Position[2] * w_inv) >> 12;
|
vertextrans->Position[2] = (vertextrans->Position[2] * w_inv) >> 12;
|
||||||
|
|
||||||
// boo
|
vertextrans->Color[0] = VertexColor[0];
|
||||||
vertextrans->Color[0] = 63;
|
vertextrans->Color[1] = VertexColor[1];
|
||||||
vertextrans->Color[1] = 0;
|
vertextrans->Color[2] = VertexColor[2];
|
||||||
vertextrans->Color[2] = 63;
|
|
||||||
|
|
||||||
/*printf("vertex trans: %f %f %f %f\n",
|
/*printf("vertex trans: %f %f %f %f\n",
|
||||||
vertextrans->Position[0]/4096.0f,
|
vertextrans->Position[0]/4096.0f,
|
||||||
|
@ -1059,6 +1059,18 @@ void ExecuteCommand()
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case 0x20: // vertex color
|
||||||
|
{
|
||||||
|
u32 c = ExecParams[0];
|
||||||
|
u32 r = c & 0x1F;
|
||||||
|
u32 g = (c >> 5) & 0x1F;
|
||||||
|
u32 b = (c >> 10) & 0x1F;
|
||||||
|
VertexColor[0] = r ? (r<<1)+1 : 0;
|
||||||
|
VertexColor[1] = g ? (g<<1)+1 : 0;
|
||||||
|
VertexColor[2] = b ? (b<<1)+1 : 0;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case 0x21:
|
case 0x21:
|
||||||
// TODO: more cycles if lights are enabled
|
// TODO: more cycles if lights are enabled
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -127,6 +127,11 @@ void RenderPolygon(Polygon* polygon)
|
||||||
//xmax = scrcoords[rcur][0] << 12;
|
//xmax = scrcoords[rcur][0] << 12;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vertex* vlcur = polygon->Vertices[lcur];
|
||||||
|
Vertex* vlnext = polygon->Vertices[lnext];
|
||||||
|
Vertex* vrcur = polygon->Vertices[rcur];
|
||||||
|
Vertex* vrnext = polygon->Vertices[rnext];
|
||||||
|
|
||||||
s32 lfactor, rfactor;
|
s32 lfactor, rfactor;
|
||||||
|
|
||||||
if (scrcoords[lnext][1] == scrcoords[lcur][1])
|
if (scrcoords[lnext][1] == scrcoords[lcur][1])
|
||||||
|
@ -139,35 +144,34 @@ void RenderPolygon(Polygon* polygon)
|
||||||
else
|
else
|
||||||
rfactor = ((y - scrcoords[rcur][1]) << 12) / (scrcoords[rnext][1] - scrcoords[rcur][1]);
|
rfactor = ((y - scrcoords[rcur][1]) << 12) / (scrcoords[rnext][1] - scrcoords[rcur][1]);
|
||||||
|
|
||||||
s32 xmin = scrcoords[lcur][0] + (((scrcoords[lnext][0] - scrcoords[lcur][0]) * lfactor) >> 12);
|
s32 xl = scrcoords[lcur][0] + (((scrcoords[lnext][0] - scrcoords[lcur][0]) * lfactor) >> 12);
|
||||||
s32 xmax = scrcoords[rcur][0] + (((scrcoords[rnext][0] - scrcoords[rcur][0]) * rfactor) >> 12);
|
s32 xr = scrcoords[rcur][0] + (((scrcoords[rnext][0] - scrcoords[rcur][0]) * rfactor) >> 12);
|
||||||
|
|
||||||
for (s32 x = xmin; x <= xmax; x++)
|
u8 rl = vlcur->Color[0] + (((vlnext->Color[0] - vlcur->Color[0]) * lfactor) >> 12);
|
||||||
|
u8 gl = vlcur->Color[1] + (((vlnext->Color[1] - vlcur->Color[1]) * lfactor) >> 12);
|
||||||
|
u8 bl = vlcur->Color[2] + (((vlnext->Color[2] - vlcur->Color[2]) * lfactor) >> 12);
|
||||||
|
|
||||||
|
u8 rr = vrcur->Color[0] + (((vrnext->Color[0] - vrcur->Color[0]) * rfactor) >> 12);
|
||||||
|
u8 gr = vrcur->Color[1] + (((vrnext->Color[1] - vrcur->Color[1]) * rfactor) >> 12);
|
||||||
|
u8 br = vrcur->Color[2] + (((vrnext->Color[2] - vrcur->Color[2]) * rfactor) >> 12);
|
||||||
|
|
||||||
|
s32 xdiv;
|
||||||
|
if (xr == xl)
|
||||||
|
xdiv = 0;
|
||||||
|
else
|
||||||
|
xdiv = 0x1000 / (xr - xl);
|
||||||
|
|
||||||
|
for (s32 x = xl; x <= xr; x++)
|
||||||
{
|
{
|
||||||
|
s32 xfactor = (x - xl) * xdiv;
|
||||||
|
|
||||||
u8* pixel = &ColorBuffer[((256*y) + x) * 4];
|
u8* pixel = &ColorBuffer[((256*y) + x) * 4];
|
||||||
pixel[0] = 0;
|
pixel[0] = rl + (((rr - rl) * xfactor) >> 12);
|
||||||
pixel[1] = 63;
|
pixel[1] = gl + (((gr - gl) * xfactor) >> 12);
|
||||||
pixel[2] = 0;
|
pixel[2] = bl + (((br - bl) * xfactor) >> 12);
|
||||||
pixel[3] = 31;
|
pixel[3] = 31;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// test
|
|
||||||
/*for (int i = 0; i < nverts; i++)
|
|
||||||
{
|
|
||||||
Vertex* vtx = polygon->Vertices[i];
|
|
||||||
|
|
||||||
s32 scrX = (((vtx->Position[0] + 0x1000) * Viewport[2]) >> 13) + Viewport[0];
|
|
||||||
s32 scrY = (((vtx->Position[1] + 0x1000) * Viewport[3]) >> 13) + Viewport[1];
|
|
||||||
if (scrX > 255) scrX = 255;
|
|
||||||
if (scrY > 191) scrY = 191;
|
|
||||||
|
|
||||||
u8* pixel = &ColorBuffer[((256*scrY) + scrX) * 4];
|
|
||||||
pixel[0] = 0;
|
|
||||||
pixel[1] = 63;
|
|
||||||
pixel[2] = 0;
|
|
||||||
pixel[3] = 31;
|
|
||||||
}*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderFrame(Vertex* vertices, Polygon* polygons, int npolys)
|
void RenderFrame(Vertex* vertices, Polygon* polygons, int npolys)
|
||||||
|
|
|
@ -148,7 +148,7 @@
|
||||||
|
|
||||||
1486777933 c:\documents\sources\melonds\gpu3d.h
|
1486777933 c:\documents\sources\melonds\gpu3d.h
|
||||||
|
|
||||||
1486777278 source:c:\documents\sources\melonds\gpu3d.cpp
|
1486782030 source:c:\documents\sources\melonds\gpu3d.cpp
|
||||||
<stdio.h>
|
<stdio.h>
|
||||||
<string.h>
|
<string.h>
|
||||||
"NDS.h"
|
"NDS.h"
|
||||||
|
|
Loading…
Reference in New Issue