QGIS API Documentation  3.26.3-Buenos Aires (65e4edfdad)
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 
41 #include "qgspointlightsettings.h"
42 
45 class QgsRectangle;
47 class QgsPreviewQuad;
48 
49 #define SIP_NO_FILE
50 
59 class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
60 {
61  Q_OBJECT
62 
63  public:
65  QgsShadowRenderingFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
66 
68  Qt3DRender::QFrameGraphNode *frameGraphRoot() { return mRenderSurfaceSelector; }
69 
71  Qt3DRender::QTexture2D *forwardRenderColorTexture() { return mForwardColorTexture; }
73  Qt3DRender::QTexture2D *forwardRenderDepthTexture() { return mForwardDepthTexture; }
75  Qt3DRender::QTexture2D *shadowMapTexture() { return mShadowMapTexture; }
76 
78  Qt3DRender::QLayer *postprocessingPassLayer() { return mPostprocessPassLayer; }
80  Qt3DRender::QLayer *previewLayer() { return mPreviewLayer; }
82  Qt3DRender::QLayer *castShadowsLayer() { return mCastShadowsLayer; }
84  Qt3DRender::QLayer *forwardRenderLayer() { return mForwardRenderLayer; }
85 
90  Qt3DRender::QLayer *transparentObjectLayer() { return mTransparentObjectsPassLayer; }
91 
93  Qt3DRender::QCamera *mainCamera() { return mMainCamera; }
95  Qt3DRender::QCamera *lightCamera() { return mLightCamera; }
97  QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
99  Qt3DCore::QEntity *rootEntity() { return mRootEntity; }
100 
102  Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
103 
105  Qt3DRender::QRenderCapture *depthRenderCapture() { return mDepthRenderCapture; }
106 
107 
109  bool frustumCullingEnabled() const { return mFrustumCullingEnabled; }
111  void setFrustumCullingEnabled( bool enabled );
112 
114  bool shadowRenderingEnabled() const { return mShadowRenderingEnabled; }
116  void setShadowRenderingEnabled( bool enabled );
117 
119  float shadowBias() const { return mShadowBias; }
121  void setShadowBias( float shadowBias );
122 
124  int shadowMapResolution() const { return mShadowMapResolution; }
126  void setShadowMapResolution( int resolution );
127 
129  void setClearColor( const QColor &clearColor );
131  QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
133  void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
135  void setupEyeDomeLighting( bool enabled, double strength, int distance );
137  void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
139  void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
141  void setSize( QSize s );
142 
147  void setRenderCaptureEnabled( bool enabled );
148 
153  bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
154 
159  void setDebugOverlayEnabled( bool enabled );
160 
161  private:
162  Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
163  Qt3DRender::QViewport *mMainViewPort = nullptr;
164  bool mFrustumCullingEnabled = true;
165 
166  Qt3DRender::QCamera *mMainCamera = nullptr;
167  Qt3DRender::QCamera *mLightCamera = nullptr;
168 
169  // Forward rendering pass branch nodes:
170  Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
171  Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
172  Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
173  Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
174  Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
175  // Forward rendering pass texture related objects:
176  Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
177  Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
178  // QDebugOverlay added in the forward pass
179 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
180  Qt3DRender::QDebugOverlay *mDebugOverlay = nullptr;
181 #endif
182 
183  // Shadow rendering pass branch nodes:
184  Qt3DRender::QCameraSelector *mLightCameraSelectorShadowPass = nullptr;
185  Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
186  Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
187  Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
188  Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
189  // Shadow rendering pass texture related objects:
190  Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
191 
192  // - The depth buffer render pass is made to copy the depth buffer into
193  // an RGB texture that can be captured into a QImage and sent to the CPU for
194  // calculating real 3D points from mouse coordinates (for zoom, rotation, drag..)
195  // Depth buffer render pass branch nodes:
196  Qt3DRender::QCameraSelector *mDepthRenderCameraSelector = nullptr;
197  Qt3DRender::QRenderStateSet *mDepthRenderStateSet = nullptr;;
198  Qt3DRender::QLayerFilter *mDepthRenderLayerFilter = nullptr;
199  Qt3DRender::QRenderTargetSelector *mDepthRenderCaptureTargetSelector = nullptr;
200  Qt3DRender::QRenderCapture *mDepthRenderCapture = nullptr;
201  // Depth buffer processing pass texture related objects:
202  Qt3DRender::QTexture2D *mDepthRenderCaptureDepthTexture = nullptr;
203  Qt3DRender::QTexture2D *mDepthRenderCaptureColorTexture = nullptr;
204 
205  // Post processing pass branch nodes:
206  Qt3DRender::QCameraSelector *mPostProcessingCameraSelector = nullptr;
207  Qt3DRender::QLayerFilter *mPostprocessPassLayerFilter = nullptr;
208  Qt3DRender::QClearBuffers *mPostprocessClearBuffers = nullptr;
209  Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
210  Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
211  // Post processing pass texture related objects:
212  Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
213  Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
214 
215  // Texture preview:
216  Qt3DRender::QLayerFilter *mPreviewLayerFilter = nullptr;
217  Qt3DRender::QRenderStateSet *mPreviewRenderStateSet = nullptr;
218  Qt3DRender::QDepthTest *mPreviewDepthTest = nullptr;
219  Qt3DRender::QCullFace *mPreviewCullFace = nullptr;
220 
221  bool mShadowRenderingEnabled = false;
222  float mShadowBias = 0.00001f;
223  int mShadowMapResolution = 2048;
224 
225  QSize mSize = QSize( 1024, 768 );
226 
227  bool mEyeDomeLightingEnabled = false;
228  double mEyeDomeLightingStrength = 1000.0;
229  int mEyeDomeLightingDistance = 1;
230 
231  QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
232  QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
233 
234  QEntity *mDepthRenderQuad = nullptr;
235 
236  QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
237 
238  Qt3DCore::QEntity *mRootEntity = nullptr;
239 
240  Qt3DRender::QLayer *mPostprocessPassLayer = nullptr;
241  Qt3DRender::QLayer *mPreviewLayer = nullptr;
242  Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
243  Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
244  Qt3DRender::QLayer *mDepthRenderPassLayer = nullptr;
245  Qt3DRender::QLayer *mTransparentObjectsPassLayer = nullptr;
246 
247  QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
248 
249  QVector<QgsPreviewQuad *> mPreviewQuads;
250 
251  Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
252  Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
253  Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
254  Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
255  Qt3DRender::QFrameGraphNode *constructDepthRenderPass();
256 
257  Qt3DCore::QEntity *constructDepthRenderQuad();
258 
259  bool mRenderCaptureEnabled = true;
260 
261  Q_DISABLE_COPY( QgsShadowRenderingFrameGraph )
262 };
263 
264 #endif // QGSSHADOWRENDERINGFRAMEGRAPH_H
QgsShadowRenderingFrameGraph::frameGraphRoot
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
Definition: qgsshadowrenderingframegraph.h:68
QgsShadowRenderingFrameGraph::setShadowBias
void setShadowBias(float shadowBias)
Sets the shadow bias value.
Definition: qgsshadowrenderingframegraph.cpp:580
QgsShadowRenderingFrameGraph::rootEntity
Qt3DCore::QEntity * rootEntity()
Returns the root entity of the entities related to the frame graph (like the post processing entity a...
Definition: qgsshadowrenderingframegraph.h:99
QgsShadowRenderingFrameGraph::setSize
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Definition: qgsshadowrenderingframegraph.cpp:661
QgsShadowRenderingFrameGraph::castShadowsLayer
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
Definition: qgsshadowrenderingframegraph.h:82
QgsShadowRenderingFrameGraph::shadowMapTexture
Qt3DRender::QTexture2D * shadowMapTexture()
Returns the shadow map (a depth texture for the shadow rendering pass)
Definition: qgsshadowrenderingframegraph.h:75
QgsShadowRenderingFrameGraph::postprocessingPassLayer
Qt3DRender::QLayer * postprocessingPassLayer()
Returns a layer object used to indicate that an entity is to be rendered during the post processing r...
Definition: qgsshadowrenderingframegraph.h:78
QgsShadowRenderingFrameGraph::setupEyeDomeLighting
void setupEyeDomeLighting(bool enabled, double strength, int distance)
Sets eye dome lighting shading related settings.
Definition: qgsshadowrenderingframegraph.cpp:604
QgsShadowRenderingFrameGraph::forwardRenderDepthTexture
Qt3DRender::QTexture2D * forwardRenderDepthTexture()
Returns the depth texture of the forward rendering pass.
Definition: qgsshadowrenderingframegraph.h:73
QgsShadowRenderingFrameGraph::addTexturePreviewOverlay
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.
Definition: qgsshadowrenderingframegraph.cpp:469
QgsShadowRenderingFrameGraph::shadowBias
float shadowBias() const
Returns the shadow bias value.
Definition: qgsshadowrenderingframegraph.h:119
QgsShadowRenderingFrameGraph::setDebugOverlayEnabled
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
Definition: qgsshadowrenderingframegraph.cpp:681
QgsShadowRenderingFrameGraph::QgsShadowRenderingFrameGraph
QgsShadowRenderingFrameGraph(QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
Definition: qgsshadowrenderingframegraph.cpp:399
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:41
QgsShadowRenderingFrameGraph
Container class that holds different objects related to shadow rendering.
Definition: qgsshadowrenderingframegraph.h:59
QgsShadowRenderingFrameGraph::mainCamera
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Definition: qgsshadowrenderingframegraph.h:93
qgspointlightsettings.h
QgsShadowRenderingFrameGraph::setupShadowMapDebugging
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
Definition: qgsshadowrenderingframegraph.cpp:614
QgsShadowRenderingFrameGraph::setupDepthMapDebugging
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
Definition: qgsshadowrenderingframegraph.cpp:637
QgsShadowRenderingFrameGraph::forwardRenderLayer
Qt3DRender::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
Definition: qgsshadowrenderingframegraph.h:84
QgsShadowRenderingFrameGraph::renderCapture
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
Definition: qgsshadowrenderingframegraph.h:102
QgsShadowRenderingFrameGraph::frustumCullingEnabled
bool frustumCullingEnabled() const
Returns whether frustum culling is enabled.
Definition: qgsshadowrenderingframegraph.h:109
QgsShadowRenderingFrameGraph::postprocessingEntity
QgsPostprocessingEntity * postprocessingEntity()
Returns the postprocessing entity.
Definition: qgsshadowrenderingframegraph.h:97
QgsShadowRenderingFrameGraph::forwardRenderColorTexture
Qt3DRender::QTexture2D * forwardRenderColorTexture()
Returns the color texture of the forward rendering pass.
Definition: qgsshadowrenderingframegraph.h:71
QgsShadowRenderingFrameGraph::setFrustumCullingEnabled
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Definition: qgsshadowrenderingframegraph.cpp:593
QgsShadowRenderingFrameGraph::depthRenderCapture
Qt3DRender::QRenderCapture * depthRenderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
Definition: qgsshadowrenderingframegraph.h:105
QgsShadowRenderingFrameGraph::setRenderCaptureEnabled
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
Definition: qgsshadowrenderingframegraph.cpp:673
QgsShadowRenderingFrameGraph::transparentObjectLayer
Qt3DRender::QLayer * transparentObjectLayer()
Returns a layer object used to indicate that the object is transparent.
Definition: qgsshadowrenderingframegraph.h:90
QgsShadowRenderingFrameGraph::shadowRenderingEnabled
bool shadowRenderingEnabled() const
Returns whether shadow rendering is enabled.
Definition: qgsshadowrenderingframegraph.h:114
QgsShadowRenderingFrameGraph::previewLayer
Qt3DRender::QLayer * previewLayer()
Returns a layer object used to indicate that an entity is to be rendered during the preview textures ...
Definition: qgsshadowrenderingframegraph.h:80
QgsShadowRenderingFrameGraph::setupDirectionalLight
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
Definition: qgsshadowrenderingframegraph.cpp:538
QgsCameraController
Object that controls camera movement based on user input.
Definition: qgscameracontroller.h:61
QgsShadowRenderingFrameGraph::lightCamera
Qt3DRender::QCamera * lightCamera()
Returns the light camera.
Definition: qgsshadowrenderingframegraph.h:95
QgsShadowRenderingFrameGraph::setClearColor
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Definition: qgsshadowrenderingframegraph.cpp:565
QgsPostprocessingEntity
An entity that is responsible for applying post processing effect.
Definition: qgspostprocessingentity.h:39
QgsShadowRenderingFrameGraph::setShadowRenderingEnabled
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
Definition: qgsshadowrenderingframegraph.cpp:570
QgsShadowRenderingFrameGraph::shadowMapResolution
int shadowMapResolution() const
Returns the shadow map resolution.
Definition: qgsshadowrenderingframegraph.h:124
QgsPreviewQuad
Rectangular quad entity used for debugging depth maps.
Definition: qgspreviewquad.h:58
QgsShadowRenderingFrameGraph::renderCaptureEnabled
bool renderCaptureEnabled() const
Returns whether it will be possible to render to an image.
Definition: qgsshadowrenderingframegraph.h:153
QgsShadowRenderingFrameGraph::setShadowMapResolution
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
Definition: qgsshadowrenderingframegraph.cpp:586
QgsDirectionalLightSettings
Definition of a directional light in a 3D map scene.
Definition: qgsdirectionallightsettings.h:33