Implement unclamped light model based upon Harry's findings. Unknown how this is turned on/off.

This commit is contained in:
Ian Curtis 2017-07-22 17:15:14 +00:00
parent 2335f3173b
commit a9b49c1676
4 changed files with 19 additions and 4 deletions

View file

@ -134,6 +134,7 @@ struct Viewport
Mat4 projectionMatrix; // projection matrix, we will calc this later when we have scene near/far vals 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) 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 spotEllipse[4]; // spotlight ellipse (see RenderViewport())
float spotRange[2]; // Z range float spotRange[2]; // Z range
float spotColor[3]; // color float spotColor[3]; // color

View file

@ -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[4] = (float)((vpnode[0x24] >> 8) & 0xFF) * (1.0f / 255.0f); // ambient intensity
vp->lightingParams[5] = 0.0; // reserved 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 m_vpAmbient = vp->lightingParams[4]; // cache this
// Spotlight // Spotlight

View file

@ -34,13 +34,16 @@ static const char *fragmentShaderR3D = R"glsl(
uniform sampler2D tex1; // base tex uniform sampler2D tex1; // base tex
uniform sampler2D tex2; // micro tex (optional) uniform sampler2D tex2; // micro tex (optional)
// texturing
uniform bool textureEnabled; uniform bool textureEnabled;
uniform bool microTexture; uniform bool microTexture;
uniform float microTextureScale; uniform float microTextureScale;
uniform vec2 baseTexSize; uniform vec2 baseTexSize;
uniform bool textureInverted; uniform bool textureInverted;
uniform bool alphaTest;
uniform bool textureAlpha; uniform bool textureAlpha;
uniform bool alphaTest;
// general
uniform vec3 fogColour; uniform vec3 fogColour;
uniform vec4 spotEllipse; // spotlight ellipse position: .x=X position (screen coordinates), .y=Y position, .z=half-width, .w=half-height) 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 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 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 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 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 specularCoefficient;// specular coefficient
uniform float shininess; // specular shininess uniform float shininess; // specular shininess
uniform float fogAttenuation; uniform float fogAttenuation;
@ -57,7 +61,7 @@ uniform float fogAmbient;
varying float fsFogFactor; varying float fsFogFactor;
varying vec3 fsViewVertex; varying vec3 fsViewVertex;
varying vec3 fsViewNormal; // per vertex normal vector varying vec3 fsViewNormal; // per vertex normal vector
varying vec4 fsColor; varying vec4 fsColor;
vec4 GetTextureValue() vec4 GetTextureValue()
{ {
@ -122,10 +126,15 @@ void main()
sunVector = lighting[0]; sunVector = lighting[0];
// Compute diffuse factor for sunlight // 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 // 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); 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_locLighting = glGetUniformLocation(m_shaderProgram, "lighting");
m_locLightEnable = glGetUniformLocation(m_shaderProgram, "lightEnable"); m_locLightEnable = glGetUniformLocation(m_shaderProgram, "lightEnable");
m_locLightClamp = glGetUniformLocation(m_shaderProgram, "lightClamp");
m_locShininess = glGetUniformLocation(m_shaderProgram, "shininess"); m_locShininess = glGetUniformLocation(m_shaderProgram, "shininess");
m_locSpecCoefficient= glGetUniformLocation(m_shaderProgram, "specularCoefficient"); m_locSpecCoefficient= glGetUniformLocation(m_shaderProgram, "specularCoefficient");
m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse"); m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse");
@ -366,6 +376,7 @@ void R3DShader::SetViewportUniforms(const Viewport *vp)
glUniform1f (m_locFogAmbient, vp->fogParams[6]); glUniform1f (m_locFogAmbient, vp->fogParams[6]);
glUniform3fv(m_locLighting, 2, vp->lightingParams); glUniform3fv(m_locLighting, 2, vp->lightingParams);
glUniform1i(m_locLightClamp, vp->lightClamp);
glUniform4fv(m_locSpotEllipse, 1, vp->spotEllipse); glUniform4fv(m_locSpotEllipse, 1, vp->spotEllipse);
glUniform2fv(m_locSpotRange, 1, vp->spotRange); glUniform2fv(m_locSpotRange, 1, vp->spotRange);
glUniform3fv(m_locSpotColor, 1, vp->spotColor); glUniform3fv(m_locSpotColor, 1, vp->spotColor);

View file

@ -70,6 +70,7 @@ private:
// lighting // lighting
GLint m_locLighting; GLint m_locLighting;
GLint m_locLightEnable; GLint m_locLightEnable;
GLint m_locLightClamp;
GLint m_locShininess; GLint m_locShininess;
GLint m_locSpecCoefficient; GLint m_locSpecCoefficient;
GLint m_locSpotEllipse; GLint m_locSpotEllipse;