psx_gte/lighting.rs
1//! Up-to-3-directional-light rig, rendered via the GTE's
2//! hardware lighting pipeline (`NCCS` / `NCDS` / `NCS` ops).
3//!
4//! # Model
5//!
6//! Each [`Light`] is a *directional* light -- a direction vector
7//! + an RGB intensity. The PSX GTE evaluates lighting as:
8//!
9//! ```text
10//! IR = LLM * V0 (N dot each light direction)
11//! IR = [BK] * 0x1000 + LCM * IR (mix light colours + ambient)
12//! MAC = IR * RGBC (modulate by material/vertex colour)
13//! RGB2 = MAC (push to RGB FIFO, readable as u32)
14//! ```
15//!
16//! - `LLM` (light direction matrix, 3×3): each **row** is one
17//! light's direction vector.
18//! - `LCM` (light colour matrix, 3×3): each **column** is one
19//! light's RGB contribution (so `LCM * IR` mixes light colours
20//! weighted by the corresponding dot-product magnitudes).
21//! - `BK` (background colour, 3×i32): ambient term added
22//! before the material multiply.
23//! - `RGBC` (data reg 6): per-vertex material / palette tint --
24//! the GTE multiplies the lit colour by this before emitting.
25//!
26//! # Object-local vs world-space lights
27//!
28//! The GTE operates on normals in their native mesh space
29//! (typically object-local). Lights packed into LLM therefore
30//! also need to be in object-local space for the dot products to
31//! come out right. Use [`LightRig::for_object`] once per object
32//! per frame to pre-rotate world-space lights into its local
33//! frame.
34//!
35//! # Cost
36//!
37//! - Rig upload (`load`): ~20 CTC2 writes per frame (cheap).
38//! - Per-object rotate: 9 integer multiplies × 3 lights = 27 mul
39//! + 9 adds on the CPU -- still cheap next to projection cost.
40//! - Per vertex: 2 MTC2 + 1 RTPS + 2 MTC2 + 1 MTC2 + 1 NCCS + 3
41//! MFC2 ≈ 10 GTE ops, ~30-40 cycles total.
42//! - Batched projection: `project_lit_triangle` uses RTPT for three
43//! positions, then NCCS per normal/material. This keeps per-vertex
44//! lighting identical while replacing three RTPS ops with one RTPT.
45//! If the three material tints match, it also uses NCCT to batch
46//! the three NCCS lighting ops.
47
48#![allow(clippy::needless_range_loop)]
49
50use crate::math::{Mat3I16, Vec3I16, Vec3I32};
51use crate::{ops, read_data, scene, write_data};
52
53/// A single directional light in some reference frame (caller's
54/// choice of world / object / eye space).
55#[derive(Copy, Clone, Debug)]
56pub struct Light {
57 /// Direction FROM the surface TOWARD the light source. Q3.12
58 /// unit vector; if you computed a "light-to-surface" direction
59 /// instead, negate it before storing here.
60 pub direction: Vec3I16,
61 /// Per-channel intensity in Q3.12 (`0x1000` = full intensity,
62 /// `0x0800` = half, `0x2000` = double / over-bright). The GTE
63 /// clamps out-of-range values at the MAC stage.
64 pub colour: (i16, i16, i16),
65}
66
67impl Light {
68 /// Convenience constructor for a "warm-white at 75%" feel --
69 /// useful while prototyping light rigs.
70 pub const fn warm_white_at(direction: Vec3I16) -> Self {
71 Self {
72 direction,
73 colour: (0x0c00, 0x0a00, 0x0800),
74 }
75 }
76
77 /// "Cool fill" preset -- bluish, dimmer, useful as a
78 /// secondary / rim light.
79 pub const fn cool_fill_at(direction: Vec3I16) -> Self {
80 Self {
81 direction,
82 colour: (0x0400, 0x0600, 0x0a00),
83 }
84 }
85
86 /// Null light -- contributes nothing. Use as a filler for
87 /// unused slots in a rig.
88 pub const OFF: Self = Self {
89 direction: Vec3I16::ZERO,
90 colour: (0, 0, 0),
91 };
92}
93
94/// A rig of up to **3** directional lights -- the maximum the
95/// PSX GTE supports natively.
96#[derive(Copy, Clone, Debug)]
97pub struct LightRig {
98 /// Three light slots; unused slots should be [`Light::OFF`].
99 pub lights: [Light; 3],
100 /// Ambient term added before material multiply. Q3.12 per
101 /// channel in an `i32` (GTE's BK register is 20-bit signed).
102 pub ambient: (i32, i32, i32),
103}
104
105impl LightRig {
106 /// Empty rig: no lights, black ambient.
107 pub const OFF: Self = Self {
108 lights: [Light::OFF; 3],
109 ambient: (0, 0, 0),
110 };
111
112 /// Build a rig from 3 lights + an ambient term.
113 pub const fn new(lights: [Light; 3], ambient: (i32, i32, i32)) -> Self {
114 Self { lights, ambient }
115 }
116
117 /// Pack this rig into the GTE's control registers:
118 /// - LLM ← rows are light directions
119 /// - LCM ← columns are light RGB contributions
120 /// - BK ← ambient
121 ///
122 /// Call once per object (or once per frame if lights are
123 /// in a universal frame). Any subsequent [`NCCS`][ops::light_color_single]
124 /// / [`NCS`][ops::light_single] / [`NCDS`][ops::light_color_depth_single] reads these.
125 pub fn load(&self) {
126 let [l0, l1, l2] = self.lights;
127
128 // LLM: rows = light directions.
129 let llm = Mat3I16 {
130 m: [
131 [l0.direction.x, l0.direction.y, l0.direction.z],
132 [l1.direction.x, l1.direction.y, l1.direction.z],
133 [l2.direction.x, l2.direction.y, l2.direction.z],
134 ],
135 };
136 scene::load_light_matrix(&llm);
137
138 // LCM: `LCM * IR` mixes light colours weighted by the
139 // dot-product intensities. IR[i] = light-i's dot product,
140 // so LCM's COLUMN i must be light-i's RGB triple. In our
141 // row-major layout that means m[channel][light].
142 let lcm = Mat3I16 {
143 m: [
144 [l0.colour.0, l1.colour.0, l2.colour.0], // R row
145 [l0.colour.1, l1.colour.1, l2.colour.1], // G row
146 [l0.colour.2, l1.colour.2, l2.colour.2], // B row
147 ],
148 };
149 scene::load_light_color_matrix(&lcm);
150
151 // BK: ambient term.
152 scene::load_background_color(Vec3I32::new(self.ambient.0, self.ambient.1, self.ambient.2));
153 }
154
155 /// Return a new rig with every light's direction rotated into
156 /// the frame in which `rotation` is the object's local → world
157 /// transform. I.e., if you pass the same `Mat3I16` you pass to
158 /// [`scene::load_rotation`] for RTPS, the returned rig is in
159 /// object-local space -- correct for feeding LLM when lighting
160 /// mesh vertices that are themselves in local space.
161 ///
162 /// Math: world_vert = R × local_vert, so local = R⁻¹ × world,
163 /// and since R is a rotation, R⁻¹ = Rᵀ. We compute
164 /// `local_dir = Rᵀ × world_dir` component-wise.
165 pub fn for_object(&self, rotation: &Mat3I16) -> LightRig {
166 let rotate = |dir: Vec3I16| {
167 // R^T * dir: the dot of `dir` with each COLUMN of R.
168 let mut out = [0i32; 3];
169 for i in 0..3 {
170 out[i] = ((rotation.m[0][i] as i32) * (dir.x as i32)
171 + (rotation.m[1][i] as i32) * (dir.y as i32)
172 + (rotation.m[2][i] as i32) * (dir.z as i32))
173 >> 12;
174 }
175 Vec3I16::new(
176 out[0].clamp(i16::MIN as i32, i16::MAX as i32) as i16,
177 out[1].clamp(i16::MIN as i32, i16::MAX as i32) as i16,
178 out[2].clamp(i16::MIN as i32, i16::MAX as i32) as i16,
179 )
180 };
181 let rot_light = |l: &Light| Light {
182 direction: rotate(l.direction),
183 colour: l.colour,
184 };
185 LightRig {
186 lights: [
187 rot_light(&self.lights[0]),
188 rot_light(&self.lights[1]),
189 rot_light(&self.lights[2]),
190 ],
191 ambient: self.ambient,
192 }
193 }
194
195 /// Return a new rig with every light's direction rotated by
196 /// `rotation` (direct `R × dir`, not the transpose).
197 ///
198 /// Used to animate world-space lights over time -- e.g. an
199 /// orbiting key light. Compose this BEFORE [`for_object`] so
200 /// the per-object transpose applies on top of the animation.
201 pub fn rotated(&self, rotation: &Mat3I16) -> LightRig {
202 let rotate = |dir: Vec3I16| {
203 // R × dir: standard row-major matrix-vector product.
204 let mut out = [0i32; 3];
205 for i in 0..3 {
206 out[i] = ((rotation.m[i][0] as i32) * (dir.x as i32)
207 + (rotation.m[i][1] as i32) * (dir.y as i32)
208 + (rotation.m[i][2] as i32) * (dir.z as i32))
209 >> 12;
210 }
211 Vec3I16::new(
212 out[0].clamp(i16::MIN as i32, i16::MAX as i32) as i16,
213 out[1].clamp(i16::MIN as i32, i16::MAX as i32) as i16,
214 out[2].clamp(i16::MIN as i32, i16::MAX as i32) as i16,
215 )
216 };
217 let rot_light = |l: &Light| Light {
218 direction: rotate(l.direction),
219 colour: l.colour,
220 };
221 LightRig {
222 lights: [
223 rot_light(&self.lights[0]),
224 rot_light(&self.lights[1]),
225 rot_light(&self.lights[2]),
226 ],
227 ambient: self.ambient,
228 }
229 }
230}
231
232/// Result of [`project_lit`]: screen-space vertex + its computed
233/// lit colour.
234#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
235#[repr(C)]
236pub struct ProjectedLit {
237 /// Screen-space X, post-projection.
238 pub sx: i16,
239 /// Screen-space Y.
240 pub sy: i16,
241 /// Depth (MAC3 after divide), 0..=0xFFFF.
242 pub sz: u16,
243 /// GTE-computed RGB after lighting + material modulation.
244 pub r: u8,
245 /// Lit green.
246 pub g: u8,
247 /// Lit blue.
248 pub b: u8,
249}
250
251/// Result of [`project_triangle_fogged`]: three projected + lit +
252/// fogged vertices, plus the AVSZ3 OT-slot key and the hardware-
253/// NCLIP back-face flag.
254#[derive(Copy, Clone, Debug, Default)]
255#[repr(C)]
256pub struct FoggedTri {
257 /// The three vertices in draw-order, each carrying its own
258 /// projected position and lit+fogged colour.
259 pub verts: [ProjectedLit; 3],
260 /// AVSZ3 result -- ZSF3-weighted average of the three projected
261 /// Z values. Commercial games scale this into an OT slot so
262 /// nearer triangles sort in front.
263 pub otz: u16,
264 /// `true` if MAC0 from NCLIP came out positive -- the triangle
265 /// is front-facing and should be drawn. `false` = back-face,
266 /// skip.
267 pub front_facing: bool,
268}
269
270/// Run the full PS1-commercial triangle pipeline with **per-vertex
271/// fog**. Three interleaved RTPS + NCDS pairs give each vertex its
272/// own `IR0` (its own depth-cue weight), then `NCLIP` + `AVSZ3`
273/// finish the bookkeeping.
274///
275/// # Why per-vertex, not batched
276///
277/// `RTPT + NCDT` is faster (4 GTE ops vs 8) but produces **uniform**
278/// fog across each triangle -- `RTPT` only writes `IR0` for the last
279/// vertex, and `NCDT` then reuses that single `IR0` for each
280/// vertex's stage-3 blend. The visible result is stepped shading:
281/// every triangle has one flat fog tint, and seams between
282/// triangles are obvious.
283///
284/// `3× RTPS + 3× NCDS` sets `IR0` per vertex, so `NCDS` blends
285/// each vertex's material toward `FC` by that vertex's own depth
286/// weight. `GP0 0x34` Gouraud-interpolates the three vertex tints
287/// across the triangle, giving a smooth per-pixel gradient with
288/// no inter-triangle seam.
289///
290/// Cost is about 2× the GTE work per triangle vs the batched path.
291/// Still well under budget for PSX-scale scenes (~100 tris/frame).
292///
293/// # Pipeline
294///
295/// For each vertex `i = 0, 1, 2`:
296/// 1. Load `verts[i]` into V0.
297/// 2. `RTPS` -- projects V0, pushes SXY + SZ FIFOs, sets `IR0`
298/// from DQA/DQB × the perspective divisor.
299/// 3. Load `normals[i]` into V0 (overwriting the position --
300/// `RTPS` already consumed it).
301/// 4. `NCDS` -- computes lit + fogged colour using the current
302/// `IR0`, pushes RGB FIFO.
303///
304/// After the loop:
305/// 5. `NCLIP` -- reads SXY0/1/2 from the FIFO, flags back-face.
306/// 6. `AVSZ3` -- reads SZ1/2/3, computes the OT-slot key.
307///
308/// `NCDS` doesn't touch the SXY or SZ FIFOs, so they still hold
309/// the three per-vertex projection results when NCLIP and AVSZ3
310/// run at the end.
311///
312/// # Prerequisites
313/// All scene state must be loaded by the caller:
314/// - Rotation matrix ([`scene::load_rotation`])
315/// - Translation ([`scene::load_translation`])
316/// - Projection plane + screen offset
317/// ([`scene::set_projection_plane`], [`scene::set_screen_offset`])
318/// - Light rig ([`LightRig::load`], `for_object` applied)
319/// - Far colour ([`scene::load_far_color`])
320/// - Depth-cue coefficients ([`scene::set_depth_cue`])
321/// - AVSZ weights ([`scene::set_average_z_weights`])
322pub fn project_triangle_fogged(
323 verts: [Vec3I16; 3],
324 normals: [Vec3I16; 3],
325 material: (u8, u8, u8),
326) -> FoggedTri {
327 // Material goes into RGBC once -- NCDS reads RGBC on every call
328 // and it doesn't change per-vertex.
329 let rgbc = (material.0 as u32) | ((material.1 as u32) << 8) | ((material.2 as u32) << 16);
330 write_data!(6, rgbc);
331
332 // Per-vertex RTPS → NCDS, interleaved so each vertex's NCDS
333 // uses the IR0 just written by its RTPS. Collect results
334 // one at a time to keep the RGB-FIFO semantics straightforward
335 // (NCDS pushes newest → slot 2; we read slot 2 immediately).
336 let mut verts_out = [ProjectedLit::default(); 3];
337 let mut screen = [(0i16, 0i16); 3];
338 for i in 0..3 {
339 // --- RTPS: project verts[i] ---
340 write_data!(0, verts[i].xy_packed());
341 write_data!(1, verts[i].z_packed());
342 // SAFETY: V0 loaded; scene setup is caller-supplied.
343 unsafe { ops::project_single() };
344 let sxy = read_data!(14); // SXY2 (latest) -- SXY has no result-read latency
345 let sz = read_data!(19) as u16; // SZ3 (latest)
346 screen[i] = (sxy as i16, (sxy >> 16) as i16);
347
348 // --- NCDS: lit + fogged colour for normals[i], using the
349 // IR0 just written by the RTPS above. ---
350 write_data!(0, normals[i].xy_packed());
351 write_data!(1, normals[i].z_packed());
352 // SAFETY: V0 holds the normal; RGBC is loaded; scene
353 // matrices / DQA / DQB / FC / IR0 come from the caller.
354 unsafe { ops::light_color_depth_single() };
355 let rgb = read_data!(22); // RGB2 (latest)
356
357 verts_out[i] = unpack_projected(sxy, sz, rgb);
358 }
359
360 // --- Back-face cull in software from the projected SXY. GTE NCLIP's
361 // MAC0 read-back is STALE on real hardware (the result-read hazard, see
362 // scene::screen_area), which mis-culls and drops faces on silicon
363 // while looking fine on emulators. The i32 cross product is exact and
364 // hazard-free; SXY itself has no read latency, so `screen` is correct. ---
365 let front_facing = crate::scene::screen_area(screen) > 0;
366
367 // --- AVSZ3: OT key from SZ1/2/3, weighted by ZSF3. ---
368 // SAFETY: three RTPS calls populated the SZ FIFO.
369 unsafe { ops::average_z3() };
370 let otz = read_data!(7) as u16;
371
372 FoggedTri {
373 verts: verts_out,
374 otz,
375 front_facing,
376 }
377}
378
379/// Shared unpack -- turns raw SXY / SZ / RGB register reads into a
380/// [`ProjectedLit`]. Factored out so both the per-vertex and batch
381/// paths agree on byte/field layout.
382#[inline]
383fn unpack_projected(sxy: u32, sz: u16, rgb: u32) -> ProjectedLit {
384 ProjectedLit {
385 sx: sxy as i16,
386 sy: (sxy >> 16) as i16,
387 sz,
388 r: (rgb & 0xff) as u8,
389 g: ((rgb >> 8) & 0xff) as u8,
390 b: ((rgb >> 16) & 0xff) as u8,
391 }
392}
393
394#[inline]
395fn rgbc_word(material: (u8, u8, u8)) -> u32 {
396 (material.0 as u32) | ((material.1 as u32) << 8) | ((material.2 as u32) << 16)
397}
398
399/// Project three vertices via RTPT, then compute each vertex's lit
400/// colour with NCCS.
401///
402/// This is the visual-preserving batched path for Gouraud meshes:
403/// projection work shares RTPT's setup cost, but lighting still runs
404/// once per vertex so different normals and material tints produce the
405/// same RGB values as three [`project_lit`] calls.
406///
407/// Prerequisites are the same as [`project_lit`]:
408/// rotation/translation/projection registers and the light rig must
409/// already be loaded.
410pub fn project_lit_triangle(
411 verts: [Vec3I16; 3],
412 normals: [Vec3I16; 3],
413 materials: [(u8, u8, u8); 3],
414) -> [ProjectedLit; 3] {
415 write_data!(0, verts[0].xy_packed());
416 write_data!(1, verts[0].z_packed());
417 write_data!(2, verts[1].xy_packed());
418 write_data!(3, verts[1].z_packed());
419 write_data!(4, verts[2].xy_packed());
420 write_data!(5, verts[2].z_packed());
421 // SAFETY: V0, V1, and V2 are loaded; scene setup is caller-supplied.
422 unsafe { ops::project_triple() };
423
424 let sxy = [read_data!(12), read_data!(13), read_data!(14)];
425 let sz = [
426 read_data!(17) as u16,
427 read_data!(18) as u16,
428 read_data!(19) as u16,
429 ];
430
431 if materials[0] == materials[1] && materials[1] == materials[2] {
432 write_data!(0, normals[0].xy_packed());
433 write_data!(1, normals[0].z_packed());
434 write_data!(2, normals[1].xy_packed());
435 write_data!(3, normals[1].z_packed());
436 write_data!(4, normals[2].xy_packed());
437 write_data!(5, normals[2].z_packed());
438 write_data!(6, rgbc_word(materials[0]));
439 // SAFETY: V0, V1, V2 hold normals and RGBC is common to all
440 // three vertices. NCCT is equivalent to NCCS for V0/V1/V2.
441 unsafe { ops::light_color_triple() };
442 let rgb = [read_data!(20), read_data!(21), read_data!(22)];
443 return [
444 unpack_projected(sxy[0], sz[0], rgb[0]),
445 unpack_projected(sxy[1], sz[1], rgb[1]),
446 unpack_projected(sxy[2], sz[2], rgb[2]),
447 ];
448 }
449
450 let mut out = [ProjectedLit::default(); 3];
451 let mut i = 0;
452 while i < 3 {
453 write_data!(0, normals[i].xy_packed());
454 write_data!(1, normals[i].z_packed());
455 write_data!(6, rgbc_word(materials[i]));
456 // SAFETY: V0 holds the normal, RGBC holds the material;
457 // LLM/LCM/BK were loaded by the caller's light rig.
458 unsafe { ops::light_color_single() };
459 out[i] = unpack_projected(sxy[i], sz[i], read_data!(22));
460 i += 1;
461 }
462
463 out
464}
465
466/// Project a vertex AND compute its lit colour in one call.
467///
468/// Does RTPS on `vert` + NCCS on `normal`, with a per-vertex
469/// `material` RGB loaded into RGBC (data reg 6) to modulate the
470/// GTE's lit output. Pass `(128, 128, 128)` as material for
471/// "unmodulated" behaviour -- the lit colour comes through as the
472/// light rig + ambient dictate.
473///
474/// Prerequisites (caller's responsibility, as with
475/// [`scene::project_vertex`]):
476///
477/// - Rotation matrix loaded ([`scene::load_rotation`])
478/// - Translation loaded ([`scene::load_translation`])
479/// - Projection plane / screen offset set
480/// ([`scene::set_projection_plane`], [`scene::set_screen_offset`])
481/// - Light rig loaded ([`LightRig::load`], with `for_object`
482/// applied so lights are in the same frame as the normal)
483pub fn project_lit(vert: Vec3I16, normal: Vec3I16, material: (u8, u8, u8)) -> ProjectedLit {
484 // --- Position: RTPS ---
485 write_data!(0, vert.xy_packed());
486 write_data!(1, vert.z_packed());
487 // SAFETY: V0 loaded; scene setup is caller's responsibility.
488 unsafe { ops::project_single() };
489 let sxy = read_data!(14); // SXY2 (packed xy)
490 let sz = read_data!(19) as u16; // SZ3
491
492 // --- Lighting: NCCS ---
493 write_data!(0, normal.xy_packed());
494 write_data!(1, normal.z_packed());
495 // RGBC layout (data reg 6): 0x00CC_BBGG_RR -- low 8 bits R,
496 // next 8 G, next 8 B, top 8 "CODE" (GPU command byte, used by
497 // some prim ops; 0 for our purposes).
498 write_data!(6, rgbc_word(material));
499 // SAFETY: V0 holds the normal, RGBC holds the material;
500 // LLM/LCM/BK were loaded via `LightRig::load`.
501 unsafe { ops::light_color_single() };
502 // Read lit colour from RGB2 (data reg 22). Same 0x00BB_GGRR
503 // layout as RGBC.
504 let lit = read_data!(22);
505
506 ProjectedLit {
507 sx: sxy as i16,
508 sy: (sxy >> 16) as i16,
509 sz,
510 r: (lit & 0xff) as u8,
511 g: ((lit >> 8) & 0xff) as u8,
512 b: ((lit >> 16) & 0xff) as u8,
513 }
514}
515
516#[cfg(all(test, not(target_arch = "mips")))]
517mod host_smoke {
518 use super::*;
519 use crate::math::{Mat3I16, Vec3I16, Vec3I32};
520 use crate::{host, scene};
521
522 fn install_scene() {
523 scene::load_rotation(&Mat3I16::IDENTITY);
524 scene::load_translation(Vec3I32::new(0, 0, 0));
525 scene::set_screen_offset(160 << 16, 120 << 16);
526 scene::set_projection_plane(280);
527 LightRig::new(
528 [
529 Light {
530 direction: Vec3I16::new(0, 0, 0x1000),
531 colour: (0x0c00, 0x0800, 0x0400),
532 },
533 Light {
534 direction: Vec3I16::new(0x0800, 0, 0x0800),
535 colour: (0x0400, 0x0800, 0x0c00),
536 },
537 Light::OFF,
538 ],
539 (0x0100, 0x0100, 0x0100),
540 )
541 .load();
542 }
543
544 #[test]
545 fn batched_lit_triangle_matches_three_project_lit_calls() {
546 let verts = [
547 Vec3I16::new(-256, -128, 1024),
548 Vec3I16::new(256, -96, 1200),
549 Vec3I16::new(0, 256, 1400),
550 ];
551 let normals = [
552 Vec3I16::new(0, 0, 0x1000),
553 Vec3I16::new(0x0400, 0, 0x0f00),
554 Vec3I16::new(-0x0300, 0x0400, 0x0e00),
555 ];
556 let materials = [(128, 96, 64), (64, 128, 96), (96, 64, 128)];
557
558 host::reset();
559 install_scene();
560 let batch = project_lit_triangle(verts, normals, materials);
561
562 host::reset();
563 install_scene();
564 let separate = [
565 project_lit(verts[0], normals[0], materials[0]),
566 project_lit(verts[1], normals[1], materials[1]),
567 project_lit(verts[2], normals[2], materials[2]),
568 ];
569
570 assert_eq!(batch, separate);
571 }
572
573 #[test]
574 fn batched_lit_triangle_shared_material_uses_same_outputs() {
575 let verts = [
576 Vec3I16::new(-192, 64, 900),
577 Vec3I16::new(64, -160, 1150),
578 Vec3I16::new(224, 192, 1500),
579 ];
580 let normals = [
581 Vec3I16::new(0, 0, 0x1000),
582 Vec3I16::new(0x0200, 0x0200, 0x0f00),
583 Vec3I16::new(-0x0200, 0x0300, 0x0f00),
584 ];
585 let materials = [(112, 144, 96); 3];
586
587 host::reset();
588 install_scene();
589 let batch = project_lit_triangle(verts, normals, materials);
590
591 host::reset();
592 install_scene();
593 let separate = [
594 project_lit(verts[0], normals[0], materials[0]),
595 project_lit(verts[1], normals[1], materials[1]),
596 project_lit(verts[2], normals[2], materials[2]),
597 ];
598
599 assert_eq!(batch, separate);
600 }
601}