Skip to content

Commit

Permalink
Refactor globals struct into own shader
Browse files Browse the repository at this point in the history
Signed-off-by: Torstein Grindvik <torstein.grindvik@nordicsemi.no>
  • Loading branch information
torsteingrindvik committed Feb 11, 2023
1 parent de98850 commit d79ecee
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
16 changes: 16 additions & 0 deletions crates/bevy_pbr/src/render/globals.wgsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#define_import_path bevy_pbr::globals

struct Globals {
// The time since startup in seconds
// Wraps to 0 after 1 hour.
time: f32,
// The delta time since the previous frame in seconds
delta_time: f32,
// Frame count since the start of the app.
// It wraps to zero when it reaches the maximum value of a u32.
frame_count: u32,
#ifdef SIXTEEN_BYTE_ALIGNMENT
// WebGL2 structs must be 16 byte aligned.
_wasm_padding: f32
#endif
}
3 changes: 3 additions & 0 deletions crates/bevy_pbr/src/render/mesh.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ pub const MESH_VERTEX_OUTPUT: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 2645551199423808407);
pub const MESH_VIEW_TYPES_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 8140454348013264787);
pub const GLOBALS_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 17924628719070609599);
pub const MESH_VIEW_BINDINGS_HANDLE: HandleUntyped =
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 9076678235888822571);
pub const MESH_TYPES_HANDLE: HandleUntyped =
Expand Down Expand Up @@ -74,6 +76,7 @@ impl Plugin for MeshRenderPlugin {
"mesh_view_types.wgsl",
Shader::from_wgsl
);
load_internal_asset!(app, GLOBALS_HANDLE, "globals.wgsl", Shader::from_wgsl);
load_internal_asset!(
app,
MESH_VIEW_BINDINGS_HANDLE,
Expand Down
16 changes: 1 addition & 15 deletions crates/bevy_pbr/src/render/mesh_view_types.wgsl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#define_import_path bevy_pbr::mesh_view_types
#import bevy_pbr::globals

struct View {
view_proj: mat4x4<f32>,
Expand Down Expand Up @@ -119,18 +120,3 @@ struct ClusterOffsetsAndCounts {
data: array<vec4<u32>, 1024u>,
};
#endif

struct Globals {
// The time since startup in seconds
// Wraps to 0 after 1 hour.
time: f32,
// The delta time since the previous frame in seconds
delta_time: f32,
// Frame count since the start of the app.
// It wraps to zero when it reaches the maximum value of a u32.
frame_count: u32,
#ifdef SIXTEEN_BYTE_ALIGNMENT
// WebGL2 structs must be 16 byte aligned.
_wasm_padding: f32
#endif
}

0 comments on commit d79ecee

Please sign in to comment.