Skip to content

Commit bacf0da

Browse files
committed
Insert DummyImage resource
1 parent 77ce055 commit bacf0da

File tree

3 files changed

+17
-9
lines changed

3 files changed

+17
-9
lines changed

crates/bevy_material/src/render/mesh.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ use static_assertions::const_assert_eq;
2323
#[cfg(debug_assertions)]
2424
pub const MESH_PIPELINE_VIEW_LAYOUT_SAFE_MAX_TEXTURES: usize = 10;
2525

26+
// A 1x1x1 'all 1.0' texture to use as a dummy texture to use in place of optional StandardMaterial textures
27+
#[derive(Resource, Clone)]
28+
pub struct DummyImage {
29+
// This dummy white texture is to be used in place of optional StandardMaterial textures
30+
pub dummy_white_image: Handle<Image>,
31+
}
32+
2633
/// All data needed to construct a pipeline for rendering 3D meshes.
2734
#[derive(Resource, Clone)]
2835
pub struct MeshPipeline {
2936
/// A reference to all the mesh pipeline view layouts.
3037
pub view_layouts: MeshPipelineViewLayouts,
31-
// This dummy white texture is to be used in place of optional StandardMaterial textures
32-
pub dummy_white_image: Handle<Image>,
3338
pub clustered_forward_buffer_binding_type: BufferBindingType,
3439
pub mesh_layouts: MeshLayouts,
3540
/// The shader asset handle.

crates/bevy_pbr/src/material.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,14 @@ pub struct MaterialsPlugin {
280280

281281
impl Plugin for MaterialsPlugin {
282282
fn build(&self, app: &mut App) {
283+
let mut images = app.world_mut().resource_mut::<Assets<Image>>();
284+
285+
// A 1x1x1 'all 1.0' texture to use as a dummy texture to use in place of optional StandardMaterial textures
286+
let image = Image::default();
287+
let dummy_white_image = images.add(image);
288+
289+
let dummy_image = DummyImage { dummy_white_image };
290+
283291
app.add_plugins((PrepassPipelinePlugin, PrepassPlugin::new(self.debug_flags)));
284292
if let Some(render_app) = app.get_sub_app_mut(RenderApp) {
285293
render_app
@@ -292,6 +300,7 @@ impl Plugin for MaterialsPlugin {
292300
.init_resource::<DrawFunctions<Shadow>>()
293301
.init_resource::<RenderMaterialInstances>()
294302
.init_resource::<MaterialBindGroupAllocators>()
303+
.insert_resource(dummy_image)
295304
.add_render_command::<Shadow, DrawPrepass>()
296305
.add_render_command::<Transmissive3d, DrawMaterial>()
297306
.add_render_command::<Transparent3d, DrawMaterial>()

crates/bevy_pbr/src/render/mesh.rs

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1261,21 +1261,15 @@ pub fn init_mesh_pipeline(world: &mut World) {
12611261
Res<RenderDevice>,
12621262
Res<RenderAdapter>,
12631263
Res<MeshPipelineViewLayouts>,
1264-
ResMut<Assets<Image>>,
12651264
)> = SystemState::new(world);
1266-
let (render_device, render_adapter, view_layouts, mut images) = system_state.get_mut(world);
1265+
let (render_device, render_adapter, view_layouts) = system_state.get_mut(world);
12671266

12681267
let clustered_forward_buffer_binding_type =
12691268
render_device.get_supported_read_only_binding_type(CLUSTERED_FORWARD_STORAGE_BUFFER_COUNT);
12701269

1271-
// A 1x1x1 'all 1.0' texture to use as a dummy texture to use in place of optional StandardMaterial textures
1272-
let image = Image::default();
1273-
let dummy_white_image = images.add(image);
1274-
12751270
let res = MeshPipeline {
12761271
view_layouts: view_layouts.clone(),
12771272
clustered_forward_buffer_binding_type,
1278-
dummy_white_image,
12791273
mesh_layouts: MeshLayouts::new(&render_device, &render_adapter),
12801274
shader,
12811275
per_object_buffer_batch_size: GpuArrayBuffer::<MeshUniform>::batch_size(

0 commit comments

Comments
 (0)