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_reflect::TypeUuid;
use bevy_render::{ use bevy_render::{
camera::ExtractedCamera, camera::ExtractedCamera,
globals::{GlobalsBuffer, GlobalsUniform},
mesh::MeshVertexBufferLayout, mesh::MeshVertexBufferLayout,
prelude::{Camera, Mesh}, prelude::{Camera, Mesh},
render_asset::RenderAssets, render_asset::RenderAssets,
@ -167,7 +168,7 @@ impl<M: Material> FromWorld for PrepassPipeline<M> {
// View // View
BindGroupLayoutEntry { BindGroupLayoutEntry {
binding: 0, binding: 0,
visibility: ShaderStages::VERTEX | ShaderStages::FRAGMENT, visibility: ShaderStages::VERTEX_FRAGMENT,
ty: BindingType::Buffer { ty: BindingType::Buffer {
ty: BufferBindingType::Uniform, ty: BufferBindingType::Uniform,
has_dynamic_offset: true, has_dynamic_offset: true,
@ -175,6 +176,17 @@ impl<M: Material> FromWorld for PrepassPipeline<M> {
}, },
count: None, 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"), label: Some("prepass_view_layout"),
}); });
@ -573,19 +585,26 @@ pub fn queue_prepass_view_bind_group<M: Material>(
render_device: Res<RenderDevice>, render_device: Res<RenderDevice>,
prepass_pipeline: Res<PrepassPipeline<M>>, prepass_pipeline: Res<PrepassPipeline<M>>,
view_uniforms: Res<ViewUniforms>, view_uniforms: Res<ViewUniforms>,
globals_buffer: Res<GlobalsBuffer>,
mut prepass_view_bind_group: ResMut<PrepassViewBindGroup>, 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 };
prepass_view_bind_group.bind_group = let Some(globals_binding) = globals_buffer.buffer.binding() else { return };
Some(render_device.create_bind_group(&BindGroupDescriptor { prepass_view_bind_group.bind_group =
entries: &[BindGroupEntry { Some(render_device.create_bind_group(&BindGroupDescriptor {
entries: &[
BindGroupEntry {
binding: 0, binding: 0,
resource: view_binding, resource: view_binding,
}], },
label: Some("prepass_view_bind_group"), BindGroupEntry {
layout: &prepass_pipeline.view_layout, binding: 1,
})); resource: globals_binding,
} },
],
label: Some("prepass_view_bind_group"),
layout: &prepass_pipeline.view_layout,
}));
} }
#[allow(clippy::too_many_arguments)] #[allow(clippy::too_many_arguments)]

View file

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