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 {
CNew3D::CNew3D(const Util::Config::Node &config)
CNew3D::CNew3D(const Util::Config::Node &config, std::string gameName)
: m_r3dShader(config),
m_r3dScrollFog(config)
m_r3dScrollFog(config),
m_gameName(gameName)
{
m_cullingRAMLo = nullptr;
m_cullingRAMHi = nullptr;
@ -782,7 +783,15 @@ void CNew3D::RenderViewport(UINT32 addr)
vp->lightingParams[4] = (float)((vpnode[0x24] >> 8) & 0xFF) * (1.0f / 255.0f); // ambient intensity
vp->lightingParams[5] = 0.0; // reserved
vp->sunClamp = 1; // TODO work out how this is passed, doesn't appear to be in the viewport .. or in the model data
// 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->intensityClamp = (m_step == 0x10); // just step 1.0 ?
vp->hardwareStep = m_step;

View file

@ -150,7 +150,7 @@ public:
* Parameters:
* config Run-time configuration.
*/
CNew3D(const Util::Config::Node &config);
CNew3D(const Util::Config::Node &config, std::string gameName);
~CNew3D(void);
private:
@ -191,6 +191,9 @@ private:
* Data
*/
// Misc
std::string m_gameName;
// Stepping
int m_step;
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 bool lightEnabled; // also used in fragment shader
uniform bool fixedShading; // also used in fragment shader
uniform bool sunClamp; // also used in fragment shader
// attributes
attribute vec3 inVertex;
@ -36,16 +37,17 @@ vec4 GetVertexColour()
vec4 polyColour = inColour;
if(fixedShading) {
if(hardwareStep==0x15) {
float lightAmbient = lighting[1].y;
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
}
if(lightEnabled) {
polyColour.rgb *= (inFixedShade + lighting[1].y); // per vertex brightness + ambient
polyColour.rgb *= (inFixedShade + lightAmbient); // per vertex brightness + ambient
}
else {
polyColour.rgb += lighting[1].y; // this is similar to above but basically a flat shaded version. So poly colour + ambient
}
}
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
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))
goto QuitError;
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
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))
goto QuitError;
if (OKAY != Render3D->Init(xOffset, yOffset, xRes, yRes, totalXRes, totalYRes))