diff options
author | StapleButter <thetotalworm@gmail.com> | 2017-03-16 00:07:36 +0100 |
---|---|---|
committer | StapleButter <thetotalworm@gmail.com> | 2017-03-16 00:07:36 +0100 |
commit | ebdc9e5442ed1fec18994ca68b3c0607fed8e57a (patch) | |
tree | 5b4d9f948234c2f0a0c2723b8126cf239d0beb5b | |
parent | 29944c3c889e4f949f9267e47ac96ccdc9a8926b (diff) |
* fix missing 3D line
* make lighting calculations accurate
* BLDCNT reading
-rw-r--r-- | GPU2D.cpp | 2 | ||||
-rw-r--r-- | GPU3D.cpp | 38 | ||||
-rw-r--r-- | GPU3D_Soft.cpp | 2 |
3 files changed, 23 insertions, 19 deletions
@@ -126,6 +126,8 @@ u16 GPU2D::Read16(u32 addr) case 0x00C: return BGCnt[2]; case 0x00E: return BGCnt[3]; + case 0x050: return BlendCnt; + case 0x064: return CaptureCnt & 0xFFFF; case 0x066: return CaptureCnt >> 16; } @@ -934,36 +934,38 @@ s32 CalculateLighting() if (!(CurPolygonAttr & (1<<i))) continue; - s32 difflevel = (LightDirection[i][0]*normaltrans[0] + + s32 difflevel = (-(LightDirection[i][0]*normaltrans[0] + LightDirection[i][1]*normaltrans[1] + - LightDirection[i][2]*normaltrans[2]) >> 10; - difflevel = -difflevel; + LightDirection[i][2]*normaltrans[2])) >> 10; if (difflevel < 0) difflevel = 0; + else if (difflevel > 255) difflevel = 255; - s32 shinelevel = (-(LightDirection[i][0]>>1)*normaltrans[0] - - (LightDirection[i][1]>>1)*normaltrans[1] - - ((LightDirection[i][2]-0x200)>>1)*normaltrans[2]) >> 10; + s32 shinelevel = -(((LightDirection[i][0]>>1)*normaltrans[0] + + (LightDirection[i][1]>>1)*normaltrans[1] + + ((LightDirection[i][2]-0x200)>>1)*normaltrans[2]) >> 10); if (shinelevel < 0) shinelevel = 0; - shinelevel = (shinelevel * shinelevel) >> 8; + shinelevel = ((shinelevel * shinelevel) >> 7) - 0x100; // really (2*shinelevel*shinelevel)-1 + if (shinelevel < 0) shinelevel = 0; + else if (shinelevel > 255) shinelevel = 255; - // checkme if (UseShininessTable) { - if (shinelevel > 127) shinelevel = 127; + // checkme + shinelevel >>= 1; shinelevel = ShininessTable[shinelevel]; } - VertexColor[0] += ((((MatSpecular[0]+1) * (LightColor[i][0]+1) * (shinelevel+1)) - 1) >> 13); - VertexColor[0] += ((((MatDiffuse[0]+1) * (LightColor[i][0]+1) * (difflevel+1)) - 1) >> 13); - VertexColor[0] += ((((MatAmbient[0]+1) * (LightColor[i][0]+1)) - 1) >> 5); + VertexColor[0] += ((MatSpecular[0] * LightColor[i][0] * shinelevel) >> 13); + VertexColor[0] += ((MatDiffuse[0] * LightColor[i][0] * difflevel) >> 13); + VertexColor[0] += ((MatAmbient[0] * LightColor[i][0]) >> 5); - VertexColor[1] += ((((MatSpecular[1]+1) * (LightColor[i][1]+1) * (shinelevel+1)) - 1) >> 13); - VertexColor[1] += ((((MatDiffuse[1]+1) * (LightColor[i][1]+1) * (difflevel+1)) - 1) >> 13); - VertexColor[1] += ((((MatAmbient[1]+1) * (LightColor[i][1]+1)) - 1) >> 5); + VertexColor[1] += ((MatSpecular[1] * LightColor[i][1] * shinelevel) >> 13); + VertexColor[1] += ((MatDiffuse[1] * LightColor[i][1] * difflevel) >> 13); + VertexColor[1] += ((MatAmbient[1] * LightColor[i][1]) >> 5); - VertexColor[2] += ((((MatSpecular[2]+1) * (LightColor[i][2]+1) * (shinelevel+1)) - 1) >> 13); - VertexColor[2] += ((((MatDiffuse[2]+1) * (LightColor[i][2]+1) * (difflevel+1)) - 1) >> 13); - VertexColor[2] += ((((MatAmbient[2]+1) * (LightColor[i][2]+1)) - 1) >> 5); + VertexColor[2] += ((MatSpecular[2] * LightColor[i][2] * shinelevel) >> 13); + VertexColor[2] += ((MatDiffuse[2] * LightColor[i][2] * difflevel) >> 13); + VertexColor[2] += ((MatAmbient[2] * LightColor[i][2]) >> 5); if (VertexColor[0] > 31) VertexColor[0] = 31; if (VertexColor[1] > 31) VertexColor[1] = 31; diff --git a/GPU3D_Soft.cpp b/GPU3D_Soft.cpp index d29573c..1566ee8 100644 --- a/GPU3D_Soft.cpp +++ b/GPU3D_Soft.cpp @@ -487,7 +487,7 @@ void RenderPolygon(Polygon* polygon, u32 wbuffer) else if (rslope) dxr = (rslope > 0) ? 0 : 0x1000; else dxr = 0x1000; - if (ybot > 191) ybot = 191; + if (ybot > 192) ybot = 192; for (s32 y = ytop; y < ybot; y++) { if (!isline) |