Remove fixed shading check from specular.

This commit is contained in:
Ian Curtis 2017-10-07 12:39:30 +00:00
parent 4d685e0750
commit 7f6df0cc84

View file

@ -164,40 +164,40 @@ void main()
float ellipse; float ellipse;
ellipse = length((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw); ellipse = length((gl_FragCoord.xy - spotEllipse.xy) / spotEllipse.zw);
ellipse = pow(ellipse, 2.0); // decay rate = square of distance from center ellipse = pow(ellipse, 2.0); // decay rate = square of distance from center
ellipse = 1.0 - ellipse; // invert ellipse = 1.0 - ellipse; // invert
ellipse = max(0.0, ellipse); // clamp ellipse = max(0.0, ellipse); // clamp
// Compute spotlight and apply lighting // Compute spotlight and apply lighting
float enable, absExtent, d, inv_r, range; float enable, absExtent, d, inv_r, range;
// start of spotlight // start of spotlight
enable = step(spotRange.x, -fsViewVertex.z); enable = step(spotRange.x, -fsViewVertex.z);
if (spotRange.y == 0.0) { if (spotRange.y == 0.0) {
range = 0.0; range = 0.0;
} }
else { else {
absExtent = abs(spotRange.y); absExtent = abs(spotRange.y);
d = spotRange.x + absExtent + fsViewVertex.z; d = spotRange.x + absExtent + fsViewVertex.z;
d = min(d, 0.0); d = min(d, 0.0);
// slope of decay function // slope of decay function
inv_r = 1.0 / (1.0 + absExtent); inv_r = 1.0 / (1.0 + absExtent);
// inverse-linear falloff // inverse-linear falloff
// Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ // Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/
// y = 1 / (d/r + 1)^2 // y = 1 / (d/r + 1)^2
range = 1.0 / pow(d * inv_r - 1.0, 2.0); range = 1.0 / pow(d * inv_r - 1.0, 2.0);
range *= enable; range *= enable;
} }
float lobeEffect = range * ellipse; float lobeEffect = range * ellipse;
float lobeFogEffect = enable * ellipse; float lobeFogEffect = enable * ellipse;
if (lightEnabled) { if (lightEnabled) {
vec3 lightIntensity; vec3 lightIntensity;
vec3 sunVector; // sun lighting vector (as reflecting away from vertex) vec3 sunVector; // sun lighting vector (as reflecting away from vertex)
float sunFactor; // sun light projection along vertex normal (0.0 to 1.0) float sunFactor; // sun light projection along vertex normal (0.0 to 1.0)
// Sun angle // Sun angle
@ -224,15 +224,15 @@ void main()
// Upper clamp is optional, step 1.5+ games will drive brightness beyond 100% // Upper clamp is optional, step 1.5+ games will drive brightness beyond 100%
if(intensityClamp) { if(intensityClamp) {
lightIntensity = min(lightIntensity,1.0); lightIntensity = min(lightIntensity,1.0);
} }
lightIntensity.rgb += spotColor*lobeEffect; lightIntensity.rgb += spotColor*lobeEffect;
finalData.rgb *= lightIntensity; finalData.rgb *= lightIntensity;
// for now assume fixed shading doesn't work with specular // for now assume fixed shading doesn't work with specular
if (specularEnabled && !fixedShading) { if (specularEnabled) {
float exponent, NdotL, specularFactor; float exponent, NdotL, specularFactor;
vec4 biasIndex, expIndex, multIndex; vec4 biasIndex, expIndex, multIndex;
@ -262,16 +262,16 @@ void main()
} }
// Final clamp: we need it for proper shading in dimmed light and dark ambients // Final clamp: we need it for proper shading in dimmed light and dark ambients
finalData.rgb = min(finalData.rgb, vec3(1.0)); finalData.rgb = min(finalData.rgb, vec3(1.0));
// Spotlight on fog // Spotlight on fog
vec3 lSpotFogColor = spotFogColor * fogAttenuation * fogColour.rgb * lobeFogEffect; vec3 lSpotFogColor = spotFogColor * fogAttenuation * fogColour.rgb * lobeFogEffect;
// Fog & spotlight applied // Fog & spotlight applied
finalData.rgb = mix(finalData.rgb, fogData.rgb + lSpotFogColor, fogData.a); finalData.rgb = mix(finalData.rgb, fogData.rgb + lSpotFogColor, fogData.a);
gl_FragColor = finalData; gl_FragColor = finalData;
} }
)glsl"; )glsl";
R3DShader::R3DShader(const Util::Config::Node &config) R3DShader::R3DShader(const Util::Config::Node &config)