fixed shading code

This commit is contained in:
Ian Curtis 2016-04-29 23:03:46 +00:00
parent 57d5bc8367
commit c499e6640c
3 changed files with 17 additions and 14 deletions

View file

@ -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[1] = (m_polyRAM[0x400 + colorIdx] >> 8) & 0xFF;
p.v[j].color[0] = (m_polyRAM[0x400 + colorIdx] >> 16) & 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 { else {
if (ph.ColorDisabled()) { // no colours were set if (ph.ColorDisabled()) { // no colours were set
p.v[j].color[0] = 255; 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 if ((ph.header[6] & 0x00800000)) { // if set, polygon is opaque
p.v[j].color[3] = 255; p.v[j].color[3] = 255;
} }

View file

@ -144,6 +144,11 @@ bool PolyHeader::PolyColor()
return (header[1] & 2) > 0; return (header[1] & 2) > 0;
} }
bool PolyHeader::FixedShading()
{
return (header[1] & 0x20) > 0;
}
// //
// header 2 // header 2
// //
@ -255,11 +260,6 @@ UINT8 PolyHeader::Transparency()
return (UINT8)(((header[6] >> 18) & 0x1F) * 255.f / 0x1F); return (UINT8)(((header[6] >> 18) & 0x1F) * 255.f / 0x1F);
} }
bool PolyHeader::FixedShading()
{
return (header[6] & 0x2000000) > 0;
}
bool PolyHeader::PolyAlpha() bool PolyHeader::PolyAlpha()
{ {
return (header[6] & 0x00800000) == 0; return (header[6] & 0x00800000) == 0;

View file

@ -21,10 +21,11 @@ x------- -------- -------- -------- Specular enable
0x01: 0x01:
xxxxxxxx xxxxxxxx xxxxxxxx-------- Polygon normal X coordinate(2.22 fixed point) xxxxxxxx xxxxxxxx xxxxxxxx-------- Polygon normal X coordinate(2.22 fixed point)
-------- -------- -------- -x------ UV scale (0 = 13.3, 1 = 16.0) -------- -------- -------- -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---- 1 = Double-sided polygon
-------- -------- -------- -----x-- If set, this is the last polygon -------- -------- -------- -----x-- If set, this is the last polygon
-------- -------- -------- ------x- Poly color, 1 = RGB, 0 = color table -------- -------- -------- ------x- Poly color, 1 = RGB, 0 = color table
-------- -------- -------- x-x-x--x ? -------- -------- -------- x---x--x ?
0x02: 0x02:
xxxxxxxx xxxxxxxx xxxxxxxx -------- Polygon normal Y coordinate(2.22 fixed point) 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) xxxxxxxx xxxxxxxx xxxxxxxx -------- Color(RGB888)
-------- -------- -------- x------- Color disabled -------- -------- -------- x------- Color disabled
-------- -------- -------- -x------ Texture page -------- -------- -------- -x------ Texture page
-------- -------- -------- --x----- ?
-------- -------- -------- ---xxxxx Upper 5 bits of texture U coordinate -------- -------- -------- ---xxxxx Upper 5 bits of texture U coordinate
-------- -------- -------- --x----- ?
0x05 : 0x05 :
xxxxxxxx xxxxxxxx xxxxxxxx -------- Specular color ? xxxxxxxx xxxxxxxx xxxxxxxx -------- Specular color ?
@ -94,6 +95,7 @@ public:
bool DoubleSided(); bool DoubleSided();
bool LastPoly(); bool LastPoly();
bool PolyColor(); // if false uses LUT from ram bool PolyColor(); // if false uses LUT from ram
bool FixedShading();
//header 2 //header 2
bool TexUMirror(); bool TexUMirror();
@ -118,7 +120,6 @@ public:
bool LightEnabled(); bool LightEnabled();
bool AlphaTest(); bool AlphaTest();
UINT8 Transparency(); // 0-255 UINT8 Transparency(); // 0-255
bool FixedShading();
bool PolyAlpha(); bool PolyAlpha();
bool TextureAlpha(); bool TextureAlpha();
bool StencilPoly(); bool StencilPoly();