Add the unclamped light model we know exists to the shaders.

This commit is contained in:
Ian Curtis 2017-08-03 10:41:18 +00:00
parent b1bd877b82
commit 3fc28159eb
4 changed files with 21 additions and 9 deletions

View file

@ -137,7 +137,8 @@ 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
bool sunClamp; // unknown how this is set
bool intensityClamp; // unknown how this is set
float spotEllipse[4]; // spotlight ellipse (see RenderViewport())
float spotRange[2]; // Z range
float spotColor[3]; // color

View file

@ -777,7 +777,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
vp->sunClamp = true; //TODO work out how this is passed, doesn't appear to be in the viewport .. or in the model data
vp->intensityClamp = 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

View file

@ -52,7 +52,8 @@ 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 bool sunClamp; // not used by daytona and la machine guns
uniform bool intensityClamp; // some games such as daytona and
uniform float specularCoefficient;// specular coefficient
uniform float shininess; // specular shininess
uniform float fogAttenuation;
@ -129,15 +130,21 @@ void main()
// Compute diffuse factor for sunlight
sunFactor = dot(sunVector, fsViewNormal);
// Optional clamping
if(lightClamp) {
// Optional clamping, value is allowed to be negative
if(sunClamp) {
sunFactor = max(sunFactor,0.0);
}
// Total light intensity: sum of all components
lightIntensity = vec3(sunFactor*lighting[1].x + lighting[1].y); // diffuse + ambient
lightIntensity = clamp(lightIntensity,0.0,1.0);
// Need a minimum clamp
lightIntensity = max(lightIntensity,0.0);
// Upper clamp is optional, so games will drive brightness beyond 100%
if(intensityClamp) {
lightIntensity = min(lightIntensity,1.0);
}
// Compute spotlight and apply lighting
float enable, range, d;
@ -250,7 +257,8 @@ 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_locSunClamp = glGetUniformLocation(m_shaderProgram, "sunClamp");
m_locIntensityClamp = glGetUniformLocation(m_shaderProgram, "intensityClamp");
m_locShininess = glGetUniformLocation(m_shaderProgram, "shininess");
m_locSpecCoefficient= glGetUniformLocation(m_shaderProgram, "specularCoefficient");
m_locSpotEllipse = glGetUniformLocation(m_shaderProgram, "spotEllipse");
@ -379,7 +387,8 @@ void R3DShader::SetViewportUniforms(const Viewport *vp)
glUniform1f (m_locFogAmbient, vp->fogParams[6]);
glUniform3fv(m_locLighting, 2, vp->lightingParams);
glUniform1i(m_locLightClamp, vp->lightClamp);
glUniform1i (m_locSunClamp, vp->sunClamp);
glUniform1i (m_locIntensityClamp, vp->intensityClamp);
glUniform4fv(m_locSpotEllipse, 1, vp->spotEllipse);
glUniform2fv(m_locSpotRange, 1, vp->spotRange);
glUniform3fv(m_locSpotColor, 1, vp->spotColor);

View file

@ -71,7 +71,8 @@ private:
// lighting / other
GLint m_locLighting;
GLint m_locLightEnable;
GLint m_locLightClamp;
GLint m_locSunClamp;
GLint m_locIntensityClamp;
GLint m_locShininess;
GLint m_locSpecCoefficient;
GLint m_locSpotEllipse;