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

/// Single texel-snapped orthographic cascade descriptor produced by `CsmCascadeSplits`.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct CsmCascadeSlice3D {
    /// Camera-space near split depth in meters.
    #[get(type(copy))]
    pub(crate) near_depth: f32,
    /// Camera-space far split depth in meters.
    #[get(type(copy))]
    pub(crate) far_depth: f32,
    /// Unsnapped world-space bounding sphere center of this frustum slice.
    #[get(type(copy))]
    pub(crate) world_center: Vec3,
    /// Light-space texel-snapped world center eliminating sub-texel shadow swimming.
    #[get(type(copy))]
    pub(crate) snapped_center: Vec3,
    /// Orthographic half-extent in meters covering the rotated frustum slice.
    #[get(type(copy))]
    pub(crate) half_extent: f32,
    /// World-space width of one shadow-map texel in meters.
    #[get(type(copy))]
    pub(crate) texel_size: f32,
    /// Orthographic light-space view matrix.
    #[get(type(copy))]
    pub(crate) light_view: Mat4,
    /// Orthographic light-space projection matrix.
    #[get(type(copy))]
    pub(crate) light_proj: Mat4,
    /// Combined light-space view-projection matrix (`light_proj * light_view`).
    #[get(type(copy))]
    pub(crate) light_view_proj: Mat4,
}

/// Practical-Split Cascaded Shadow Map configuration and texel-snapped cascade matrices.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct CsmCascadeSplits {
    /// Active number of shadow cascades (`1..=CSM_MAX_CASCADES`).
    #[get(type(copy))]
    pub(crate) cascade_count: usize,
    /// Practical split logarithmic/uniform blend weight in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) lambda: f32,
    /// Effective camera near plane in meters.
    #[get(type(copy))]
    pub(crate) near_plane: f32,
    /// Effective maximum shadow distance in meters.
    #[get(type(copy))]
    pub(crate) far_plane: f32,
    /// Shadow map edge resolution in texels used for texel snapping.
    #[get(type(copy))]
    pub(crate) shadow_map_resolution: u32,
    /// Fixed-capacity array of computed cascade slices (`0..cascade_count` active).
    #[get(type(copy))]
    pub(crate) slices: [CsmCascadeSlice3D; CSM_MAX_CASCADES],
}

/// Physical directional Sun/Moon emitter with Cascaded Shadow Map parameters.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct RigDirectionalLight3D {
    /// Unit direction vector pointing from the scene toward the light source.
    #[get(type(copy))]
    pub(crate) direction: Vec3,
    /// Linear HDR RGB radiance tint.
    #[get(type(copy))]
    pub(crate) color: Vec3,
    /// Luminous illuminance multiplier.
    #[get(type(copy))]
    pub(crate) illuminance: f32,
    /// Angular disc radius in radians (`~0.00465` for Earth's sun).
    #[get(type(copy))]
    pub(crate) angular_radius_rad: f32,
    /// Whether directional shadows are enabled.
    #[get(type(copy))]
    pub(crate) cast_shadows: bool,
    /// Depth receiver bias reducing shadow acne.
    #[get(type(copy))]
    pub(crate) shadow_bias: f32,
    /// Requested cascade count clamped to `1..=CSM_MAX_CASCADES`.
    #[get(type(copy))]
    pub(crate) cascade_count: usize,
    /// Practical split scheme lambda in `[0.0, 1.0]`.
    #[get(type(copy))]
    pub(crate) csm_lambda: f32,
    /// Maximum world-space shadow coverage distance in meters.
    #[get(type(copy))]
    pub(crate) max_shadow_distance: f32,
}

/// Single face descriptor of a 6-face omnidirectional cubemap shadow frustum for a point light.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct CubeShadowFace3D {
    /// Cubemap face index (`0=+X, 1=-X, 2=+Y, 3=-Y, 4=+Z, 5=-Z`).
    #[get(type(copy))]
    pub(crate) face_index: u8,
    /// Unit world-space forward axis of this cubemap face.
    #[get(type(copy))]
    pub(crate) forward: Vec3,
    /// Unit world-space up axis of this cubemap face.
    #[get(type(copy))]
    pub(crate) up: Vec3,
    /// Combined 90-degree square perspective view-projection matrix.
    #[get(type(copy))]
    pub(crate) view_proj: Mat4,
    /// Extracted 6-plane culling frustum for this shadow face.
    #[get(type(copy))]
    pub(crate) frustum: Frustum3D,
}

/// Physical omnidirectional point light with finite emitter radius, Lagarde range windowing, and cube-shadow frustums.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct RigPointLight3D {
    /// World-space emitter 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,
    /// Physical emitter sphere radius `r` stabilizing `1 / (d^2 + r^2)`.
    #[get(type(copy))]
    pub(crate) source_radius: f32,
    /// Maximum smooth Lagarde attenuation range in meters.
    #[get(type(copy))]
    pub(crate) range: f32,
    /// Whether 6-face omnidirectional shadows are enabled.
    #[get(type(copy))]
    pub(crate) cast_shadows: bool,
    /// Near clipping plane distance for cube-shadow face projections.
    #[get(type(copy))]
    pub(crate) shadow_near: f32,
}

/// Physical spotlight with smoothstep inner/outer penumbra and 2D cookie/gobo projection mask.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct RigSpotLight3D {
    /// World-space emitter origin in meters.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Unit beam direction pointing from emitter into scene.
    #[get(type(copy))]
    pub(crate) direction: Vec3,
    /// Reference up hint orienting the 2D cookie projection basis.
    #[get(type(copy))]
    pub(crate) up_hint: Vec3,
    /// Linear HDR RGB emission color.
    #[get(type(copy))]
    pub(crate) color: Vec3,
    /// Luminous intensity multiplier.
    #[get(type(copy))]
    pub(crate) intensity: f32,
    /// Physical emitter radius stabilizing inverse-square falloff.
    #[get(type(copy))]
    pub(crate) source_radius: f32,
    /// Maximum smooth attenuation range in meters.
    #[get(type(copy))]
    pub(crate) range: f32,
    /// Inner full-intensity cone half-angle in radians.
    #[get(type(copy))]
    pub(crate) inner_angle_rad: f32,
    /// Outer zero-cutoff cone half-angle in radians.
    #[get(type(copy))]
    pub(crate) outer_angle_rad: f32,
    /// Whether perspective shadow projection is enabled.
    #[get(type(copy))]
    pub(crate) cast_shadows: bool,
    /// 2D procedural or custom-grid cookie/gobo projection mask.
    pub(crate) cookie: SpotCookieMask,
}

/// Physical analytical area light supporting Rectangular quad, Elliptical Disk, and Linear Tube/Capsule emitters.
#[derive(Clone, Copy, Data, Debug, PartialEq)]
pub struct RigAreaLight3D {
    /// World-space emitter center position in meters.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Unit emitting surface normal pointing outward into the scene.
    #[get(type(copy))]
    pub(crate) direction: Vec3,
    /// Unit tangent axis along emitter width (or tube segment axis).
    #[get(type(copy))]
    pub(crate) right: Vec3,
    /// Unit bitangent axis along emitter height.
    #[get(type(copy))]
    pub(crate) up: Vec3,
    /// Linear HDR RGB emission radiance color.
    #[get(type(copy))]
    pub(crate) color: Vec3,
    /// Luminous radiance intensity multiplier.
    #[get(type(copy))]
    pub(crate) intensity: f32,
    /// Emitter aperture width (or linear tube length) in meters.
    #[get(type(copy))]
    pub(crate) width: f32,
    /// Emitter aperture height (or linear tube diameter `2 * radius`) in meters.
    #[get(type(copy))]
    pub(crate) height: f32,
    /// Maximum smooth range window cutoff in meters.
    #[get(type(copy))]
    pub(crate) range: f32,
    /// Aperture shape (`Rect`, `Disk`, or `Tube`).
    #[get(type(copy))]
    pub(crate) shape: RigAreaLightShape3D,
    /// Whether the emitter radiates from both front and back sides.
    #[get(type(copy))]
    pub(crate) two_sided: bool,
}

/// World-space emissive triangle stored inside `EmissiveMeshLight3D`.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct EmissiveTriangle3D {
    /// First world-space triangle vertex.
    #[get(type(copy))]
    pub(crate) v0: Vec3,
    /// Second world-space triangle vertex.
    #[get(type(copy))]
    pub(crate) v1: Vec3,
    /// Third world-space triangle vertex.
    #[get(type(copy))]
    pub(crate) v2: Vec3,
    /// Outward unit triangle face normal.
    #[get(type(copy))]
    pub(crate) normal: Vec3,
    /// Triangle surface area in square meters.
    #[get(type(copy))]
    pub(crate) area: f32,
    /// Linear HDR emissive RGB radiance of this triangle.
    #[get(type(copy))]
    pub(crate) emissive_radiance: Vec3,
}

/// Importance-sampled point on an `EmissiveMeshLight3D` surface.
#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
pub struct EmissiveMeshSample3D {
    /// Sampled world-space point on the emissive mesh surface.
    #[get(type(copy))]
    pub(crate) position: Vec3,
    /// Outward unit surface normal at the sampled point.
    #[get(type(copy))]
    pub(crate) normal: Vec3,
    /// Linear HDR emissive RGB radiance at the sampled point.
    #[get(type(copy))]
    pub(crate) radiance: Vec3,
    /// Exact area probability density function `p(x)` in inverse square meters.
    #[get(type(copy))]
    pub(crate) pdf_area: f32,
}

/// Triangle-area flux-weighted CDF importance sampler for arbitrary emissive `Mesh3D` emitters.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct EmissiveMeshLight3D {
    /// World-space non-degenerate emissive triangles extracted from the source mesh.
    pub(crate) triangles: Vec<EmissiveTriangle3D>,
    /// Monotonically increasing normalized cumulative distribution over `triangles`.
    pub(crate) cdf: Vec<f32>,
    /// Total emitting triangle area in square meters.
    #[get(type(copy))]
    pub(crate) total_area: f32,
    /// Total flux weight (`sum(area * luminance(radiance))`) normalizing the CDF.
    #[get(type(copy))]
    pub(crate) total_flux_weight: f32,
    /// Enclosing world-space axis-aligned bounding box.
    #[get(type(copy))]
    pub(crate) bounds: AxisAlignedBox3D,
    /// Smooth attenuation cutoff range in meters.
    #[get(type(copy))]
    pub(crate) range: f32,
    /// Whether both faces of emissive triangles radiate light.
    #[get(type(copy))]
    pub(crate) two_sided: bool,
}

/// Unified composable 3D scene lighting rig aggregating directional, point, spot, area, and emissive mesh emitters.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct LightRig3D {
    /// Directional Sun/Moon lights with Cascaded Shadow Map parameters.
    pub(crate) directional_lights: Vec<RigDirectionalLight3D>,
    /// Omnidirectional physical point lights.
    pub(crate) point_lights: Vec<RigPointLight3D>,
    /// Conical spotlights with optional 2D cookie/gobo masks.
    pub(crate) spot_lights: Vec<RigSpotLight3D>,
    /// Analytical Rect, Disk, and Tube area lights.
    pub(crate) area_lights: Vec<RigAreaLight3D>,
    /// Emissive triangle-mesh emitters with area-CDF importance sampling.
    pub(crate) emissive_meshes: Vec<EmissiveMeshLight3D>,
    /// Fallback ambient radiance color.
    #[get(type(copy))]
    pub(crate) ambient_color: Vec3,
    /// Fallback ambient intensity multiplier.
    #[get(type(copy))]
    pub(crate) ambient_intensity: f32,
}

/// Compact clustered light handle pairing source kind, source array index, and world bounding sphere.
#[derive(Clone, Copy, Data, Debug, Default, New, PartialEq)]
pub struct ClusteredLightRef {
    /// Source light collection kind (`Point`, `Spot`, or `Area`).
    #[get(type(copy))]
    pub(crate) kind: ClusteredLightKind,
    /// Zero-based index into the corresponding `LightRig3D` light vector.
    #[get(type(copy))]
    pub(crate) index: u32,
    /// World-space bounding sphere center used for frustum cluster culling.
    #[get(type(copy))]
    pub(crate) bounding_center: Vec3,
    /// World-space bounding sphere radius in meters.
    #[get(type(copy))]
    pub(crate) bounding_radius: f32,
}

/// Pre-allocated 3D Froxel Clustered Forward+ light culler (`nx x ny x nz`) with exact sphere-vs-cluster-AABB assignment and zero steady-state allocations.
#[derive(Clone, Data, Debug, PartialEq)]
pub struct ForwardPlusLightGrid {
    /// Horizontal cluster grid resolution.
    #[get(type(copy))]
    pub(crate) nx: usize,
    /// Vertical cluster grid resolution.
    #[get(type(copy))]
    pub(crate) ny: usize,
    /// Exponential depth slice count.
    #[get(type(copy))]
    pub(crate) nz: usize,
    /// Maximum light indices stored per individual cluster.
    #[get(type(copy))]
    pub(crate) max_lights_per_cluster: usize,
    /// Active camera near clipping plane in meters.
    #[get(type(copy))]
    pub(crate) near_plane: f32,
    /// Active camera far clipping plane in meters.
    #[get(type(copy))]
    pub(crate) far_plane: f32,
    /// Active vertical half-tangent `tan(eff_fov_rad * 0.5)`.
    #[get(type(copy))]
    pub(crate) tan_half_y: f32,
    /// Active horizontal half-tangent `tan_half_y * aspect`.
    #[get(type(copy))]
    pub(crate) tan_half_x: f32,
    /// Precomputed `nz / ln(far / near)` mapping positive view depth to slice index.
    #[get(type(copy))]
    pub(crate) log_depth_scale: f32,
    /// Total light-to-cluster assignments recorded in the latest rebuild.
    #[get(type(copy))]
    pub(crate) total_assignments: usize,
    /// Pre-allocated depth slice boundaries (`len == nz + 1`).
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) depth_splits: Vec<f32>,
    /// Pre-allocated view-space axis-aligned bounding box for every cluster (`len == nx * ny * nz`).
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) cluster_aabbs_view: Vec<AxisAlignedBox3D>,
    /// Pre-allocated frame light reference list populated on `rebuild`.
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) light_refs: Vec<ClusteredLightRef>,
    /// Pre-allocated per-cluster assigned light counts (`len == nx * ny * nz`).
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) cluster_counts: Vec<u32>,
    /// Pre-allocated flat light index table (`len == nx * ny * nz * max_lights_per_cluster`).
    #[get(pub(crate))]
    #[get_mut(pub(crate))]
    #[set(pub(crate))]
    pub(crate) cluster_indices: Vec<u32>,
}