1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
//! Rust mirrors of uniforms.wgsl: the view and frame data of group 0 and the
//! per-instance object record of group 1.
/// `View::flags`: a static specular probe capture face.
pub(crate) const VIEW_PROBE_CAPTURE: u32 = 1;
/// `DirectionalLight::flags`: the light has the frame's shadow cascades.
pub(crate) const DIRECTIONAL_LIGHT_SHADOW: u32 = 1;
/// `Frame::flags`: the frame has a fog volume to sample (its volumetric fog
/// or its sky's aerial perspective ran); draws fog themselves from it.
pub(crate) const FRAME_FOG: u32 = 1;
/// `Frame::flags`: baked (fixed) lighting is on.
pub(crate) const FRAME_BAKED_LIGHTING: u32 = 2;
/// `Frame::flags`: an irradiance atlas is installed.
pub(crate) const FRAME_IRRADIANCE_ATLAS: u32 = 4;
/// `Frame::flags`: the backdrop is `backdrop_color`, not the panorama.
pub(crate) const FRAME_BACKDROP_COLOR: u32 = 8;
/// `Frame::flags`: the camera's shadows take the temporal filter.
pub(crate) const FRAME_TEMPORAL_SHADOW_FILTER: u32 = 16;
/// `Frame::flags`: the camera's shadows take one hardware 2×2 tap.
pub(crate) const FRAME_HARDWARE_SHADOW_FILTER: u32 = 32;
/// `Frame::flags`: the dynamic GI volume lights the frame.
pub(crate) const FRAME_DYNAMIC_GI: u32 = 64;
/// `Frame::flags`: the irradiance volume lights the frame.
pub(crate) const FRAME_IRRADIANCE_VOLUME: u32 = 128;
/// `Frame::flags`: the backdrop is the procedural sky (`FrameEnvironment::Sky`):
/// the sky-view table and the lights' discs.
pub(crate) const FRAME_BACKDROP_SKY: u32 = 256;
/// `Frame::flags`: the camera's shadows take the soft filter, with the
/// temporal filter's bit.
pub(crate) const FRAME_SOFT_SHADOW_FILTER: u32 = 512;
/// `Object::flags`: a static instance; a moving one has the bit clear.
pub(crate) const OBJECT_STATIC: u32 = 1;
/// `Object::flags`: the main camera draws it (`InstanceState::visible`).
pub(crate) const OBJECT_VISIBLE: u32 = 2;
/// `Object::flags`: the other views show it
/// (`InstanceState::capture_visible`).
pub(crate) const OBJECT_CAPTURE_VISIBLE: u32 = 4;
/// `Object::flags`: it deforms.
pub(crate) const OBJECT_DEFORMING: u32 = 8;
/// One rendered view (`View` in uniforms.wgsl).
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct ViewUniform {
pub view: [[f32; 4]; 4],
/// Unjittered.
pub projection: [[f32; 4]; 4],
/// The jittered projection times the view.
pub view_projection: [[f32; 4]; 4],
pub inverse_view_projection: [[f32; 4]; 4],
/// Unjittered, for motion.
pub stable_view_projection: [[f32; 4]; 4],
pub previous_view_projection: [[f32; 4]; 4],
pub eye: [f32; 3],
pub mip_bias: f32,
/// Half the NDC jitter.
pub jitter: [f32; 2],
pub viewport: [f32; 2],
pub flags: u32,
/// WGSL rounds `View` up to its 16-byte alignment.
pub padding: [u32; 3],
}
/// One directional light (`DirectionalLight` in uniforms.wgsl).
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct DirectionalLightUniform {
/// From a receiver toward the light; any nonzero length.
pub direction_to_light: [f32; 3],
/// `DIRECTIONAL_LIGHT_*` bits.
pub flags: u32,
pub color: [f32; 3],
/// Zero for no light.
pub illuminance: f32,
/// The scale of its light in the volumetric fog.
pub fog_energy: f32,
/// How dark its shadow is, 0..=1.
pub shadow_opacity: f32,
/// The tangent of half its angular diameter: the radius of its disc at
/// unit distance, which sizes its highlights and its rays.
pub disc_radius: f32,
/// WGSL rounds `DirectionalLight` up to its 16-byte alignment.
pub padding: f32,
}
/// One directional shadow cascade (`ShadowCascade` in uniforms.wgsl).
#[repr(C)]
#[derive(Clone, Copy, Debug, PartialEq, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct ShadowCascadeUniform {
pub clip_from_world: [[f32; 4]; 4],
pub texel_size: f32,
pub far_bound: f32,
/// WGSL rounds `ShadowCascade` up to its 16-byte alignment.
pub padding: [f32; 2],
}
/// What every view of one frame shares (`Frame` in uniforms.wgsl).
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct FrameUniform {
pub directional_lights: [DirectionalLightUniform; 2],
pub shadow_cascades: [ShadowCascadeUniform; crate::view::cascades::MAX_SHADOW_CASCADES],
pub hemisphere_sky_color: [f32; 3],
pub hemisphere_intensity: f32,
pub hemisphere_ground_color: [f32; 3],
pub diffuse_environment_yaw: f32,
pub backdrop_color: [f32; 3],
pub diffuse_environment_intensity: f32,
pub mist_thin_color: [f32; 3],
pub mist_opacity: f32,
pub mist_dense_color: [f32; 3],
pub backdrop_yaw: f32,
pub mist_size: [f32; 2],
pub mist_drift: [f32; 2],
pub backdrop_brightness: f32,
pub reflection_yaw: f32,
pub reflection_intensity: f32,
pub elapsed_seconds: f32,
pub fixed_irradiance_scale: f32,
pub visibility_mask: u32,
/// `FRAME_*` bits.
pub flags: u32,
pub shadow_cascade_count: u32,
/// Frames since history restarted.
pub frame_count: u32,
/// `shading::material::animation_phase` of the frame's time.
pub animation_phase: f32,
/// WGSL aligns `lightmap_chart` to 16 bytes.
pub padding_chart: [f32; 2],
pub lightmap_chart: [f32; 4],
/// With `FRAME_DYNAMIC_GI`, the scene's dynamic GI volume: its first
/// probe's position, its probes' spacing and their count on each axis,
/// and its scroll, where they are stored.
pub dynamic_gi_origin: [f32; 3],
/// WGSL aligns each `vec3` to 16 bytes.
pub padding_origin: f32,
pub dynamic_gi_spacing: [f32; 3],
pub padding_spacing: f32,
pub dynamic_gi_probes: [u32; 3],
pub padding_probes: u32,
pub dynamic_gi_scroll: [u32; 3],
pub padding_scroll: u32,
/// With `FRAME_IRRADIANCE_VOLUME`, the scene's irradiance volume: its
/// first cell's least corner, its cells' size and their count on each
/// axis.
pub irradiance_volume_origin: [f32; 3],
pub padding_volume_origin: f32,
pub irradiance_volume_cell_size: [f32; 3],
pub padding_cell_size: f32,
pub irradiance_volume_cells: [u32; 3],
/// The last submitted frame's `elapsed_seconds` and `animation_phase`,
/// which a material's vertex function evaluates motion at; this
/// frame's after history restarts.
pub previous_elapsed_seconds: f32,
pub previous_animation_phase: f32,
/// The last submitted frame's backdrop panorama yaw, which the sky's
/// motion turns from; `backdrop_yaw` after history restarts or where
/// either frame's backdrop is a colour.
pub previous_backdrop_yaw: f32,
/// With `FRAME_BACKDROP_SKY`, the camera's distance from the planet's
/// centre, metres.
pub sky_camera_radius: f32,
pub padding_sky: f32,
/// With `FRAME_BACKDROP_SKY`, each directional light's disc: its
/// radiance through the air (rgb) and its angular radius (a); black for
/// a light that is off.
pub sky_discs: [[f32; 4]; 2],
/// With `FRAME_FOG`, the frame's one fog volume's slices, which draws
/// sample it by (`shading::fog::FogLayout`).
pub fog: crate::shading::fog::FogLayout,
/// WGSL rounds `Frame` up to its 16-byte alignment.
pub padding_fog: [u32; 3],
}
/// One instance's record (`Object` in uniforms.wgsl), at its index in the
/// scene's object buffer (`scene::objects`).
#[repr(C)]
#[derive(Clone, Copy, Debug, bytemuck::Pod, bytemuck::Zeroable)]
pub(crate) struct ObjectUniform {
pub model: [[f32; 4]; 4],
pub previous_model: [[f32; 4]; 4],
pub baked_irradiance: [[f32; 4]; 6],
/// `OBJECT_*` bits.
pub flags: u32,
/// A deforming instance's vertices in the scene source: its positions
/// this frame and in the last submitted frame, and its normals and
/// tangents (`shading::deformation`). Zero for one that does not deform.
pub deformed_positions: u32,
pub previous_positions: u32,
pub deformed_normals: u32,
}
/// The camera's view and frame data as last uploaded.
#[derive(Clone, Copy, Debug)]
pub(crate) struct FrameValues {
pub view: ViewUniform,
pub frame: FrameUniform,
}