mirror of
https://github.com/RetroPortingToolKit/psxrecomp
synced 2026-10-28 02:56:36 -04:00
ab04da86e3
PGXP depth shattered the scene, and the reason was a category error rather than a tuning problem. It derived depth from a_q, which is q/qmax -- a perspective weight normalised WITHIN one triangle. Every triangle therefore got its own private 0..1 range, so the value said nothing about where one triangle sat relative to another, which is the only thing a depth buffer is for. The real depth was already in hand and being thrown away. prepare_texture_triangle reads a 16-bit GTE screen Z per vertex via gte_precision_load_word, then normalises it away on the very next line because UV correction only needs relative weights. That Z is a single global scale, so it is exactly what a depth buffer wants. Adds gr_set_depth_triangle alongside gr_set_perspective_triangle rather than widening it: the two carry different quantities for different purposes, and a null-safe hook leaves the software backend untouched. The GL backend takes it as its own vertex attribute (a_z, location 10) and maps it straight to NDC. Verified in 3D attract-mode gameplay: with pgxp_depth on the scene renders intact -- track, perspective-correct texturing and effects all correct -- where before it shattered. On the 2D title screen the on/off frames are bit-identical, because no primitive there carries GTE provenance, so a_z is 0 and depth stays off. Still default-off in config; this makes the feature viable, it does not turn it on. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>