VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
renderPassPostprocessing.cpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4// Created by Arnis Lektauers on 11.12.2025.
5//
7
12
13namespace visutwin::canvas
14{
15 RenderPassPostprocessing::RenderPassPostprocessing(const std::shared_ptr<GraphicsDevice>& device, Renderer* renderer,
16 RenderAction* renderAction): RenderPass(device), _renderer(renderer), _renderAction(renderAction)
17 {
18 init(nullptr);
19
20 if (!_renderAction || !_renderAction->camera) {
21 return;
22 }
23
24 const auto& dof = _renderAction->camera->dof();
25 const auto& taa = _renderAction->camera->taa();
26 _composePass = std::make_shared<RenderPassCompose>(device);
27
28 auto* camera = _renderAction->camera->camera();
29 Texture* sceneTexture = camera && camera->renderTarget()
30 ? camera->renderTarget()->colorBuffer()
31 : nullptr;
32 if (!sceneTexture) {
33 const auto dofRt = _renderAction->camera->dofSceneRenderTarget();
34 sceneTexture = dofRt ? dofRt->colorBuffer() : nullptr;
35 }
36
37 if (taa.enabled && sceneTexture) {
38 _taaPass = _renderAction->camera->ensureTaaPass(device, sceneTexture);
39 if (_taaPass) {
40 _taaPass->setSourceTexture(sceneTexture);
41 sceneTexture = _taaPass->update().get();
42 addBeforePass(_taaPass);
43 }
44 }
45
46 // SSAO pass (runs before compose, reads depth buffer)
47 const auto& ssao = _renderAction->camera->ssao();
48 if (ssao.enabled && sceneTexture) {
49 _ssaoPass = std::make_shared<RenderPassSsao>(
50 device, sceneTexture, _renderAction->camera, ssao.blurEnabled);
51 _ssaoPass->radius = ssao.radius;
52 _ssaoPass->intensity = ssao.intensity;
53 _ssaoPass->power = ssao.power;
54 _ssaoPass->sampleCount = ssao.samples;
55 _ssaoPass->minAngle = ssao.minAngle;
56 _ssaoPass->randomize = ssao.randomize;
57 if (ssao.scale != 1.0f) {
58 _ssaoPass->setScale(ssao.scale);
59 }
60 addBeforePass(_ssaoPass);
61 }
62
63 _composePass->sceneTexture = sceneTexture;
64 _composePass->ssaoTexture = _ssaoPass ? _ssaoPass->ssaoTexture() : nullptr;
65 _composePass->dofEnabled = dof.enabled;
66
67 if (dof.enabled && sceneTexture) {
68 _dofPass = std::make_shared<RenderPassDof>(device, _renderAction->camera, sceneTexture, sceneTexture,
69 dof.highQuality, dof.nearBlur);
70 _dofPass->focusDistance = dof.focusDistance;
71 _dofPass->focusRange = dof.focusRange;
72 _dofPass->blurRadius = dof.blurRadius;
73 _dofPass->blurRings = dof.blurRings;
74 _dofPass->blurRingPoints = dof.blurRingPoints;
75 _dofPass->highQuality = dof.highQuality;
76 _dofPass->nearBlur = dof.nearBlur;
77 _composePass->cocTexture = _dofPass->cocTexture();
78 _composePass->blurTexture = _dofPass->blurTexture();
79 _composePass->dofEnabled = true;
80 addBeforePass(_dofPass);
81 _passesBuilt = true;
82 }
83
84 if (_composePass) {
85 _composePass->dofIntensity = 1.0f;
86 }
87 }
88
90 {
91 if (!_composePass) {
92 return;
93 }
94
95 _composePass->execute();
96 }
97}
virtual void init(const std::shared_ptr< RenderTarget > &renderTarget=nullptr, const std::shared_ptr< RenderPassOptions > &options=nullptr)
std::shared_ptr< GraphicsDevice > device() const
Definition renderPass.h:124
RenderPass(const std::shared_ptr< GraphicsDevice > &device)
Definition renderPass.h:66
void addBeforePass(const std::shared_ptr< RenderPass > &renderPass)
RenderPassPostprocessing(const std::shared_ptr< GraphicsDevice > &device, Renderer *renderer, RenderAction *renderAction)
GPU texture resource supporting 2D, cubemap, volume, and array formats with mipmap management.
Definition texture.h:57