Skip to main content

cvkg_render_gpu/passes/
deferred_lighting.rs

1//! Deferred lighting resolve pass.
2//! Reconstructs lighting by combining G-buffer values, SSAO, and shadow atlas.
3
4use crate::kvasir::nodes::PassId;
5use crate::kvasir::{ExecutionContext, KvasirNode, ResourceId};
6
7/// Deferred Lighting Pass Node.
8pub struct DeferredLightingNode {
9    /// SSAO occlusion input texture.
10    pub ssao_occlusion: ResourceId,
11    /// Shadow map / atlas resource.
12    pub shadow_atlas: ResourceId,
13    /// Output scene target to resolve into.
14    pub scene_output: ResourceId,
15    /// Cached inputs slice container.
16    pub inputs: [ResourceId; 2],
17}
18
19impl KvasirNode for DeferredLightingNode {
20    fn label(&self) -> &'static str {
21        "DeferredLightingPass"
22    }
23
24    fn inputs(&self) -> &[ResourceId] {
25        &self.inputs
26    }
27
28    fn outputs(&self) -> &[ResourceId] {
29        std::slice::from_ref(&self.scene_output)
30    }
31
32    fn pass_id(&self) -> PassId {
33        PassId::Opaque3d
34    }
35
36    fn execute(&self, ctx: &mut ExecutionContext) {
37        tracing::debug!("DeferredLightingNode::execute - Resolving deferred PBR shading equations");
38
39        let dest_view = match ctx.registry.get_texture_view(self.scene_output) {
40            Some(v) => v,
41            None => return,
42        };
43
44        // Render pass to draw full-screen quad evaluating PBR lighting
45        let mut _pass = ctx.encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
46            label: Some("Deferred Lighting Resolve Pass"),
47            color_attachments: &[Some(wgpu::RenderPassColorAttachment {
48                view: &dest_view,
49                resolve_target: None,
50                ops: wgpu::Operations {
51                    load: wgpu::LoadOp::Load,
52                    store: wgpu::StoreOp::Store,
53                },
54                depth_slice: None,
55            })],
56            depth_stencil_attachment: None,
57            timestamp_writes: None,
58            occlusion_query_set: None,
59            multiview_mask: None,
60        });
61
62        // Bind G-buffer textures (Albedo, Normals, Depth), SSAO, and Shadow Atlas.
63        // Draw screen quad evaluating BRDF + shadowing + ambient terms.
64    }
65}