QGIS API Documentation  3.27.0-Master (0e23467727)
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  public:
63  QgsShadowRenderingFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
64 
66  Qt3DRender::QFrameGraphNode *frameGraphRoot() { return mRenderSurfaceSelector; }
67 
69  Qt3DRender::QTexture2D *forwardRenderColorTexture() { return mForwardColorTexture; }
71  Qt3DRender::QTexture2D *forwardRenderDepthTexture() { return mForwardDepthTexture; }
73  Qt3DRender::QTexture2D *shadowMapTexture() { return mShadowMapTexture; }
74 
76  Qt3DRender::QLayer *postprocessingPassLayer() { return mPostprocessPassLayer; }
78  Qt3DRender::QLayer *previewLayer() { return mPreviewLayer; }
80  Qt3DRender::QLayer *castShadowsLayer() { return mCastShadowsLayer; }
82  Qt3DRender::QLayer *forwardRenderLayer() { return mForwardRenderLayer; }
83 
88  Qt3DRender::QLayer *transparentObjectLayer() { return mTransparentObjectsPassLayer; }
89 
91  Qt3DRender::QCamera *mainCamera() { return mMainCamera; }
93  Qt3DRender::QCamera *lightCamera() { return mLightCamera; }
95  QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
97  Qt3DCore::QEntity *rootEntity() { return mRootEntity; }
98 
100  Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
101 
103  Qt3DRender::QRenderCapture *depthRenderCapture() { return mDepthRenderCapture; }
104 
105 
107  bool frustumCullingEnabled() const { return mFrustumCullingEnabled; }
109  void setFrustumCullingEnabled( bool enabled );
110 
112  bool shadowRenderingEnabled() const { return mShadowRenderingEnabled; }
114  void setShadowRenderingEnabled( bool enabled );
115 
117  float shadowBias() const { return mShadowBias; }
119  void setShadowBias( float shadowBias );
120 
122  int shadowMapResolution() const { return mShadowMapResolution; }
124  void setShadowMapResolution( int resolution );
125 
127  void setClearColor( const QColor &clearColor );
129  QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
131  void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
133  void setupEyeDomeLighting( bool enabled, double strength, int distance );
135  void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
137  void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
139  void setSize( QSize s );
140 
145  void setRenderCaptureEnabled( bool enabled );
146 
151  bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
152 
157  void setDebugOverlayEnabled( bool enabled );
158 
159  private:
160  Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
161  Qt3DRender::QViewport *mMainViewPort = nullptr;
162  bool mFrustumCullingEnabled = true;
163 
164  Qt3DRender::QCamera *mMainCamera = nullptr;
165  Qt3DRender::QCamera *mLightCamera = nullptr;
166 
167  // Forward rendering pass branch nodes:
168  Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
169  Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
170  Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
171  Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
172  Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
173  // Forward rendering pass texture related objects:
174  Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
175  Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
176  // QDebugOverlay added in the forward pass
177 #if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
178  Qt3DRender::QDebugOverlay *mDebugOverlay = nullptr;
179 #endif
180 
181  // Shadow rendering pass branch nodes:
182  Qt3DRender::QCameraSelector *mLightCameraSelectorShadowPass = nullptr;
183  Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
184  Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
185  Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
186  Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
187  // Shadow rendering pass texture related objects:
188  Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
189 
190  // - The depth buffer render pass is made to copy the depth buffer into
191  // an RGB texture that can be captured into a QImage and sent to the CPU for
192  // calculating real 3D points from mouse coordinates (for zoom, rotation, drag..)
193  // Depth buffer render pass branch nodes:
194  Qt3DRender::QCameraSelector *mDepthRenderCameraSelector = nullptr;
195  Qt3DRender::QRenderStateSet *mDepthRenderStateSet = nullptr;;
196  Qt3DRender::QLayerFilter *mDepthRenderLayerFilter = nullptr;
197  Qt3DRender::QRenderTargetSelector *mDepthRenderCaptureTargetSelector = nullptr;
198  Qt3DRender::QRenderCapture *mDepthRenderCapture = nullptr;
199  // Depth buffer processing pass texture related objects:
200  Qt3DRender::QTexture2D *mDepthRenderCaptureDepthTexture = nullptr;
201  Qt3DRender::QTexture2D *mDepthRenderCaptureColorTexture = nullptr;
202 
203  // Post processing pass branch nodes:
204  Qt3DRender::QCameraSelector *mPostProcessingCameraSelector = nullptr;
205  Qt3DRender::QLayerFilter *mPostprocessPassLayerFilter = nullptr;
206  Qt3DRender::QClearBuffers *mPostprocessClearBuffers = nullptr;
207  Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
208  Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
209  // Post processing pass texture related objects:
210  Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
211  Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
212 
213  // Texture preview:
214  Qt3DRender::QLayerFilter *mPreviewLayerFilter = nullptr;
215  Qt3DRender::QRenderStateSet *mPreviewRenderStateSet = nullptr;
216  Qt3DRender::QDepthTest *mPreviewDepthTest = nullptr;
217  Qt3DRender::QCullFace *mPreviewCullFace = nullptr;
218 
219  bool mShadowRenderingEnabled = false;
220  float mShadowBias = 0.00001f;
221  int mShadowMapResolution = 2048;
222 
223  QSize mSize = QSize( 1024, 768 );
224 
225  bool mEyeDomeLightingEnabled = false;
226  double mEyeDomeLightingStrength = 1000.0;
227  int mEyeDomeLightingDistance = 1;
228 
229  QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
230  QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
231 
232  QEntity *mDepthRenderQuad = nullptr;
233 
234  QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
235 
236  Qt3DCore::QEntity *mRootEntity = nullptr;
237 
238  Qt3DRender::QLayer *mPostprocessPassLayer = nullptr;
239  Qt3DRender::QLayer *mPreviewLayer = nullptr;
240  Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
241  Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
242  Qt3DRender::QLayer *mDepthRenderPassLayer = nullptr;
243  Qt3DRender::QLayer *mTransparentObjectsPassLayer = nullptr;
244 
245  QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
246 
247  QVector<QgsPreviewQuad *> mPreviewQuads;
248 
249  Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
250  Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
251  Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
252  Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
253  Qt3DRender::QFrameGraphNode *constructDepthRenderPass();
254 
255  Qt3DCore::QEntity *constructDepthRenderQuad();
256 
257  bool mRenderCaptureEnabled = true;
258 
259  Q_DISABLE_COPY( QgsShadowRenderingFrameGraph )
260 };
261 
262 #endif // QGSSHADOWRENDERINGFRAMEGRAPH_H
A rectangle specified with double values.
Definition: qgsrectangle.h:42
Qt3DRender::QTexture2D * forwardRenderDepthTexture()
Returns the depth texture of the forward rendering pass.
int shadowMapResolution() const
Returns the shadow map resolution.
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
bool renderCaptureEnabled() const
Returns whether it will be possible to render to an image.
Qt3DRender::QLayer * transparentObjectLayer()
Returns a layer object used to indicate that the object is transparent.
QgsShadowRenderingFrameGraph(QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
Qt3DRender::QTexture2D * shadowMapTexture()
Returns the shadow map (a depth texture for the shadow rendering pass)
Qt3DRender::QTexture2D * forwardRenderColorTexture()
Returns the color texture of the forward rendering pass.
void setupShadowMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the shadow map debugging view port.
void setShadowBias(float shadowBias)
Sets the shadow bias value.
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
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::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
Qt3DRender::QCamera * lightCamera()
Returns the light camera.
bool shadowRenderingEnabled() const
Returns whether shadow rendering is enabled.
Qt3DRender::QLayer * forwardRenderLayer()
Returns a layer object used to indicate that an entity will be rendered during the forward rendering ...
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
bool frustumCullingEnabled() const
Returns whether frustum culling is enabled.
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Qt3DRender::QRenderCapture * depthRenderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Qt3DCore::QEntity * rootEntity()
Returns the root entity of the entities related to the frame graph (like the post processing entity a...
QgsPostprocessingEntity * postprocessingEntity()
Returns the postprocessing entity.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Qt3DRender::QLayer * previewLayer()
Returns a layer object used to indicate that an entity is to be rendered during the preview textures ...
Qt3DRender::QLayer * postprocessingPassLayer()
Returns a layer object used to indicate that an entity is to be rendered during the post processing r...
Qt3DRender::QFrameGraphNode * frameGraphRoot()
Returns the root of the frame graph object.
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
float shadowBias() const
Returns the shadow bias value.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.