QGIS API Documentation 4.1.0-Master (31622b25bb0)
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"
17
18#include "qgs3dutils.h"
21#include "qgsbloomrenderview.h"
22#include "qgsdepthrenderview.h"
25#include "qgsframegraphutils.h"
30#include "qgsshadowrenderview.h"
31
32#include <Qt3DCore/QAttribute>
33#include <Qt3DCore/QBuffer>
34#include <Qt3DCore/QGeometry>
35#include <Qt3DRender/QAbstractTexture>
36#include <Qt3DRender/QBlendEquation>
37#include <Qt3DRender/QBlendEquationArguments>
38#include <Qt3DRender/QColorMask>
39#include <Qt3DRender/QGeometryRenderer>
40#include <Qt3DRender/QGraphicsApiFilter>
41#include <Qt3DRender/QNoDepthMask>
42#include <Qt3DRender/QNoDraw>
43#include <Qt3DRender/QSortPolicy>
44#include <Qt3DRender/QTechnique>
45
46#include "moc_qgsframegraph.cpp"
47
48const QString QgsFrameGraph::FORWARD_RENDERVIEW = "forward";
49const QString QgsFrameGraph::SHADOW_RENDERVIEW = "shadow";
50const QString QgsFrameGraph::AXIS3D_RENDERVIEW = "3daxis";
51const QString QgsFrameGraph::DEPTH_RENDERVIEW = "depth";
52const QString QgsFrameGraph::OVERLAY_RENDERVIEW = "overlay_texture";
53const QString QgsFrameGraph::AMBIENT_OCCLUSION_RENDERVIEW = "ambient_occlusion";
54const QString QgsFrameGraph::BLOOM_RENDERVIEW = "bloom";
55const QString QgsFrameGraph::HIGHLIGHTS_RENDERVIEW = "highlights";
56
57void QgsFrameGraph::constructForwardRenderPass()
58{
59 registerRenderView( std::make_unique<QgsForwardRenderView>( FORWARD_RENDERVIEW, mMainCamera ), FORWARD_RENDERVIEW );
60}
61
62void QgsFrameGraph::constructHighlightsPass()
63{
64 registerRenderView( std::make_unique<QgsHighlightsRenderView>( HIGHLIGHTS_RENDERVIEW, forwardRenderView().renderTargetSelector()->target(), mMainCamera ), HIGHLIGHTS_RENDERVIEW );
65}
66
67void QgsFrameGraph::constructShadowRenderPass()
68{
69 registerRenderView( std::make_unique<QgsShadowRenderView>( SHADOW_RENDERVIEW, mRootEntity ), SHADOW_RENDERVIEW );
70}
71
72void QgsFrameGraph::constructOverlayTexturePass( Qt3DRender::QFrameGraphNode *topNode )
73{
74 registerRenderView( std::make_unique<QgsOverlayTextureRenderView>( OVERLAY_RENDERVIEW ), OVERLAY_RENDERVIEW, topNode );
75}
76
77Qt3DRender::QFrameGraphNode *QgsFrameGraph::constructSubPostPassForProcessing()
78{
79 Qt3DRender::QLayerFilter *layerFilter = new Qt3DRender::QLayerFilter();
80
81 // could be the first of this branch
82 new Qt3DRender::QClearBuffers( layerFilter );
83
84 Qt3DRender::QLayer *postProcessingLayer = new Qt3DRender::QLayer();
85 mPostprocessingEntity = new QgsPostprocessingEntity( this, postProcessingLayer, mRootEntity );
86 layerFilter->addLayer( postProcessingLayer );
87 mPostprocessingEntity->setObjectName( "PostProcessingPassEntity" );
88
89 return layerFilter;
90}
91
92Qt3DRender::QFrameGraphNode *QgsFrameGraph::constructSubPostPassForRenderCapture()
93{
94 Qt3DRender::QFrameGraphNode *top = new Qt3DRender::QNoDraw;
95 top->setObjectName( "Sub pass RenderCapture" );
96
97 mRenderCapture = new Qt3DRender::QRenderCapture( top );
98
99 return top;
100}
101
102Qt3DRender::QFrameGraphNode *QgsFrameGraph::constructPostprocessingPass()
103{
104 mRenderCaptureTargetSelector = new Qt3DRender::QRenderTargetSelector;
105 mRenderCaptureTargetSelector->setObjectName( "Postprocessing render pass" );
106 mRenderCaptureTargetSelector->setEnabled( mRenderCaptureEnabled );
107
108 Qt3DRender::QRenderTarget *renderTarget = new Qt3DRender::QRenderTarget( mRenderCaptureTargetSelector );
109
110 // The lifetime of the objects created here is managed
111 // automatically, as they become children of this object.
112
113 // Create a render target output for rendering color.
114 Qt3DRender::QRenderTargetOutput *colorOutput = new Qt3DRender::QRenderTargetOutput( renderTarget );
115 colorOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
116
117 // Create a texture to render into.
118 mRenderCaptureColorTexture = new Qt3DRender::QTexture2D( colorOutput );
119 mRenderCaptureColorTexture->setSize( mSize.width(), mSize.height() );
120 mRenderCaptureColorTexture->setFormat( Qt3DRender::QAbstractTexture::RGB8_UNorm );
121 mRenderCaptureColorTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
122 mRenderCaptureColorTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
123 mRenderCaptureColorTexture->setObjectName( "PostProcessingPass::ColorTarget" );
124
125 // Hook the texture up to our output, and the output up to this object.
126 colorOutput->setTexture( mRenderCaptureColorTexture );
127 renderTarget->addOutput( colorOutput );
128
129 Qt3DRender::QRenderTargetOutput *depthOutput = new Qt3DRender::QRenderTargetOutput( renderTarget );
130
131 depthOutput->setAttachmentPoint( Qt3DRender::QRenderTargetOutput::Depth );
132 mRenderCaptureDepthTexture = new Qt3DRender::QTexture2D( depthOutput );
133 mRenderCaptureDepthTexture->setSize( mSize.width(), mSize.height() );
134 mRenderCaptureDepthTexture->setFormat( Qt3DRender::QAbstractTexture::DepthFormat );
135 mRenderCaptureDepthTexture->setMinificationFilter( Qt3DRender::QAbstractTexture::Linear );
136 mRenderCaptureDepthTexture->setMagnificationFilter( Qt3DRender::QAbstractTexture::Linear );
137 mRenderCaptureDepthTexture->setComparisonFunction( Qt3DRender::QAbstractTexture::CompareLessEqual );
138 mRenderCaptureDepthTexture->setComparisonMode( Qt3DRender::QAbstractTexture::CompareRefToTexture );
139 mRenderCaptureDepthTexture->setObjectName( "PostProcessingPass::DepthTarget" );
140
141 depthOutput->setTexture( mRenderCaptureDepthTexture );
142 renderTarget->addOutput( depthOutput );
143
144 mRenderCaptureTargetSelector->setTarget( renderTarget );
145
146 // sub passes:
147 constructSubPostPassForProcessing()->setParent( mRenderCaptureTargetSelector );
148 constructOverlayTexturePass( mRenderCaptureTargetSelector );
149 constructSubPostPassForRenderCapture()->setParent( mRenderCaptureTargetSelector );
150
151 return mRenderCaptureTargetSelector;
152}
153
154void QgsFrameGraph::constructAmbientOcclusionRenderPass()
155{
156 Qt3DRender::QTexture2D *forwardDepthTexture = forwardRenderView().depthTexture();
157
158 QgsAmbientOcclusionRenderView *aorv = new QgsAmbientOcclusionRenderView( AMBIENT_OCCLUSION_RENDERVIEW, mMainCamera, mSize, forwardDepthTexture, mRootEntity );
159 registerRenderView( std::unique_ptr<QgsAmbientOcclusionRenderView>( aorv ), AMBIENT_OCCLUSION_RENDERVIEW );
160}
161
162void QgsFrameGraph::constructBloomRenderPass()
163{
164 Qt3DRender::QTexture2D *forwardColorTexture = forwardRenderView().colorTexture();
165
166 QgsBloomRenderView *rv = new QgsBloomRenderView( BLOOM_RENDERVIEW, forwardColorTexture, mSize, mRootEntity );
167 registerRenderView( std::unique_ptr<QgsBloomRenderView>( rv ), BLOOM_RENDERVIEW );
168}
169
170Qt3DRender::QFrameGraphNode *QgsFrameGraph::constructRubberBandsPass()
171{
172 mRubberBandsCameraSelector = new Qt3DRender::QCameraSelector;
173 mRubberBandsCameraSelector->setObjectName( "RubberBands Pass CameraSelector" );
174 mRubberBandsCameraSelector->setCamera( mMainCamera );
175
176 mRubberBandsLayerFilter = new Qt3DRender::QLayerFilter( mRubberBandsCameraSelector );
177 mRubberBandsLayerFilter->addLayer( mRubberBandsLayer );
178
179 Qt3DRender::QBlendEquationArguments *blendState = new Qt3DRender::QBlendEquationArguments;
180 blendState->setSourceRgb( Qt3DRender::QBlendEquationArguments::SourceAlpha );
181 blendState->setDestinationRgb( Qt3DRender::QBlendEquationArguments::OneMinusSourceAlpha );
182
183 Qt3DRender::QBlendEquation *blendEquation = new Qt3DRender::QBlendEquation;
184 blendEquation->setBlendFunction( Qt3DRender::QBlendEquation::Add );
185
186 mRubberBandsStateSet = new Qt3DRender::QRenderStateSet( mRubberBandsLayerFilter );
187 Qt3DRender::QDepthTest *depthTest = new Qt3DRender::QDepthTest;
188 depthTest->setDepthFunction( Qt3DRender::QDepthTest::Always );
189 mRubberBandsStateSet->addRenderState( depthTest );
190 mRubberBandsStateSet->addRenderState( blendState );
191 mRubberBandsStateSet->addRenderState( blendEquation );
192
193 // Here we attach our drawings to the render target also used by forward pass.
194 // This is kind of okay, but as a result, post-processing effects get applied
195 // to rubber bands too. Ideally we would want them on top of everything.
196 mRubberBandsRenderTargetSelector = new Qt3DRender::QRenderTargetSelector( mRubberBandsStateSet );
197 mRubberBandsRenderTargetSelector->setTarget( forwardRenderView().renderTargetSelector()->target() );
198
199 return mRubberBandsCameraSelector;
200}
201
202void QgsFrameGraph::constructDepthRenderPass()
203{
204 // entity used to draw the depth texture and convert it to rgb image
205 Qt3DRender::QTexture2D *forwardDepthTexture = forwardRenderView().depthTexture();
206 QgsDepthRenderView *rv = new QgsDepthRenderView( DEPTH_RENDERVIEW, mSize, forwardDepthTexture, mRootEntity );
207 registerRenderView( std::unique_ptr<QgsDepthRenderView>( rv ), DEPTH_RENDERVIEW );
208}
209
210Qt3DRender::QRenderCapture *QgsFrameGraph::depthRenderCapture()
211{
213}
214
215void QgsFrameGraph::addGlobalParameters( const QList<Qt3DRender::QParameter *> &parameters )
216{
217 for ( Qt3DRender::QParameter *param : parameters )
218 {
219 mGlobalParamsStorage->addParameter( param );
220 }
221}
222
223QgsFrameGraph::QgsFrameGraph( QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root )
224 : Qt3DCore::QEntity( root )
225 , mSize( s )
226{
227 // general overview of how the frame graph looks:
228 //
229 // +------------------------+ using window or
230 // | QRenderSurfaceSelector | offscreen surface
231 // +------------------------+
232 // |
233 // +-----------+
234 // | QViewport | (0,0,1,1)
235 // +-----------+
236 // |
237 // +---------------------+---------------+------------------------+-------------------+
238 // | | | | |
239 // | | | (optional) | |
240 // +--------------+ +------------------+ +-----------------+ +-----------------+ +-----------------+
241 // | shadows pass | | forward passes | | MSAA blit | | depth buffer | | post-processing |
242 // | | | (solid objects, | | (color + depth) | | processing pass | | passes |
243 // +--------------+ | transparent, | +-----------------+ +-----------------+ +-----------------+
244 // | highlights, |
245 // | rubber bands) |
246 // +------------------+
247 //
248 // Notes:
249 // - (optional) MSAA blits multisampled (4 samples) color and depth textures
250 // so that other passes can sample them
251 // - shadows pass MUST come before other forward passes, as we use the shadow
252 // information in the material shaders
253 // - depth buffer processing pass is used whenever we need depth map information
254 // (for camera navigation) and it converts depth texture to a color texture
255 // so that we can capture it with QRenderCapture - currently it is unable
256 // to capture depth buffer, only colors (see QTBUG-65155)
257 // - there are multiple post-processing passes that take rendered output
258 // of the scene, optionally apply effects (add shadows, ambient occlusion,
259 // eye dome lighting) and finally output to the given surface
260 // - there may be also two more passes when 3D axis is shown - see Qgs3DAxis
261
262 mRootEntity = root;
263 mMainCamera = mainCamera;
264
265 mRubberBandsLayer = new Qt3DRender::QLayer;
266 mRubberBandsLayer->setObjectName( "mRubberBandsLayer" );
267 mRubberBandsLayer->setRecursive( true );
268
269 mRenderSurfaceSelector = new Qt3DRender::QRenderSurfaceSelector;
270
271 QObject *surfaceObj = dynamic_cast<QObject *>( surface );
272 Q_ASSERT( surfaceObj );
273
274 mRenderSurfaceSelector->setSurface( surfaceObj );
275 mRenderSurfaceSelector->setExternalRenderTargetSize( mSize );
276
277 mMainViewPort = new Qt3DRender::QViewport( mRenderSurfaceSelector );
278 mMainViewPort->setNormalizedRect( QRectF( 0.0f, 0.0f, 1.0f, 1.0f ) );
279
280 mGlobalParamsStorage = new Qt3DRender::QRenderPassFilter( mMainViewPort );
281 mGlobalParamsStorage->setObjectName( "GlobalParametersStore" );
282
283 // shadow rendering pass -- must be constructed BEFORE the forward render pass,
284 // to ensure it always has the correct depth available.
285 constructShadowRenderPass();
286
287 // Forward render
288 constructForwardRenderPass();
289
290 // Highlighted items pass
291 constructHighlightsPass();
292
293 // rubber bands (they should be always on top)
294 Qt3DRender::QFrameGraphNode *rubberBandsPass = constructRubberBandsPass();
295 rubberBandsPass->setObjectName( "rubberBandsPass" );
296 rubberBandsPass->setParent( mGlobalParamsStorage );
297
298 mMsaaBlitNode = new Qt3DRender::QBlitFramebuffer( mGlobalParamsStorage );
299 mMsaaBlitNode->setObjectName( "MsaaBlitFramebuffer" );
300 mMsaaBlitNode->setEnabled( false );
301
302 mMsaaDepthBlitNode = new Qt3DRender::QBlitFramebuffer( mGlobalParamsStorage );
303 mMsaaDepthBlitNode->setObjectName( "MsaaDepthBlitFramebuffer" );
304 mMsaaDepthBlitNode->setEnabled( false );
305
306 // depth buffer processing
307 constructDepthRenderPass();
308
309 // Ambient occlusion factor render pass
310 constructAmbientOcclusionRenderPass();
311
312 constructBloomRenderPass();
313
314 // post process
315 Qt3DRender::QFrameGraphNode *postprocessingPass = constructPostprocessingPass();
316 postprocessingPass->setParent( mGlobalParamsStorage );
317 postprocessingPass->setObjectName( "PostProcessingPass" );
318
319 mRubberBandsRootEntity = new Qt3DCore::QEntity( mRootEntity );
320 mRubberBandsRootEntity->setObjectName( "mRubberBandsRootEntity" );
321 mRubberBandsRootEntity->addComponent( mRubberBandsLayer );
322}
323
324void QgsFrameGraph::unregisterRenderView( const QString &name )
325{
326 if ( mRenderViewMap.find( name ) != mRenderViewMap.end() )
327 {
328 mRenderViewMap[name]->topGraphNode()->setParent( ( QNode * ) nullptr );
329 mRenderViewMap.erase( name );
330 }
331}
332
333bool QgsFrameGraph::registerRenderView( std::unique_ptr<QgsAbstractRenderView> renderView, const QString &name, Qt3DRender::QFrameGraphNode *topNode )
334{
335 bool out;
336 if ( mRenderViewMap.find( name ) == mRenderViewMap.end() )
337 {
338 mRenderViewMap[name] = std::move( renderView );
339 mRenderViewMap[name]->topGraphNode()->setParent( topNode ? topNode : mGlobalParamsStorage );
340 mRenderViewMap[name]->updateWindowResize( mSize.width(), mSize.height() );
341 out = true;
342 }
343 else
344 out = false;
345
346 return out;
347}
348
349void QgsFrameGraph::setRenderViewEnabled( const QString &name, bool enable )
350{
351 if ( mRenderViewMap[name] )
352 {
353 mRenderViewMap[name]->setEnabled( enable );
354 }
355}
356
358{
359 if ( mRenderViewMap.find( name ) != mRenderViewMap.end() )
360 {
361 return mRenderViewMap[name].get();
362 }
363 return nullptr;
364}
365
366bool QgsFrameGraph::isRenderViewEnabled( const QString &name )
367{
368 return mRenderViewMap[name] != nullptr && mRenderViewMap[name]->isEnabled();
369}
370
372{
374
375 aoRenderView.setRadius( settings.radius() );
376 aoRenderView.setIntensity( settings.intensity() );
377 aoRenderView.setThreshold( settings.threshold() );
378 aoRenderView.setEnabled( settings.isEnabled() );
379
380 mPostprocessingEntity->setAmbientOcclusionEnabled( settings.isEnabled() );
381}
382
384{
385 mPostprocessingEntity->setEyeDomeLightingEnabled( settings.eyeDomeLightingEnabled() );
386 mPostprocessingEntity->setEyeDomeLightingStrength( settings.eyeDomeLightingStrength() );
387 mPostprocessingEntity->setEyeDomeLightingDistance( settings.eyeDomeLightingDistance() );
388}
389
391{
393
394 renderView.setEnabled( settings.isEnabled() );
395 mPostprocessingEntity->setBloomEnabled( settings.isEnabled() );
396 mPostprocessingEntity->setBloomFactor( static_cast< float >( settings.intensity() ) );
397 renderView.setFilterRadius( static_cast< float >( settings.radius() ) );
398}
399
400void QgsFrameGraph::updateShadowSettings( const QgsShadowSettings &shadowSettings, const QList<QgsLightSource *> &lightSources )
401{
402 if ( shadowSettings.renderShadows() )
403 {
404 int selectedLight = shadowSettings.selectedDirectionalLight();
405 QgsDirectionalLightSettings *light = nullptr;
406 int globalLightIndex = 0;
407 for ( int i = 0, dirLight = 0; !light && i < lightSources.size(); i++ )
408 {
409 if ( lightSources[i]->type() == Qgis::LightSourceType::Directional )
410 {
411 if ( dirLight == selectedLight )
412 {
413 light = qgis::down_cast< QgsDirectionalLightSettings * >( lightSources[i] );
414 globalLightIndex = i;
415 }
416 dirLight++;
417 }
418 }
419
420 if ( light )
421 {
422 const int size = shadowSettings.qualityToMapResolution( shadowSettings.shadowQuality() );
423 shadowRenderView().setMapSize( size, size );
425 mPostprocessingEntity->setShadowRenderingEnabled( true );
426 mPostprocessingEntity->setShadowMapResolution( size );
427 mPostprocessingEntity->setShadowLightIndex( globalLightIndex );
428 mPostprocessingEntity->setShadowBias( static_cast<float>( shadowSettings.shadowBias() ) );
429 mPostprocessingEntity->updateShadowSettings( *light, static_cast<float>( shadowSettings.maximumShadowRenderingDistance() ) );
430 mPostprocessingEntity->setShowCascadingShadowSplits( shadowSettings.showCascadeSplits() );
431 }
432 }
433 else
434 {
435 shadowRenderView().setEnabled( false );
436 mPostprocessingEntity->setShadowRenderingEnabled( false );
437 }
438}
439
441{
442 QgsOverlayTextureRenderView *debugRenderView = dynamic_cast<QgsOverlayTextureRenderView *>( mRenderViewMap[OVERLAY_RENDERVIEW].get() );
443 if ( !debugRenderView )
444 return;
445
446 if ( !mDepthTextureDebugging && settings.debugDepthMapEnabled() )
447 {
448 Qt3DRender::QTexture2D *forwardDepthTexture = forwardRenderView().depthTexture();
449 mDepthTextureDebugging = new QgsOverlayTextureEntity( forwardDepthTexture, debugRenderView->overlayLayer(), this );
450 }
451
452 debugRenderView->setEnabled( settings.debugDepthMapEnabled() || settings.is2DMapOverlayEnabled() );
453
454 if ( mDepthTextureDebugging )
455 {
456 mDepthTextureDebugging->setEnabled( settings.debugDepthMapEnabled() );
457 if ( settings.debugDepthMapEnabled() )
458 mDepthTextureDebugging->setPosition( settings.debugDepthMapCorner(), settings.debugDepthMapSize() );
459 else
460 {
461 delete mDepthTextureDebugging;
462 mDepthTextureDebugging = nullptr;
463 }
464 }
465}
466
468{
469 QObject *top = mRenderSurfaceSelector;
470 while ( top->parent() && dynamic_cast<Qt3DRender::QFrameGraphNode *>( top->parent() ) )
471 top = top->parent();
472
474 context.lowestId = mMainCamera->id().id();
475 QStringList strList = QgsFrameGraphUtils::dumpFrameGraph( dynamic_cast<Qt3DRender::QFrameGraphNode *>( top ), context );
476
477 return strList.join( "\n" ) + QString( "\n" );
478}
479
481{
482 QStringList strList = QgsFrameGraphUtils::dumpSceneGraph( mRootEntity, QgsFrameGraphUtils::FgDumpContext() );
483 return strList.join( "\n" ) + QString( "\n" );
484}
485
486void QgsFrameGraph::setClearColor( const QColor &clearColor )
487{
488 forwardRenderView().setClearColor( clearColor );
489}
490
495
497{
498 mSize = s;
499 for ( auto it = mRenderViewMap.begin(); it != mRenderViewMap.end(); ++it )
500 {
501 QgsAbstractRenderView *rv = it->second.get();
502 rv->updateWindowResize( mSize.width(), mSize.height() );
503 }
504
505 mRenderCaptureColorTexture->setSize( mSize.width(), mSize.height() );
506 mRenderCaptureDepthTexture->setSize( mSize.width(), mSize.height() );
507 mRenderSurfaceSelector->setExternalRenderTargetSize( mSize );
508
509 mMsaaBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
510 mMsaaBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
511 mMsaaDepthBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
512 mMsaaDepthBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
513}
514
515Qt3DRender::QRenderCapture *QgsFrameGraph::renderCapture()
516{
517 return mRenderCapture;
518}
519
521{
522 if ( enabled == mRenderCaptureEnabled )
523 return;
524 mRenderCaptureEnabled = enabled;
525 mRenderCaptureTargetSelector->setEnabled( mRenderCaptureEnabled );
526}
527
532
534{
535 mMsaaEnabled = enabled;
536
537 if ( !enabled && mMsaaBlitConfigured )
538 {
539 mMsaaBlitNode->setSource( nullptr );
540 mMsaaBlitNode->setDestination( nullptr );
541 mMsaaDepthBlitNode->setSource( nullptr );
542 mMsaaDepthBlitNode->setDestination( nullptr );
543 mMsaaBlitConfigured = false;
544 }
545
547
548 if ( enabled && !mMsaaBlitConfigured )
549 {
550 mMsaaBlitConfigured = true;
551 mMsaaBlitNode->setSource( forwardRenderView().msaaRenderTarget() );
552 mMsaaBlitNode->setDestination( forwardRenderView().regularRenderTarget() );
553 mMsaaBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
554 mMsaaBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
555 mMsaaBlitNode->setSourceAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
556 mMsaaBlitNode->setDestinationAttachmentPoint( Qt3DRender::QRenderTargetOutput::Color0 );
557 mMsaaBlitNode->setInterpolationMethod( Qt3DRender::QBlitFramebuffer::Nearest );
558
559 mMsaaDepthBlitNode->setSource( forwardRenderView().msaaRenderTarget() );
560 mMsaaDepthBlitNode->setDestination( forwardRenderView().regularRenderTarget() );
561 mMsaaDepthBlitNode->setSourceRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
562 mMsaaDepthBlitNode->setDestinationRect( QRect( 0, 0, mSize.width(), mSize.height() ) );
563 mMsaaDepthBlitNode->setSourceAttachmentPoint( Qt3DRender::QRenderTargetOutput::DepthStencil );
564 mMsaaDepthBlitNode->setDestinationAttachmentPoint( Qt3DRender::QRenderTargetOutput::DepthStencil );
565 mMsaaDepthBlitNode->setInterpolationMethod( Qt3DRender::QBlitFramebuffer::Nearest );
566 }
567
568 Qt3DRender::QRenderTarget *target = enabled ? forwardRenderView().msaaRenderTarget() : forwardRenderView().regularRenderTarget();
570 mRubberBandsRenderTargetSelector->setTarget( target );
571 mMsaaBlitNode->setEnabled( enabled );
572 mMsaaDepthBlitNode->setEnabled( enabled );
573}
574
579
580void QgsFrameGraph::addClipPlanes( int nrClipPlanes )
581{
582 forwardRenderView().addClipPlanes( nrClipPlanes );
583}
584
586{
588 return *( dynamic_cast<QgsForwardRenderView *>( rv ) );
589}
590
592{
594 return *( dynamic_cast<QgsShadowRenderView *>( rv ) );
595}
596
598{
599 QgsAbstractRenderView *rv = mRenderViewMap[QgsFrameGraph::DEPTH_RENDERVIEW].get();
600 return *( dynamic_cast<QgsDepthRenderView *>( rv ) );
601}
602
608
610{
611 QgsAbstractRenderView *rv = mRenderViewMap[QgsFrameGraph::BLOOM_RENDERVIEW].get();
612 return *( dynamic_cast<QgsBloomRenderView *>( rv ) );
613}
614
620
@ Directional
Directional light source.
Definition qgis.h:4406
Definition of the world.
Qt::Corner debugDepthMapCorner() const
Returns the corner where the shadow map preview is displayed.
bool debugDepthMapEnabled() const
Returns whether the shadow map debugging is enabled.
double eyeDomeLightingStrength() const
Returns the eye dome lighting strength value.
double debugDepthMapSize() const
Returns the size of the shadow map preview.
bool is2DMapOverlayEnabled() const
Returns whether 2D map overlay is enabled.
int eyeDomeLightingDistance() const
Returns the eye dome lighting distance value (contributes to the contrast of the image).
bool eyeDomeLightingEnabled() const
Returns whether eye dome lighting is used.
Base class for 3D render view.
virtual void setEnabled(bool enable)
Enable or disable via enable the render view sub tree.
virtual bool isEnabled() const
Returns true if render view is enabled.
virtual void updateWindowResize(int width, int height)
Called when 3D window is resized.
Container class that holds different objects related to ambient occlusion rendering.
void setRadius(float radius)
Delegates to QgsAmbientOcclusionRenderEntity::setRadius.
void setEnabled(bool enable) override
Enable or disable via enable the render view sub tree.
void setIntensity(float intensity)
Delegates to QgsAmbientOcclusionRenderEntity::setIntensity.
void setThreshold(float threshold)
Delegates to QgsAmbientOcclusionRenderEntity::setThreshold.
Contains the configuration of ambient occlusion rendering.
float radius() const
Returns the radius parameter of the ambient occlusion effect.
bool isEnabled() const
Returns whether ambient occlusion effect is enabled.
float intensity() const
Returns the shading factor of the ambient occlusion effect.
float threshold() const
Returns at what amount of occlusion the effect will kick in.
Container class that holds different objects related to bloom rendering.
Contains the configuration of the lighting "bloom" effect.
double intensity() const
Returns the intensity of the bloom effect.
double radius() const
Returns the filter radius for the bloom.
bool isEnabled() const
Returns whether the bloom effect is enabled.
Container class that holds different objects related to depth rendering.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
Definition of a directional light in a 3D map scene.
Container class that holds different objects related to forward rendering.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color).
Qt3DRender::QTexture2D * colorTexture() const
Returns forward color texture.
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
void setMsaaEnabled(bool enabled)
Sets whether multisample anti-aliasing (MSAA) is enabled.
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
Qt3DRender::QTexture2D * depthTexture() const
Returns forward depth texture.
void addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
void removeClipPlanes()
Disables OpenGL clipping.
Qt3DRender::QRenderTarget * msaaRenderTarget() const
Returns the multisampled render target used as blit source when MSAA is enabled.
Qt3DRender::QRenderTarget * regularRenderTarget() const
Returns the regular (single-sample) render target used as blit destination and postprocessing input.
static QStringList dumpFrameGraph(const Qt3DCore::QNode *node, FgDumpContext context)
Returns a tree view of the frame graph starting from node. The object ids will be given relatively to...
static QStringList dumpSceneGraph(const Qt3DCore::QNode *node, FgDumpContext context)
Returns a tree view of the scene graph starting from node. The object ids will be given relatively to...
void addGlobalParameters(const QList< Qt3DRender::QParameter * > &parameters)
Adds additional global parameters to the graph.
void setMsaaEnabled(bool enabled)
Sets whether multisample anti-aliasing (MSAA) is enabled.
void updateAmbientOcclusionSettings(const QgsAmbientOcclusionSettings &settings)
Updates settings for ambient occlusion.
void updateEyeDomeSettings(const Qgs3DMapSettings &settings)
Updates settings for eye dome lighting.
void updateBloomSettings(const QgsBloomSettings &settings)
Updates settings for the bloom lighting effect.
bool isRenderViewEnabled(const QString &name)
Returns true if the render view named name is found and enabled.
void setRenderViewEnabled(const QString &name, bool enable)
Enables or disables the render view named name according to enable.
void updateShadowSettings(const QgsShadowSettings &shadowSettings, const QList< QgsLightSource * > &lightSources)
Updates shadow bias, light and texture size according to shadowSettings and lightSources.
void addClipPlanes(int nrClipPlanes)
Setups nrClipPlanes clip planes in the forward pass to enable OpenGL clipping.
void unregisterRenderView(const QString &name)
Unregisters the render view named name, if any.
bool registerRenderView(std::unique_ptr< QgsAbstractRenderView > renderView, const QString &name, Qt3DRender::QFrameGraphNode *topNode=nullptr)
Registers a new the render view renderView with name name.
QString dumpFrameGraph() const
Dumps frame graph as string.
void setRenderCaptureEnabled(bool enabled)
Sets whether it will be possible to render to an image.
QgsAmbientOcclusionRenderView & ambientOcclusionRenderView()
Returns ambient occlusion renderview.
Qt3DRender::QRenderCapture * depthRenderCapture()
Returns the render capture object used to take an image of the depth buffer of the scene.
QgsAbstractRenderView * renderView(const QString &name)
Returns the render view named name, if any.
void removeClipPlanes()
Disables OpenGL clipping.
static const QString AMBIENT_OCCLUSION_RENDERVIEW
Ambient occlusion render view name.
QgsDepthRenderView & depthRenderView()
Returns depth renderview.
void setClearColor(const QColor &clearColor)
Sets the clear color of the scene (background color).
static const QString FORWARD_RENDERVIEW
void setFrustumCullingEnabled(bool enabled)
Sets whether frustum culling is enabled.
static const QString SHADOW_RENDERVIEW
void setDebugOverlayEnabled(bool enabled)
Sets whether debug overlay is enabled.
static const QString HIGHLIGHTS_RENDERVIEW
QgsHighlightsRenderView & highlightsRenderView()
Returns the highlights renderview, used for rendering highlight overlays of identified features.
static const QString OVERLAY_RENDERVIEW
void updateDebugDepthMapSettings(const Qgs3DMapSettings &settings)
Updates settings for depth debug map.
static const QString AXIS3D_RENDERVIEW
QgsForwardRenderView & forwardRenderView()
Returns forward renderview.
QgsOverlayTextureRenderView & overlayTextureRenderView()
Returns overlay texture renderview.
QString dumpSceneGraph() const
Dumps scene graph as string.
QgsShadowRenderView & shadowRenderView()
Returns shadow renderview.
void setSize(QSize s)
Sets the size of the buffers used for rendering.
static const QString BLOOM_RENDERVIEW
QgsBloomRenderView & bloomRenderView()
Returns the bloom render view.
static const QString DEPTH_RENDERVIEW
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
QgsFrameGraph(QSurface *surface, QSize s, Qt3DRender::QCamera *mainCamera, Qt3DCore::QEntity *root)
Constructor.
Qt3DRender::QRenderCapture * renderCapture()
Returns the render capture object used to take an image of the scene.
Container class that holds different objects related to highlighting identified features.
void setRenderTarget(Qt3DRender::QRenderTarget *target)
Switches the render target (called when toggling MSAA on/off).
An entity responsible for rendering an overlay texture in 3D view.
Simple render view to preview overlay textures in 3D view.
Qt3DRender::QLayer * overlayLayer() const
Returns layer in which entities must be added in the in order to be processed by this renderview.
Container class that holds different objects related to shadow rendering.
void setMapSize(int width, int height)
Update shadow depth texture size.
void setEnabled(bool enable) override
Enable or disable via enable the renderview sub tree.
Contains configuration for rendering shadows.
int selectedDirectionalLight() const
Returns the selected direcctional light used to cast shadows.
bool renderShadows() const
Returns whether shadow rendering is enabled.
static int qualityToMapResolution(Qgis::ShadowQuality quality)
Returns the shadow map resolution corresponding to the specified shadow quality.
double maximumShadowRenderingDistance() const
Returns the maximum shadow rendering distance accounted for when rendering shadows Objects further aw...
double shadowBias() const
Returns the shadow bias used to correct the numerical imprecision of shadows (for the depth test) Thi...
Qgis::ShadowQuality shadowQuality() const
Returns the quality of the shadow map texture used to generate the shadows.
bool showCascadeSplits() const
Returns true if the cascading shadow splits should be tinted in the view.