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 Default for ToneMapNode {
24    fn default() -> Self {
25        Self::new()
26    }
27}
28
29impl KvasirNode for ToneMapNode {
30    fn label(&self) -> &'static str {
31        "ToneMap"
32    }
33
34    fn inputs(&self) -> &[crate::kvasir::resource::ResourceId] {
35        &self.inputs
36    }
37
38    fn outputs(&self) -> &[crate::kvasir::resource::ResourceId] {
39        &self.outputs
40    }
41
42    fn pass_id(&self) -> PassId {
43        PassId::PostProcess {
44            pipeline_id: 0x544F4E45, // "TONE"
45        }
46    }
47
48    fn execute(&self, _ctx: &mut ExecutionContext) {
49        // Tone mapping is handled by the dedicated tonemap pipeline in end_frame.
50        // This node exists to reserve the PassId slot in the render graph.
51        tracing::trace!("[Kvasir] ToneMap: pass executed (pipeline in end_frame)");
52    }
53}