Skip to main content

BillboardCache

Struct BillboardCache 

Source
pub struct BillboardCache {
    pub resolution: u32,
    pub snapshots: Vec<BillboardSnapshot>,
}
Expand description

Per-grid lazy cache of 26 BillboardSnapshots indexed by the 26 canonical_viewpoints directions.

Construction modes:

  • Self::new_empty: allocate an empty cache, populate later via Self::build.
  • Self::build: render all 26 snapshots in one call. Use this from the render-time lazy path: when a grid first lands on Lod::Far, the S6.3 dispatch checks Grid::billboards; if None, calls build and stores.

Fields§

§resolution: u32

Snapshot resolution in pixels (square). Pinned at build time; rebuilds construct a fresh BillboardCache rather than resizing in place.

§snapshots: Vec<BillboardSnapshot>

26 snapshots, indexed in the same order as canonical_viewpoints. Empty (Vec::new) iff this cache is uninitialised.

Implementations§

Source§

impl BillboardCache

Source

pub fn new_empty(resolution: u32) -> Self

Allocate an empty cache. snapshots is empty; future Self::build populates it. Cheap — no allocations beyond the empty Vec header.

Source

pub fn len(&self) -> usize

Number of snapshots populated. 0 for an empty cache, 26 after Self::build.

Source

pub fn is_empty(&self) -> bool

true iff this cache has not yet been populated (no snapshots stored).

Source

pub fn build(grid: &Grid, resolution: u32) -> Self

Render all 26 viewpoint snapshots of grid into a fresh cache.

Cost: O(26 × resolution² × grid_render_cost). For resolution = 128 and a small ship grid this is roughly equivalent to a single full-frame render. Intended to be called once per grid-edit cycle (caches are invalidated on edits via Grid::set_voxel et al.).

An empty grid (no populated chunks) yields 26 all-sky snapshots. The cache is still populated so the S6.3 blit path doesn’t keep retrying — a Far-tier empty grid’s blit is then a no-op (every pixel skipped via SKY_SENTINEL).

Sky-pixel detection: the pool’s skycast colour is set to SKY_SENTINEL before each snapshot render so opticast writes the sentinel (not a real sky colour) into pixels rays missed. Post-render, every sentinel pixel’s depth is reset to f32::INFINITY (opticast writes a finite “sky distance” for these pixels, which would otherwise leak through the blit’s depth check).

Source

pub fn pick_nearest(&self, query: DVec3) -> Option<&BillboardSnapshot>

Pick the snapshot whose view_dir is closest to query (largest dot product). Returns None iff the cache is empty.

query is the unit vector from the grid centre to the current camera position in grid-local space — the same frame the snapshot view_dirs live in. Caller is responsible for normalisation.

Tie-breaking is “first in viewpoint order”; with the 26 canonical viewpoints, ties only happen for query directions exactly equidistant between two viewpoints, which is a measure-zero set under f64.

Trait Implementations§

Source§

impl Clone for BillboardCache

Source§

fn clone(&self) -> BillboardCache

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BillboardCache

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.