mirror of
https://github.com/flyinghead/flycast.git
synced 2026-11-07 09:16:10 -10:00
Vulkan without VK_EXT_provoking_vertex, DX9 and DX11 take flat-shaded colors from the first vertex, while on Dreamcast it's the last. For the depth-sorted triangle list, setFirstProvokingVertex() copied each triangle's last vertex colors onto its first vertex. But sortTriangles() builds these triangles from strips, so neighbors share vertices: tri0=(P0,P1,P2), tri1=(P2,P1,P3). P2 is tri0's source and tri1's destination, and the list is processed in depth order, so one triangle's flat color can overwrite another's before it's read. In strips of three or more triangles, consecutive triangles even share their first vertex. Flat-shaded translucent polygons then pick up a neighbor's color, e.g. the player shadow decals in Tony Hawk's Pro Skater 2 and Mat Hoffman's Pro BMX turn uniformly dark. Each sorted triangle has its own three slots in idx, so rotate them (a,b,c) -> (c,a,b) instead. The winding is unchanged and the provoking vertex comes first, without touching shared vertices. Strips keep the color copy, which is safe there. Adds SorterTest, which fails on the old code and passes with this change. Co-authored-by: Claude Opus 5.5 <[email protected]> [ci skip]