MCPcopy Create free account
hub / github.com/Bloom-Engine/engine / cell_center_uv

Function cell_center_uv

tools/imposter-baker/src/octahedral.rs:28–33  ·  view source on GitHub ↗

Cell-center UV in `[-1, 1]^2` for grid coords `(i, j)` of an `N×N` atlas. Matches the runtime `floor(oct * GRID)` cell selection: the runtime samples the cell whose lower-left corner is `cell / N`, so the bake direction must be the *center* of that cell, i.e. `(cell + 0.5) / N` mapped from `[0, 1]` to `[-1, 1]`.

(i: u32, j: u32, n: u32)

Source from the content-addressed store, hash-verified

26/// the bake direction must be the *center* of that cell, i.e.
27/// `(cell + 0.5) / N` mapped from `[0, 1]` to `[-1, 1]`.
28pub fn cell_center_uv(i: u32, j: u32, n: u32) -> [f32; 2] {
29 let nf = n as f32;
30 let u = ((i as f32 + 0.5) / nf) * 2.0 - 1.0;
31 let v = ((j as f32 + 0.5) / nf) * 2.0 - 1.0;
32 [u, v]
33}
34
35/// Direction (model → camera) for cell `(i, j)`.
36pub fn cell_direction(i: u32, j: u32, n: u32) -> [f32; 3] {

Callers 1

cell_directionFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected