QGIS API Documentation  3.24.2-Tisler (13c1a02865)
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 
38 #include "qgspointlightsettings.h"
39 
42 class QgsRectangle;
44 class QgsPreviewQuad;
45 
46 #define SIP_NO_FILE
47 
56 class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
57 {
58  public:
60  QgsShadowRenderingFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
61 
63  Qt3DRender::QFrameGraphNode *frameGraphRoot() { return mRenderSurfaceSelector; }
64 
66  Qt3DRender::QTexture2D *forwardRenderColorTexture() { return mForwardColorTexture; }
68  Qt3DRender::QTexture2D *forwardRenderDepthTexture() { return mForwardDepthTexture; }
70  Qt3DRender::QTexture2D *shadowMapTexture() { return mShadowMapTexture; }
71 
73  Qt3DRender::QLayer *postprocessingPassLayer() { return mPostprocessPassLayer; }
75  Qt3DRender::QLayer *previewLayer() { return mPreviewLayer; }
77  Qt3DRender::QLayer *castShadowsLayer() { return mCastShadowsLayer; }
79  Qt3DRender::QLayer *forwardRenderLayer() { return mForwardRenderLayer; }
80 
82  Qt3DRender::QCamera *mainCamera() { return mMainCamera; }
84  Qt3DRender::QCamera *lightCamera() { return mLightCamera; }
86  QgsPostprocessingEntity *postprocessingEntity() { return mPostprocessingEntity; }
88  Qt3DCore::QEntity *rootEntity() { return mRootEntity; }
89 
91  Qt3DRender::QRenderCapture *renderCapture() { return mRenderCapture; }
92 
94  Qt3DRender::QRenderCapture *depthRenderCapture() { return mDepthRenderCapture; }
95 
96 
98  bool frustumCullingEnabled() const { return mFrustumCullingEnabled; }
100  void setFrustumCullingEnabled( bool enabled );
101 
103  bool shadowRenderingEnabled() const { return mShadowRenderingEnabled; }
105  void setShadowRenderingEnabled( bool enabled );
106 
108  float shadowBias() const { return mShadowBias; }
110  void setShadowBias( float shadowBias );
111 
113  int shadowMapResolution() const { return mShadowMapResolution; }
115  void setShadowMapResolution( int resolution );
116 
118  void setClearColor( const QColor &clearColor );
120  QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
122  void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
124  void setupEyeDomeLighting( bool enabled, double strength, int distance );
126  void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
128  void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
130  void setSize( QSize s );
131 
136  void setRenderCaptureEnabled( bool enabled );
137 
142  bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
143  private:
144  Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
145  Qt3DRender::QViewport *mMainViewPort = nullptr;
146  bool mFrustumCullingEnabled = true;
147 
148  Qt3DRender::QCamera *mMainCamera = nullptr;
149  Qt3DRender::QCamera *mLightCamera = nullptr;
150 
151  // Forward rendering pass branch nodes:
152  Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
153  Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
154  Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
155  Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
156  Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
157  // Forward rendering pass texture related objects:
158  Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
159  Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
160 
161  // Shadow rendering pass branch nodes:
162  Qt3DRender::QCameraSelector *mLightCameraSelectorShadowPass = nullptr;
163  Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
164  Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
165  Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
166  Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
167  // Shadow rendering pass texture related objects:
168  Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
169 
170  // - The depth buffer render pass is made to copy the depth buffer into
171  // an RGB texture that can be captured into a QImage and sent to the CPU for
172  // calculating real 3D points from mouse coordinates (for zoom, rotation, drag..)
173  // Depth buffer render pass branch nodes:
174  Qt3DRender::QCameraSelector *mDepthRenderCameraSelector = nullptr;
175  Qt3DRender::QRenderStateSet *mDepthRenderStateSet = nullptr;;
176  Qt3DRender::QLayerFilter *mDepthRenderLayerFilter = nullptr;
177  Qt3DRender::QRenderTargetSelector *mDepthRenderCaptureTargetSelector = nullptr;
178  Qt3DRender::QRenderCapture *mDepthRenderCapture = nullptr;
179  // Depth buffer processing pass texture related objects:
180  Qt3DRender::QTexture2D *mDepthRenderCaptureDepthTexture = nullptr;
181  Qt3DRender::QTexture2D *mDepthRenderCaptureColorTexture = nullptr;
182 
183  // Post processing pass branch nodes:
184  Qt3DRender::QCameraSelector *mPostProcessingCameraSelector = nullptr;
185  Qt3DRender::QLayerFilter *mPostprocessPassLayerFilter = nullptr;
186  Qt3DRender::QClearBuffers *mPostprocessClearBuffers = nullptr;
187  Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
188  Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
189  // Post processing pass texture related objects:
190  Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
191  Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
192 
193  // Texture preview:
194  Qt3DRender::QLayerFilter *mPreviewLayerFilter = nullptr;
195  Qt3DRender::QRenderStateSet *mPreviewRenderStateSet = nullptr;
196  Qt3DRender::QDepthTest *mPreviewDepthTest = nullptr;
197  Qt3DRender::QCullFace *mPreviewCullFace = nullptr;
198 
199  bool mShadowRenderingEnabled = false;
200  float mShadowBias = 0.00001f;
201  int mShadowMapResolution = 2048;
202 
203  QSize mSize = QSize( 1024, 768 );
204 
205  bool mEyeDomeLightingEnabled = false;
206  double mEyeDomeLightingStrength = 1000.0;
207  int mEyeDomeLightingDistance = 1;
208 
209  QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
210  QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
211 
212  QEntity *mDepthRenderQuad = nullptr;
213 
214  QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
215 
216  Qt3DCore::QEntity *mRootEntity = nullptr;
217 
218  Qt3DRender::QLayer *mPostprocessPassLayer = nullptr;
219  Qt3DRender::QLayer *mPreviewLayer = nullptr;
220  Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
221  Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
222  Qt3DRender::QLayer *mDepthRenderPassLayer = nullptr;
223 
224  QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
225 
226  QVector<QgsPreviewQuad *> mPreviewQuads;
227 
228  Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
229  Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
230  Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
231  Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
232  Qt3DRender::QFrameGraphNode *constructDepthRenderPass();
233 
234  Qt3DCore::QEntity *constructDepthRenderQuad();
235 
236  bool mRenderCaptureEnabled = true;
237 
238  Q_DISABLE_COPY( QgsShadowRenderingFrameGraph )
239 };
240 
241 #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.
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 ...
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.