QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsshadowrenderingframegraph.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsshadowrenderingframegraph.h
3 --------------------------------------
4 Date : August 2020
5 Copyright : (C) 2020 by Belgacem Nedjima
6 Email : gb underscore nedjima at esi dot dz
7 ***************************************************************************
8 * *
9 * This program is free software; you can redistribute it and/or modify *
10 * it under the terms of the GNU General Public License as published by *
11 * the Free Software Foundation; either version 2 of the License, or *
12 * (at your option) any later version. *
13 * *
14 ***************************************************************************/
15
16#ifndef QGSSHADOWRENDERINGFRAMEGRAPH_H
17#define QGSSHADOWRENDERINGFRAMEGRAPH_H
18
19#include <QWindow>
20#include <Qt3DRender/QCamera>
21#include <Qt3DRender/QRenderSurfaceSelector>
22#include <Qt3DRender/QViewport>
23#include <Qt3DRender/QCameraSelector>
24#include <Qt3DRender/QLayerFilter>
25#include <Qt3DRender/QLayer>
26#include <Qt3DRender/QRenderTargetSelector>
27#include <Qt3DRender/QRenderTarget>
28#include <Qt3DRender/QTexture>
29#include <Qt3DRender/QClearBuffers>
30#include <Qt3DRender/QParameter>
31#include <Qt3DRender/QFrustumCulling>
32#include <Qt3DRender/QRenderStateSet>
33#include <Qt3DRender/QDepthTest>
34#include <Qt3DRender/QCullFace>
35#include <Qt3DRender/QPolygonOffset>
36#include <Qt3DRender/QRenderCapture>
37#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
38#include <Qt3DRender/QDebugOverlay>
39#endif
40
42
45class QgsRectangle;
48class QgsPreviewQuad;
50
51#define SIP_NO_FILE
52
61class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
62{
63 Q_OBJECT
64
65 public:
67 QgsShadowRenderingFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
68
70 Qt3DRender::QFrameGraphNode *frameGraphRoot() { return mRenderSurfaceSelector; }
71
73 Qt3DRender::QTexture2D *forwardRenderColorTexture() { return mForwardColorTexture; }
75 Qt3DRender::QTexture2D *forwardRenderDepthTexture() { return mForwardDepthTexture; }
77 Qt3DRender::QTexture2D *shadowMapTexture() { return mShadowMapTexture; }
78
83 Qt3DRender::QTexture2D *ambientOcclusionFactorMap() { return mAmbientOcclusionRenderTexture; }
84
89 Qt3DRender::QTexture2D *blurredAmbientOcclusionFactorMap() { return mAmbientOcclusionBlurTexture; }
90
92 Qt3DRender::QLayer *previewLayer() { return mPreviewLayer; }
94 Qt3DRender::QLayer *castShadowsLayer() { return mCastShadowsLayer; }
96 Qt3DRender::QLayer *forwardRenderLayer() { return mForwardRenderLayer; }
97
102 Qt3DRender::QLayer *transparentObjectLayer() { return mTransparentObjectsPassLayer; }
103
105 Qt3DRender::QCamera *mainCamera() { return mMainCamera; }
107 Qt3DRender::QCamera *lightCamera() { return mLightCamera; }
109 QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
111 Qt3DCore::QEntity *rootEntity() { return mRootEntity; }
112
114 Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
115
117 Qt3DRender::QRenderCapture *depthRenderCapture() { return mDepthRenderCapture; }
118
119
121 bool frustumCullingEnabled() const { return mFrustumCullingEnabled; }
123 void setFrustumCullingEnabled( bool enabled );
124
126 bool shadowRenderingEnabled() const { return mShadowRenderingEnabled; }
128 void setShadowRenderingEnabled( bool enabled );
129
131 float shadowBias() const { return mShadowBias; }
133 void setShadowBias( float shadowBias );
134
136 int shadowMapResolution() const { return mShadowMapResolution; }
138 void setShadowMapResolution( int resolution );
139
140
145 void setAmbientOcclusionEnabled( bool enabled );
146
151 bool ambientOcclusionEnabled() const { return mAmbientOcclusionEnabled; }
152
157 void setAmbientOcclusionIntensity( float intensity );
158
163 float ambientOcclusionIntensity() const { return mAmbientOcclusionIntensity; }
164
169 void setAmbientOcclusionRadius( float radius );
170
175 float ambientOcclusionRadius() const { return mAmbientOcclusionRadius; }
176
181 void setAmbientOcclusionThreshold( float threshold );
182
187 float ambientOcclusionThreshold() const { return mAmbientOcclusionThreshold; }
188
190 void setClearColor( const QColor &clearColor );
192 QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
194 void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
196 void setupEyeDomeLighting( bool enabled, double strength, int distance );
198 void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
200 void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
202 void setSize( QSize s );
203
208 void setRenderCaptureEnabled( bool enabled );
209
214 bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
215
220 void setDebugOverlayEnabled( bool enabled );
221
222 private:
223 Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
224 Qt3DRender::QViewport *mMainViewPort = nullptr;
225 bool mFrustumCullingEnabled = true;
226
227 Qt3DRender::QCamera *mMainCamera = nullptr;
228 Qt3DRender::QCamera *mLightCamera = nullptr;
229
230 // Forward rendering pass branch nodes:
231 Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
232 Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
233 Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
234 Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
235 Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
236 // Forward rendering pass texture related objects:
237 Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
238 Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
239 // QDebugOverlay added in the forward pass
240#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
241 Qt3DRender::QDebugOverlay *mDebugOverlay = nullptr;
242#endif
243
244 // Shadow rendering pass branch nodes:
245 Qt3DRender::QCameraSelector *mLightCameraSelectorShadowPass = nullptr;
246 Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
247 Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
248 Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
249 Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
250 // Shadow rendering pass texture related objects:
251 Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
252
253 // - The depth buffer render pass is made to copy the depth buffer into
254 // an RGB texture that can be captured into a QImage and sent to the CPU for
255 // calculating real 3D points from mouse coordinates (for zoom, rotation, drag..)
256 // Depth buffer render pass branch nodes:
257 Qt3DRender::QCameraSelector *mDepthRenderCameraSelector = nullptr;
258 Qt3DRender::QRenderStateSet *mDepthRenderStateSet = nullptr;;
259 Qt3DRender::QLayerFilter *mDepthRenderLayerFilter = nullptr;
260 Qt3DRender::QRenderTargetSelector *mDepthRenderCaptureTargetSelector = nullptr;
261 Qt3DRender::QRenderCapture *mDepthRenderCapture = nullptr;
262 // Depth buffer processing pass texture related objects:
263 Qt3DRender::QTexture2D *mDepthRenderCaptureDepthTexture = nullptr;
264 Qt3DRender::QTexture2D *mDepthRenderCaptureColorTexture = nullptr;
265
266 // Post processing pass branch nodes:
267 Qt3DRender::QCameraSelector *mPostProcessingCameraSelector = nullptr;
268 Qt3DRender::QLayerFilter *mPostprocessPassLayerFilter = nullptr;
269 Qt3DRender::QClearBuffers *mPostprocessClearBuffers = nullptr;
270 Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
271 Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
272 // Post processing pass texture related objects:
273 Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
274 Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
275
276 // Ambient occlusion factor generation pass
277 Qt3DRender::QCameraSelector *mAmbientOcclusionRenderCameraSelector = nullptr;
278 Qt3DRender::QRenderStateSet *mAmbientOcclusionRenderStateSet = nullptr;;
279 Qt3DRender::QLayerFilter *mAmbientOcclusionRenderLayerFilter = nullptr;
280 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionRenderCaptureTargetSelector = nullptr;
281 // Ambient occlusion factor generation pass texture related objects:
282 Qt3DRender::QTexture2D *mAmbientOcclusionRenderTexture = nullptr;
283
284 // Ambient occlusion factor blur pass
285 Qt3DRender::QCameraSelector *mAmbientOcclusionBlurCameraSelector = nullptr;
286 Qt3DRender::QRenderStateSet *mAmbientOcclusionBlurStateSet = nullptr;;
287 Qt3DRender::QLayerFilter *mAmbientOcclusionBlurLayerFilter = nullptr;
288 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionBlurRenderCaptureTargetSelector = nullptr;
289 // Ambient occlusion factor blur pass texture related objects:
290 Qt3DRender::QTexture2D *mAmbientOcclusionBlurTexture = nullptr;
291
292 // Texture preview:
293 Qt3DRender::QLayerFilter *mPreviewLayerFilter = nullptr;
294 Qt3DRender::QRenderStateSet *mPreviewRenderStateSet = nullptr;
295 Qt3DRender::QDepthTest *mPreviewDepthTest = nullptr;
296 Qt3DRender::QCullFace *mPreviewCullFace = nullptr;
297
298 bool mShadowRenderingEnabled = false;
299 float mShadowBias = 0.00001f;
300 int mShadowMapResolution = 2048;
301
302 // Ambient occlusion related settings
303 bool mAmbientOcclusionEnabled = false;
304 float mAmbientOcclusionIntensity = 0.5f;
305 float mAmbientOcclusionRadius = 25.f;
306 float mAmbientOcclusionThreshold = 0.5f;
307
308 QSize mSize = QSize( 1024, 768 );
309
310 bool mEyeDomeLightingEnabled = false;
311 double mEyeDomeLightingStrength = 1000.0;
312 int mEyeDomeLightingDistance = 1;
313
314 QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
315 QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
316
317 QEntity *mDepthRenderQuad = nullptr;
318
319 QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
320
321 Qt3DCore::QEntity *mRootEntity = nullptr;
322
323 Qt3DRender::QLayer *mPreviewLayer = nullptr;
324 Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
325 Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
326 Qt3DRender::QLayer *mDepthRenderPassLayer = nullptr;
327 Qt3DRender::QLayer *mTransparentObjectsPassLayer = nullptr;
328
329 QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
330 QgsAmbientOcclusionRenderEntity *mAmbientOcclusionRenderEntity = nullptr;
331 QgsAmbientOcclusionBlurEntity *mAmbientOcclusionBlurEntity = nullptr;
332
333 QVector<QgsPreviewQuad *> mPreviewQuads;
334
335 Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
336 Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
337 Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
338 Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
339 Qt3DRender::QFrameGraphNode *constructDepthRenderPass();
340 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionRenderPass();
341 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionBlurPass();
342
343 Qt3DCore::QEntity *constructDepthRenderQuad();
344
345 bool mRenderCaptureEnabled = true;
346
347 Q_DISABLE_COPY( QgsShadowRenderingFrameGraph )
348};
349
350#endif // QGSSHADOWRENDERINGFRAMEGRAPH_H
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Qt3DRender::QTexture2D * ambientOcclusionFactorMap()
Returns ambient occlusion factor values texture.
int shadowMapResolution() const
Returns the shadow map resolution.
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
Qt3DRender::QLayer * transparentObjectLayer()
Returns a layer object used to indicate that the object is transparent.
bool renderCaptureEnabled() const
Returns whether it will be possible to render to an image.
Qt3DRender::QTexture2D * shadowMapTexture()
Returns the shadow map (a depth texture for the shadow rendering pass)
void setAmbientOcclusionThreshold(float threshold)
Sets the ambient occlusion threshold.
QgsShadowRenderingFrameGraph(QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
void setShadowBias(float shadowBias)
Sets the shadow bias value.
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
void setAmbientOcclusionIntensity(float intensity)
Sets the ambient occlusion intensity.
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
QgsPostprocessingEntity * postprocessingEntity()
Returns the postprocessing entity.
void setupEyeDomeLighting(bool enabled, double strength, int distance)
Sets eye dome lighting shading related settings.
QgsPreviewQuad * addTexturePreviewOverlay(Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector< Qt3DRender::QParameter * > additionalShaderParameters=QVector< Qt3DRender::QParameter * >())
Adds an preview entity that shows a texture in real time for debugging purposes.
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
float ambientOcclusionRadius() const
Returns the ambient occlusion radius.
float ambientOcclusionIntensity() const
Returns the ambient occlusion intensity.
bool shadowRenderingEnabled() const
Returns whether shadow rendering is enabled.
Qt3DRender::QCamera * lightCamera()
Returns the light camera.
Qt3DRender::QTexture2D * forwardRenderColorTexture()
Returns the color texture of the forward rendering pass.
bool ambientOcclusionEnabled() const
Returns whether Screen Space Ambient Occlusion is enabled.
Qt3DRender::QRenderCapture * depthRenderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
void setAmbientOcclusionRadius(float radius)
Sets the ambient occlusion radius.
Qt3DRender::QLayer * previewLayer()
Returns a layer object used to indicate that an entity is to be rendered during the preview textures ...
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
bool frustumCullingEnabled() const
Returns whether frustum culling is enabled.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether Screen Space Ambient Occlusion will be enabled.
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Qt3DRender::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
Qt3DRender::QTexture2D * forwardRenderDepthTexture()
Returns the depth texture of the forward rendering pass.
Qt3DCore::QEntity * rootEntity()
Returns the root entity of the entities related to the frame graph (like the post processing entity a...
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
float ambientOcclusionThreshold() const
Returns the ambient occlusion threshold.
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
float shadowBias() const
Returns the shadow bias value.
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Qt3DRender::QTexture2D * blurredAmbientOcclusionFactorMap()
Returns blurred ambient occlusion factor values texture.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.