euv-core 0.52.0

Core cross-platform runtime for euv featuring arena-based fine-grained reactivity, deterministic layout, flat scene graph, multi-mode rendering, and direct OS platform adapters.
Documentation
use super::*;

/// Persistent zero-allocation photorealistic ocean & origami paper boat renderer producing RGBA8 frames with perspective stormy-sunset sky, multi-scale Gerstner ocean waves, dual-lobe GGX sun glitter, emerald subsurface scattering, 3D floating origami boat with wave-warped reflection, and quarter-res HDR bloom.
#[derive(Clone, Data, Debug)]
pub struct LiquidOpticalRenderer {
    /// Active scalar field grid width in cells for PBF interactive wake transfer.
    #[get(type(copy))]
    pub(crate) field_w: usize,
    /// Active scalar field grid height in cells for PBF interactive wake transfer.
    #[get(type(copy))]
    pub(crate) field_h: usize,
    /// Smoothed PBF horizontal flow velocity wake field.
    pub(crate) flow_u: Vec<f32>,
    /// Smoothed PBF vertical flow velocity wake field.
    pub(crate) flow_v: Vec<f32>,
    /// Smoothed PBF wave-crest foam intensity wake field.
    pub(crate) foam: Vec<f32>,
    /// Separable horizontal smoothing scratch buffer.
    pub(crate) wake_tmp: Vec<f32>,
    /// Persistent packed RGBA8 PBF wake field (`field_w * field_h * 4`) eliminating per-frame heap allocation in `build_gpu_ocean_pass`.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) wake_rgba8: Vec<u8>,
    /// Persistent linear HDR RGB frame scratch buffer (`len == out_w * out_h * 3`) feeding filmic tone-mapping and HDR sun/glitter bloom.
    pub(crate) hdr_rgb: Vec<f32>,
    /// Quarter-resolution HDR bloom extraction and vertical blur buffer.
    pub(crate) bloom_a: Vec<[f32; 3]>,
    /// Quarter-resolution HDR bloom horizontal blur scratch buffer.
    pub(crate) bloom_b: Vec<[f32; 3]>,
    /// Pre-baked `SKY_LUT_W x SKY_LUT_H` spherical stormy-sunset sky dome radiance LUT (excluding full-res sun disk).
    pub(crate) sky_lut: Vec<[f32; 3]>,
    /// Pre-baked `REFL_LUT_W x REFL_LUT_H` spherical ocean-reflection sky radiance LUT.
    pub(crate) refl_lut: Vec<[f32; 3]>,
    /// Precomputed 1025-entry L1-resident ACES filmic tone-mapping + sRGB gamma LUT eliminating per-pixel `powf`.
    pub(crate) aces_lut: Vec<u8>,
    /// Simulation timestamp at which `sky_lut` and `refl_lut` were last baked.
    #[get(type(copy))]
    pub(crate) last_sky_lut_time: f32,
    /// Last rendered output width in pixels.
    #[get(type(copy))]
    pub(crate) last_width: u32,
    /// Last rendered output height in pixels.
    #[get(type(copy))]
    pub(crate) last_height: u32,
    /// Whether persistent dt-invariant camera and boat damping state has been initialized from a live snapshot.
    #[get(type(copy))]
    pub(crate) cam_initialized: bool,
    /// Previous snapshot simulation timestamp in seconds driving dt-invariant camera damping across 60/120/180Hz+ renders.
    #[get(type(copy))]
    pub(crate) cam_last_sim_time: f32,
    /// Exponentially damped camera horizon roll angle in radians.
    #[get(type(copy))]
    pub(crate) cam_roll_rad: f32,
    /// Exponentially damped normalized screen horizon Y coordinate decoupled from transient PBF slosh.
    #[get(type(copy))]
    pub(crate) cam_horizon_v: f32,
    /// Exponentially damped ocean wave agitation multiplier preventing single-frame wave-height twitching.
    #[get(type(copy))]
    pub(crate) cam_agitation: f32,
    /// Exponentially damped horizontal sailboat sway offset derived from buoyant physics.
    #[get(type(copy))]
    pub(crate) cam_sway_x: f32,
    /// Exponentially damped sailboat angular sway offset derived from buoyant physics.
    #[get(type(copy))]
    pub(crate) cam_sway_angle: f32,
}

/// Pre-projected screen-space 3D origami paper boat triangle ready for per-pixel barycentric depth shading and wave-warped water reflection.
#[derive(Clone, Copy, Data, Debug, Default)]
pub(crate) struct ProjectedBoatTri {
    /// Projected screen X coordinates `(x0, x1, x2)` in viewport pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) sx: [f32; 3],
    /// Projected screen Y coordinates `(y0, y1, y2)` in viewport pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) sy: [f32; 3],
    /// View-space depth Z at each vertex `(z0, z1, z2)` in meters.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) depth: [f32; 3],
    /// Local height above boat waterline `(h0, h1, h2)` in meters for wet-paper capillary absorption.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) local_y: [f32; 3],
    /// Reciprocal signed 2D screen area for fast barycentric interpolation.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) inv_area: f32,
    /// Reciprocal screen pixel lengths `(1/|v1v2|, 1/|v2v0|, 1/|v0v1|)` for analytical 1.35px edge anti-aliasing.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) edge_inv_len: [f32; 3],
    /// Sign of the signed 2D screen area (`+1.0` or `-1.0`) orienting signed pixel edge distances inward.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) area_sign: f32,
    /// Precomputed linear HDR diffuse + translucent paper color `[r, g, b]` for this facet.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) base_rgb: [f32; 3],
    /// Screen-space bounding box `(min_x, max_x, min_y, max_y)` in pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) bbox: [f32; 4],
    /// Origami facet classification (`0=outer_wing`, `1=center_flap`, `2=sail_peak`, `3=inner_cavity`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) facet_kind: u8,
    /// Whether this triangle is valid and visible in front of the camera.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) valid: bool,
}

/// Immutable per-frame ocean, sky, sun, gyro-tilt, and projected 3D origami boat parameters shared across parallel scanline workers.
#[derive(Clone, Copy, Data, Debug)]
pub(crate) struct OceanShadeParams {
    /// Output framebuffer width in pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) out_w: usize,
    /// Output framebuffer height in pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) out_h: usize,
    /// PBF wake field width in cells.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) field_w: usize,
    /// PBF wake field height in cells.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) field_h: usize,
    /// Monotonic simulation time in seconds driving continuous ocean swells and drifting storm clouds.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) sim_time: f32,
    /// Dynamic wave choppiness multiplier amplified by PBF kinetic energy, shaking, and stirring (`1.0..=2.0`).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) wave_agitation: f32,
    /// Effective normalized screen horizon Y coordinate (`~0.545`, subtly shifted by fill level).
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) horizon_v: f32,
    /// Cosine of active camera horizon roll angle derived from gravity/gyroscope.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) roll_cos: f32,
    /// Sine of active camera horizon roll angle derived from gravity/gyroscope.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) roll_sin: f32,
    /// Normalized 3D sun direction vector `[lx, ly, lz]` in ocean camera coordinates.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) sun_dir: [f32; 3],
    /// Projected screen X coordinate of the origami paper boat center in pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) boat_screen_x: f32,
    /// Projected screen Y coordinate of the origami paper boat waterline in pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) boat_waterline_y: f32,
    /// Overall projected screen bounding box `[min_x, max_x, min_y, max_y]` of the origami paper boat in pixels.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) boat_bbox: [f32; 4],
    /// Pre-projected origami paper boat triangles ready for per-pixel shading and water reflection.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) boat_tris: [ProjectedBoatTri; BOAT_TRI_COUNT],
    /// Precomputed per-frame wave temporal phase offsets `sim_time * speed[i]` for all 8 wave trains.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) wave_time_phases: [f32; 8],
    /// Whether the PBF wake field contains non-negligible interactive stirring or foam requiring bilinear sampling.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) has_active_wake: bool,
}

/// Read-only borrowed slice bundle of interactive PBF wake fields and pre-baked spherical sky LUTs for parallel ocean shading.
#[derive(Clone, Copy, Data, Debug)]
pub(crate) struct FluidWakeViews<'a> {
    /// Smoothed PBF horizontal flow velocity wake field.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) flow_u: &'a [f32],
    /// Smoothed PBF vertical flow velocity wake field.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) flow_v: &'a [f32],
    /// Smoothed PBF foam intensity wake field.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) foam: &'a [f32],
    /// Pre-baked `SKY_LUT_W x SKY_LUT_H` primary storm-cloud dome radiance LUT.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) sky_lut: &'a [[f32; 3]],
    /// Pre-baked `REFL_LUT_W x REFL_LUT_H` ocean-reflection sky radiance LUT.
    #[get(pub(crate), type(copy))]
    #[set(pub(crate))]
    pub(crate) refl_lut: &'a [[f32; 3]],
}