VisuTwin Canvas
C++ 3D Engine — Metal Backend
Loading...
Searching...
No Matches
renderPassCameraFrame.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2025-2026 Arnis Lektauers
3//
4//
5#pragma once
6
7#include <memory>
8#include <string>
9#include <string_view>
10#include <vector>
11
15#include "scene/constants.h"
16#include "renderPassConstants.h"
17
18namespace visutwin::canvas
19{
20 class LayerComposition;
21 class Renderer;
22 class Scene;
26 class RenderPassSsao;
27 class RenderPassTAA;
29 class RenderPassBloom;
30 class RenderPassDof;
32
34 {
35 std::vector<PixelFormat> formats;
36 bool stencil = false;
37 int samples = 1;
38 bool sceneColorMap = false;
43 bool taaEnabled = false;
44 bool bloomEnabled = false;
45 float bloomIntensity = 0.01f;
46 float sharpness = 0.0f;
47 std::string_view ssaoType = SSAOTYPE_NONE;
48 bool ssaoBlurEnabled = true;
49 bool prepassEnabled = false;
50 bool dofEnabled = false;
51 bool dofNearBlur = false;
52 bool dofHighQuality = true;
53
54 // Vignette
55 bool vignetteEnabled = false;
56 float vignetteInner = 0.5f;
57 float vignetteOuter = 1.0f;
58 float vignetteCurvature = 0.5f;
59 float vignetteIntensity = 0.3f;
60 };
61
63 {
64 public:
65 RenderPassCameraFrame(const std::shared_ptr<GraphicsDevice>& device, LayerComposition* layerComposition, Scene* scene,
66 Renderer* renderer, const std::vector<RenderAction*>& sourceActions, CameraComponent* cameraComponent,
67 const std::shared_ptr<RenderTarget>& targetRenderTarget);
68
69 void destroy();
70 void reset();
71 void update(const CameraFrameOptions& options);
72 bool needsReset(const CameraFrameOptions& options) const;
74
75 // DEVIATION: upstream RenderPassCameraFrame uses addLayers() to self-build
76 // render actions from the LayerComposition. This version receives sourceActions
77 // from ForwardRenderer. updateSourceActions() refreshes per-frame data (source
78 // actions, composition, scene, renderer) without recreating GPU textures.
79 void updateSourceActions(const std::vector<RenderAction*>& sourceActions,
80 LayerComposition* layerComposition, Scene* scene, Renderer* renderer,
81 const std::shared_ptr<RenderTarget>& targetRenderTarget);
82
83 void setRenderTargetScale(float value);
84 float renderTargetScale() const { return _renderTargetScale; }
85
86 void frameUpdate() const override;
87
88 private:
89 std::shared_ptr<RenderTarget> createRenderTarget(const std::string& name, bool depth, bool stencil, int samples) const;
90 void setupRenderPasses(const CameraFrameOptions& options);
91 void createPasses(const CameraFrameOptions& options);
92 void setupScenePrepass(const CameraFrameOptions& options);
93 struct ScenePassesInfo
94 {
95 int lastAddedIndex = -1;
96 bool clearRenderTarget = true;
97 };
98 ScenePassesInfo setupScenePass(const CameraFrameOptions& options);
99 void setupSsaoPass(const CameraFrameOptions& options);
100 Texture* setupTaaPass(const CameraFrameOptions& options);
101 void setupSceneHalfPass(const CameraFrameOptions& options, Texture* sourceTexture);
102 void setupBloomPass(const CameraFrameOptions& options, Texture* inputTexture);
103 void setupDofPass(const CameraFrameOptions& options, Texture* inputTexture, Texture* inputTextureHalf);
104 void setupComposePass(const CameraFrameOptions& options);
105 void setupAfterPass(const CameraFrameOptions& options, const ScenePassesInfo& scenePassesInfo);
106
107 std::vector<std::shared_ptr<RenderPass>> collectPasses() const;
108 int appendActionsToPass(const std::shared_ptr<RenderPassForward>& pass, int fromIndex, int toIndex,
109 const std::shared_ptr<RenderTarget>& target, bool firstLayerClears = true);
110 int findActionIndex(int targetLayerId, bool targetTransparent, int fromIndex) const;
111 static std::shared_ptr<RenderAction> cloneActionWithTarget(const RenderAction* source,
112 const std::shared_ptr<RenderTarget>& renderTarget);
113
114 CameraFrameOptions _options;
115 LayerComposition* _layerComposition = nullptr;
116 Scene* _scene = nullptr;
117 Renderer* _renderer = nullptr;
118 CameraComponent* _cameraComponent = nullptr;
119 std::shared_ptr<RenderTarget> _targetRenderTarget;
120 std::vector<RenderAction*> _sourceActions;
121
123 bool _bloomEnabled = false;
124 bool _sceneHalfEnabled = false;
125 float _renderTargetScale = 1.0f;
126 std::shared_ptr<RenderPassOptions> _sceneOptions;
127 bool _needsReset = false;
128
129 std::shared_ptr<RenderTarget> _sceneRenderTarget;
130 std::shared_ptr<Texture> _sceneTexture;
131 std::shared_ptr<Texture> _sceneDepthTexture;
132 std::shared_ptr<RenderTarget> _sceneHalfRenderTarget;
133 std::shared_ptr<Texture> _sceneTextureHalf;
134
135 std::shared_ptr<RenderPassPrepass> _prePass;
136 std::shared_ptr<RenderPassForward> _scenePass;
137 std::shared_ptr<RenderPassColorGrab> _colorGrabPass;
138 std::shared_ptr<RenderPassForward> _scenePassTransparent;
139 std::shared_ptr<RenderPassSsao> _ssaoPass;
140 std::shared_ptr<RenderPassTAA> _taaPass;
141 std::shared_ptr<RenderPassDownsample> _scenePassHalf;
142 std::shared_ptr<RenderPassBloom> _bloomPass;
143 std::shared_ptr<RenderPassDof> _dofPass;
144 std::shared_ptr<RenderPassCompose> _composePass;
145 std::shared_ptr<RenderPassForward> _afterPass;
146
147 mutable Texture* _sceneTextureResolved = nullptr;
148 std::vector<std::shared_ptr<RenderAction>> _ownedActions;
149 };
150}
CameraFrameOptions sanitizeOptions(const CameraFrameOptions &options) const
void updateSourceActions(const std::vector< RenderAction * > &sourceActions, LayerComposition *layerComposition, Scene *scene, Renderer *renderer, const std::shared_ptr< RenderTarget > &targetRenderTarget)
bool needsReset(const CameraFrameOptions &options) const
RenderPassCameraFrame(const std::shared_ptr< GraphicsDevice > &device, LayerComposition *layerComposition, Scene *scene, Renderer *renderer, const std::vector< RenderAction * > &sourceActions, CameraComponent *cameraComponent, const std::shared_ptr< RenderTarget > &targetRenderTarget)
void update(const CameraFrameOptions &options)
std::shared_ptr< RenderTarget > renderTarget() const
Definition renderPass.h:98
std::shared_ptr< GraphicsDevice > device() const
Definition renderPass.h:124
RenderPass(const std::shared_ptr< GraphicsDevice > &device)
Definition renderPass.h:66
Container for the scene graph, lighting environment, fog, skybox, and layer composition.
Definition scene.h:29
constexpr std::string_view SSAOTYPE_NONE
constexpr int LAYERID_IMMEDIATE
Definition constants.h:27
constexpr int LAYERID_SKYBOX
Definition constants.h:21