Finish fixed shading for 2.0 hardware. I'm pretty sure it actually works identically to step 1.5 hardware. The oddball is LA machine guns where the viewport ambient doesn't seem to effect the brightness. But the ambient works differently in this game because it uses the unclamped light model. Still need to investigate if the diffuse factor effects fixed shading.

This commit is contained in:
Ian Curtis 2017-08-15 23:21:57 +00:00
parent b1cc9a615d
commit 0efd4dac39
4 changed files with 28 additions and 14 deletions

View file

@ -12,9 +12,10 @@
namespace New3D { namespace New3D {
CNew3D::CNew3D(const Util::Config::Node &config) CNew3D::CNew3D(const Util::Config::Node &config, std::string gameName)
: m_r3dShader(config), : m_r3dShader(config),
m_r3dScrollFog(config) m_r3dScrollFog(config),
m_gameName(gameName)
{ {
m_cullingRAMLo = nullptr; m_cullingRAMLo = nullptr;
m_cullingRAMHi = nullptr; m_cullingRAMHi = nullptr;
@ -781,8 +782,16 @@ void CNew3D::RenderViewport(UINT32 addr)
vp->lightingParams[3] = std::max(0.f, std::min(*(float *)&vpnode[0x07], 1.0f)); // sun intensity (clamp to 0-1) vp->lightingParams[3] = std::max(0.f, std::min(*(float *)&vpnode[0x07], 1.0f)); // sun intensity (clamp to 0-1)
vp->lightingParams[4] = (float)((vpnode[0x24] >> 8) & 0xFF) * (1.0f / 255.0f); // ambient intensity vp->lightingParams[4] = (float)((vpnode[0x24] >> 8) & 0xFF) * (1.0f / 255.0f); // ambient intensity
vp->lightingParams[5] = 0.0; // reserved vp->lightingParams[5] = 0.0; // reserved
// this is a hack because we haven't yet found in memory where these are set
// these two games use a slightly different light model to the test of the games
if (m_gameName == "lamachin" || m_gameName == "dayto2pe") {
vp->sunClamp = false;
}
else {
vp->sunClamp = true;
}
vp->sunClamp = 1; // TODO work out how this is passed, doesn't appear to be in the viewport .. or in the model data
vp->intensityClamp = (m_step == 0x10); // just step 1.0 ? vp->intensityClamp = (m_step == 0x10); // just step 1.0 ?
vp->hardwareStep = m_step; vp->hardwareStep = m_step;

View file

@ -150,7 +150,7 @@ public:
* Parameters: * Parameters:
* config Run-time configuration. * config Run-time configuration.
*/ */
CNew3D(const Util::Config::Node &config); CNew3D(const Util::Config::Node &config, std::string gameName);
~CNew3D(void); ~CNew3D(void);
private: private:
@ -191,6 +191,9 @@ private:
* Data * Data
*/ */
// Misc
std::string m_gameName;
// Stepping // Stepping
int m_step; int m_step;
int m_offset; // offset to subtract for words 3 and higher of culling nodes int m_offset; // offset to subtract for words 3 and higher of culling nodes

View file

@ -16,6 +16,7 @@ uniform int hardwareStep;
uniform vec3 lighting[2]; // also used in fragment shader uniform vec3 lighting[2]; // also used in fragment shader
uniform bool lightEnabled; // also used in fragment shader uniform bool lightEnabled; // also used in fragment shader
uniform bool fixedShading; // also used in fragment shader uniform bool fixedShading; // also used in fragment shader
uniform bool sunClamp; // also used in fragment shader
// attributes // attributes
attribute vec3 inVertex; attribute vec3 inVertex;
@ -36,16 +37,17 @@ vec4 GetVertexColour()
vec4 polyColour = inColour; vec4 polyColour = inColour;
if(fixedShading) { if(fixedShading) {
if(hardwareStep==0x15) {
if(lightEnabled) { float lightAmbient = lighting[1].y;
polyColour.rgb *= (inFixedShade + lighting[1].y); // per vertex brightness + ambient if(!sunClamp) {
} lightAmbient = 0; // guess work here. La machine guns is the only game to use this light model. Black is black in this game, it's not effected by ambient
else { }
polyColour.rgb += lighting[1].y; // this is similar to above but basically a flat shaded version. So poly colour + ambient
} if(lightEnabled) {
polyColour.rgb *= (inFixedShade + lightAmbient); // per vertex brightness + ambient
} }
else { else {
polyColour.rgb *= inFixedShade; //todo work out what ambient does. Probably a min clamp or 1-min clamp for signed values polyColour.rgb += lightAmbient; // this is similar to above but basically a flat shaded version. So poly colour + ambient
} }
} }

View file

@ -829,7 +829,7 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In
// Initialize the renderers // Initialize the renderers
CRender2D *Render2D = new CRender2D(s_runtime_config); CRender2D *Render2D = new CRender2D(s_runtime_config);
IRender3D *Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); IRender3D *Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config, Model3->GetGame().name)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config));
if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))
goto QuitError; goto QuitError;
if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))
@ -971,7 +971,7 @@ int Supermodel(const Game &game, ROMSet *rom_set, IEmulator *Model3, CInputs *In
// Recreate renderers and attach to the emulator // Recreate renderers and attach to the emulator
Render2D = new CRender2D(s_runtime_config); Render2D = new CRender2D(s_runtime_config);
Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config)); Render3D = s_runtime_config["New3DEngine"].ValueAs<bool>() ? ((IRender3D *) new New3D::CNew3D(s_runtime_config, Model3->GetGame().name)) : ((IRender3D *) new Legacy3D::CLegacy3D(s_runtime_config));
if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) if (OKAY != Render2D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))
goto QuitError; goto QuitError;
if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes)) if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))