euv_core/game/engine3d/raytrace/scene/struct.rs
1use super::*;
2
3/// Physically based ray-tracing material supporting Lambert/Oren-Nayar, GGX metal, clearcoat, dielectric glass/water with Beer-Lambert absorption, and area emission.
4#[derive(Clone, Copy, Data, Debug, PartialEq)]
5pub struct RtMaterial {
6 /// Active physical BSDF family.
7 #[get(type(copy))]
8 pub(crate) kind: RtMaterialKind,
9 /// Linear base RGB reflectance / transmittance tint in `[0.0, 1.0]`.
10 #[get(type(copy))]
11 pub(crate) albedo: Vec3,
12 /// Conductor blend weight in `[0.0, 1.0]`.
13 #[get(type(copy))]
14 pub(crate) metallic: f32,
15 /// Perceptual microfacet roughness in `[0.0, 1.0]`.
16 #[get(type(copy))]
17 pub(crate) roughness: f32,
18 /// Dielectric index of refraction (`1.5` glass, `1.333` water).
19 #[get(type(copy))]
20 pub(crate) ior: f32,
21 /// Dielectric transmission weight in `[0.0, 1.0]`.
22 #[get(type(copy))]
23 pub(crate) transmission: f32,
24 /// Beer-Lambert volumetric absorption coefficient `sigma_a` (`1 / meters`) attenuating transmitted rays by `exp(-sigma_a * distance)`.
25 #[get(type(copy))]
26 pub(crate) absorption: Vec3,
27 /// Dielectric clearcoat top-layer weight in `[0.0, 1.0]`.
28 #[get(type(copy))]
29 pub(crate) clearcoat: f32,
30 /// Clearcoat top-layer roughness in `[0.0, 1.0]`.
31 #[get(type(copy))]
32 pub(crate) clearcoat_roughness: f32,
33 /// Emitted linear HDR RGB radiance.
34 #[get(type(copy))]
35 pub(crate) emission: Vec3,
36 /// Oren-Nayar micro-surface diffuse roughness standard deviation in `[0.0, 1.0]`.
37 #[get(type(copy))]
38 pub(crate) oren_nayar_sigma: f32,
39}
40
41/// Physical scene light combining emitter geometry with linear HDR color and intensity.
42#[derive(Clone, Copy, Data, Debug, PartialEq)]
43pub struct RtLight {
44 /// Emitter geometric shape and orientation.
45 #[get(type(copy))]
46 pub(crate) kind: RtLightKind,
47 /// Linear HDR RGB chromaticity color.
48 #[get(type(copy))]
49 pub(crate) color: Vec3,
50 /// Scalar radiant intensity or surface radiance multiplier.
51 #[get(type(copy))]
52 pub(crate) intensity: f32,
53}
54
55/// Evaluated direct lighting sample returned by `RtLight::sample_light`.
56#[derive(Clone, Copy, Data, Debug, New, PartialEq)]
57pub struct RtLightSample {
58 /// Unit direction pointing from the shaded hit point toward the sampled point on the light.
59 #[get(type(copy))]
60 pub(crate) direction: Vec3,
61 /// Distance in meters to the sampled point on the light (`RT_RAY_T_MAX` for directional lights).
62 #[get(type(copy))]
63 pub(crate) distance: f32,
64 /// Incident HDR radiance arriving from the sampled direction (already including inverse-square falloff for delta point/spot lights).
65 #[get(type(copy))]
66 pub(crate) radiance: Vec3,
67 /// Solid-angle sampling probability density `p(omega)` (`1.0` for pure delta lights).
68 #[get(type(copy))]
69 pub(crate) pdf: f32,
70 /// Whether this light sample comes from a Dirac delta distribution (exempt from BSDF MIS).
71 #[get(type(copy))]
72 pub(crate) is_delta: bool,
73}
74
75/// Pinhole and Thin-Lens Depth-of-Field camera generating jittered primary rays for anti-aliasing and bokeh defocus.
76#[derive(Clone, Copy, Data, Debug, PartialEq)]
77pub struct RtCamera {
78 /// World-space eye / lens center position.
79 #[get(type(copy))]
80 pub(crate) position: Vec3,
81 /// Unit forward look direction.
82 #[get(type(copy))]
83 pub(crate) forward: Vec3,
84 /// Unit horizontal right basis vector.
85 #[get(type(copy))]
86 pub(crate) right: Vec3,
87 /// Unit vertical up basis vector.
88 #[get(type(copy))]
89 pub(crate) up: Vec3,
90 /// Vertical field of view in radians.
91 #[get(type(copy))]
92 pub(crate) fov_y_rad: f32,
93 /// Viewport width-to-height aspect ratio.
94 #[get(type(copy))]
95 pub(crate) aspect: f32,
96 /// Thin-lens aperture radius in meters (`0.0` = sharp pinhole camera).
97 #[get(type(copy))]
98 pub(crate) aperture_radius: f32,
99 /// Distance in meters from lens plane to the plane of sharp focus.
100 #[get(type(copy))]
101 pub(crate) focal_distance: f32,
102}
103
104/// Complete ray-traceable 3D scene holding BLAS/TLAS geometry, analytic primitives, SDF volumes, materials, lights, sky environment, and camera.
105#[derive(Clone, Data, Debug)]
106pub struct RaytraceScene {
107 /// Shared local-space triangle BLAS table referenced by `RtInstance::blas_id`.
108 pub(crate) blas_list: Vec<Blas3D>,
109 /// Dynamic top-level acceleration structure over all instanced meshes.
110 pub(crate) tlas: Tlas3D,
111 /// Analytic primitives intersected directly without tessellation.
112 pub(crate) primitives: Vec<RtPrimitive>,
113 /// Implicit SDF/CSG volumes evaluated via Lipschitz sphere tracing.
114 pub(crate) sdf_tracers: Vec<SdfSphereTracer>,
115 /// Material table referenced by `material_id` across instances, primitives, and SDFs.
116 pub(crate) materials: Vec<RtMaterial>,
117 /// Physical scene light emitters sampled by direct lighting and MIS NEE.
118 pub(crate) lights: Vec<RtLight>,
119 /// Environment dome evaluated when rays escape all geometry.
120 #[get(type(copy))]
121 pub(crate) environment: RtEnvironment,
122 /// Active thin-lens or pinhole ray-tracing camera.
123 #[get(type(copy))]
124 pub(crate) camera: RtCamera,
125 /// Monotonic revision bumped whenever scene geometry, materials, lights, or environment mutate.
126 #[get(type(copy))]
127 pub(crate) revision: u64,
128}
129
130/// Fluent scene builder and curated preset generator for `RaytraceScene`.
131#[derive(Clone, Data, Debug)]
132pub struct RaytraceSceneBuilder {
133 /// Scene under construction.
134 pub(crate) scene: RaytraceScene,
135}