Skip to main content
← PSoXide SDK guides and examples · SDK f2fec1c301f1 · All Cargo features enabled; check feature gates before use.

project_triangle_fogged

Function project_triangle_fogged 

Source
pub fn project_triangle_fogged(
    verts: [Vec3I16; 3],
    normals: [Vec3I16; 3],
    material: (u8, u8, u8),
) -> FoggedTri
Expand description

Run the full PS1-commercial triangle pipeline with per-vertex fog. Three interleaved RTPS + NCDS pairs give each vertex its own IR0 (its own depth-cue weight), then NCLIP + AVSZ3 finish the bookkeeping.

§Why per-vertex, not batched

RTPT + NCDT is faster (4 GTE ops vs 8) but produces uniform fog across each triangle – RTPT only writes IR0 for the last vertex, and NCDT then reuses that single IR0 for each vertex’s stage-3 blend. The visible result is stepped shading: every triangle has one flat fog tint, and seams between triangles are obvious.

3× RTPS + 3× NCDS sets IR0 per vertex, so NCDS blends each vertex’s material toward FC by that vertex’s own depth weight. GP0 0x34 Gouraud-interpolates the three vertex tints across the triangle, giving a smooth per-pixel gradient with no inter-triangle seam.

Cost is about 2× the GTE work per triangle vs the batched path. Still well under budget for PSX-scale scenes (~100 tris/frame).

§Pipeline

For each vertex i = 0, 1, 2:

  1. Load verts[i] into V0.
  2. RTPS – projects V0, pushes SXY + SZ FIFOs, sets IR0 from DQA/DQB × the perspective divisor.
  3. Load normals[i] into V0 (overwriting the position – RTPS already consumed it).
  4. NCDS – computes lit + fogged colour using the current IR0, pushes RGB FIFO.

After the loop: 5. NCLIP – reads SXY0/1/2 from the FIFO, flags back-face. 6. AVSZ3 – reads SZ1/2/3, computes the OT-slot key.

NCDS doesn’t touch the SXY or SZ FIFOs, so they still hold the three per-vertex projection results when NCLIP and AVSZ3 run at the end.

§Prerequisites

All scene state must be loaded by the caller: