Overte C++ Documentation
RenderDeferredTask.h
1 //
2 // RenderDeferredTask.h
3 // render-utils/src/
4 //
5 // Created by Sam Gateau on 5/29/15.
6 // Copyright 2016 High Fidelity, Inc.
7 // Copyright 2024 Overte e.V.
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 //
12 
13 #ifndef hifi_RenderDeferredTask_h
14 #define hifi_RenderDeferredTask_h
15 
16 #include <gpu/Pipeline.h>
17 #include <render/RenderFetchCullSortTask.h>
18 #include "AssembleLightingStageTask.h"
19 #include "LightingModel.h"
20 #include "LightClusters.h"
21 #include "RenderShadowTask.h"
22 
23 class RenderTransparentDeferredConfig : public render::Job::Config {
24  Q_OBJECT
25  Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY newStats)
26  Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
27 
28 public:
29  int getNumDrawn() { return _numDrawn; }
30  void setNumDrawn(int numDrawn) {
31  _numDrawn = numDrawn;
32  emit newStats();
33  }
34 
35  int maxDrawn{ -1 };
36 
37 signals:
38  void newStats();
39  void dirty();
40 
41 protected:
42  int _numDrawn{ 0 };
43 };
44 
45 class RenderTransparentDeferred {
46 public:
47  using Inputs = render::VaryingSet8<render::ItemBounds, HazeStage::FramePointer, LightStage::FramePointer, LightingModelPointer, LightClustersPointer, LightStage::ShadowFramePointer, DeferredFrameTransformPointer, DeferredFramebufferPointer>;
48  using Config = RenderTransparentDeferredConfig;
49  using JobModel = render::Job::ModelI<RenderTransparentDeferred, Inputs, Config>;
50 
51  RenderTransparentDeferred(render::ShapePlumberPointer shapePlumber, uint transformSlot)
52  : _shapePlumber(shapePlumber), _transformSlot(transformSlot) {}
53 
54  void configure(const Config& config) { _maxDrawn = config.maxDrawn; }
55  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
56 
57 protected:
58  render::ShapePlumberPointer _shapePlumber;
59  uint _transformSlot;
60  int _maxDrawn; // initialized by Config
61 };
62 
63 class DrawStateSortConfig : public render::Job::Config {
64  Q_OBJECT
65  Q_PROPERTY(int numDrawn READ getNumDrawn NOTIFY numDrawnChanged)
66  Q_PROPERTY(int maxDrawn MEMBER maxDrawn NOTIFY dirty)
67  Q_PROPERTY(bool stateSort MEMBER stateSort NOTIFY dirty)
68 public:
69  int getNumDrawn() { return numDrawn; }
70  void setNumDrawn(int num) {
71  numDrawn = num;
72  emit numDrawnChanged();
73  }
74 
75  int maxDrawn{ -1 };
76  bool stateSort{ true };
77 
78 signals:
79  void numDrawnChanged();
80  void dirty();
81 
82 protected:
83  int numDrawn{ 0 };
84 };
85 
86 class DrawStateSortDeferred {
87 public:
88  using Inputs = render::VaryingSet3<render::ItemBounds, LightingModelPointer, DeferredFrameTransformPointer>;
89 
90  using Config = DrawStateSortConfig;
91  using JobModel = render::Job::ModelI<DrawStateSortDeferred, Inputs, Config>;
92 
93  DrawStateSortDeferred(render::ShapePlumberPointer shapePlumber, uint transformSlot)
94  : _shapePlumber(shapePlumber), _transformSlot(transformSlot) {
95  }
96 
97  void configure(const Config& config) {
98  _maxDrawn = config.maxDrawn;
99  _stateSort = config.stateSort;
100  }
101  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
102 
103 protected:
104  render::ShapePlumberPointer _shapePlumber;
105  uint _transformSlot;
106  int _maxDrawn; // initialized by Config
107  bool _stateSort;
108 };
109 
110 class SetSeparateDeferredDepthBuffer {
111 public:
112  using Inputs = DeferredFramebufferPointer;
113  using JobModel = render::Job::ModelI<SetSeparateDeferredDepthBuffer, Inputs>;
114 
115  SetSeparateDeferredDepthBuffer() = default;
116 
117  void run(const render::RenderContextPointer& renderContext, const Inputs& inputs);
118 
119 protected:
120  gpu::FramebufferPointer _framebuffer;
121 };
122 
123 class RenderDeferredTaskConfig : public render::Task::Config {
124  Q_OBJECT
125  Q_PROPERTY(float fadeScale MEMBER fadeScale NOTIFY dirty)
126  Q_PROPERTY(float fadeDuration MEMBER fadeDuration NOTIFY dirty)
127  Q_PROPERTY(float resolutionScale MEMBER resolutionScale NOTIFY dirty)
128  Q_PROPERTY(bool debugFade MEMBER debugFade NOTIFY dirty)
129  Q_PROPERTY(float debugFadePercent MEMBER debugFadePercent NOTIFY dirty)
130 public:
131  float fadeScale{ 0.5f };
132  float fadeDuration{ 3.0f };
133  float resolutionScale{ 1.f };
134  float debugFadePercent{ 0.f };
135  bool debugFade{ false };
136 
137 signals:
138  void dirty();
139 };
140 
141 class RenderDeferredTask {
142 public:
143  using Input = render::VaryingSet4<RenderFetchCullSortTask::Output, LightingModelPointer, AssembleLightingStageTask::Output, RenderShadowTask::Output>;
144  using Config = RenderDeferredTaskConfig;
145  using JobModel = render::Task::ModelI<RenderDeferredTask, Input, Config>;
146 
147  void configure(const Config& config);
148  void build(JobModel& task, const render::Varying& input, render::Varying& output, render::CullFunctor cullFunctor, uint transformOffset, size_t depth);
149 };
150 
151 
152 class PreparePrimaryFramebufferConfig : public render::Job::Config {
153  Q_OBJECT
154  Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale)
155 public:
156  float getResolutionScale() const { return resolutionScale; }
157  void setResolutionScale(float scale) {
158  const float SCALE_RANGE_MIN = 0.1f;
159  const float SCALE_RANGE_MAX = 2.0f;
160  resolutionScale = std::max(SCALE_RANGE_MIN, std::min(SCALE_RANGE_MAX, scale));
161  }
162 
163 signals:
164  void dirty();
165 
166 protected:
167  float resolutionScale{ 1.0f };
168 };
169 
170 class PreparePrimaryFramebuffer {
171 public:
172 
173  using Output = gpu::FramebufferPointer;
174  using Config = PreparePrimaryFramebufferConfig;
175  using JobModel = render::Job::ModelO<PreparePrimaryFramebuffer, Output, Config>;
176 
177  PreparePrimaryFramebuffer(float resolutionScale = 1.0f) : _resolutionScale{ resolutionScale } {}
178  void configure(const Config& config);
179  void run(const render::RenderContextPointer& renderContext, Output& primaryFramebuffer);
180 
181  gpu::FramebufferPointer _primaryFramebuffer;
182  float _resolutionScale{ 1.0f };
183 
184 private:
185 
186  static gpu::FramebufferPointer createFramebuffer(const char* name, const glm::uvec2& size);
187 };
188 
189 #endif // hifi_RenderDeferredTask_h