Added Globals struct to prepass shader (#8070)

This commit is contained in:
Anti-Alias 2023-03-13 14:55:47 -04:00 committed by GitHub
parent dcc0edf8a7
commit 884b9b62af
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View file

@ -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<M: Material> FromWorld for PrepassPipeline<M> {
// 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<M: Material> FromWorld for PrepassPipeline<M> {
},
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,20 +585,27 @@ pub fn queue_prepass_view_bind_group<M: Material>(
render_device: Res<RenderDevice>,
prepass_pipeline: Res<PrepassPipeline<M>>,
view_uniforms: Res<ViewUniforms>,
globals_buffer: Res<GlobalsBuffer>,
mut prepass_view_bind_group: ResMut<PrepassViewBindGroup>,
) {
if let Some(view_binding) = view_uniforms.uniforms.binding() {
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 {
entries: &[
BindGroupEntry {
binding: 0,
resource: view_binding,
}],
},
BindGroupEntry {
binding: 1,
resource: globals_binding,
},
],
label: Some("prepass_view_bind_group"),
layout: &prepass_pipeline.view_layout,
}));
}
}
#[allow(clippy::too_many_arguments)]
pub fn queue_prepass_material_meshes<M: Material>(

View file

@ -6,6 +6,9 @@
@group(0) @binding(0)
var<uniform> view: View;
@group(0) @binding(1)
var<uniform> globals: Globals;
// Material bindings will be in @group(1)
@group(2) @binding(0)
@ -16,3 +19,4 @@ var<uniform> mesh: Mesh;
var<uniform> joint_matrices: SkinnedMesh;
#import bevy_pbr::skinning
#endif