From a9b49c16768629785b842653c309fdd648ca00c3 Mon Sep 17 00:00:00 2001 From: Ian Curtis Date: Sat, 22 Jul 2017 17:15:14 +0000 Subject: [PATCH] Implement unclamped light model based upon Harry's findings. Unknown how this is turned on/off. --- Src/Graphics/New3D/Model.h | 1 + Src/Graphics/New3D/New3D.cpp | 2 ++ Src/Graphics/New3D/R3DShader.cpp | 19 +++++++++++++++---- Src/Graphics/New3D/R3DShader.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/Src/Graphics/New3D/Model.h b/Src/Graphics/New3D/Model.h index 76cdaa2..0ad3774 100644 --- a/Src/Graphics/New3D/Model.h +++ b/Src/Graphics/New3D/Model.h @@ -134,6 +134,7 @@ struct Viewport Mat4 projectionMatrix; // projection matrix, we will calc this later when we have scene near/far vals float lightingParams[6]; // lighting parameters (see RenderViewport() and vertex shader) + bool lightClamp; // unknown how this is set float spotEllipse[4]; // spotlight ellipse (see RenderViewport()) float spotRange[2]; // Z range float spotColor[3]; // color diff --git a/Src/Graphics/New3D/New3D.cpp b/Src/Graphics/New3D/New3D.cpp index 53a6d44..c6e20d5 100644 --- a/Src/Graphics/New3D/New3D.cpp +++ b/Src/Graphics/New3D/New3D.cpp @@ -770,6 +770,8 @@ 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->lightClamp = true; //TODO work out how this is passed, doesn't appear to be in the viewport .. or in the model data + m_vpAmbient = vp->lightingParams[4]; // cache this // Spotlight diff --git a/Src/Graphics/New3D/R3DShader.cpp b/Src/Graphics/New3D/R3DShader.cpp index 7f5b545..ffda1cd 100644 --- a/Src/Graphics/New3D/R3DShader.cpp +++ b/Src/Graphics/New3D/R3DShader.cpp @@ -34,13 +34,16 @@ static const char *fragmentShaderR3D = R"glsl( uniform sampler2D tex1; // base tex uniform sampler2D tex2; // micro tex (optional) +// texturing uniform bool textureEnabled; uniform bool microTexture; uniform float microTextureScale; uniform vec2 baseTexSize; uniform bool textureInverted; -uniform bool alphaTest; uniform bool textureAlpha; +uniform bool alphaTest; + +// general uniform vec3 fogColour; uniform vec4 spotEllipse; // spotlight ellipse position: .x=X position (screen coordinates), .y=Y position, .z=half-width, .w=half-height) uniform vec2 spotRange; // spotlight Z range: .x=start (viewspace coordinates), .y=limit @@ -48,6 +51,7 @@ uniform vec3 spotColor; // spotlight RGB color uniform vec3 spotFogColor; // spotlight RGB color on fog uniform vec3 lighting[2]; // lighting state (lighting[0] = sun direction, lighting[1].x,y = diffuse, ambient intensities from 0-1.0) uniform bool lightEnable; // lighting enabled (1.0) or luminous (0.0), drawn at full intensity +uniform bool lightClamp; // not used by daytona and la machine guns uniform float specularCoefficient;// specular coefficient uniform float shininess; // specular shininess uniform float fogAttenuation; @@ -57,7 +61,7 @@ uniform float fogAmbient; varying float fsFogFactor; varying vec3 fsViewVertex; varying vec3 fsViewNormal; // per vertex normal vector -varying vec4 fsColor; +varying vec4 fsColor; vec4 GetTextureValue() { @@ -122,10 +126,15 @@ void main() sunVector = lighting[0]; // Compute diffuse factor for sunlight - sunFactor = max(dot(sunVector, fsViewNormal), 0.0); + sunFactor = dot(sunVector, fsViewNormal); + + // Optional clamping + if(lightClamp) { + sunFactor = max(sunFactor,0.0); + } // Total light intensity: sum of all components - lightIntensity = vec3(sunFactor*lighting[1].x + min(lighting[1].y,0.75)); // diffuse + ambient (clamped to max 0.75) + lightIntensity = vec3(sunFactor*lighting[1].x + lighting[1].y); // diffuse + ambient lightIntensity = clamp(lightIntensity,0.0,1.0); @@ -239,6 +248,7 @@ bool R3DShader::LoadShader(const char* vertexShader, const char* fragmentShader) m_locLighting = glGetUniformLocation(m_shaderProgram, "lighting"); m_locLightEnable = glGetUniformLocation(m_shaderProgram, "lightEnable"); + m_locLightClamp = glGetUniformLocation(m_shaderProgram, "lightClamp"); m_locShininess = glGetUniformLocation(m_shaderProgram, "shininess"); m_locSpecCoefficient= glGetUniformLocation(m_shaderProgram, "specularCoefficient"); m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse"); @@ -366,6 +376,7 @@ void R3DShader::SetViewportUniforms(const Viewport *vp) glUniform1f (m_locFogAmbient, vp->fogParams[6]); glUniform3fv(m_locLighting, 2, vp->lightingParams); + glUniform1i(m_locLightClamp, vp->lightClamp); glUniform4fv(m_locSpotEllipse, 1, vp->spotEllipse); glUniform2fv(m_locSpotRange, 1, vp->spotRange); glUniform3fv(m_locSpotColor, 1, vp->spotColor); diff --git a/Src/Graphics/New3D/R3DShader.h b/Src/Graphics/New3D/R3DShader.h index b2d2580..dfe6a4b 100644 --- a/Src/Graphics/New3D/R3DShader.h +++ b/Src/Graphics/New3D/R3DShader.h @@ -70,6 +70,7 @@ private: // lighting GLint m_locLighting; GLint m_locLightEnable; + GLint m_locLightClamp; GLint m_locShininess; GLint m_locSpecCoefficient; GLint m_locSpotEllipse;