Skip to content

Commit

Permalink
Use empty buffer as stand in for empty array buffers
Browse files Browse the repository at this point in the history
With a fallback "empty" binding, we no longer have to send junk point
light and occluder data to the GPU (which I believe has been causing
some issues).
  • Loading branch information
jgayfer committed Aug 22, 2024
1 parent 9ac762e commit 5bb8b63
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 17 deletions.
15 changes: 0 additions & 15 deletions src/render/extract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,6 @@ pub fn extract_point_lights(
cast_shadows: if point_light.cast_shadows { 1 } else { 0 },
});
}

// BufferVec won't write to the GPU if there aren't any point lights.
// For now we can spawn an empty point light to get around this.
commands.spawn(ExtractedPointLight2d {
transform: Vec2::ZERO,
intensity: 0.0,
radius: 0.0,
falloff: 0.0,
color: LinearRgba::BLACK,
cast_shadows: 0,
});
}

pub fn extract_light_occluders(
Expand All @@ -79,10 +68,6 @@ pub fn extract_light_occluders(

commands.get_or_spawn(entity).insert(extracted_occluder);
}

// BufferVec won't write to the GPU if there aren't any point lights.
// For now we can spawn an empty occluder to get around this.
commands.spawn(ExtractedLightOccluder2d::default());
}

pub fn extract_ambient_lights(
Expand Down
4 changes: 3 additions & 1 deletion src/render/light_map/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use bevy::render::renderer::RenderDevice;
use bevy::render::view::{ViewUniformOffset, ViewUniforms};
use smallvec::{smallvec, SmallVec};

use crate::render::empty_buffer::EmptyBuffer;
use crate::render::extract::{ExtractedAmbientLight2d, ExtractedPointLight2d};
use crate::render::sdf::SdfTexture;

Expand Down Expand Up @@ -58,7 +59,8 @@ impl ViewNode for LightMapNode {
.binding(),
world
.resource::<GpuArrayBuffer<ExtractedPointLight2d>>()
.binding(),
.binding()
.or(world.resource::<EmptyBuffer>().binding()),
world.resource::<PointLightMetaBuffer>().buffer.binding(),
)
else {
Expand Down
4 changes: 3 additions & 1 deletion src/render/sdf/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ use bevy::render::renderer::RenderDevice;
use bevy::render::view::{ViewUniformOffset, ViewUniforms};
use smallvec::{smallvec, SmallVec};

use crate::render::empty_buffer::EmptyBuffer;
use crate::render::extract::ExtractedLightOccluder2d;

use super::pipeline::SdfPipeline;
Expand Down Expand Up @@ -39,7 +40,8 @@ impl ViewNode for SdfNode {
world.resource::<ViewUniforms>().uniforms.binding(),
world
.resource::<GpuArrayBuffer<ExtractedLightOccluder2d>>()
.binding(),
.binding()
.or(world.resource::<EmptyBuffer>().binding()),
) else {
return Ok(());
};
Expand Down

0 comments on commit 5bb8b63

Please sign in to comment.