Skip to main content

euv_core/game/fluid/renderer/
struct.rs

1use super::*;
2
3/// 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.
4#[derive(Clone, Data, Debug)]
5pub struct LiquidOpticalRenderer {
6    /// Active scalar field grid width in cells for PBF interactive wake transfer.
7    #[get(type(copy))]
8    pub(crate) field_w: usize,
9    /// Active scalar field grid height in cells for PBF interactive wake transfer.
10    #[get(type(copy))]
11    pub(crate) field_h: usize,
12    /// Smoothed PBF horizontal flow velocity wake field.
13    pub(crate) flow_u: Vec<f32>,
14    /// Smoothed PBF vertical flow velocity wake field.
15    pub(crate) flow_v: Vec<f32>,
16    /// Smoothed PBF wave-crest foam intensity wake field.
17    pub(crate) foam: Vec<f32>,
18    /// Separable horizontal smoothing scratch buffer.
19    pub(crate) wake_tmp: Vec<f32>,
20    /// Persistent linear HDR RGB frame scratch buffer (`len == out_w * out_h * 3`) feeding filmic tone-mapping and HDR sun/glitter bloom.
21    pub(crate) hdr_rgb: Vec<f32>,
22    /// Quarter-resolution HDR bloom extraction and vertical blur buffer.
23    pub(crate) bloom_a: Vec<[f32; 3]>,
24    /// Quarter-resolution HDR bloom horizontal blur scratch buffer.
25    pub(crate) bloom_b: Vec<[f32; 3]>,
26    /// Pre-baked `SKY_LUT_W x SKY_LUT_H` spherical stormy-sunset sky dome radiance LUT (excluding full-res sun disk).
27    pub(crate) sky_lut: Vec<[f32; 3]>,
28    /// Pre-baked `REFL_LUT_W x REFL_LUT_H` spherical ocean-reflection sky radiance LUT.
29    pub(crate) refl_lut: Vec<[f32; 3]>,
30    /// Precomputed 1025-entry L1-resident ACES filmic tone-mapping + sRGB gamma LUT eliminating per-pixel `powf`.
31    pub(crate) aces_lut: Vec<u8>,
32    /// Simulation timestamp at which `sky_lut` and `refl_lut` were last baked.
33    #[get(type(copy))]
34    pub(crate) last_sky_lut_time: f32,
35    /// Last rendered output width in pixels.
36    #[get(type(copy))]
37    pub(crate) last_width: u32,
38    /// Last rendered output height in pixels.
39    #[get(type(copy))]
40    pub(crate) last_height: u32,
41}
42
43/// Pre-projected screen-space 3D origami paper boat triangle ready for per-pixel barycentric depth shading and wave-warped water reflection.
44#[derive(Clone, Copy, Data, Debug, Default)]
45pub(crate) struct ProjectedBoatTri {
46    /// Projected screen X coordinates `(x0, x1, x2)` in viewport pixels.
47    #[get(pub(crate), type(copy))]
48    #[set(pub(crate))]
49    pub(crate) sx: [f32; 3],
50    /// Projected screen Y coordinates `(y0, y1, y2)` in viewport pixels.
51    #[get(pub(crate), type(copy))]
52    #[set(pub(crate))]
53    pub(crate) sy: [f32; 3],
54    /// View-space depth Z at each vertex `(z0, z1, z2)` in meters.
55    #[get(pub(crate), type(copy))]
56    #[set(pub(crate))]
57    pub(crate) depth: [f32; 3],
58    /// Local height above boat waterline `(h0, h1, h2)` in meters for wet-paper capillary absorption.
59    #[get(pub(crate), type(copy))]
60    #[set(pub(crate))]
61    pub(crate) local_y: [f32; 3],
62    /// Reciprocal signed 2D screen area for fast barycentric interpolation.
63    #[get(pub(crate), type(copy))]
64    #[set(pub(crate))]
65    pub(crate) inv_area: f32,
66    /// Reciprocal screen pixel lengths `(1/|v1v2|, 1/|v2v0|, 1/|v0v1|)` for analytical 1.35px edge anti-aliasing.
67    #[get(pub(crate), type(copy))]
68    #[set(pub(crate))]
69    pub(crate) edge_inv_len: [f32; 3],
70    /// Sign of the signed 2D screen area (`+1.0` or `-1.0`) orienting signed pixel edge distances inward.
71    #[get(pub(crate), type(copy))]
72    #[set(pub(crate))]
73    pub(crate) area_sign: f32,
74    /// Precomputed linear HDR diffuse + translucent paper color `[r, g, b]` for this facet.
75    #[get(pub(crate), type(copy))]
76    #[set(pub(crate))]
77    pub(crate) base_rgb: [f32; 3],
78    /// Screen-space bounding box `(min_x, max_x, min_y, max_y)` in pixels.
79    #[get(pub(crate), type(copy))]
80    #[set(pub(crate))]
81    pub(crate) bbox: [f32; 4],
82    /// Origami facet classification (`0=outer_wing`, `1=center_flap`, `2=sail_peak`, `3=inner_cavity`).
83    #[get(pub(crate), type(copy))]
84    #[set(pub(crate))]
85    pub(crate) facet_kind: u8,
86    /// Whether this triangle is valid and visible in front of the camera.
87    #[get(pub(crate), type(copy))]
88    #[set(pub(crate))]
89    pub(crate) valid: bool,
90}
91
92/// Immutable per-frame ocean, sky, sun, gyro-tilt, and projected 3D origami boat parameters shared across parallel scanline workers.
93#[derive(Clone, Copy, Data, Debug)]
94pub(crate) struct OceanShadeParams {
95    /// Output framebuffer width in pixels.
96    #[get(pub(crate), type(copy))]
97    #[set(pub(crate))]
98    pub(crate) out_w: usize,
99    /// Output framebuffer height in pixels.
100    #[get(pub(crate), type(copy))]
101    #[set(pub(crate))]
102    pub(crate) out_h: usize,
103    /// PBF wake field width in cells.
104    #[get(pub(crate), type(copy))]
105    #[set(pub(crate))]
106    pub(crate) field_w: usize,
107    /// PBF wake field height in cells.
108    #[get(pub(crate), type(copy))]
109    #[set(pub(crate))]
110    pub(crate) field_h: usize,
111    /// Monotonic simulation time in seconds driving continuous ocean swells and drifting storm clouds.
112    #[get(pub(crate), type(copy))]
113    #[set(pub(crate))]
114    pub(crate) sim_time: f32,
115    /// Dynamic wave choppiness multiplier amplified by PBF kinetic energy, shaking, and stirring (`1.0..=2.0`).
116    #[get(pub(crate), type(copy))]
117    #[set(pub(crate))]
118    pub(crate) wave_agitation: f32,
119    /// Effective normalized screen horizon Y coordinate (`~0.545`, subtly shifted by fill level).
120    #[get(pub(crate), type(copy))]
121    #[set(pub(crate))]
122    pub(crate) horizon_v: f32,
123    /// Cosine of active camera horizon roll angle derived from gravity/gyroscope.
124    #[get(pub(crate), type(copy))]
125    #[set(pub(crate))]
126    pub(crate) roll_cos: f32,
127    /// Sine of active camera horizon roll angle derived from gravity/gyroscope.
128    #[get(pub(crate), type(copy))]
129    #[set(pub(crate))]
130    pub(crate) roll_sin: f32,
131    /// Normalized 3D sun direction vector `[lx, ly, lz]` in ocean camera coordinates.
132    #[get(pub(crate), type(copy))]
133    #[set(pub(crate))]
134    pub(crate) sun_dir: [f32; 3],
135    /// Projected screen X coordinate of the origami paper boat center in pixels.
136    #[get(pub(crate), type(copy))]
137    #[set(pub(crate))]
138    pub(crate) boat_screen_x: f32,
139    /// Projected screen Y coordinate of the origami paper boat waterline in pixels.
140    #[get(pub(crate), type(copy))]
141    #[set(pub(crate))]
142    pub(crate) boat_waterline_y: f32,
143    /// Overall projected screen bounding box `[min_x, max_x, min_y, max_y]` of the origami paper boat in pixels.
144    #[get(pub(crate), type(copy))]
145    #[set(pub(crate))]
146    pub(crate) boat_bbox: [f32; 4],
147    /// Pre-projected origami paper boat triangles ready for per-pixel shading and water reflection.
148    #[get(pub(crate), type(copy))]
149    #[set(pub(crate))]
150    pub(crate) boat_tris: [ProjectedBoatTri; BOAT_TRI_COUNT],
151    /// Precomputed per-frame wave temporal phase offsets `sim_time * speed[i]` for all 8 wave trains.
152    #[get(pub(crate), type(copy))]
153    #[set(pub(crate))]
154    pub(crate) wave_time_phases: [f32; 8],
155    /// Whether the PBF wake field contains non-negligible interactive stirring or foam requiring bilinear sampling.
156    #[get(pub(crate), type(copy))]
157    #[set(pub(crate))]
158    pub(crate) has_active_wake: bool,
159}
160
161/// Read-only borrowed slice bundle of interactive PBF wake fields and pre-baked spherical sky LUTs for parallel ocean shading.
162#[derive(Clone, Copy, Data, Debug)]
163pub(crate) struct FluidWakeViews<'a> {
164    /// Smoothed PBF horizontal flow velocity wake field.
165    #[get(pub(crate), type(copy))]
166    #[set(pub(crate))]
167    pub(crate) flow_u: &'a [f32],
168    /// Smoothed PBF vertical flow velocity wake field.
169    #[get(pub(crate), type(copy))]
170    #[set(pub(crate))]
171    pub(crate) flow_v: &'a [f32],
172    /// Smoothed PBF foam intensity wake field.
173    #[get(pub(crate), type(copy))]
174    #[set(pub(crate))]
175    pub(crate) foam: &'a [f32],
176    /// Pre-baked `SKY_LUT_W x SKY_LUT_H` primary storm-cloud dome radiance LUT.
177    #[get(pub(crate), type(copy))]
178    #[set(pub(crate))]
179    pub(crate) sky_lut: &'a [[f32; 3]],
180    /// Pre-baked `REFL_LUT_W x REFL_LUT_H` ocean-reflection sky radiance LUT.
181    #[get(pub(crate), type(copy))]
182    #[set(pub(crate))]
183    pub(crate) refl_lut: &'a [[f32; 3]],
184}