-
-
Save superdump/0e3189a600b4765604e0fb164a81c989 to your computer and use it in GitHub Desktop.
Further split mesh_view_types.wgsl into pbr_lighting_types.wgsl and clustered_forward_types.wgsl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/crates/bevy_pbr/src/lib.rs b/crates/bevy_pbr/src/lib.rs | |
index c0b5668e1..7d29b35d7 100644 | |
--- a/crates/bevy_pbr/src/lib.rs | |
+++ b/crates/bevy_pbr/src/lib.rs | |
@@ -56,8 +56,12 @@ pub const PBR_BINDINGS_SHADER_HANDLE: HandleUntyped = | |
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 5635987986427308186); | |
pub const UTILS_HANDLE: HandleUntyped = | |
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 1900548483293416725); | |
+pub const CLUSTERED_FORWARD_TYPES_HANDLE: HandleUntyped = | |
+ HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 12602194095923130873); | |
pub const CLUSTERED_FORWARD_HANDLE: HandleUntyped = | |
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 166852093121196815); | |
+pub const PBR_LIGHTING_TYPES_HANDLE: HandleUntyped = | |
+ HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 15635206709404467685); | |
pub const PBR_LIGHTING_HANDLE: HandleUntyped = | |
HandleUntyped::weak_from_u64(Shader::TYPE_UUID, 14170772752254856967); | |
pub const SHADOWS_HANDLE: HandleUntyped = | |
@@ -86,12 +90,24 @@ impl Plugin for PbrPlugin { | |
Shader::from_wgsl | |
); | |
load_internal_asset!(app, UTILS_HANDLE, "render/utils.wgsl", Shader::from_wgsl); | |
+ load_internal_asset!( | |
+ app, | |
+ CLUSTERED_FORWARD_TYPES_HANDLE, | |
+ "render/clustered_forward_types.wgsl", | |
+ Shader::from_wgsl | |
+ ); | |
load_internal_asset!( | |
app, | |
CLUSTERED_FORWARD_HANDLE, | |
"render/clustered_forward.wgsl", | |
Shader::from_wgsl | |
); | |
+ load_internal_asset!( | |
+ app, | |
+ PBR_LIGHTING_TYPES_HANDLE, | |
+ "render/pbr_lighting_types.wgsl", | |
+ Shader::from_wgsl | |
+ ); | |
load_internal_asset!( | |
app, | |
PBR_LIGHTING_HANDLE, | |
diff --git a/crates/bevy_pbr/src/render/clustered_forward_types.wgsl b/crates/bevy_pbr/src/render/clustered_forward_types.wgsl | |
new file mode 100644 | |
index 000000000..f0753d868 | |
--- /dev/null | |
+++ b/crates/bevy_pbr/src/render/clustered_forward_types.wgsl | |
@@ -0,0 +1,46 @@ | |
+#define_import_path bevy_pbr::clustered_forward_types | |
+ | |
+struct Lights { | |
+ // NOTE: this array size must be kept in sync with the constants defined bevy_pbr2/src/render/light.rs | |
+ directional_lights: array<DirectionalLight, 1u>; | |
+ ambient_color: vec4<f32>; | |
+ // x/y/z dimensions and n_clusters in w | |
+ cluster_dimensions: vec4<u32>; | |
+ // xy are vec2<f32>(cluster_dimensions.xy) / vec2<f32>(view.width, view.height) | |
+ // | |
+ // For perspective projections: | |
+ // z is cluster_dimensions.z / log(far / near) | |
+ // w is cluster_dimensions.z * log(near) / log(far / near) | |
+ // | |
+ // For orthographic projections: | |
+ // NOTE: near and far are +ve but -z is infront of the camera | |
+ // z is -near | |
+ // w is cluster_dimensions.z / (-far - -near) | |
+ cluster_factors: vec4<f32>; | |
+ n_directional_lights: u32; | |
+}; | |
+ | |
+#ifdef NO_STORAGE_BUFFERS_SUPPORT | |
+struct PointLights { | |
+ data: array<PointLight, 256u>; | |
+}; | |
+struct ClusterLightIndexLists { | |
+ // each u32 contains 4 u8 indices into the PointLights array | |
+ data: array<vec4<u32>, 1024u>; | |
+}; | |
+struct ClusterOffsetsAndCounts { | |
+ // each u32 contains a 24-bit index into ClusterLightIndexLists in the high 24 bits | |
+ // and an 8-bit count of the number of lights in the low 8 bits | |
+ data: array<vec4<u32>, 1024u>; | |
+}; | |
+#else | |
+struct PointLights { | |
+ data: array<PointLight>; | |
+}; | |
+struct ClusterLightIndexLists { | |
+ data: array<u32>; | |
+}; | |
+struct ClusterOffsetsAndCounts { | |
+ data: array<vec2<u32>>; | |
+}; | |
+#endif | |
diff --git a/crates/bevy_pbr/src/render/mesh_view_bindings.wgsl b/crates/bevy_pbr/src/render/mesh_view_bindings.wgsl | |
index ec6f5dbb4..f6fd7ee22 100644 | |
--- a/crates/bevy_pbr/src/render/mesh_view_bindings.wgsl | |
+++ b/crates/bevy_pbr/src/render/mesh_view_bindings.wgsl | |
@@ -1,6 +1,8 @@ | |
#define_import_path bevy_pbr::mesh_view_bindings | |
#import bevy_pbr::mesh_view_types | |
+#import bevy_pbr::lighting_types | |
+#import bevy_pbr::clustered_forward_types | |
[[group(0), binding(0)]] | |
var<uniform> view: View; | |
diff --git a/crates/bevy_pbr/src/render/mesh_view_types.wgsl b/crates/bevy_pbr/src/render/mesh_view_types.wgsl | |
index 3892cdefb..4caa2b13d 100644 | |
--- a/crates/bevy_pbr/src/render/mesh_view_types.wgsl | |
+++ b/crates/bevy_pbr/src/render/mesh_view_types.wgsl | |
@@ -9,73 +9,3 @@ struct View { | |
width: f32; | |
height: f32; | |
}; | |
- | |
-struct PointLight { | |
- // NOTE: [2][2] [2][3] [3][2] [3][3] | |
- projection_lr: vec4<f32>; | |
- color_inverse_square_range: vec4<f32>; | |
- position_radius: vec4<f32>; | |
- // 'flags' is a bit field indicating various options. u32 is 32 bits so we have up to 32 options. | |
- flags: u32; | |
- shadow_depth_bias: f32; | |
- shadow_normal_bias: f32; | |
-}; | |
- | |
-let POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u; | |
- | |
-struct DirectionalLight { | |
- view_projection: mat4x4<f32>; | |
- color: vec4<f32>; | |
- direction_to_light: vec3<f32>; | |
- // 'flags' is a bit field indicating various options. u32 is 32 bits so we have up to 32 options. | |
- flags: u32; | |
- shadow_depth_bias: f32; | |
- shadow_normal_bias: f32; | |
-}; | |
- | |
-let DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u; | |
- | |
-struct Lights { | |
- // NOTE: this array size must be kept in sync with the constants defined bevy_pbr2/src/render/light.rs | |
- directional_lights: array<DirectionalLight, 1u>; | |
- ambient_color: vec4<f32>; | |
- // x/y/z dimensions and n_clusters in w | |
- cluster_dimensions: vec4<u32>; | |
- // xy are vec2<f32>(cluster_dimensions.xy) / vec2<f32>(view.width, view.height) | |
- // | |
- // For perspective projections: | |
- // z is cluster_dimensions.z / log(far / near) | |
- // w is cluster_dimensions.z * log(near) / log(far / near) | |
- // | |
- // For orthographic projections: | |
- // NOTE: near and far are +ve but -z is infront of the camera | |
- // z is -near | |
- // w is cluster_dimensions.z / (-far - -near) | |
- cluster_factors: vec4<f32>; | |
- n_directional_lights: u32; | |
-}; | |
- | |
-#ifdef NO_STORAGE_BUFFERS_SUPPORT | |
-struct PointLights { | |
- data: array<PointLight, 256u>; | |
-}; | |
-struct ClusterLightIndexLists { | |
- // each u32 contains 4 u8 indices into the PointLights array | |
- data: array<vec4<u32>, 1024u>; | |
-}; | |
-struct ClusterOffsetsAndCounts { | |
- // each u32 contains a 24-bit index into ClusterLightIndexLists in the high 24 bits | |
- // and an 8-bit count of the number of lights in the low 8 bits | |
- data: array<vec4<u32>, 1024u>; | |
-}; | |
-#else | |
-struct PointLights { | |
- data: array<PointLight>; | |
-}; | |
-struct ClusterLightIndexLists { | |
- data: array<u32>; | |
-}; | |
-struct ClusterOffsetsAndCounts { | |
- data: array<vec2<u32>>; | |
-}; | |
-#endif | |
diff --git a/crates/bevy_pbr/src/render/pbr_lighting_types.wgsl b/crates/bevy_pbr/src/render/pbr_lighting_types.wgsl | |
new file mode 100644 | |
index 000000000..5f4103a4a | |
--- /dev/null | |
+++ b/crates/bevy_pbr/src/render/pbr_lighting_types.wgsl | |
@@ -0,0 +1,26 @@ | |
+#define_import_path bevy_pbr::lighting_types | |
+ | |
+struct PointLight { | |
+ // NOTE: [2][2] [2][3] [3][2] [3][3] | |
+ projection_lr: vec4<f32>; | |
+ color_inverse_square_range: vec4<f32>; | |
+ position_radius: vec4<f32>; | |
+ // 'flags' is a bit field indicating various options. u32 is 32 bits so we have up to 32 options. | |
+ flags: u32; | |
+ shadow_depth_bias: f32; | |
+ shadow_normal_bias: f32; | |
+}; | |
+ | |
+let POINT_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u; | |
+ | |
+struct DirectionalLight { | |
+ view_projection: mat4x4<f32>; | |
+ color: vec4<f32>; | |
+ direction_to_light: vec3<f32>; | |
+ // 'flags' is a bit field indicating various options. u32 is 32 bits so we have up to 32 options. | |
+ flags: u32; | |
+ shadow_depth_bias: f32; | |
+ shadow_normal_bias: f32; | |
+}; | |
+ | |
+let DIRECTIONAL_LIGHT_FLAGS_SHADOWS_ENABLED_BIT: u32 = 1u; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment