QGIS API Documentation  3.18.1-Zürich (202f1bf7e5)
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  bool frustumCullingEnabled() const { return mFrustumCullingEnabled; }
96  void setFrustumCullingEnabled( bool enabled );
97 
99  bool shadowRenderingEnabled() const { return mShadowRenderingEnabled; }
101  void setShadowRenderingEnabled( bool enabled );
102 
104  float shadowBias() const { return mShadowBias; }
106  void setShadowBias( float shadowBias );
107 
109  int shadowMapResolution() const { return mShadowMapResolution; }
111  void setShadowMapResolution( int resolution );
112 
114  void setClearColor( const QColor &clearColor );
116  QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
118  void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
120  void setupEyeDomeLighting( bool enabled, double strength, int distance );
122  void setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size );
124  void setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size );
126  void setSize( QSize s );
127 
132  void setRenderCaptureEnabled( bool enabled );
133 
138  bool renderCaptureEnabled() const { return mRenderCaptureEnabled; }
139  private:
140  Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
141  Qt3DRender::QViewport *mMainViewPort = nullptr;
142  Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
143  Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
144  Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
145  Qt3DRender::QRenderTarget *mForwardRenderTarget = nullptr;
146  Qt3DRender::QRenderTargetOutput *mForwardRenderTargetColorOutput = nullptr;
147  Qt3DRender::QRenderTargetOutput *mForwardRenderTargetDepthOutput = nullptr;
148  Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
149  Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
150  Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
151  Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
152  bool mFrustumCullingEnabled = true;
153 
154  Qt3DRender::QCamera *mMainCamera = nullptr;
155  Qt3DRender::QLayerFilter *mPostprocessPassLayerFilter = nullptr;
156  Qt3DRender::QClearBuffers *mPostprocessClearBuffers = nullptr;
157 
158  // texture preview
159  Qt3DRender::QLayerFilter *mPreviewLayerFilter = nullptr;
160  Qt3DRender::QRenderStateSet *mPreviewRenderStateSet = nullptr;
161  Qt3DRender::QDepthTest *mPreviewDepthTest = nullptr;
162  Qt3DRender::QCullFace *mPreviewCullFace = nullptr;
163 
164  // shadow rendering pass
165  Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
166  Qt3DRender::QRenderTarget *mShadowRenderTarget = nullptr;
167  Qt3DRender::QRenderTargetOutput *mShadowRenderTargetOutput = nullptr;
168  Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
169  Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
170  Qt3DRender::QCamera *mLightCamera = nullptr;
171  Qt3DRender::QCameraSelector *mLightCameraSelector = nullptr;
172 
173  Qt3DRender::QRenderTargetSelector *mRenderCaptureTargetSelector = nullptr;
174  Qt3DRender::QTexture2D *mRenderCaptureColorTexture = nullptr;
175  Qt3DRender::QTexture2D *mRenderCaptureDepthTexture = nullptr;
176 
177  bool mShadowRenderingEnabled = false;
178  float mShadowBias = 0.00001f;
179  int mShadowMapResolution = 2048;
180 
181  QSize mSize = QSize( 1024, 768 );
182 
183  bool mEyeDomeLightingEnabled = false;
184  double mEyeDomeLightingStrength = 1000.0;
185  int mEyeDomeLightingDistance = 1;
186 
187  QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
188  QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;
189 
190  Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
191  Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
192  Qt3DRender::QCullFace *mShadowCullFace = nullptr;
193  Qt3DRender::QDepthTest *mShadowDepthTest = nullptr;
194 
195  Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
196 
197  QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
198 
199  Qt3DCore::QEntity *mRootEntity = nullptr;
200 
201  Qt3DRender::QLayer *mPostprocessPassLayer = nullptr;
202  Qt3DRender::QLayer *mPreviewLayer = nullptr;
203  Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
204  Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
205 
206  QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
207 
208  QVector<QgsPreviewQuad *> mPreviewQuads;
209 
210  Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
211  Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
212  Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
213  Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
214 
215  bool mRenderCaptureEnabled = true;
216 
217  Q_DISABLE_COPY( QgsShadowRenderingFrameGraph )
218 };
219 
220 #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.
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.