use crate::gpu::GpuContext;
use crate::hot_shader::{HotPostProcessPass, HotWorldPostProcessPass};
use crate::post_process::{PostProcessPass, WorldPostProcessPass};
use crate::render_graph::{RenderContext, RenderNode};
pub struct PostProcessNode {
pub pass: PostProcessPass,
}
impl PostProcessNode {
pub fn new(pass: PostProcessPass) -> Self {
Self { pass }
}
}
impl RenderNode for PostProcessNode {
fn execute(
&self,
ctx: &mut RenderContext,
target: &wgpu::TextureView,
input: Option<&wgpu::TextureView>,
) {
let input_view = input.expect("PostProcessNode requires an input from a previous pass");
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
self.pass
.render(ctx.gpu, &mut render_pass, ctx.time, input_view);
}
}
pub struct WorldPostProcessNode {
pub pass: WorldPostProcessPass,
}
impl WorldPostProcessNode {
pub fn new(pass: WorldPostProcessPass) -> Self {
Self { pass }
}
}
impl RenderNode for WorldPostProcessNode {
fn execute(
&self,
ctx: &mut RenderContext,
target: &wgpu::TextureView,
input: Option<&wgpu::TextureView>,
) {
let input_view =
input.expect("WorldPostProcessNode requires an input from a previous pass");
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
self.pass
.render(ctx.gpu, &mut render_pass, ctx.time, ctx.camera, input_view);
}
}
pub struct HotPostProcessNode {
pub pass: HotPostProcessPass,
}
impl HotPostProcessNode {
pub fn new(pass: HotPostProcessPass) -> Self {
Self { pass }
}
pub fn check_reload(&mut self, gpu: &GpuContext) {
self.pass.check_reload(gpu);
}
}
impl RenderNode for HotPostProcessNode {
fn execute(
&self,
ctx: &mut RenderContext,
target: &wgpu::TextureView,
input: Option<&wgpu::TextureView>,
) {
let input_view = input.expect("HotPostProcessNode requires an input from a previous pass");
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
self.pass
.render(ctx.gpu, &mut render_pass, ctx.time, input_view);
}
fn check_hot_reload(&mut self, gpu: &GpuContext) {
self.pass.check_reload(gpu);
}
}
pub struct HotWorldPostProcessNode {
pub pass: HotWorldPostProcessPass,
}
impl HotWorldPostProcessNode {
pub fn new(pass: HotWorldPostProcessPass) -> Self {
Self { pass }
}
pub fn check_reload(&mut self, gpu: &GpuContext) {
self.pass.check_reload(gpu);
}
}
impl RenderNode for HotWorldPostProcessNode {
fn execute(
&self,
ctx: &mut RenderContext,
target: &wgpu::TextureView,
input: Option<&wgpu::TextureView>,
) {
let input_view =
input.expect("HotWorldPostProcessNode requires an input from a previous pass");
let mut render_pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
label: None,
color_attachments: &[Some(wgpu::RenderPassColorAttachment {
view: target,
resolve_target: None,
ops: wgpu::Operations {
load: wgpu::LoadOp::Clear(wgpu::Color::BLACK),
store: wgpu::StoreOp::Store,
},
depth_slice: None,
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
});
self.pass
.render(ctx.gpu, &mut render_pass, ctx.time, ctx.camera, input_view);
}
fn check_hot_reload(&mut self, gpu: &GpuContext) {
self.pass.check_reload(gpu);
}
}