Skip to main content

hotham/
scene_data.rs

1// TODO: Should these be components?
2use nalgebra::{vector, Matrix4, Vector3, Vector4};
3use serde::{Deserialize, Serialize};
4
5/// Data about the current scene. Sent to the vertex and fragment shaders
6#[derive(Deserialize, Serialize, Clone, Debug, Copy)]
7#[repr(C)]
8pub struct SceneData {
9    /// Projection matrices (one per eye)
10    pub projection: [Matrix4<f32>; 2],
11    /// View matrices (one per eye)
12    pub view: [Matrix4<f32>; 2],
13    /// Position of the cameras (one per eye)
14    pub camera_position: [Vector4<f32>; 2],
15}
16
17impl Default for SceneData {
18    fn default() -> Self {
19        Self {
20            view: [Matrix4::identity(), Matrix4::identity()],
21            projection: [Matrix4::identity(), Matrix4::identity()],
22            camera_position: [Vector4::zeros(), Vector4::zeros()],
23        }
24    }
25}
26
27/// Parameters sent to the fragment shader to tweak the scene
28/// See `pbr.frag` for more information
29#[derive(Deserialize, Serialize, Clone, Debug, Copy)]
30#[repr(C)]
31pub struct SceneParams {
32    /// Direction of the global light
33    pub light_direction: Vector4<f32>,
34    /// Level of exposure
35    pub exposure: f32,
36    /// Gamma
37    pub gamma: f32,
38    /// Prefiltered Cube MIP Levels
39    pub prefiltered_cube_mip_levels: f32,
40    /// How much should the IBL ambient light be scaled?
41    pub scale_ibl_ambient: f32,
42    /// Debug view inputs (see pbr.frag)
43    pub debug_view_inputs: f32,
44    /// Debug view equation (see pbr.frag)
45    pub debug_view_equation: f32,
46}
47
48impl Default for SceneParams {
49    fn default() -> Self {
50        let light_source: Vector3<f32> =
51            vector![75_f32.to_radians(), 40_f32.to_radians(), 0_f32.to_radians()];
52        let x = light_source.x.sin() * light_source.y.cos();
53        let y = light_source.y.sin();
54        let z = light_source.x.cos() * light_source.y.cos();
55
56        let light_direction = vector![x, y, z, 0.];
57        SceneParams {
58            light_direction,
59            exposure: 4.5,
60            gamma: 2.2,
61            prefiltered_cube_mip_levels: 10.,
62            scale_ibl_ambient: 0.1,
63            debug_view_inputs: 0.,
64            debug_view_equation: 0.,
65        }
66    }
67}