PK k³AK®6}• • diff.patchdiff -ur --binary model3emu/Src/Graphics/New3D/New3D.cpp model3emu-patch/Src/Graphics/New3D/New3D.cpp --- model3emu/Src/Graphics/New3D/New3D.cpp 2017-10-01 22:16:03.000000000 +0200 +++ model3emu-patch/Src/Graphics/New3D/New3D.cpp 2017-10-01 22:13:17.385742100 +0200 @@ -801,9 +801,11 @@ vp->spotRange[0] = 1.0f / (*(float *)&vpnode[0x21]); // spotlight start vp->spotRange[1] = *(float *)&vpnode[0x1F]; // spotlight extent - // Star Wars Trilogy needs this + // Star Wars Trilogy needs this (?) + /* vp->spotRange[0] = std::min(vp->spotRange[0], std::numeric_limits::max()); vp->spotRange[0] = std::max(vp->spotRange[0], std::numeric_limits::lowest()); + */ vp->spotColor[0] = color[spotColorIdx][0]; // spotlight color vp->spotColor[1] = color[spotColorIdx][1]; diff -ur --binary model3emu/Src/Graphics/New3D/R3DShader.cpp model3emu-patch/Src/Graphics/New3D/R3DShader.cpp --- model3emu/Src/Graphics/New3D/R3DShader.cpp 2017-10-01 22:16:03.000000000 +0200 +++ model3emu-patch/Src/Graphics/New3D/R3DShader.cpp 2017-10-01 22:15:55.310546800 +0200 @@ -167,6 +167,34 @@ ellipse = 1.0 - ellipse; // invert ellipse = max(0.0, ellipse); // clamp + // Compute spotlight and apply lighting + float enable, absExtent, d, inv_r, range; + + // start of spotlight + enable = step(spotRange.x, -fsViewVertex.z); + + if (spotRange.y == 0.0) { + range = 0.0; + } + else { + absExtent = abs(spotRange.y); + + d = spotRange.x + absExtent + fsViewVertex.z; + d = min(d, 0.0); + + // slope of decay function + inv_r = 1.0 / (1.0 + absExtent); + + // inverse-linear falloff + // Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ + // y = 1 / (d/r + 1)^2 + range = 1.0 / pow(d * inv_r - 1.0, 2.0); + range *= enable; + } + + float lobeEffect = range * ellipse; + float lobeFogEffect = enable * ellipse; + if (lightEnabled) { vec3 lightIntensity; vec3 sunVector; // sun lighting vector (as reflecting away from vertex) @@ -199,22 +227,6 @@ lightIntensity = min(lightIntensity,1.0); } - // Compute spotlight and apply lighting - float enable, range, d; - float inv_r = 1.0 / spotEllipse.z; // slope of decay function - - d = spotRange.x + spotRange.y + fsViewVertex.z; - enable = step(spotRange.x + min(spotRange.y, 0.0), -fsViewVertex.z); - - // inverse-linear falloff - // Reference: https://imdoingitwrong.wordpress.com/2011/01/31/light-attenuation/ - // y = 1 / (d/r + 1)^2 - range = 1.0 / pow(min(0.0, d * inv_r) - 1.0, 2.0); - range = clamp(range, 0.0, 1.0); - range *= enable; - - float lobeEffect = range * ellipse; - lightIntensity.rgb += spotColor*lobeEffect; finalData.rgb *= lightIntensity; @@ -253,10 +265,10 @@ finalData.rgb = min(finalData.rgb, vec3(1.0)); // Spotlight on fog - vec3 lSpotFogColor = spotFogColor * ellipse * fogColour.rgb; + vec3 lSpotFogColor = spotFogColor * fogAttenuation * fogColour.rgb * lobeFogEffect; // Fog & spotlight applied - finalData.rgb = mix(finalData.rgb, lSpotFogColor * fogAttenuation + fogData.rgb, fogData.a); + finalData.rgb = mix(finalData.rgb, fogData.rgb + lSpotFogColor, fogData.a); gl_FragColor = finalData; } PK k³AK®6}• • $ diff.patch &%°ó:Ó&%°ó:ÓãÃî¦ó:ÓPK\½