Skip to content

Improve undoVanillaShading - #1161

Open
SirFancyBacon wants to merge 12 commits into
117HD:masterfrom
SirFancyBacon:undoVanillaShadingOverhaul
Open

Improve undoVanillaShading#1161
SirFancyBacon wants to merge 12 commits into
117HD:masterfrom
SirFancyBacon:undoVanillaShadingOverhaul

Conversation

@SirFancyBacon

@SirFancyBacon SirFancyBacon commented Aug 8, 2026

Copy link
Copy Markdown
Contributor

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 11f floor 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.2f slope provides the massive lift needed to successfully flatten mid-tone surfaces (like the Falador walls).

  • Prevents Artifacting: The gentle 0.012f brake 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:
image
image

image image

@SirFancyBacon
SirFancyBacon marked this pull request as draft August 8, 2026 02:19
@SirFancyBacon

Copy link
Copy Markdown
Contributor Author

Master/PR(Unlit screens):
image
image

@SirFancyBacon
SirFancyBacon marked this pull request as ready for review August 9, 2026 01:42
@SirFancyBacon SirFancyBacon changed the title Improve removal of Vanilla Shading Improve undoVanillaShading Aug 9, 2026
@SirFancyBacon
SirFancyBacon force-pushed the undoVanillaShadingOverhaul branch from 2c687dc to a4dc925 Compare August 13, 2026 21:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant