QGIS API Documentation 3.30.0-'s-Hertogenbosch (f186b8efe0)
qgsshadowrenderingframegraph.cpp
Go to the documentation of this file.
1/***************************************************************************
2 qgsshadowrenderingframegraph.cpp
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
19#include "qgspreviewquad.h"
20#include "qgs3dutils.h"
23
24#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
25#include <Qt3DRender/QAttribute>
26#include <Qt3DRender/QBuffer>
27#include <Qt3DRender/QGeometry>
28
29typedef Qt3DRender::QAttribute Qt3DQAttribute;
30typedef Qt3DRender::QBuffer Qt3DQBuffer;
31typedef Qt3DRender::QGeometry Qt3DQGeometry;
32#else
33#include <Qt3DCore/QAttribute>
34#include <Qt3DCore/QBuffer>
35#include <Qt3DCore/QGeometry>
36
37typedef Qt3DCore::QAttribute Qt3DQAttribute;
38typedef Qt3DCore::QBuffer Qt3DQBuffer;
39typedef Qt3DCore::QGeometry Qt3DQGeometry;
40#endif
41
42#include <Qt3DRender/QGeometryRenderer>
43#include <Qt3DRender/QTechnique>
44#include <Qt3DRender/QGraphicsApiFilter>
45#include <Qt3DRender/QBlendEquation>
46#include <Qt3DRender/QSortPolicy>
47#include <Qt3DRender/QNoDepthMask>
48#include <Qt3DRender/QBlendEquationArguments>
49
50Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructTexturesPreviewPass()
51{
52 mPreviewLayerFilter = new Qt3DRender::QLayerFilter;
53 mPreviewLayerFilter->addLayer( mPreviewLayer );
54
55 mPreviewRenderStateSet = new Qt3DRender::QRenderStateSet( mPreviewLayerFilter );
56 mPreviewDepthTest = new Qt3DRender::QDepthTest;
57 mPreviewDepthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
58 mPreviewRenderStateSet->addRenderState( mPreviewDepthTest );
59 mPreviewCullFace = new Qt3DRender::QCullFace;
60 mPreviewCullFace->setMode( Qt3DRender::QCullFace::NoCulling );
61 mPreviewRenderStateSet->addRenderState( mPreviewCullFace );
62
63 return mPreviewLayerFilter;
64}
65
66Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructForwardRenderPass()
67{
68 // The branch structure:
69 // mMainCameraSelector
70 // mForwardRenderLayerFilter
71 // mForwardRenderTargetSelector
72 // opaqueObjectsFilter | transparentObjectsLayerFilter
73 // forwaredRenderStateSet | sortPolicy
74 // mFrustumCulling | transparentObjectsRenderStateSet
75 // mForwardClearBuffers |
76 // mDebugOverlay |
77 mMainCameraSelector = new Qt3DRender::QCameraSelector;
78 mMainCameraSelector->setCamera( mMainCamera );
79
80 mForwardRenderLayerFilter = new Qt3DRender::QLayerFilter( mMainCameraSelector );
81 mForwardRenderLayerFilter->addLayer( mForwardRenderLayer );
82
83 mForwardColorTexture = new Qt3DRender::QTexture2D;
84 mForwardColorTexture->setWidth( mSize.width() );
85 mForwardColorTexture->setHeight( mSize.height() );
86 mForwardColorTexture->setFormat( Qt3DRender::QAbstractTexture::RGB8_UNorm );
87 mForwardColorTexture->setGenerateMipMaps( false );
88 mForwardColorTexture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
89 mForwardColorTexture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
90 mForwardColorTexture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::ClampToEdge );
91 mForwardColorTexture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::ClampToEdge );
92
93 mForwardDepthTexture = new Qt3DRender::QTexture2D;
94 mForwardDepthTexture->setWidth( mSize.width() );
95 mForwardDepthTexture->setHeight( mSize.height() );
96 mForwardDepthTexture->setFormat( Qt3DRender::QTexture2D::TextureFormat::DepthFormat );
97 mForwardDepthTexture->setGenerateMipMaps( false );
98 mForwardDepthTexture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
99 mForwardDepthTexture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
100 mForwardDepthTexture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::ClampToEdge );
101 mForwardDepthTexture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::ClampToEdge );
102
103 Qt3DRender::QRenderTarget *forwardRenderTarget = new Qt3DRender::QRenderTarget;
104 Qt3DRender::QRenderTargetOutput *forwardRenderTargetDepthOutput = new Qt3DRender::QRenderTargetOutput;
105 forwardRenderTargetDepthOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Depth );
106 forwardRenderTargetDepthOutput->setTexture( mForwardDepthTexture );
107 forwardRenderTarget->addOutput( forwardRenderTargetDepthOutput );
108 Qt3DRender::QRenderTargetOutput *forwardRenderTargetColorOutput = new Qt3DRender::QRenderTargetOutput;
109 forwardRenderTargetColorOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
110 forwardRenderTargetColorOutput->setTexture( mForwardColorTexture );
111 forwardRenderTarget->addOutput( forwardRenderTargetColorOutput );
112
113 mForwardRenderTargetSelector = new Qt3DRender::QRenderTargetSelector( mForwardRenderLayerFilter );
114 mForwardRenderTargetSelector->setTarget( forwardRenderTarget );
115
116 Qt3DRender::QLayerFilter *opaqueObjectsFilter = new Qt3DRender::QLayerFilter( mForwardRenderTargetSelector );
117 opaqueObjectsFilter->addLayer( mTransparentObjectsPassLayer );
118 opaqueObjectsFilter->setFilterMode( Qt3DRender::QLayerFilter::DiscardAnyMatchingLayers );
119
120 Qt3DRender::QRenderStateSet *forwaredRenderStateSet = new Qt3DRender::QRenderStateSet( opaqueObjectsFilter );
121
122 Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest;
123 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Less );
124 forwaredRenderStateSet->addRenderState( depthTest );
125
126 Qt3DRender::QCullFace *cullFace = new Qt3DRender::QCullFace;
127 cullFace->setMode( Qt3DRender::QCullFace::CullingMode::Back );
128 forwaredRenderStateSet->addRenderState( cullFace );
129
130 mFrustumCulling = new Qt3DRender::QFrustumCulling( forwaredRenderStateSet );
131
132 mForwardClearBuffers = new Qt3DRender::QClearBuffers( mFrustumCulling );
133 mForwardClearBuffers->setClearColor( QColor::fromRgbF( 0.0, 0.0, 1.0, 1.0 ) );
134 mForwardClearBuffers->setBuffers( Qt3DRender::QClearBuffers::ColorDepthBuffer );
135 mForwardClearBuffers->setClearDepthValue( 1.0f );
136
137 Qt3DRender::QLayerFilter *transparentObjectsLayerFilter = new Qt3DRender::QLayerFilter( mForwardRenderTargetSelector );
138 transparentObjectsLayerFilter->addLayer( mTransparentObjectsPassLayer );
139 transparentObjectsLayerFilter->setFilterMode( Qt3DRender::QLayerFilter::AcceptAnyMatchingLayers );
140
141 Qt3DRender::QSortPolicy *sortPolicy = new Qt3DRender::QSortPolicy( transparentObjectsLayerFilter );
142 QVector<Qt3DRender::QSortPolicy::SortType> sortTypes;
143 sortTypes.push_back( Qt3DRender::QSortPolicy::BackToFront );
144 sortPolicy->setSortTypes( sortTypes );
145
146 Qt3DRender::QRenderStateSet *transparentObjectsRenderStateSet = new Qt3DRender::QRenderStateSet( sortPolicy );
147 {
148 Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest;
149 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Less );
150 transparentObjectsRenderStateSet->addRenderState( depthTest );
151
152 Qt3DRender::QNoDepthMask *noDepthMask = new Qt3DRender::QNoDepthMask;
153 transparentObjectsRenderStateSet->addRenderState( noDepthMask );
154
155 Qt3DRender::QCullFace *cullFace = new Qt3DRender::QCullFace;
156 cullFace->setMode( Qt3DRender::QCullFace::CullingMode::NoCulling );
157 transparentObjectsRenderStateSet->addRenderState( cullFace );
158
159 Qt3DRender::QBlendEquation *blendEquation = new Qt3DRender::QBlendEquation;
160 blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
161 transparentObjectsRenderStateSet->addRenderState( blendEquation );
162
163 Qt3DRender::QBlendEquationArguments *blenEquationArgs = new Qt3DRender::QBlendEquationArguments;
164 blenEquationArgs->setSourceRgb( Qt3DRender::QBlendEquationArguments::Blending::One );
165 blenEquationArgs->setDestinationRgb( Qt3DRender::QBlendEquationArguments::Blending::OneMinusSource1Alpha );
166 blenEquationArgs->setSourceAlpha( Qt3DRender::QBlendEquationArguments::Blending::One );
167 blenEquationArgs->setDestinationAlpha( Qt3DRender::QBlendEquationArguments::Blending::OneMinusSource1Alpha );
168 transparentObjectsRenderStateSet->addRenderState( blenEquationArgs );
169 }
170
171#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
172 mDebugOverlay = new Qt3DRender::QDebugOverlay( mForwardClearBuffers );
173 mDebugOverlay->setEnabled( false );
174#endif
175
176 // cppcheck wrongly believes transparentObjectsRenderStateSet will leak
177 // cppcheck-suppress memleak
178 return mMainCameraSelector;
179}
180
181Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructShadowRenderPass()
182{
183 mLightCameraSelectorShadowPass = new Qt3DRender::QCameraSelector;
184 mLightCameraSelectorShadowPass->setCamera( mLightCamera );
185
186 mShadowSceneEntitiesFilter = new Qt3DRender::QLayerFilter( mLightCameraSelectorShadowPass );
187 mShadowSceneEntitiesFilter->addLayer( mCastShadowsLayer );
188
189 mShadowMapTexture = new Qt3DRender::QTexture2D;
190 mShadowMapTexture->setWidth( mShadowMapResolution );
191 mShadowMapTexture->setHeight( mShadowMapResolution );
192 mShadowMapTexture->setFormat( Qt3DRender::QTexture2D::TextureFormat::DepthFormat );
193 mShadowMapTexture->setGenerateMipMaps( false );
194 mShadowMapTexture->setMagnificationFilter( Qt3DRender::QTexture2D::Linear );
195 mShadowMapTexture->setMinificationFilter( Qt3DRender::QTexture2D::Linear );
196 mShadowMapTexture->wrapMode()->setX( Qt3DRender::QTextureWrapMode::ClampToEdge );
197 mShadowMapTexture->wrapMode()->setY( Qt3DRender::QTextureWrapMode::ClampToEdge );
198
199 Qt3DRender::QRenderTarget *shadowRenderTarget = new Qt3DRender::QRenderTarget;
200 Qt3DRender::QRenderTargetOutput *shadowRenderTargetOutput = new Qt3DRender::QRenderTargetOutput;
201 shadowRenderTargetOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Depth );
202 shadowRenderTargetOutput->setTexture( mShadowMapTexture );
203 shadowRenderTarget->addOutput( shadowRenderTargetOutput );
204
205 mShadowRenderTargetSelector = new Qt3DRender::QRenderTargetSelector( mShadowSceneEntitiesFilter );
206 mShadowRenderTargetSelector->setTarget( shadowRenderTarget );
207
208 mShadowClearBuffers = new Qt3DRender::QClearBuffers( mShadowRenderTargetSelector );
209 mShadowClearBuffers->setBuffers( Qt3DRender::QClearBuffers::BufferType::ColorDepthBuffer );
210 mShadowClearBuffers->setClearColor( QColor::fromRgbF( 0.0f, 1.0f, 0.0f ) );
211
212 mShadowRenderStateSet = new Qt3DRender::QRenderStateSet( mShadowClearBuffers );
213
214 Qt3DRender::QDepthTest *shadowDepthTest = new Qt3DRender::QDepthTest;
215 shadowDepthTest->setDepthFunction( Qt3DRender::QDepthTest::Less );
216 mShadowRenderStateSet->addRenderState( shadowDepthTest );
217
218 Qt3DRender::QCullFace *shadowCullFace = new Qt3DRender::QCullFace;
219 shadowCullFace->setMode( Qt3DRender::QCullFace::CullingMode::Front );
220 mShadowRenderStateSet->addRenderState( shadowCullFace );
221
222 Qt3DRender::QPolygonOffset *polygonOffset = new Qt3DRender::QPolygonOffset;
223 polygonOffset->setDepthSteps( 4.0 );
224 polygonOffset->setScaleFactor( 1.1 );
225 mShadowRenderStateSet->addRenderState( polygonOffset );
226
227 return mLightCameraSelectorShadowPass;
228}
229
230Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructPostprocessingPass()
231{
232 mPostProcessingCameraSelector = new Qt3DRender::QCameraSelector;
233 mPostProcessingCameraSelector->setCamera( mLightCamera );
234
235 mPostprocessPassLayerFilter = new Qt3DRender::QLayerFilter( mPostProcessingCameraSelector );
236
237 mPostprocessClearBuffers = new Qt3DRender::QClearBuffers( mPostprocessPassLayerFilter );
238
239 mRenderCaptureTargetSelector = new Qt3DRender::QRenderTargetSelector( mPostprocessClearBuffers );
240
241 Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget( mRenderCaptureTargetSelector );
242
243 // The lifetime of the objects created here is managed
244 // automatically, as they become children of this object.
245
246 // Create a render target output for rendering color.
247 Qt3DRender::QRenderTargetOutput *colorOutput = new Qt3DRender::QRenderTargetOutput( renderTarget );
248 colorOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
249
250 // Create a texture to render into.
251 mRenderCaptureColorTexture = new Qt3DRender::QTexture2D( colorOutput );
252 mRenderCaptureColorTexture->setSize( mSize.width(), mSize.height() );
253 mRenderCaptureColorTexture->setFormat( Qt3DRender::QAbstractTexture::RGB8_UNorm );
254 mRenderCaptureColorTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
255 mRenderCaptureColorTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
256
257 // Hook the texture up to our output, and the output up to this object.
258 colorOutput->setTexture( mRenderCaptureColorTexture );
259 renderTarget->addOutput( colorOutput );
260
261 Qt3DRender::QRenderTargetOutput *depthOutput = new Qt3DRender::QRenderTargetOutput( renderTarget );
262
263 depthOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Depth );
264 mRenderCaptureDepthTexture = new Qt3DRender::QTexture2D( depthOutput );
265 mRenderCaptureDepthTexture->setSize( mSize.width(), mSize.height() );
266 mRenderCaptureDepthTexture->setFormat( Qt3DRender::QAbstractTexture::DepthFormat );
267 mRenderCaptureDepthTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
268 mRenderCaptureDepthTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
269 mRenderCaptureDepthTexture->setComparisonFunction( Qt3DRender::QAbstractTexture::CompareLessEqual );
270 mRenderCaptureDepthTexture->setComparisonMode( Qt3DRender::QAbstractTexture::CompareRefToTexture );
271
272 depthOutput->setTexture( mRenderCaptureDepthTexture );
273 renderTarget->addOutput( depthOutput );
274
275 mRenderCaptureTargetSelector->setTarget( renderTarget );
276
277 mRenderCapture = new Qt3DRender::QRenderCapture( mRenderCaptureTargetSelector );
278
279 mPostprocessingEntity = new QgsPostprocessingEntity( this, mRootEntity );
280 mPostprocessPassLayerFilter->addLayer( mPostprocessingEntity->layer() );
281
282 return mPostProcessingCameraSelector;
283}
284
285Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructAmbientOcclusionRenderPass()
286{
287 mAmbientOcclusionRenderCameraSelector = new Qt3DRender::QCameraSelector;
288 mAmbientOcclusionRenderCameraSelector->setCamera( mMainCamera );
289
290 mAmbientOcclusionRenderStateSet = new Qt3DRender::QRenderStateSet( mAmbientOcclusionRenderCameraSelector );
291
292 Qt3DRender::QDepthTest *depthRenderDepthTest = new Qt3DRender::QDepthTest;
293 depthRenderDepthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );;
294 Qt3DRender::QCullFace *depthRenderCullFace = new Qt3DRender::QCullFace;
295 depthRenderCullFace->setMode( Qt3DRender::QCullFace::NoCulling );
296
297 mAmbientOcclusionRenderStateSet->addRenderState( depthRenderDepthTest );
298 mAmbientOcclusionRenderStateSet->addRenderState( depthRenderCullFace );
299
300 mAmbientOcclusionRenderLayerFilter = new Qt3DRender::QLayerFilter( mAmbientOcclusionRenderStateSet );
301
302 mAmbientOcclusionRenderCaptureTargetSelector = new Qt3DRender::QRenderTargetSelector( mAmbientOcclusionRenderLayerFilter );
303 Qt3DRender::QRenderTarget *depthRenderTarget = new Qt3DRender::QRenderTarget( mAmbientOcclusionRenderCaptureTargetSelector );
304
305 // The lifetime of the objects created here is managed
306 // automatically, as they become children of this object.
307
308 // Create a render target output for rendering color.
309 Qt3DRender::QRenderTargetOutput *colorOutput = new Qt3DRender::QRenderTargetOutput( depthRenderTarget );
310 colorOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
311
312 // Create a texture to render into.
313 mAmbientOcclusionRenderTexture = new Qt3DRender::QTexture2D( colorOutput );
314 mAmbientOcclusionRenderTexture->setSize( mSize.width(), mSize.height() );
315 mAmbientOcclusionRenderTexture->setFormat( Qt3DRender::QAbstractTexture::R32F );
316 mAmbientOcclusionRenderTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
317 mAmbientOcclusionRenderTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
318
319 // Hook the texture up to our output, and the output up to this object.
320 colorOutput->setTexture( mAmbientOcclusionRenderTexture );
321 depthRenderTarget->addOutput( colorOutput );
322
323 mAmbientOcclusionRenderCaptureTargetSelector->setTarget( depthRenderTarget );
324
325 mAmbientOcclusionRenderEntity = new QgsAmbientOcclusionRenderEntity( mForwardDepthTexture, mMainCamera, mRootEntity );
326 mAmbientOcclusionRenderLayerFilter->addLayer( mAmbientOcclusionRenderEntity->layer() );
327
328 return mAmbientOcclusionRenderCameraSelector;
329}
330
331Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructAmbientOcclusionBlurPass()
332{
333 mAmbientOcclusionBlurCameraSelector = new Qt3DRender::QCameraSelector;
334 mAmbientOcclusionBlurCameraSelector->setCamera( mMainCamera );
335
336 mAmbientOcclusionBlurStateSet = new Qt3DRender::QRenderStateSet( mAmbientOcclusionBlurCameraSelector );
337
338 Qt3DRender::QDepthTest *depthRenderDepthTest = new Qt3DRender::QDepthTest;
339 depthRenderDepthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );;
340 Qt3DRender::QCullFace *depthRenderCullFace = new Qt3DRender::QCullFace;
341 depthRenderCullFace->setMode( Qt3DRender::QCullFace::NoCulling );
342
343 mAmbientOcclusionBlurStateSet->addRenderState( depthRenderDepthTest );
344 mAmbientOcclusionBlurStateSet->addRenderState( depthRenderCullFace );
345
346 mAmbientOcclusionBlurLayerFilter = new Qt3DRender::QLayerFilter( mAmbientOcclusionBlurStateSet );
347
348 mAmbientOcclusionBlurRenderCaptureTargetSelector = new Qt3DRender::QRenderTargetSelector( mAmbientOcclusionBlurLayerFilter );
349 Qt3DRender::QRenderTarget *depthRenderTarget = new Qt3DRender::QRenderTarget( mAmbientOcclusionBlurRenderCaptureTargetSelector );
350
351 // The lifetime of the objects created here is managed
352 // automatically, as they become children of this object.
353
354 // Create a render target output for rendering color.
355 Qt3DRender::QRenderTargetOutput *colorOutput = new Qt3DRender::QRenderTargetOutput( depthRenderTarget );
356 colorOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
357
358 // Create a texture to render into.
359 mAmbientOcclusionBlurTexture = new Qt3DRender::QTexture2D( colorOutput );
360 mAmbientOcclusionBlurTexture->setSize( mSize.width(), mSize.height() );
361 mAmbientOcclusionBlurTexture->setFormat( Qt3DRender::QAbstractTexture::R32F );
362 mAmbientOcclusionBlurTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
363 mAmbientOcclusionBlurTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
364
365 // Hook the texture up to our output, and the output up to this object.
366 colorOutput->setTexture( mAmbientOcclusionBlurTexture );
367 depthRenderTarget->addOutput( colorOutput );
368
369 mAmbientOcclusionBlurRenderCaptureTargetSelector->setTarget( depthRenderTarget );
370
371 mAmbientOcclusionBlurEntity = new QgsAmbientOcclusionBlurEntity( mAmbientOcclusionRenderTexture, mRootEntity );
372 mAmbientOcclusionBlurLayerFilter->addLayer( mAmbientOcclusionBlurEntity->layer() );
373
374 return mAmbientOcclusionBlurCameraSelector;
375}
376
377
378
379Qt3DRender::QFrameGraphNode *QgsShadowRenderingFrameGraph::constructDepthRenderPass()
380{
381 // depth buffer render to copy pass
382
383 mDepthRenderCameraSelector = new Qt3DRender::QCameraSelector;
384 mDepthRenderCameraSelector->setCamera( mMainCamera );
385
386 mDepthRenderStateSet = new Qt3DRender::QRenderStateSet( mDepthRenderCameraSelector );
387
388 Qt3DRender::QDepthTest *depthRenderDepthTest = new Qt3DRender::QDepthTest;
389 depthRenderDepthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );;
390 Qt3DRender::QCullFace *depthRenderCullFace = new Qt3DRender::QCullFace;
391 depthRenderCullFace->setMode( Qt3DRender::QCullFace::NoCulling );
392
393 mDepthRenderStateSet->addRenderState( depthRenderDepthTest );
394 mDepthRenderStateSet->addRenderState( depthRenderCullFace );
395
396 mDepthRenderLayerFilter = new Qt3DRender::QLayerFilter( mDepthRenderStateSet );
397 mDepthRenderLayerFilter->addLayer( mDepthRenderPassLayer );
398
399 mDepthRenderCaptureTargetSelector = new Qt3DRender::QRenderTargetSelector( mDepthRenderLayerFilter );
400 Qt3DRender::QRenderTarget *depthRenderTarget = new Qt3DRender::QRenderTarget( mDepthRenderCaptureTargetSelector );
401
402 // The lifetime of the objects created here is managed
403 // automatically, as they become children of this object.
404
405 // Create a render target output for rendering color.
406 Qt3DRender::QRenderTargetOutput *colorOutput = new Qt3DRender::QRenderTargetOutput( depthRenderTarget );
407 colorOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
408
409 // Create a texture to render into.
410 mDepthRenderCaptureColorTexture = new Qt3DRender::QTexture2D( colorOutput );
411 mDepthRenderCaptureColorTexture->setSize( mSize.width(), mSize.height() );
412 mDepthRenderCaptureColorTexture->setFormat( Qt3DRender::QAbstractTexture::RGB8_UNorm );
413 mDepthRenderCaptureColorTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
414 mDepthRenderCaptureColorTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
415
416 // Hook the texture up to our output, and the output up to this object.
417 colorOutput->setTexture( mDepthRenderCaptureColorTexture );
418 depthRenderTarget->addOutput( colorOutput );
419
420 Qt3DRender::QRenderTargetOutput *depthOutput = new Qt3DRender::QRenderTargetOutput( depthRenderTarget );
421
422 depthOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Depth );
423 mDepthRenderCaptureDepthTexture = new Qt3DRender::QTexture2D( depthOutput );
424 mDepthRenderCaptureDepthTexture->setSize( mSize.width(), mSize.height() );
425 mDepthRenderCaptureDepthTexture->setFormat( Qt3DRender::QAbstractTexture::DepthFormat );
426 mDepthRenderCaptureDepthTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
427 mDepthRenderCaptureDepthTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
428 mDepthRenderCaptureDepthTexture->setComparisonFunction( Qt3DRender::QAbstractTexture::CompareLessEqual );
429 mDepthRenderCaptureDepthTexture->setComparisonMode( Qt3DRender::QAbstractTexture::CompareRefToTexture );
430
431 depthOutput->setTexture( mDepthRenderCaptureDepthTexture );
432 depthRenderTarget->addOutput( depthOutput );
433
434 mDepthRenderCaptureTargetSelector->setTarget( depthRenderTarget );
435
436 // Note: We do not a clear buffers node since we are drawing a quad that will override the buffer's content anyway
437 mDepthRenderCapture = new Qt3DRender::QRenderCapture( mDepthRenderCaptureTargetSelector );
438
439 return mDepthRenderCameraSelector;
440}
441
442Qt3DCore::QEntity *QgsShadowRenderingFrameGraph::constructDepthRenderQuad()
443{
444 Qt3DCore::QEntity *quad = new Qt3DCore::QEntity;
445 quad->setObjectName( "depthRenderQuad" );
446
447 Qt3DQGeometry *geom = new Qt3DQGeometry;
448 Qt3DQAttribute *positionAttribute = new Qt3DQAttribute;
449 const QVector<float> vert = { -1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, 1.0f, 1.0f };
450
451 const QByteArray vertexArr( ( const char * ) vert.constData(), vert.size() * sizeof( float ) );
452 Qt3DQBuffer *vertexBuffer = nullptr;
453 vertexBuffer = new Qt3DQBuffer( this );
454 vertexBuffer->setData( vertexArr );
455
456 positionAttribute->setName( Qt3DQAttribute::defaultPositionAttributeName() );
457 positionAttribute->setVertexBaseType( Qt3DQAttribute::Float );
458 positionAttribute->setVertexSize( 3 );
459 positionAttribute->setAttributeType( Qt3DQAttribute::VertexAttribute );
460 positionAttribute->setBuffer( vertexBuffer );
461 positionAttribute->setByteOffset( 0 );
462 positionAttribute->setByteStride( 3 * sizeof( float ) );
463 positionAttribute->setCount( 6 );
464
465 geom->addAttribute( positionAttribute );
466
467 Qt3DRender::QGeometryRenderer *renderer = new Qt3DRender::QGeometryRenderer;
468 renderer->setPrimitiveType( Qt3DRender::QGeometryRenderer::PrimitiveType::Triangles );
469 renderer->setGeometry( geom );
470
471 quad->addComponent( renderer );
472
473 QMatrix4x4 modelMatrix;
474 modelMatrix.setToIdentity();
475
476 // construct material
477
478 Qt3DRender::QMaterial *material = new Qt3DRender::QMaterial;
479 Qt3DRender::QParameter *textureParameter = new Qt3DRender::QParameter( "depthTexture", mForwardDepthTexture );
480 Qt3DRender::QParameter *textureTransformParameter = new Qt3DRender::QParameter( "modelMatrix", QVariant::fromValue( modelMatrix ) );
481 material->addParameter( textureParameter );
482 material->addParameter( textureTransformParameter );
483
484 Qt3DRender::QEffect *effect = new Qt3DRender::QEffect;
485
486 Qt3DRender::QTechnique *technique = new Qt3DRender::QTechnique;
487
488 Qt3DRender::QGraphicsApiFilter *graphicsApiFilter = technique->graphicsApiFilter();
489 graphicsApiFilter->setApi( Qt3DRender::QGraphicsApiFilter::Api::OpenGL );
490 graphicsApiFilter->setProfile( Qt3DRender::QGraphicsApiFilter::OpenGLProfile::CoreProfile );
491 graphicsApiFilter->setMajorVersion( 1 );
492 graphicsApiFilter->setMinorVersion( 5 );
493
494 Qt3DRender::QRenderPass *renderPass = new Qt3DRender::QRenderPass;
495
496 Qt3DRender::QShaderProgram *shader = new Qt3DRender::QShaderProgram;
497 shader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( "qrc:/shaders/depth_render.vert" ) ) );
498 shader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( "qrc:/shaders/depth_render.frag" ) ) );
499 renderPass->setShaderProgram( shader );
500
501 technique->addRenderPass( renderPass );
502
503 effect->addTechnique( technique );
504 material->setEffect( effect );
505
506 quad->addComponent( material );
507
508 return quad;
509}
510
511QgsShadowRenderingFrameGraph::QgsShadowRenderingFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root )
512 : Qt3DCore::QEntity( root )
513 , mSize( s )
514{
515 mRootEntity = root;
516 mMainCamera = mainCamera;
517 mLightCamera = new Qt3DRender::QCamera;
518
519 mPreviewLayer = new Qt3DRender::QLayer;
520 mCastShadowsLayer = new Qt3DRender::QLayer;
521 mForwardRenderLayer = new Qt3DRender::QLayer;
522 mDepthRenderPassLayer = new Qt3DRender::QLayer;
523 mTransparentObjectsPassLayer = new Qt3DRender::QLayer;
524
525 mPreviewLayer->setRecursive( true );
526 mCastShadowsLayer->setRecursive( true );
527 mForwardRenderLayer->setRecursive( true );
528 mDepthRenderPassLayer->setRecursive( true );
529 mTransparentObjectsPassLayer->setRecursive( true );
530
531 mRenderSurfaceSelector = new Qt3DRender::QRenderSurfaceSelector;
532
533 QObject *surfaceObj = dynamic_cast< QObject * >( surface );
534 Q_ASSERT( surfaceObj );
535
536 mRenderSurfaceSelector->setSurface( surfaceObj );
537 mRenderSurfaceSelector->setExternalRenderTargetSize( mSize );
538
539 mMainViewPort = new Qt3DRender::QViewport( mRenderSurfaceSelector );
540 mMainViewPort->setNormalizedRect( QRectF( 0.0f, 0.0f, 1.0f, 1.0f ) );
541
542 // Forward render
543 Qt3DRender::QFrameGraphNode *forwardRenderPass = constructForwardRenderPass();
544 forwardRenderPass->setParent( mMainViewPort );
545
546 // shadow rendering pass
547
548 Qt3DRender::QFrameGraphNode *shadowRenderPass = constructShadowRenderPass();
549 shadowRenderPass->setParent( mMainViewPort );
550
551 // depth buffer processing
552 Qt3DRender::QFrameGraphNode *depthBufferProcessingPass = constructDepthRenderPass();
553 depthBufferProcessingPass->setParent( mMainViewPort );
554
555 // Ambient occlusion factor render pass
556 Qt3DRender::QFrameGraphNode *ambientOcclusionFactorRender = constructAmbientOcclusionRenderPass();
557 ambientOcclusionFactorRender->setParent( mMainViewPort );
558
559 Qt3DRender::QFrameGraphNode *ambientOcclusionBlurPass = constructAmbientOcclusionBlurPass();
560 ambientOcclusionBlurPass->setParent( mMainViewPort );
561
562 // post process
563 Qt3DRender::QFrameGraphNode *postprocessingPass = constructPostprocessingPass();
564 postprocessingPass->setParent( mMainViewPort );
565
566 // textures preview pass
567 Qt3DRender::QFrameGraphNode *previewPass = constructTexturesPreviewPass();
568 previewPass->setParent( mMainViewPort );
569
570 Qt3DRender::QParameter *depthMapIsDepthParam = new Qt3DRender::QParameter( "isDepth", true );
571 Qt3DRender::QParameter *shadowMapIsDepthParam = new Qt3DRender::QParameter( "isDepth", true );
572
573 mDebugDepthMapPreviewQuad = this->addTexturePreviewOverlay( mForwardDepthTexture, QPointF( 0.9f, 0.9f ), QSizeF( 0.1, 0.1 ), QVector<Qt3DRender::QParameter *> { depthMapIsDepthParam } );
574 mDebugShadowMapPreviewQuad = this->addTexturePreviewOverlay( mShadowMapTexture, QPointF( 0.9f, 0.9f ), QSizeF( 0.1, 0.1 ), QVector<Qt3DRender::QParameter *> { shadowMapIsDepthParam } );
575 mDebugDepthMapPreviewQuad->setEnabled( false );
576 mDebugShadowMapPreviewQuad->setEnabled( false );
577
578 mDepthRenderQuad = constructDepthRenderQuad();
579 mDepthRenderQuad->addComponent( mDepthRenderPassLayer );
580 mDepthRenderQuad->setParent( mRootEntity );
581}
582
583QgsPreviewQuad *QgsShadowRenderingFrameGraph::addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerTexCoords, const QSizeF &sizeTexCoords, QVector<Qt3DRender::QParameter *> additionalShaderParameters )
584{
585 QgsPreviewQuad *previewQuad = new QgsPreviewQuad( texture, centerTexCoords, sizeTexCoords, additionalShaderParameters );
586 previewQuad->addComponent( mPreviewLayer );
587 previewQuad->setParent( mRootEntity );
588 mPreviewQuads.push_back( previewQuad );
589 return previewQuad;
590}
591
592// computes the portion of the Y=y plane the camera is looking at
593void calculateViewExtent( Qt3DRender::QCamera *camera, float shadowRenderingDistance, float y, float &minX, float &maxX, float &minY, float &maxY, float &minZ, float &maxZ )
594{
595 const QVector3D cameraPos = camera->position();
596 const QMatrix4x4 projectionMatrix = camera->projectionMatrix();
597 const QMatrix4x4 viewMatrix = camera->viewMatrix();
598 float depth = 1.0f;
599 QVector4D viewCenter = viewMatrix * QVector4D( camera->viewCenter(), 1.0f );
600 viewCenter /= viewCenter.w();
601 viewCenter = projectionMatrix * viewCenter;
602 viewCenter /= viewCenter.w();
603 depth = viewCenter.z();
604 QVector<QVector3D> viewFrustumPoints =
605 {
606 QVector3D( 0.0f, 0.0f, depth ),
607 QVector3D( 0.0f, 1.0f, depth ),
608 QVector3D( 1.0f, 0.0f, depth ),
609 QVector3D( 1.0f, 1.0f, depth ),
610 QVector3D( 0.0f, 0.0f, 0 ),
611 QVector3D( 0.0f, 1.0f, 0 ),
612 QVector3D( 1.0f, 0.0f, 0 ),
613 QVector3D( 1.0f, 1.0f, 0 )
614 };
615 maxX = std::numeric_limits<float>::lowest();
616 maxY = std::numeric_limits<float>::lowest();
617 maxZ = std::numeric_limits<float>::lowest();
618 minX = std::numeric_limits<float>::max();
619 minY = std::numeric_limits<float>::max();
620 minZ = std::numeric_limits<float>::max();
621 for ( int i = 0; i < viewFrustumPoints.size(); ++i )
622 {
623 // convert from view port space to world space
624 viewFrustumPoints[i] = viewFrustumPoints[i].unproject( viewMatrix, projectionMatrix, QRect( 0, 0, 1, 1 ) );
625 minX = std::min( minX, viewFrustumPoints[i].x() );
626 maxX = std::max( maxX, viewFrustumPoints[i].x() );
627 minY = std::min( minY, viewFrustumPoints[i].y() );
628 maxY = std::max( maxY, viewFrustumPoints[i].y() );
629 minZ = std::min( minZ, viewFrustumPoints[i].z() );
630 maxZ = std::max( maxZ, viewFrustumPoints[i].z() );
631 // find the intersection between the line going from cameraPos to the frustum quad point
632 // and the horizontal plane Y=y
633 // if the intersection is on the back side of the viewing panel we get a point that is
634 // shadowRenderingDistance units in front of the camera
635 const QVector3D pt = cameraPos;
636 const QVector3D vect = ( viewFrustumPoints[i] - pt ).normalized();
637 float t = ( y - pt.y() ) / vect.y();
638 if ( t < 0 )
639 t = shadowRenderingDistance;
640 else
641 t = std::min( t, shadowRenderingDistance );
642 viewFrustumPoints[i] = pt + t * vect;
643 minX = std::min( minX, viewFrustumPoints[i].x() );
644 maxX = std::max( maxX, viewFrustumPoints[i].x() );
645 minY = std::min( minY, viewFrustumPoints[i].y() );
646 maxY = std::max( maxY, viewFrustumPoints[i].y() );
647 minZ = std::min( minZ, viewFrustumPoints[i].z() );
648 maxZ = std::max( maxZ, viewFrustumPoints[i].z() );
649 }
650}
651
652void QgsShadowRenderingFrameGraph::setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance )
653{
654 float minX, maxX, minY, maxY, minZ, maxZ;
655 QVector3D lookingAt = mMainCamera->viewCenter();
656 const float d = 2 * ( mMainCamera->position() - mMainCamera->viewCenter() ).length();
657
658 const QVector3D vertical = QVector3D( 0.0f, d, 0.0f );
659 const QVector3D lightDirection = QVector3D( light.direction().x(), light.direction().y(), light.direction().z() ).normalized();
660 calculateViewExtent( mMainCamera, maximumShadowRenderingDistance, lookingAt.y(), minX, maxX, minY, maxY, minZ, maxZ );
661
662 lookingAt = QVector3D( 0.5 * ( minX + maxX ), mMainCamera->viewCenter().y(), 0.5 * ( minZ + maxZ ) );
663 const QVector3D lightPosition = lookingAt + vertical;
664 mLightCamera->setPosition( lightPosition );
665 mLightCamera->setViewCenter( lookingAt );
666 mLightCamera->setUpVector( QVector3D( 0.0f, 1.0f, 0.0f ) );
667 mLightCamera->rotateAboutViewCenter( QQuaternion::rotationTo( vertical.normalized(), -lightDirection.normalized() ) );
668
669 mLightCamera->setProjectionType( Qt3DRender::QCameraLens::ProjectionType::OrthographicProjection );
670 mLightCamera->lens()->setOrthographicProjection(
671 - 0.7 * ( maxX - minX ), 0.7 * ( maxX - minX ),
672 - 0.7 * ( maxZ - minZ ), 0.7 * ( maxZ - minZ ),
673 1.0f, 2 * ( lookingAt - lightPosition ).length() );
674
675 mPostprocessingEntity->setupShadowRenderingExtent( minX, maxX, minZ, maxZ );
676 mPostprocessingEntity->setupDirectionalLight( lightPosition, lightDirection );
677}
678
679void QgsShadowRenderingFrameGraph::setClearColor( const QColor &clearColor )
680{
681 mForwardClearBuffers->setClearColor( clearColor );
682}
683
685{
686 mShadowRenderingEnabled = enabled;
687 mPostprocessingEntity->setShadowRenderingEnabled( mShadowRenderingEnabled );
688 if ( mShadowRenderingEnabled )
689 mShadowSceneEntitiesFilter->setEnabled( true );
690 else
691 mShadowSceneEntitiesFilter->setEnabled( false );
692}
693
695{
696 mShadowBias = shadowBias;
697 mPostprocessingEntity->setShadowBias( mShadowBias );
698}
699
701{
702 mShadowMapResolution = resolution;
703 mShadowMapTexture->setWidth( mShadowMapResolution );
704 mShadowMapTexture->setHeight( mShadowMapResolution );
705}
706
708{
709 mAmbientOcclusionEnabled = enabled;
710 mAmbientOcclusionRenderEntity->setEnabled( enabled );
711 mPostprocessingEntity->setAmbientOcclusionEnabled( enabled );
712}
713
715{
716 mAmbientOcclusionIntensity = intensity;
717 mAmbientOcclusionRenderEntity->setIntensity( intensity );
718}
719
721{
722 mAmbientOcclusionRadius = radius;
723 mAmbientOcclusionRenderEntity->setRadius( radius );
724}
725
727{
728 mAmbientOcclusionThreshold = threshold;
729 mAmbientOcclusionRenderEntity->setThreshold( threshold );
730}
731
733{
734 if ( enabled == mFrustumCullingEnabled )
735 return;
736 mFrustumCullingEnabled = enabled;
737 if ( mFrustumCullingEnabled )
738 mFrustumCulling->setParent( mForwardClearBuffers );
739 else
740 mFrustumCulling->setParent( ( Qt3DCore::QNode * )nullptr );
741}
742
743void QgsShadowRenderingFrameGraph::setupEyeDomeLighting( bool enabled, double strength, int distance )
744{
745 mEyeDomeLightingEnabled = enabled;
746 mEyeDomeLightingStrength = strength;
747 mEyeDomeLightingDistance = distance;
748 mPostprocessingEntity->setEyeDomeLightingEnabled( enabled );
749 mPostprocessingEntity->setEyeDomeLightingStrength( strength );
750 mPostprocessingEntity->setEyeDomeLightingDistance( distance );
751}
752
753void QgsShadowRenderingFrameGraph::setupShadowMapDebugging( bool enabled, Qt::Corner corner, double size )
754{
755 mDebugShadowMapPreviewQuad->setEnabled( enabled );
756 if ( enabled )
757 {
758 switch ( corner )
759 {
760 case Qt::Corner::TopRightCorner:
761 mDebugShadowMapPreviewQuad->setViewPort( QPointF( 1.0f - size / 2, 0.0f + size / 2 ), 0.5 * QSizeF( size, size ) );
762 break;
763 case Qt::Corner::TopLeftCorner:
764 mDebugShadowMapPreviewQuad->setViewPort( QPointF( 0.0f + size / 2, 0.0f + size / 2 ), 0.5 * QSizeF( size, size ) );
765 break;
766 case Qt::Corner::BottomRightCorner:
767 mDebugShadowMapPreviewQuad->setViewPort( QPointF( 1.0f - size / 2, 1.0f - size / 2 ), 0.5 * QSizeF( size, size ) );
768 break;
769 case Qt::Corner::BottomLeftCorner:
770 mDebugShadowMapPreviewQuad->setViewPort( QPointF( 0.0f + size / 2, 1.0f - size / 2 ), 0.5 * QSizeF( size, size ) );
771 break;
772 }
773 }
774}
775
776void QgsShadowRenderingFrameGraph::setupDepthMapDebugging( bool enabled, Qt::Corner corner, double size )
777{
778 mDebugDepthMapPreviewQuad->setEnabled( enabled );
779
780 if ( enabled )
781 {
782 switch ( corner )
783 {
784 case Qt::Corner::TopRightCorner:
785 mDebugDepthMapPreviewQuad->setViewPort( QPointF( 1.0f - size / 2, 0.0f + size / 2 ), 0.5 * QSizeF( size, size ) );
786 break;
787 case Qt::Corner::TopLeftCorner:
788 mDebugDepthMapPreviewQuad->setViewPort( QPointF( 0.0f + size / 2, 0.0f + size / 2 ), 0.5 * QSizeF( size, size ) );
789 break;
790 case Qt::Corner::BottomRightCorner:
791 mDebugDepthMapPreviewQuad->setViewPort( QPointF( 1.0f - size / 2, 1.0f - size / 2 ), 0.5 * QSizeF( size, size ) );
792 break;
793 case Qt::Corner::BottomLeftCorner:
794 mDebugDepthMapPreviewQuad->setViewPort( QPointF( 0.0f + size / 2, 1.0f - size / 2 ), 0.5 * QSizeF( size, size ) );
795 break;
796 }
797 }
798}
799
801{
802 mSize = s;
803 mForwardColorTexture->setSize( mSize.width(), mSize.height() );
804 mForwardDepthTexture->setSize( mSize.width(), mSize.height() );
805 mRenderCaptureColorTexture->setSize( mSize.width(), mSize.height() );
806 mRenderCaptureDepthTexture->setSize( mSize.width(), mSize.height() );
807 mDepthRenderCaptureDepthTexture->setSize( mSize.width(), mSize.height() );
808 mDepthRenderCaptureColorTexture->setSize( mSize.width(), mSize.height() );
809 mRenderSurfaceSelector->setExternalRenderTargetSize( mSize );
810
811 mAmbientOcclusionRenderTexture->setSize( mSize.width(), mSize.height() );
812 mAmbientOcclusionBlurTexture->setSize( mSize.width(), mSize.height() );
813}
814
816{
817 if ( enabled == mRenderCaptureEnabled )
818 return;
819 mRenderCaptureEnabled = enabled;
820 mRenderCaptureTargetSelector->setEnabled( mRenderCaptureEnabled );
821}
822
824{
825#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0)
826 mDebugOverlay->setEnabled( enabled );
827#else
828 Q_UNUSED( enabled )
829 qDebug() << "Cannot display debug overlay. Qt version 5.15 or above is needed.";
830#endif
831}
void setThreshold(float threshold)
Sets the amount of occlusion when the effects starts to kick in.
void setRadius(float radius)
Sets the radius for the ambient occlusion effect.
void setIntensity(float intensity)
Sets the intensity for the ambient occlusion effect.
QgsVector3D direction() const
Returns the direction of the light in degrees.
void setupShadowRenderingExtent(float minX, float maxX, float minZ, float maxZ)
Sets the parts of the scene where objects cast shadows.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether screen space ambient occlusion is enabled.
void setShadowRenderingEnabled(bool enabled)
Sets whether shadow rendering is enabled.
void setEyeDomeLightingDistance(int distance)
Sets the eye dome lighting distance (contributes to the contrast of the image)
void setShadowBias(float shadowBias)
Sets the shadow bias value.
void setEyeDomeLightingStrength(double strength)
Sets the eye dome lighting strength.
void setupDirectionalLight(QVector3D position, QVector3D direction)
Sets up a directional light that is used to render shadows.
void setEyeDomeLightingEnabled(bool enabled)
Sets whether eye dome lighting is enabled.
void setViewPort(const QPointF &centerNDC, const QSizeF &size)
Sets where the quad will be located on the scene.
Qt3DRender::QLayer * layer()
Returns the layer object used to select this entity for rendering in a specific rendering pass.
void setupDepthMapDebugging(bool enabled, Qt::Corner corner, double size)
Sets the depth map debugging view port.
void setAmbientOcclusionThreshold(float threshold)
Sets the ambient occlusion threshold.
QgsShadowRenderingFrameGraph(QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
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 setAmbientOcclusionIntensity(float intensity)
Sets the ambient occlusion intensity.
void setShadowMapResolution(int resolution)
Sets the resolution of the shadow map.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
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.
void setAmbientOcclusionRadius(float radius)
Sets the ambient occlusion radius.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
void setAmbientOcclusionEnabled(bool enabled)
Sets whether Screen Space Ambient Occlusion will be enabled.
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color)
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.
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
void setShadowRenderingEnabled(bool enabled)
Sets whether the shadow rendering is enabled.
double y() const
Returns Y coordinate.
Definition: qgsvector3d.h:51
double z() const
Returns Z coordinate.
Definition: qgsvector3d.h:53
double x() const
Returns X coordinate.
Definition: qgsvector3d.h:49
Qt3DCore::QAttribute Qt3DQAttribute
Definition: qgs3daxis.cpp:28
Qt3DCore::QBuffer Qt3DQBuffer
Definition: qgs3daxis.cpp:30
Qt3DCore::QGeometry Qt3DQGeometry
Definition: qgs3daxis.cpp:29
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
void calculateViewExtent(Qt3DRender::QCamera *camera, float shadowRenderingDistance, float y, float &minX, float &maxX, float &minY, float &maxY, float &minZ, float &maxZ)
Qt3DCore::QGeometry Qt3DQGeometry