From 630fbcd2e02d6c6bb16e5aa143e4e078ba09a059 Mon Sep 17 00:00:00 2001 From: Charlotte McElwain Date: Sun, 7 Jul 2024 17:00:27 -0700 Subject: [PATCH] Isf. --- bevy_nannou_isf/src/render.rs | 46 +++++++------------ .../isf/Test-TempBufferDifferingSizes.fs | 2 + examples/isf/simple.rs | 2 +- 3 files changed, 19 insertions(+), 31 deletions(-) diff --git a/bevy_nannou_isf/src/render.rs b/bevy_nannou_isf/src/render.rs index ef635fbfe..f766ca1d9 100644 --- a/bevy_nannou_isf/src/render.rs +++ b/bevy_nannou_isf/src/render.rs @@ -78,8 +78,6 @@ pub struct IsfRenderTargets(Vec>); pub struct IsfPass { size: UVec2, target: Handle, - resolve: Handle, - dummy: Handle, format: TextureFormat, clear: bool, } @@ -90,7 +88,6 @@ fn update_render_targets( mut render_targets: ResMut, mut images: ResMut>, isfs: Res>, - msaa: Res, ) { let Ok((camera, isf)) = cameras_q.get_single() else { return; @@ -121,7 +118,7 @@ fn update_render_targets( render_targets.resize(isf.isf.passes.len(), None); for (pass_idx, pass) in isf.isf.passes.iter().enumerate() { if let None = pass.target { - render_targets.insert(pass_idx, None); + render_targets[pass_idx] = None; continue; } @@ -153,19 +150,18 @@ fn update_render_targets( if let Some(Some(IsfPass { size, .. })) = render_targets.get(pass_idx) { if size.x == width && size.y == height { - info!("Skipping resize of render target"); continue; } } - let mut resolve = Image::default(); + let mut target = Image::default(); let format = if pass.float { TextureFormat::Rgba32Float } else { TextureFormat::Rgba8UnormSrgb }; - resolve.texture_descriptor.format = format; - resolve.texture_descriptor.usage = TextureUsages::RENDER_ATTACHMENT + target.texture_descriptor.format = format; + target.texture_descriptor.usage = TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING | TextureUsages::COPY_DST; let size = Extent3d { @@ -173,27 +169,17 @@ fn update_render_targets( height, ..default() }; - resolve.resize(size); - let mut target = resolve.clone(); - // target.texture_descriptor.sample_count = msaa.samples(); - target.texture_descriptor.usage = - TextureUsages::RENDER_ATTACHMENT | TextureUsages::COPY_DST; + target.resize(size); let target = images.add(target); - let dummy = images.add(resolve.clone()); - let resolve = images.add(resolve); - - render_targets.insert( - pass_idx, - Some(IsfPass { - size: UVec2::new(width, height), - target, - resolve, - dummy, - format, - clear: !pass.persistent, - }), - ); + + render_targets[pass_idx] = Some(IsfPass { + size: UVec2::new(width, height), + target, + format, + clear: !pass.persistent, + }); } + if render_targets.is_empty() { render_targets.push(None); } @@ -372,6 +358,7 @@ fn prepare_isf_bind_groups( let num_images = gpu_isf.isf.num_images(); let mut textures_bind_groups = vec![]; + let dummy_image = gpu_images.get(&Handle::::default()).unwrap(); // Passes for pass in isf_render_targets.iter() { let mut pass_bindings = bindings.clone(); @@ -384,10 +371,9 @@ fn prepare_isf_bind_groups( textures_bind_groups.push(textures_bind_group); continue; }; - let Some(gpu_image) = gpu_images.get(&pass.resolve) else { + let Some(gpu_image) = gpu_images.get(&pass.target) else { return; }; - let dummy_image = gpu_images.get(&pass.dummy).unwrap(); pass_bindings.push(BindGroupEntry { binding, resource: dummy_image.texture_view.into_binding(), @@ -479,7 +465,7 @@ impl ViewNode for IsfNode { resolve_target: None, ops: if pass.clear { Operations { - load: LoadOp::Clear(Color::srgb(0.1, 0.1, 1.0).to_linear().into()), + load: LoadOp::Load, store: StoreOp::Store, } } else { diff --git a/examples/assets/isf/Test-TempBufferDifferingSizes.fs b/examples/assets/isf/Test-TempBufferDifferingSizes.fs index 4967abc58..aeb1ce9aa 100644 --- a/examples/assets/isf/Test-TempBufferDifferingSizes.fs +++ b/examples/assets/isf/Test-TempBufferDifferingSizes.fs @@ -33,5 +33,7 @@ void main() // second pass: read from "bufferVariableNameA". output looks chunky and low-res. else if (PASSINDEX == 1) { gl_FragColor = IMG_THIS_NORM_PIXEL(bufferVariableNameA); + } else { + gl_FragColor = vec4(0.5); } } diff --git a/examples/isf/simple.rs b/examples/isf/simple.rs index 21f74a597..f732a169a 100644 --- a/examples/isf/simple.rs +++ b/examples/isf/simple.rs @@ -1,7 +1,7 @@ use nannou::prelude::*; fn main() { - nannou::app(model).model_ui().update(update).run(); + nannou::app(model).update(update).run(); } #[derive(Reflect)]