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