euv-core 0.50.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::*;

/// Dynamic physically based omnidirectional 3D point light for UE5 Clustered Deferred Shading.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct PointLight3D {
    /// World-space light center position in meters.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Linear HDR RGB emission color.
    #[get(type(copy))]
    pub(crate) color: Vec3,
    /// Luminous intensity multiplier.
    #[get(type(copy))]
    pub(crate) intensity: f32,
    /// Maximum attenuation influence radius in meters.
    #[get(type(copy))]
    pub(crate) radius: f32,
    /// Whether this light casts local shadows when enabled.
    #[get(type(copy))]
    pub(crate) cast_shadows: bool,
}

/// Dynamic physically based 3D spotlight (vehicle headlights, streetlamps, volumetric beams) for Clustered Deferred Shading.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct SpotLight3D {
    /// World-space spotlight origin in meters.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Unit world-space beam direction pointing away from the emitter.
    #[get(type(copy))]
    pub(crate) direction: Vec3,
    /// Linear HDR RGB emission color.
    #[get(type(copy))]
    pub(crate) color: Vec3,
    /// Luminous intensity multiplier.
    #[get(type(copy))]
    pub(crate) intensity: f32,
    /// Maximum beam attenuation range in meters.
    #[get(type(copy))]
    pub(crate) range: f32,
    /// Cosine of inner full-brightness half-angle.
    #[get(type(copy))]
    pub(crate) inner_cos: f32,
    /// Cosine of outer cutoff half-angle.
    #[get(type(copy))]
    pub(crate) outer_cos: f32,
}

/// Cache-compact 64-byte unified local light record stored contiguously inside `LightClusterGrid3D`.
#[repr(C, align(16))]
#[derive(Clone, Copy, Debug, Default, PartialEq)]
pub(crate) struct PackedLocalLight {
    /// World position `(x, y, z)` and inverse squared radius `1 / r^2`.
    pub(crate) pos_inv_r2: [f32; 4],
    /// Pre-scaled linear HDR radiance `(r, g, b)` and radius `r`.
    pub(crate) radiance_radius: [f32; 4],
    /// Unit beam direction `(dx, dy, dz)` and `outer_cos` (`-2.0` marks omnidirectional point light).
    pub(crate) dir_outer_cos: [f32; 4],
    /// Reciprocal cone transition `1 / (inner_cos - outer_cos)` and padding.
    pub(crate) inv_cone_span: [f32; 4],
}

/// UE5-style 3D Froxel Clustered Deferred Lighting grid binning up to 256 dynamic point and spot lights with zero per-frame heap allocations.
#[derive(Clone, Data, Debug)]
pub struct LightClusterGrid3D {
    /// Near frustum depth bound in meters for logarithmic Z slicing.
    #[get(type(copy))]
    pub(crate) near_plane: f32,
    /// Far frustum depth bound in meters for logarithmic Z slicing.
    #[get(type(copy))]
    pub(crate) far_plane: f32,
    /// Precomputed `LIGHT_CLUSTER_GRID_Z / ln(far / near)` mapping camera depth to Z slice in O(1).
    #[get(type(copy))]
    pub(crate) log_depth_scale: f32,
    /// Precomputed upper depth boundary in meters for each of the 16 logarithmic Z slices (zero `ln()` calls during shading).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) depth_slice_max: [f32; LIGHT_CLUSTER_GRID_Z],
    /// Active packed local light count for the current frame.
    #[get(type(copy))]
    pub(crate) active_light_count: usize,
    /// Total light-to-froxel assignments recorded during the latest cluster build.
    #[get(type(copy))]
    pub(crate) total_assignments: usize,
    /// Contiguous packed point and spot light records.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) packed_lights: Vec<PackedLocalLight>,
    /// Number of lights assigned to each froxel (`len == 16 * 9 * 16`).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cluster_counts: Vec<u16>,
    /// Flat froxel light index table (`len == 16 * 9 * 16 * 16`).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) cluster_indices: Vec<u16>,
}

/// Single orthographic directional shadow cascade inside `VirtualShadowMap` with static page caching.
#[derive(Clone, Data, Debug)]
pub struct VsmCascade {
    /// Cascade texture edge resolution in texels.
    #[get(type(copy))]
    pub(crate) resolution: usize,
    /// World-space half-extent covered by this cascade in meters.
    #[get(type(copy))]
    pub(crate) half_extent_m: f32,
    /// Snapped world-space cascade center preventing sub-texel shadow swimming.
    #[get(type(copy))]
    pub(crate) snapped_center: Vec3,
    /// Light-space right basis vector.
    #[get(type(copy))]
    pub(crate) light_right: Vec3,
    /// Light-space up basis vector.
    #[get(type(copy))]
    pub(crate) light_up: Vec3,
    /// Light-space forward direction pointing toward the sun.
    #[get(type(copy))]
    pub(crate) light_forward: Vec3,
    /// World-space projection depth range `(min_z, max_z)` along `light_forward`.
    #[get(type(copy))]
    pub(crate) depth_min: f32,
    /// Maximum light-space depth along `light_forward`.
    #[get(type(copy))]
    pub(crate) depth_max: f32,
    /// Whether the cached static page depth buffer is clean and valid.
    #[get(type(copy))]
    pub(crate) static_valid: bool,
    /// Cached static geometry shadow depth map (`0.0..=1.0`, `1.0` = far).
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) static_depth: Vec<f32>,
    /// Composite active shadow depth map combining static cache plus dynamic casters.
    #[get(skip)]
    #[get_mut(skip)]
    #[set(skip)]
    pub(crate) active_depth: Vec<f32>,
}

/// UE5-style 2-Cascade Virtual Shadow Map with texel-snapped static page caching and 4-tap PCF soft filtering.
#[derive(Clone, Data, Debug)]
pub struct VirtualShadowMap {
    /// Near high-resolution shadow cascade (`0..36m`).
    pub(crate) cascade_near: VsmCascade,
    /// Far city-wide shadow cascade (`36..120m`).
    pub(crate) cascade_far: VsmCascade,
    /// Cached sun direction validating static shadow pages.
    #[get(type(copy))]
    pub(crate) cached_sun_dir: Vec3,
    /// Cached `World3D::static_bvh_rebuilds` counter validating static shadow pages.
    #[get(type(copy))]
    pub(crate) cached_static_epoch: u64,
    /// Total static cascade page cache hits (zero-re-rasterize frames).
    #[get(type(copy))]
    pub(crate) static_cache_hits: u64,
    /// Total static cascade rebuilds executed.
    #[get(type(copy))]
    pub(crate) static_rebuilds: u64,
}