diff --git a/crates/bevy_pbr/src/prepass/mod.rs b/crates/bevy_pbr/src/prepass/mod.rs index b890de737d..2766f985d8 100644 --- a/crates/bevy_pbr/src/prepass/mod.rs +++ b/crates/bevy_pbr/src/prepass/mod.rs @@ -17,6 +17,7 @@ use bevy_ecs::{ use bevy_reflect::TypeUuid; use bevy_render::{ camera::ExtractedCamera, + globals::{GlobalsBuffer, GlobalsUniform}, mesh::MeshVertexBufferLayout, prelude::{Camera, Mesh}, render_asset::RenderAssets, @@ -167,7 +168,7 @@ impl FromWorld for PrepassPipeline { // View BindGroupLayoutEntry { binding: 0, - visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, + visibility: ShaderStages::VERTEX_FRAGMENT, ty: BindingType::Buffer { ty: BufferBindingType::Uniform, has_dynamic_offset: true, @@ -175,6 +176,17 @@ impl FromWorld for PrepassPipeline { }, count: None, }, + // Globals + BindGroupLayoutEntry { + binding: 1, + visibility: ShaderStages::VERTEX_FRAGMENT, + ty: BindingType::Buffer { + ty: BufferBindingType::Uniform, + has_dynamic_offset: false, + min_binding_size: Some(GlobalsUniform::min_size()), + }, + count: None, + }, ], label: Some("prepass_view_layout"), }); @@ -573,19 +585,26 @@ pub fn queue_prepass_view_bind_group( render_device: Res, prepass_pipeline: Res>, view_uniforms: Res, + globals_buffer: Res, mut prepass_view_bind_group: ResMut, ) { - if let Some(view_binding) = view_uniforms.uniforms.binding() { - prepass_view_bind_group.bind_group = - Some(render_device.create_bind_group(&BindGroupDescriptor { - entries: &[BindGroupEntry { + let Some(view_binding) = view_uniforms.uniforms.binding() else { return }; + let Some(globals_binding) = globals_buffer.buffer.binding() else { return }; + prepass_view_bind_group.bind_group = + Some(render_device.create_bind_group(&BindGroupDescriptor { + entries: &[ + BindGroupEntry { binding: 0, resource: view_binding, - }], - label: Some("prepass_view_bind_group"), - layout: &prepass_pipeline.view_layout, - })); - } + }, + BindGroupEntry { + binding: 1, + resource: globals_binding, + }, + ], + label: Some("prepass_view_bind_group"), + layout: &prepass_pipeline.view_layout, + })); } #[allow(clippy::too_many_arguments)] diff --git a/crates/bevy_pbr/src/prepass/prepass_bindings.wgsl b/crates/bevy_pbr/src/prepass/prepass_bindings.wgsl index cd338af0ed..528f2e596d 100644 --- a/crates/bevy_pbr/src/prepass/prepass_bindings.wgsl +++ b/crates/bevy_pbr/src/prepass/prepass_bindings.wgsl @@ -6,6 +6,9 @@ @group(0) @binding(0) var view: View; +@group(0) @binding(1) +var globals: Globals; + // Material bindings will be in @group(1) @group(2) @binding(0) @@ -16,3 +19,4 @@ var mesh: Mesh; var joint_matrices: SkinnedMesh; #import bevy_pbr::skinning #endif +