QGIS API Documentation  3.16.0-Hannover (43b64b13f3)
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 
57 {
58  public:
60  QgsShadowRenderingFrameGraph( QWindow *window, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root );
61 
63  Qt3DRender::QFrameGraphNode *getFrameGraphRoot() { 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  void 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 );
119  private:
120  Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
121  Qt3DRender::QViewport *mMainViewPort = nullptr;
122  Qt3DRender::QCameraSelector *mMainCameraSelector = nullptr;
123  Qt3DRender::QLayerFilter *mForwardRenderLayerFilter = nullptr;
124  Qt3DRender::QRenderTargetSelector *mForwardRenderTargetSelector = nullptr;
125  Qt3DRender::QRenderTarget *mForwardRenderTarget = nullptr;
126  Qt3DRender::QRenderTargetOutput *mForwardRenderTargetColorOutput = nullptr;
127  Qt3DRender::QRenderTargetOutput *mForwardRenderTargetDepthOutput = nullptr;
128  Qt3DRender::QTexture2D *mForwardColorTexture = nullptr;
129  Qt3DRender::QTexture2D *mForwardDepthTexture = nullptr;
130  Qt3DRender::QClearBuffers *mForwardClearBuffers = nullptr;
131  Qt3DRender::QFrustumCulling *mFrustumCulling = nullptr;
132  bool mFrustumCullingEnabled = true;
133 
134  Qt3DRender::QCamera *mMainCamera = nullptr;
135  Qt3DRender::QLayerFilter *mPostprocessPassLayerFilter = nullptr;
136  Qt3DRender::QClearBuffers *mPostprocessClearBuffers = nullptr;
137 
138  // texture preview
139  Qt3DRender::QLayerFilter *mPreviewLayerFilter = nullptr;
140  Qt3DRender::QRenderStateSet *mPreviewRenderStateSet = nullptr;
141  Qt3DRender::QDepthTest *mPreviewDepthTest = nullptr;
142  Qt3DRender::QCullFace *mPreviewCullFace = nullptr;
143 
144  // shadow rendering pass
145  Qt3DRender::QRenderTargetSelector *mShadowRenderTargetSelector = nullptr;
146  Qt3DRender::QRenderTarget *mShadowRenderTarget = nullptr;
147  Qt3DRender::QRenderTargetOutput *mShadowRenderTargetOutput = nullptr;
148  Qt3DRender::QTexture2D *mShadowMapTexture = nullptr;
149  Qt3DRender::QClearBuffers *mShadowClearBuffers = nullptr;
150  Qt3DRender::QCamera *mLightCamera = nullptr;
151  Qt3DRender::QCameraSelector *mLightCameraSelector = nullptr;
152  bool mShadowRenderingEnabled = false;
153  float mShadowBias = 0.00001f;
154  int mShadowMapResolution = 2048;
155 
156  Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
157  Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
158  Qt3DRender::QCullFace *mShadowCullFace = nullptr;
159  Qt3DRender::QDepthTest *mShadowDepthTest = nullptr;
160 
161  Qt3DRender::QRenderCapture *mRenderCapture = nullptr;
162 
163  QVector3D mLightDirection = QVector3D( 0.0, -1.0f, 0.0f );
164 
165  Qt3DCore::QEntity *mRootEntity = nullptr;
166 
167  Qt3DRender::QLayer *mPostprocessPassLayer = nullptr;
168  Qt3DRender::QLayer *mPreviewLayer = nullptr;
169  Qt3DRender::QLayer *mForwardRenderLayer = nullptr;
170  Qt3DRender::QLayer *mCastShadowsLayer = nullptr;
171 
172  QgsPostprocessingEntity *mPostprocessingEntity = nullptr;
173 
174  QVector<QgsPreviewQuad *> mPreviewQuads;
175 
176  Qt3DRender::QFrameGraphNode *constructShadowRenderPass();
177  Qt3DRender::QFrameGraphNode *constructForwardRenderPass();
178  Qt3DRender::QFrameGraphNode *constructTexturesPreviewPass();
179  Qt3DRender::QFrameGraphNode *constructPostprocessingPass();
180 
181  Q_DISABLE_COPY( QgsShadowRenderingFrameGraph )
182 };
183 
184 #endif // QGSSHADOWRENDERINGFRAMEGRAPH_H
QgsShadowRenderingFrameGraph::setShadowBias
void setShadowBias(float shadowBias)
Sets the shadow bias value.
Definition: qgsshadowrenderingframegraph.cpp:321
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:88
QgsShadowRenderingFrameGraph::QgsShadowRenderingFrameGraph
QgsShadowRenderingFrameGraph(QWindow *window, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
Definition: qgsshadowrenderingframegraph.cpp:146
QgsShadowRenderingFrameGraph::castShadowsLayer
Qt3DRender::QLayer * castShadowsLayer()
Returns a layer object used to indicate that an entity will cast shadows.
Definition: qgsshadowrenderingframegraph.h:77
QgsShadowRenderingFrameGraph::shadowMapTexture
Qt3DRender::QTexture2D * shadowMapTexture()
Returns the shadow map (a depth texture for the shadow rendering pass)
Definition: qgsshadowrenderingframegraph.h:70
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:73
QgsShadowRenderingFrameGraph::addTexturePreviewOverlay
void 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:197
QgsShadowRenderingFrameGraph::forwardRenderDepthTexture
Qt3DRender::QTexture2D * forwardRenderDepthTexture()
Returns the depth texture of the forward rendering pass.
Definition: qgsshadowrenderingframegraph.h:68
QgsShadowRenderingFrameGraph::shadowBias
float shadowBias() const
Returns the shadow bias value.
Definition: qgsshadowrenderingframegraph.h:104
QgsRectangle
A rectangle specified with double values.
Definition: qgsrectangle.h:42
QgsShadowRenderingFrameGraph
3 Container class that holds different objects related to shadow rendering
Definition: qgsshadowrenderingframegraph.h:57
QgsShadowRenderingFrameGraph::mainCamera
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Definition: qgsshadowrenderingframegraph.h:82
qgspointlightsettings.h
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:79
QgsShadowRenderingFrameGraph::renderCapture
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
Definition: qgsshadowrenderingframegraph.h:91
QgsShadowRenderingFrameGraph::frustumCullingEnabled
bool frustumCullingEnabled() const
Returns whether frustum culling is enabled.
Definition: qgsshadowrenderingframegraph.h:94
QgsShadowRenderingFrameGraph::postprocessingEntity
QgsPostprocessingEntity * postprocessingEntity()
Returns the postprocessing entity.
Definition: qgsshadowrenderingframegraph.h:86
QgsShadowRenderingFrameGraph::forwardRenderColorTexture
Qt3DRender::QTexture2D * forwardRenderColorTexture()
Returns the color texture of the forward rendering pass.
Definition: qgsshadowrenderingframegraph.h:66
QgsShadowRenderingFrameGraph::setFrustumCullingEnabled
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Definition: qgsshadowrenderingframegraph.cpp:334
QgsShadowRenderingFrameGraph::getFrameGraphRoot
Qt3DRender::QFrameGraphNode * getFrameGraphRoot()
Returns the root of the frame graph object.
Definition: qgsshadowrenderingframegraph.h:63
QgsShadowRenderingFrameGraph::shadowRenderingEnabled
bool shadowRenderingEnabled() const
Returns whether shadow rendering is enabled.
Definition: qgsshadowrenderingframegraph.h:99
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:75
QgsShadowRenderingFrameGraph::setupDirectionalLight
void setupDirectionalLight(const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance)
Sets shadow rendering to use a directional light.
Definition: qgsshadowrenderingframegraph.cpp:279
QgsCameraController
3 Object that controls camera movement based on user input
Definition: qgscameracontroller.h:60
QgsShadowRenderingFrameGraph::lightCamera
Qt3DRender::QCamera * lightCamera()
Returns the light camera.
Definition: qgsshadowrenderingframegraph.h:84
QgsShadowRenderingFrameGraph::setClearColor
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
Definition: qgsshadowrenderingframegraph.cpp:306
QgsPostprocessingEntity
3 An entity that is responsible for applying post processing effect Now it is used to make shadows
Definition: qgspostprocessingentity.h:39
QgsShadowRenderingFrameGraph::setShadowRenderingEnabled
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
Definition: qgsshadowrenderingframegraph.cpp:311
QgsShadowRenderingFrameGraph::shadowMapResolution
int shadowMapResolution() const
Returns the shadow map resolution.
Definition: qgsshadowrenderingframegraph.h:109
QgsPreviewQuad
3 Rectangular quad entity used for debugging depth maps
Definition: qgspreviewquad.h:52
QgsShadowRenderingFrameGraph::setShadowMapResolution
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
Definition: qgsshadowrenderingframegraph.cpp:327
QgsDirectionalLightSettings
3 Definition of a directional light in a 3D map scene
Definition: qgsdirectionallightsettings.h:33