Improve undoVanillaShading - #1161
Open
SirFancyBacon wants to merge 12 commits into
Open
Conversation
SirFancyBacon
marked this pull request as draft
August 8, 2026 02:19
Contributor
Author
SirFancyBacon
marked this pull request as ready for review
August 9, 2026 01:42
SirFancyBacon
force-pushed
the
undoVanillaShadingOverhaul
branch
from
August 13, 2026 21:30
2c687dc to
a4dc925
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Reworks the undoVanillaShading function to more accurately reverse vanilla shading.
The previous heuristic relied on an artificial cut-off (
IGNORE_LOW_LIGHTNESS) that crushed deep blacks into flat blobs and caused artifacting across gradients.By replacing the old piecewise math with a single, perfectly smooth polynomial curve, we achieved much more accurate global un-shading while simultaneously reducing the CPU overhead per vertex.
Key Changes & Improvements:
The "Golden" Monotonic Curve: Replaced the old threshold logic with a continuous polynomial curve (
11f + (l * 2.2f) - (l * l * 0.012f)).Fixes Crushed Blacks: The
11ffloor safely lifts the darkest vertices without grouping them together, restoring rich gradients to dark grey objects (like rocks and pillars).Flattens Mid-Tones: The
2.2fslope provides the massive lift needed to successfully flatten mid-tone surfaces (like the Falador walls).Prevents Artifacting: The gentle
0.012fbrake ensures the curve never bends backward (non-monotonic inversion), eliminating the harsh, unnatural shading bands present in previous iterations.CPU Optimization: Since this method runs constantly on vertex data, we stripped out expensive operations:
Replaced division and branching with a single fast inverse square root (
1.0f / Math.sqrt(len)).Factored out the uniform vanilla light vector
(0.577, 0.577, 0.577). Instead of three separate axis multiplications, the engine now sums the normals and performs a single multiplication for the dot product.Code Cleanup: Removed the legacy variables (
IGNORE_LOW_LIGHTNESS,LIGHTNESS_MULTIPLIER,BASE_LIGHTEN) and the dynamic sun vector matrices that are no longer needed by this unified math profile.Master/PR:

