melonDS-emu / melonDS

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

Misc fixes to shadow/masks and the <= depth test #1994

Open Jaklyy opened 6 months ago

Jaklyy commented 6 months ago

Small fix. Fixes swapped spans not overwriting/not being overwritten by another polygon via "less than" depth test mode when their z values are equal.

Examples: image image

repurposing this pr for my misc fixes because there's a lot of them and they all overlap in some way

Changes: New: swapped spans have their back facing & front facing flags inverted. New: xmajor top edges over xmajor bottom edges/ymajor left edge over ymajor right edges invert the back facing flag's role in the <= depth test. Rework: edge flags now track xmajor top/bottom, ymajor left/right instead of top/bottom/left/right edge Fix: shadow masks dont care about their alpha value unless it's 0 (and even then it's only used to determine edge fill) New: begin support for scfg raster rev bit (currently: alters stencil buffer clear behavior, partially fixes a bug with compressed textures) Fix: stencil buffer is only cleared when starting a mask polygon, and only if a shadow polygon has been rendered after the last mask Fix: opaque shadow polygons don't write/push down the depth/attr buffer Cleanup: Remove a bunch of useless variables from the shadow mask function. Fix: shadow and shadow mask polygons don't have a <= depth test Fix: shadow polygons dont render when wireframe Fix: translucent pixels dont update the back facing flag Fix: always push down the depth buffer, even when it 'should' be useless, because a niche quirk with shadow masks can result in it being used anyway Cleanup: restructure shadow/mask handling to trust that the 2nd bit cannot be set without the first bit also being set. Fix: opaque shadows need a different opaque poly id to render (not sure about translucent id?) Fix: shadow, shadow mask, and decal polygons all count as translucent for poly sorting when a translucent texture mode is applied. Fix: pixels with translucency from textures should be filled New: implement the interaction between edge marking and edge flags New: implement the bug that causes 4x4 compressed textures to be 1/64th darker than they should otherwise be in modes that use interpolated colors Fix: when using 4x4 compressed textures, the interpolated colors do not discard color precision down to 5 bit, they stay 6 bit