QGIS API Documentation 3.41.0-Master (af5edcb665c)
Loading...
Searching...
No Matches
qgsframegraph.h
Go to the documentation of this file.
1/***************************************************************************
2 qgsframegraph.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 QGSFRAMEGRAPH_H
17#define QGSFRAMEGRAPH_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#include <Qt3DRender/QDebugOverlay>
38
40
43class QgsRectangle;
46class QgsPreviewQuad;
48
49#define SIP_NO_FILE
50
61class QgsFrameGraph : public Qt3DCore::QEntity
62{
63 Q_OBJECT
64
65 public:
67 QgsFrameGraph( 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 *blurredAmbientOcclusionFactorMap() { return mAmbientOcclusionBlurTexture; }
84
86 Qt3DRender::QLayer *previewLayer() { return mPreviewLayer; }
88 Qt3DRender::QLayer *castShadowsLayer() { return mCastShadowsLayer; }
90 Qt3DRender::QLayer *forwardRenderLayer() { return mForwardRenderLayer; }
91
96 Qt3DRender::QLayer *transparentObjectLayer() { return mTransparentObjectsPassLayer; }
97
99 Qt3DRender::QCamera *mainCamera() { return mMainCamera; }
101 Qt3DRender::QCamera *lightCamera() { return mLightCamera; }
103 QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
105 Qt3DCore::QEntity *rootEntity() { return mRootEntity; }
106
108 Qt3DCore::QEntity *rubberBandsRootEntity() { return mRubberBandsRootEntity; }
109
111 Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
112
114 Qt3DRender::QRenderCapture *depthRenderCapture() { return mDepthRenderCapture; }
115
116
118 bool frustumCullingEnabled() const { return mFrustumCullingEnabled; }
120 void setFrustumCullingEnabled( bool enabled );
121
123 bool shadowRenderingEnabled() const { return mShadowRenderingEnabled; }
125 void setShadowRenderingEnabled( bool enabled );
126
128 float shadowBias() const { return mShadowBias; }
130 void setShadowBias( float shadowBias );
131
133 int shadowMapResolution() const { return mShadowMapResolution; }
135 void setShadowMapResolution( int resolution );
136
137
142 void setAmbientOcclusionEnabled( bool enabled );
143
148 bool ambientOcclusionEnabled() const { return mAmbientOcclusionEnabled; }
149
154 void setAmbientOcclusionIntensity( float intensity );
155
160 float ambientOcclusionIntensity() const { return mAmbientOcclusionIntensity; }
161
166 void setAmbientOcclusionRadius( float radius );
167
172 float ambientOcclusionRadius() const { return mAmbientOcclusionRadius; }
173
178 void setAmbientOcclusionThreshold( float threshold );
179
184 float ambientOcclusionThreshold() const { return mAmbientOcclusionThreshold; }
185
187 void setClearColor( const QColor &clearColor );
189 QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
191 void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
193 void setupEyeDomeLighting( bool enabled, double strength, int distance );
195 void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
197 void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
199 void setSize( QSize s );
200
205 void setRenderCaptureEnabled( bool enabled );
206
211 bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
212
217 void setDebugOverlayEnabled( bool enabled );
218
220 QString dumpFrameGraph() const;
221
223 QString dumpSceneGraph() const;
224
232 void addClipPlanes( int nrClipPlanes );
233
240 void removeClipPlanes();
241
242 private:
243 Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
244 Qt3DRender::QViewport *mMainViewPort = nullptr;
245 bool mFrustumCullingEnabled = true;
246
247 Qt3DRender::QCamera *mMainCamera = nullptr;
248 Qt3DRender::QCamera *mLightCamera = nullptr;
249
250 // Forward rendering pass branch nodes:
251 Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
252 Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
253 Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
254 Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
255 Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
256 // Forward rendering pass texture related objects:
257 Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
258 Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
259 // QDebugOverlay added in the forward pass
260 Qt3DRender::QDebugOverlay *mDebugOverlay = nullptr;
261
262 // Shadow rendering pass branch nodes:
263 Qt3DRender::QCameraSelector *mLightCameraSelectorShadowPass = nullptr;
264 Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
265 Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
266 Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
267 Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
268 // Shadow rendering pass texture related objects:
269 Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
270
271 // - The depth buffer render pass is made to copy the depth buffer into
272 // an RGB texture that can be captured into a QImage and sent to the CPU for
273 // calculating real 3D points from mouse coordinates (for zoom, rotation, drag..)
274 // Depth buffer render pass branch nodes:
275 Qt3DRender::QCameraSelector *mDepthRenderCameraSelector = nullptr;
276 Qt3DRender::QRenderStateSet *mDepthRenderStateSet = nullptr;
277 Qt3DRender::QLayerFilter *mDepthRenderLayerFilter = nullptr;
278 Qt3DRender::QRenderTargetSelector *mDepthRenderCaptureTargetSelector = nullptr;
279 Qt3DRender::QRenderCapture *mDepthRenderCapture = nullptr;
280 // Depth buffer processing pass texture related objects:
281 Qt3DRender::QTexture2D *mDepthRenderCaptureDepthTexture = nullptr;
282 Qt3DRender::QTexture2D *mDepthRenderCaptureColorTexture = nullptr;
283
284 // Post processing pass branch nodes:
285 Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
286 Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
287 // Post processing pass texture related objects:
288 Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
289 Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
290
291 // Ambient occlusion factor generation pass
292 Qt3DRender::QCameraSelector *mAmbientOcclusionRenderCameraSelector = nullptr;
293 Qt3DRender::QRenderStateSet *mAmbientOcclusionRenderStateSet = nullptr;
294 Qt3DRender::QLayerFilter *mAmbientOcclusionRenderLayerFilter = nullptr;
295 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionRenderCaptureTargetSelector = nullptr;
296 // Ambient occlusion factor generation pass texture related objects:
297 Qt3DRender::QTexture2D *mAmbientOcclusionRenderTexture = nullptr;
298
299 // Ambient occlusion factor blur pass
300 Qt3DRender::QCameraSelector *mAmbientOcclusionBlurCameraSelector = nullptr;
301 Qt3DRender::QRenderStateSet *mAmbientOcclusionBlurStateSet = nullptr;
302 Qt3DRender::QLayerFilter *mAmbientOcclusionBlurLayerFilter = nullptr;
303 Qt3DRender::QRenderTargetSelector *mAmbientOcclusionBlurRenderCaptureTargetSelector = nullptr;
304 // Ambient occlusion factor blur pass texture related objects:
305 Qt3DRender::QTexture2D *mAmbientOcclusionBlurTexture = nullptr;
306
307 // Rubber bands pass
308 Qt3DRender::QCameraSelector *mRubberBandsCameraSelector = nullptr;
309 Qt3DRender::QLayerFilter *mRubberBandsLayerFilter = nullptr;
310 Qt3DRender::QRenderStateSet *mRubberBandsStateSet = nullptr;
311 Qt3DRender::QRenderTargetSelector *mRubberBandsRenderTargetSelector = nullptr;
312
313 bool mShadowRenderingEnabled = false;
314 float mShadowBias = 0.00001f;
315 int mShadowMapResolution = 2048;
316
317 // Ambient occlusion related settings
318 bool mAmbientOcclusionEnabled = false;
319 float mAmbientOcclusionIntensity = 0.5f;
320 float mAmbientOcclusionRadius = 25.f;
321 float mAmbientOcclusionThreshold = 0.5f;
322
323 QSize mSize = QSize( 1024, 768 );
324
325 bool mEyeDomeLightingEnabled = false;
326 double mEyeDomeLightingStrength = 1000.0;
327 int mEyeDomeLightingDistance = 1;
328
329 QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
330 QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
331
332 QEntity *mDepthRenderQuad = nullptr;
333
334 QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
335
336 // clip planes render state
337 Qt3DRender::QRenderStateSet *mClipRenderStateSet = nullptr;
338
339 Qt3DCore::QEntity *mRootEntity = nullptr;
340
341 Qt3DRender::QLayer *mPreviewLayer = nullptr;
342 Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
343 Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
344 Qt3DRender::QLayer *mDepthRenderPassLayer = nullptr;
345 Qt3DRender::QLayer *mTransparentObjectsPassLayer = nullptr;
346 Qt3DRender::QLayer *mRubberBandsLayer = nullptr;
347
348 QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
349 QgsAmbientOcclusionRenderEntity *mAmbientOcclusionRenderEntity = nullptr;
350 QgsAmbientOcclusionBlurEntity *mAmbientOcclusionBlurEntity = nullptr;
351
352 Qt3DCore::QEntity *mRubberBandsRootEntity = nullptr;
353
354 QVector<QgsPreviewQuad *> mPreviewQuads;
355
356 Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
357 Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
358 Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
359 Qt3DRender::QFrameGraphNode *constructDepthRenderPass();
360 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionRenderPass();
361 Qt3DRender::QFrameGraphNode *constructAmbientOcclusionBlurPass();
362 Qt3DRender::QFrameGraphNode *constructRubberBandsPass();
363
364 Qt3DRender::QFrameGraphNode *constructSubPostPassForProcessing();
365 Qt3DRender::QFrameGraphNode *constructSubPostPassForRenderCapture();
366 Qt3DRender::QFrameGraphNode *constructSubPostPassForTexturesPreview();
367
368 Qt3DCore::QEntity *constructDepthRenderQuad();
369
370 bool mRenderCaptureEnabled = false;
371
372 Q_DISABLE_COPY( QgsFrameGraph )
373};
374
375#endif // QGSFRAMEGRAPH_H
bool renderCaptureEnabled() const
Returns whether it will be possible to render to an image.
Qt3DRender::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
bool frustumCullingEnabled() const
Returns whether frustum culling is enabled.
void addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
int shadowMapResolution() const
Returns the shadow map resolution.
QString dumpFrameGraph() const
Dumps frame graph as string.
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
Qt3DRender::QRenderCapture * depthRenderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
void removeClipPlanes()
Disables OpenGL clipping.
Qt3DCore::QEntity * rootEntity()
Returns the root entity of the entities related to the frame graph (like the post processing entity a...
void setShadowBias(float shadowBias)
Sets the shadow bias value.
bool ambientOcclusionEnabled() const
Returns whether Screen Space Ambient Occlusion is enabled.
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
Qt3DRender::QTexture2D * shadowMapTexture()
Returns the shadow map (a depth texture for the shadow rendering pass)
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
bool shadowRenderingEnabled() const
Returns whether shadow rendering is enabled.
QgsPostprocessingEntity * postprocessingEntity()
Returns the postprocessing entity.
Qt3DRender::QTexture2D * forwardRenderColorTexture()
Returns the color texture of the forward rendering pass.
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
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.
void setAmbientOcclusionIntensity(float intensity)
Sets the ambient occlusion intensity.
float shadowBias() const
Returns the shadow bias value.
Qt3DCore::QEntity * rubberBandsRootEntity()
Returns entity for all rubber bands (to show them always on top)
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Qt3DRender::QLayer * transparentObjectLayer()
Returns a layer object used to indicate that the object is transparent.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
Qt3DRender::QLayer * previewLayer()
Returns a layer object used to indicate that an entity is to be rendered during the preview textures ...
float ambientOcclusionRadius() const
Returns the ambient occlusion radius.
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
float ambientOcclusionIntensity() const
Returns the ambient occlusion intensity.
void setAmbientOcclusionThreshold(float threshold)
Sets the ambient occlusion threshold.
Qt3DRender::QCamera * lightCamera()
Returns the light camera.
Qt3DRender::QTexture2D * blurredAmbientOcclusionFactorMap()
Returns blurred ambient occlusion factor values texture.
QString dumpSceneGraph() const
Dumps scene graph as string.
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
float ambientOcclusionThreshold() const
Returns the ambient occlusion threshold.
void setupEyeDomeLighting(bool enabled, double strength, int distance)
Sets eye dome lighting shading related settings.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Qt3DRender::QTexture2D * forwardRenderDepthTexture()
Returns the depth texture of the forward rendering pass.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether Screen Space Ambient Occlusion will be enabled.
void setAmbientOcclusionRadius(float radius)
Sets the ambient occlusion radius.
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
A rectangle specified with double values.