From 5bb8b63bc6c4d8170a7aed59e8cfd862e453ecc9 Mon Sep 17 00:00:00 2001 From: James Gayfer <10660608+jgayfer@users.noreply.github.com> Date: Wed, 21 Aug 2024 21:14:24 -0700 Subject: [PATCH] Use empty buffer as stand in for empty array buffers 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). --- src/render/extract.rs | 15 --------------- src/render/light_map/node.rs | 4 +++- src/render/sdf/node.rs | 4 +++- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/src/render/extract.rs b/src/render/extract.rs index 72f7942..30deb74 100644 --- a/src/render/extract.rs +++ b/src/render/extract.rs @@ -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( @@ -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( diff --git a/src/render/light_map/node.rs b/src/render/light_map/node.rs index 931e527..8f58d12 100644 --- a/src/render/light_map/node.rs +++ b/src/render/light_map/node.rs @@ -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; @@ -58,7 +59,8 @@ impl ViewNode for LightMapNode { .binding(), world .resource::>() - .binding(), + .binding() + .or(world.resource::().binding()), world.resource::().buffer.binding(), ) else { diff --git a/src/render/sdf/node.rs b/src/render/sdf/node.rs index 8c79cdc..496b7b0 100644 --- a/src/render/sdf/node.rs +++ b/src/render/sdf/node.rs @@ -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; @@ -39,7 +40,8 @@ impl ViewNode for SdfNode { world.resource::().uniforms.binding(), world .resource::>() - .binding(), + .binding() + .or(world.resource::().binding()), ) else { return Ok(()); };