1use bytemuck::{Pod, Zeroable};
2
3#[repr(C)]
4#[derive(Copy, Clone, Debug, Pod, Zeroable)]
5pub struct Vertex {
6 pub position: [f32; 3],
7 pub color: [f32; 3],
8 pub normal: [f32; 3],
9 pub tex_coords: [f32; 2],
10 pub joint_indices: [u32; 4],
11 pub joint_weights: [f32; 4],
12 pub tangent: [f32; 4],
13}
14
15impl Default for Vertex {
16 fn default() -> Self {
17 Self {
18 position: [0.0; 3],
19 color: [1.0; 3],
20 normal: [0.0, 1.0, 0.0],
21 tex_coords: [0.0; 2],
22 joint_indices: [0; 4],
23 joint_weights: [0.0; 4],
24 tangent: [1.0, 0.0, 0.0, 1.0],
25 }
26 }
27}
28
29impl Vertex {
30 pub fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
31 wgpu::VertexBufferLayout {
32 array_stride: std::mem::size_of::<Vertex>() as wgpu::BufferAddress,
33 step_mode: wgpu::VertexStepMode::Vertex,
34 attributes: &[
35 wgpu::VertexAttribute {
36 offset: 0,
37 shader_location: 0,
38 format: wgpu::VertexFormat::Float32x3,
39 },
40 wgpu::VertexAttribute {
41 offset: std::mem::size_of::<[f32; 3]>() as wgpu::BufferAddress,
42 shader_location: 1,
43 format: wgpu::VertexFormat::Float32x3,
44 },
45 wgpu::VertexAttribute {
46 offset: std::mem::size_of::<[f32; 6]>() as wgpu::BufferAddress,
47 shader_location: 2,
48 format: wgpu::VertexFormat::Float32x3,
49 },
50 wgpu::VertexAttribute {
51 offset: std::mem::size_of::<[f32; 9]>() as wgpu::BufferAddress,
52 shader_location: 3,
53 format: wgpu::VertexFormat::Float32x2,
54 },
55 wgpu::VertexAttribute {
56 offset: std::mem::size_of::<[f32; 11]>() as wgpu::BufferAddress,
57 shader_location: 4,
58 format: wgpu::VertexFormat::Uint32x4,
59 },
60 wgpu::VertexAttribute {
61 offset: (std::mem::size_of::<[f32; 11]>() + std::mem::size_of::<[u32; 4]>())
62 as wgpu::BufferAddress,
63 shader_location: 5,
64 format: wgpu::VertexFormat::Float32x4,
65 },
66 wgpu::VertexAttribute {
67 offset: (std::mem::size_of::<[f32; 11]>() + std::mem::size_of::<[u32; 4]>() + std::mem::size_of::<[f32; 4]>())
68 as wgpu::BufferAddress,
69 shader_location: 6,
70 format: wgpu::VertexFormat::Float32x4,
71 },
72 ],
73 }
74 }
75}
76
77#[repr(C)]
78#[derive(Copy, Clone, Debug, Pod, Zeroable)]
79pub struct LightData {
80 pub position: [f32; 4], pub color: [f32; 4], pub direction: [f32; 4], pub params: [f32; 4], }
85
86#[repr(C)]
87#[derive(Copy, Clone, Debug, Pod, Zeroable)]
88pub struct PostProcessUniforms {
89 pub bloom_intensity: f32,
90 pub bloom_threshold: f32,
91 pub exposure: f32,
92 pub chromatic_aberration: f32,
93 pub vignette_intensity: f32,
94 pub film_grain_intensity: f32,
95 pub dof_focus_dist: f32,
96 pub dof_focus_range: f32,
97 pub dof_blur_size: f32,
98 pub _padding: [f32; 3],
99}
100
101#[repr(C)]
103#[derive(Copy, Clone, Debug, Pod, Zeroable)]
104pub struct ShadowVsUniform {
105 pub light_view_proj: [[f32; 4]; 4],
106}
107
108#[repr(C)]
109#[derive(Copy, Clone, Debug, Pod, Zeroable)]
110pub struct SceneUniforms {
111 pub view_proj: [[f32; 4]; 4],
112 pub camera_pos: [f32; 4],
113 pub sun_direction: [f32; 4],
114 pub sun_color: [f32; 4],
115 pub lights: [LightData; 10],
116 pub light_view_proj: [[[f32; 4]; 4]; 4],
118 pub cascade_splits: [f32; 4],
120 pub camera_forward: [f32; 4],
122 pub cascade_params: [f32; 4],
124 pub num_lights: u32,
125 pub exposure: f32,
126 pub _pre_align_pad: [u32; 2], pub _align_pad: [u32; 3], pub environment_blend_t: f32, pub environment_preset: u32, pub point_shadows_enabled: u32, pub environment_preset_2: u32, pub shading_mode: u32, }
135
136#[repr(C)]
137#[derive(Copy, Clone, Debug, Pod, Zeroable)]
138pub struct InstanceRaw {
139 pub model: [[f32; 4]; 4],
140 pub albedo_color: [f32; 4],
141 pub roughness: f32,
142 pub metallic: f32,
143 pub unlit: f32,
144 pub _padding: f32,
145}