Skip to main content

cvkg_render_gpu/passes/
tonemap.rs

1use crate::kvasir::node::{ExecutionContext, KvasirNode};
2use crate::kvasir::nodes::{PassId, RES_SCENE};
3
4/// Tone mapping pass node.
5/// Converts HDR scene texture to LDR output using ACES filmic tone mapping.
6/// When HDR is disabled, this pass is a no-op (scene is already LDR).
7pub struct ToneMapNode {
8    pub inputs: Vec<crate::kvasir::resource::ResourceId>,
9    pub outputs: Vec<crate::kvasir::resource::ResourceId>,
10    pub target_view: Option<wgpu::TextureView>,
11}
12
13impl ToneMapNode {
14    pub fn new() -> Self {
15        Self {
16            inputs: vec![RES_SCENE],
17            outputs: vec![RES_SCENE],
18            target_view: None,
19        }
20    }
21}
22
23impl KvasirNode for ToneMapNode {
24    fn label(&self) -> &'static str {
25        "ToneMap"
26    }
27
28    fn inputs(&self) -> &[crate::kvasir::resource::ResourceId] {
29        &self.inputs
30    }
31
32    fn outputs(&self) -> &[crate::kvasir::resource::ResourceId] {
33        &self.outputs
34    }
35
36    fn pass_id(&self) -> PassId {
37        PassId::PostProcess {
38            pipeline_id: 0x544F4E45, // "TONE"
39        }
40    }
41
42    fn execute(&self, _ctx: &mut ExecutionContext) {
43        // Tone mapping is handled by the dedicated tonemap pipeline in end_frame.
44        // This node exists to reserve the PassId slot in the render graph.
45        log::trace!("[Kvasir] ToneMap: pass executed (pipeline in end_frame)");
46    }
47}