melonDS-emu / melonDS

DS emulator, sorta
https://melonds.kuribo64.net
GNU General Public License v3.0
2.99k stars 497 forks source link

Improve calculation of light colors #1967

Open Jaklyy opened 5 months ago

Jaklyy commented 5 months ago

Edit: This pr improves the algorithm for diffuse lighting to be (near?) perfect, thanks to discoveries by asuza. This also changes the way fractional color precision is handled to be maintained until all lights are calculated.

Previous text: Fixes https://github.com/melonDS-emu/melonDS/issues/1966 Results in lighting being noticeably brighter when multiple lights are enabled. Colors seem to match hardware better. Doesn't appear to be perfect, though it's possible those imperfections are due to inaccurate interpolation rather than problems with the lighting calc itself. Definitely needs some test rom verification, though.

Before: image After: image HW Capture (frame dump "reconstructed full color" screenshot): image

Jaklyy commented 5 months ago

messing with a test rom reveals that there's definitely still something ever so slightly off in the color calcs but it seems to overall be much closer to hardware

Jaklyy commented 4 months ago

Emissive and Ambient lighting are pixel perfect. Diffuse light should be pixel perfect (minus overflow behavior) Specular still needs work.

Updated Lugia: image