From c499e6640cdf2d618e8e236fb8b0579a088eef4a Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Fri, 29 Apr 2016 23:03:46 +0000 Subject: [PATCH] fixed shading code --- Src/Graphics/New3D/New3D.cpp | 14 ++++++++------ Src/Graphics/New3D/PolyHeader.cpp | 10 +++++----- Src/Graphics/New3D/PolyHeader.h | 7 ++++--- 3 files changed, 17 insertions(+), 14 deletions(-) diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 1e1fadb..3b0a2b4 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -906,12 +906,6 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data) p.v[j].color[1] = (m_polyRAM[0x400 + colorIdx] >> 8) & 0xFF; p.v[j].color[0] = (m_polyRAM[0x400 + colorIdx] >> 16) & 0xFF; } - else if (0 /* fixed shading bit as of yet unknown */) { - UINT8 shade = (UINT8)((ix & 0xFF) + 128); - p.v[j].color[0] = shade; - p.v[j].color[1] = shade; - p.v[j].color[2] = shade; - } else { if (ph.ColorDisabled()) { // no colours were set p.v[j].color[0] = 255; @@ -925,6 +919,14 @@ void CNew3D::CacheModel(Model *m, const UINT32 *data) } } + if (ph.FixedShading() && ph.LightEnabled()) { + float shade = ((ix & 0xFF) + 128) / 255.f; + UINT8 colour = (UINT8)(p.v[j].color[0] * shade); // green & blue values seem not to be valid + p.v[j].color[0] = colour; + p.v[j].color[1] = colour; + p.v[j].color[2] = colour; + } + if ((ph.header[6] & 0x00800000)) { // if set, polygon is opaque p.v[j].color[3] = 255; } diff --git a/Src/Graphics/New3D/PolyHeader.cpp b/Src/Graphics/New3D/PolyHeader.cpp index daceca1..9a9f6e7 100644 --- a/Src/Graphics/New3D/PolyHeader.cpp +++ b/Src/Graphics/New3D/PolyHeader.cpp @@ -144,6 +144,11 @@ bool PolyHeader::PolyColor() return (header[1] & 2) > 0; } +bool PolyHeader::FixedShading() +{ + return (header[1] & 0x20) > 0; +} + // // header 2 // @@ -255,11 +260,6 @@ UINT8 PolyHeader::Transparency() return (UINT8)(((header[6] >> 18) & 0x1F) * 255.f / 0x1F); } -bool PolyHeader::FixedShading() -{ - return (header[6] & 0x2000000) > 0; -} - bool PolyHeader::PolyAlpha() { return (header[6] & 0x00800000) == 0; diff --git a/Src/Graphics/New3D/PolyHeader.h b/Src/Graphics/New3D/PolyHeader.h index 129e713..c684f81 100644 --- a/Src/Graphics/New3D/PolyHeader.h +++ b/Src/Graphics/New3D/PolyHeader.h @@ -21,10 +21,11 @@ x------- -------- -------- -------- Specular enable 0x01: xxxxxxxx xxxxxxxx xxxxxxxx-------- Polygon normal X coordinate(2.22 fixed point) -------- -------- -------- -x------ UV scale (0 = 13.3, 1 = 16.0) +-------- -------- -------- --x----- Fixed shading (seems to only be enabled if lighting is enabled) -------- -------- -------- ---x---- 1 = Double-sided polygon -------- -------- -------- -----x-- If set, this is the last polygon -------- -------- -------- ------x- Poly color, 1 = RGB, 0 = color table --------- -------- -------- x-x-x--x ? +-------- -------- -------- x---x--x ? 0x02: xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Y coordinate(2.22 fixed point) @@ -41,8 +42,8 @@ xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Z coordinate(2.22 fixed poin xxxxxxxx xxxxxxxx xxxxxxxx -------- Color(RGB888) -------- -------- -------- x------- Color disabled -------- -------- -------- -x------ Texture page --------- -------- -------- --x----- ? -------- -------- -------- ---xxxxx Upper 5 bits of texture U coordinate +-------- -------- -------- --x----- ? 0x05 : xxxxxxxx xxxxxxxx xxxxxxxx -------- Specular color ? @@ -94,6 +95,7 @@ public: bool DoubleSided(); bool LastPoly(); bool PolyColor(); // if false uses LUT from ram + bool FixedShading(); //header 2 bool TexUMirror(); @@ -118,7 +120,6 @@ public: bool LightEnabled(); bool AlphaTest(); UINT8 Transparency(); // 0-255 - bool FixedShading(); bool PolyAlpha(); bool TextureAlpha(); bool StencilPoly();