flycast icon indicating copy to clipboard operation
flycast copied to clipboard

Hybrid transparency: Weighted-Blended OIT for standard alpha, A-buffer for special effects

Open Xipong opened this issue 2 months ago • 1 comments

Summary Flycast’s Per-Pixel OIT (A-buffer) is visually correct across all PVR2 transparency modes, but it can introduce sporadic frame-time spikes on some PCs (notably AMD + VRR) due to atomics, per-pixel linked lists and sorting. I propose a hybrid transparency path:

Use Weighted-Blended OIT (WB-OIT) only when the polygon’s blend mode is standard alpha blend (src * α + dst * (1 − α)).

Fallback to the existing Per-Pixel OIT for any non-standard modes (additive/subtractive, modifier volumes, etc.).

Why this makes sense – WB-OIT is very fast and yields smooth frame pacing, but it’s not exact for PVR2’s special modes (as already noted by the maintainer). – Many “heavy” effects in real games (car glass/headlights/smoke in TXR2, etc.) use standard alpha blending, so they benefit from WB-OIT without correctness issues. – Rare special effects still render via A-buffer, preserving accuracy where WB-OIT wouldn’t be correct.

High-level implementation sketch

Parse PVR2 blending flags as usual.

Route transparent polygons into two buckets per frame: • WB-OIT bucket (only if standard alpha); • A-buffer bucket (everything else).

Rendering order (one of the safe orders): – Draw opaque; – Draw A-buffer and resolve; – Draw WB-OIT (MRT accum/reveal) and resolve over the current color buffer. (Alternatively WB-OIT before A-buffer — whichever shows fewer artifacts in practice.)

Core option: Alpha Sorting = Per-Triangle / Per-Pixel (accurate) / Hybrid (WB-OIT where possible).

GL4 & D3D11: WB-OIT needs two color targets (e.g. RGBA16F accum and R16F reveal), trivial blend states (accum: ONE,ONE; reveal: ZERO, INV_SRC_ALPHA), and a fullscreen resolve shader.

Benefits – Significantly smoother frame pacing on PCs sensitive to A-buffer spikes, while keeping visual correctness for special PVR2 effects. – Users can choose the most suitable path: accuracy, speed, or hybrid.

Notes – This does not replace Per-Pixel OIT; it’s an optional hybrid mode. – If desired, we can add a hidden debug overlay (max A-buffer depth per-pixel) to help profiling.

Xipong avatar Oct 27 '25 00:10 Xipong

This is simply impossible: imagine you have 2 transparent triangles intersecting, one using the standard blending, the other one a "non-standard" blending mode. Which one should be drawn first? Well, there is no answer: this is has to be decided at the pixel level.

flyinghead avatar Oct 27 '25 08:10 flyinghead