Skip to content
Permalink
Browse files

Added configuration to debug shadow and forward depth textures

  • Loading branch information
NEDJIMAbelgacem authored and wonder-sk committed Nov 6, 2020
1 parent 1e9e4d7 commit c3ef5cc324ebf0faa82e6d454c9cee838785617c
@@ -454,14 +454,47 @@ Sets the eye dome lighting distance value (contributes to the contrast of the im
Returns the eye dome lighting distance value (contributes to the contrast of the image)
%End

void setDebugShadowMapSettings( bool enabled, int corner, double size );
void setDebugShadowMapSettings( bool enabled, const QString &corner, double size );
%Docstring
Sets the debugging settings of the shadowmap
Sets the debugging settings of the shadow map

.. versionadded:: 3.18
\see

.. seealso:: :py:func:`debugShadowMapEnabled`
%End
bool debugShadowMapEnabled() const;
%Docstring
Returns whether the shadow map debugging is enabled
%End
QString debugShadowMapCorner() const;
%Docstring
Returns the corner where the shadow map preview is displayed
%End
double debugShadowMapSize() const;
%Docstring
Returns the size of the shadow map preview
%End

void setDebugDepthMapSettings( bool enabled, const QString &corner, double size );
%Docstring
Sets the debugging settings of the depth map

.. versionadded:: 3.18

.. seealso:: :py:func:`debugDepthMapEnabled`
%End
bool debugDepthMapEnabled() const;
%Docstring
Returns whether the shadow map debugging is enabled
%End
QString debugDepthMapCorner() const;
%Docstring
Returns the corner where the shadow map preview is displayed
%End
double debugDepthMapSize() const;
%Docstring
Returns the size of the shadow map preview
%End

QList<QgsPointLightSettings> pointLights() const;
%Docstring
@@ -667,6 +700,20 @@ Emitted when the eye dome lighting strength has changed
%Docstring
Emitted when the eye dome lighting distance has changed

.. versionadded:: 3.18
%End

void debugShadowMapSettingsChanged();
%Docstring
Emitted when shadow map debugging has changed

.. versionadded:: 3.18
%End

void debugDepthMapSettingsChanged();
%Docstring
Emitted when depth map debugging has changed

.. versionadded:: 3.18
%End

@@ -134,6 +134,8 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *
connect( &map, &Qgs3DMapSettings::eyeDomeLightingEnabledChanged, this, &Qgs3DMapScene::onEyeDomeShadingSettingsChanged );
connect( &map, &Qgs3DMapSettings::eyeDomeLightingStrengthChanged, this, &Qgs3DMapScene::onEyeDomeShadingSettingsChanged );
connect( &map, &Qgs3DMapSettings::eyeDomeLightingDistanceChanged, this, &Qgs3DMapScene::onEyeDomeShadingSettingsChanged );
connect( &map, &Qgs3DMapSettings::debugShadowMapSettingsChanged, this, &Qgs3DMapScene::onDebugShadowMapSettingsChanged );
connect( &map, &Qgs3DMapSettings::debugDepthMapSettingsChanged, this, &Qgs3DMapScene::onDebugDepthMapSettingsChanged );

connect( QgsApplication::instance()->sourceCache(), &QgsSourceCache::remoteSourceFetched, this, [ = ]( const QString & url )
{
@@ -219,6 +221,9 @@ Qgs3DMapScene::Qgs3DMapScene( const Qgs3DMapSettings &map, QgsAbstract3DEngine *
onCameraChanged();
// force initial update of eye dome shadng
onEyeDomeShadingSettingsChanged();
// force initial update of debugging setting of preview quads
onDebugShadowMapSettingsChanged();
onDebugDepthMapSettingsChanged();
}

void Qgs3DMapScene::viewZoomFull()
@@ -967,6 +972,24 @@ void Qgs3DMapScene::onShadowSettingsChanged()
shadowRenderingFrameGraph->setShadowRenderingEnabled( false );
}

void Qgs3DMapScene::onDebugShadowMapSettingsChanged()
{
QgsWindow3DEngine *windowEngine = dynamic_cast<QgsWindow3DEngine *>( mEngine );
if ( windowEngine == nullptr )
return;
QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = windowEngine->shadowRenderingFrameGraph();
shadowRenderingFrameGraph->setupShadowMapDebugging( mMap.debugShadowMapEnabled(), mMap.debugShadowMapCorner(), mMap.debugShadowMapSize() );
}

void Qgs3DMapScene::onDebugDepthMapSettingsChanged()
{
QgsWindow3DEngine *windowEngine = dynamic_cast<QgsWindow3DEngine *>( mEngine );
if ( windowEngine == nullptr )
return;
QgsShadowRenderingFrameGraph *shadowRenderingFrameGraph = windowEngine->shadowRenderingFrameGraph();
shadowRenderingFrameGraph->setupDepthMapDebugging( mMap.debugDepthMapEnabled(), mMap.debugDepthMapCorner(), mMap.debugDepthMapSize() );
}

void Qgs3DMapScene::onEyeDomeShadingSettingsChanged()
{
QgsWindow3DEngine *windowEngine = dynamic_cast<QgsWindow3DEngine *>( mEngine );
@@ -145,6 +145,8 @@ class _3D_EXPORT Qgs3DMapScene : public Qt3DCore::QEntity
void onSkyboxSettingsChanged();
void onShadowSettingsChanged();
void onEyeDomeShadingSettingsChanged();
void onDebugShadowMapSettingsChanged();
void onDebugDepthMapSettingsChanged();

private:
void addLayerEntity( QgsMapLayer *layer );
@@ -242,6 +242,15 @@ void Qgs3DMapSettings::readXml( const QDomElement &elem, const QgsReadWriteConte
mEyeDomeLightingStrength = elemEyeDomeLighting.attribute( "eye-dome-lighting-strength", QStringLiteral( "1000.0" ) ).toDouble();
mEyeDomeLightingDistance = elemEyeDomeLighting.attribute( "eye-dome-lighting-distance", QStringLiteral( "1" ) ).toInt();

QDomElement elemDebugSettings = elem.firstChildElement( QStringLiteral( "debug-settings" ) );
mDebugShadowMapEnabled = elemDebugSettings.attribute( QStringLiteral( "shadowmap-enabled" ), QStringLiteral( "0" ) ).toInt();
mDebugShadowMapCorner = elemDebugSettings.attribute( QStringLiteral( "shadowmap-corner" ), QStringLiteral( "Top Left" ) );
mDebugShadowMapSize = elemDebugSettings.attribute( QStringLiteral( "shadowmap-size" ), QStringLiteral( "0.2" ) ).toDouble();

mDebugDepthMapEnabled = elemDebugSettings.attribute( QStringLiteral( "depthmap-enabled" ), QStringLiteral( "0" ) ).toInt();
mDebugDepthMapCorner = elemDebugSettings.attribute( QStringLiteral( "depthmap-corner" ), QStringLiteral( "Top Right" ) );
mDebugDepthMapSize = elemDebugSettings.attribute( QStringLiteral( "depthmap-size" ), QStringLiteral( "0.2" ) ).toDouble();

QDomElement elemDebug = elem.firstChildElement( QStringLiteral( "debug" ) );
mShowTerrainBoundingBoxes = elemDebug.attribute( QStringLiteral( "bounding-boxes" ), QStringLiteral( "0" ) ).toInt();
mShowTerrainTileInfo = elemDebug.attribute( QStringLiteral( "terrain-tile-info" ), QStringLiteral( "0" ) ).toInt();
@@ -361,6 +370,16 @@ QDomElement Qgs3DMapSettings::writeXml( QDomDocument &doc, const QgsReadWriteCon
elemEyeDomeLighting.setAttribute( "eye-dome-lighting-distance", mEyeDomeLightingDistance );
elem.appendChild( elemEyeDomeLighting );


QDomElement elemDebugSettings = doc.createElement( QStringLiteral( "debug-settings" ) );
elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-enabled" ), mDebugShadowMapEnabled );
elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-corner" ), mDebugShadowMapCorner );
elemDebugSettings.setAttribute( QStringLiteral( "shadowmap-size" ), mDebugShadowMapSize );
elemDebugSettings.setAttribute( QStringLiteral( "depthmap-enabled" ), mDebugDepthMapEnabled );
elemDebugSettings.setAttribute( QStringLiteral( "depthmap-corner" ), mDebugDepthMapCorner );
elemDebugSettings.setAttribute( QStringLiteral( "depthmap-size" ), mDebugDepthMapSize );
elem.appendChild( elemDebugSettings );

QDomElement elemTemporalRange = doc.createElement( QStringLiteral( "temporal-range" ) );
elemTemporalRange.setAttribute( QStringLiteral( "start" ), temporalRange().begin().toString( Qt::ISODate ) );
elemTemporalRange.setAttribute( QStringLiteral( "end" ), temporalRange().end().toString( Qt::ISODate ) );
@@ -705,7 +724,18 @@ void Qgs3DMapSettings::setShadowSettings( const QgsShadowSettings &shadowSetting
emit shadowSettingsChanged();
}

void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, int corner, double size )
void Qgs3DMapSettings::setDebugShadowMapSettings( bool enabled, const QString &corner, double size )
{
mDebugShadowMapEnabled = enabled;
mDebugShadowMapCorner = corner;
mDebugShadowMapSize = size;
emit debugShadowMapSettingsChanged();
}

void Qgs3DMapSettings::setDebugDepthMapSettings( bool enabled, const QString &corner, double size )
{
mDebugDepthMapEnabled = enabled;
mDebugDepthMapCorner = corner;
mDebugDepthMapSize = size;
emit debugDepthMapSettingsChanged();
}
@@ -390,13 +390,30 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
int eyeDomeLightingDistance() const { return mEyeDomeLightingDistance; }

/**
* Sets the debugging settings of the shadowmap
* Sets the debugging settings of the shadow map
* \since QGIS 3.18
* \see
* \see debugShadowMapEnabled() debugShadowMapCorner() debugShadowMapSize()
*/
void setDebugShadowMapSettings( bool enabled, int corner, double size );
void setDebugShadowMapSettings( bool enabled, const QString &corner, double size );
//! Returns whether the shadow map debugging is enabled
bool debugShadowMapEnabled() const { return mDebugShadowMapEnabled; }
//! Returns the corner where the shadow map preview is displayed
QString debugShadowMapCorner() const { return mDebugShadowMapCorner; }
//! Returns the size of the shadow map preview
double debugShadowMapSize() const { return mDebugShadowMapSize; }

// bool debugShadowMapEnabled() { return }
/**
* Sets the debugging settings of the depth map
* \since QGIS 3.18
* \see debugDepthMapEnabled() debugDepthMapCorner() debugDepthMapSize()
*/
void setDebugDepthMapSettings( bool enabled, const QString &corner, double size );
//! Returns whether the shadow map debugging is enabled
bool debugDepthMapEnabled() const { return mDebugDepthMapEnabled; }
//! Returns the corner where the shadow map preview is displayed
QString debugDepthMapCorner() const { return mDebugDepthMapCorner; }
//! Returns the size of the shadow map preview
double debugDepthMapSize() const { return mDebugDepthMapSize; }

/**
* Returns list of point lights defined in the scene
@@ -580,6 +597,18 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
*/
void eyeDomeLightingDistanceChanged();

/**
* Emitted when shadow map debugging has changed
* \since QGIS 3.18
*/
void debugShadowMapSettingsChanged();

/**
* Emitted when depth map debugging has changed
* \since QGIS 3.18
*/
void debugDepthMapSettingsChanged();

/**
* Emitted when the list of point lights changes
* \since QGIS 3.6
@@ -655,12 +684,12 @@ class _3D_EXPORT Qgs3DMapSettings : public QObject, public QgsTemporalRangeObjec
int mEyeDomeLightingDistance = 1;

bool mDebugShadowMapEnabled = false;
int mDebugShadowMapCorner = 0;
double mDebugShadowMapSize = 0.1;
QString mDebugShadowMapCorner = "Top Left";
double mDebugShadowMapSize = 0.2;

bool mDebugDepthMapEnabled = false;
int mDebugDepthMapCorner = 0;
double mDebugDepthMapSize = 0.1;
QString mDebugDepthMapCorner = "Top Right";
double mDebugDepthMapSize = 0.2;
};


@@ -71,6 +71,15 @@ QgsPreviewQuad::QgsPreviewQuad( Qt3DRender::QAbstractTexture *texture,
addComponent( mMaterial );
}

void QgsPreviewQuad::setViewPort( const QPointF &centerNDC, const QSizeF &size )
{
QMatrix4x4 modelMatrix;
modelMatrix.setToIdentity();
modelMatrix.translate( centerNDC.x(), centerNDC.y() );
modelMatrix.scale( size.width(), size.height() );
mMaterial->setModelMatrix( modelMatrix );
}

QgsPreviewQuadMaterial::QgsPreviewQuadMaterial( Qt3DRender::QAbstractTexture *texture, const QMatrix4x4 &modelMatrix, QVector<Qt3DRender::QParameter *> additionalShaderParameters, QNode *parent )
: Qt3DRender::QMaterial( parent )
{
@@ -103,3 +112,7 @@ QgsPreviewQuadMaterial::QgsPreviewQuadMaterial( Qt3DRender::QAbstractTexture *te
setEffect( mEffect );
}

void QgsPreviewQuadMaterial::setModelMatrix( const QMatrix4x4 &modelMatrix )
{
mTextureTransformParameter->setValue( modelMatrix );
}
@@ -35,6 +35,8 @@ class QgsPreviewQuadMaterial : public Qt3DRender::QMaterial
public:
//! Constructor
QgsPreviewQuadMaterial( Qt3DRender::QAbstractTexture *texture, const QMatrix4x4 &modelMatrix, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>(), QNode *parent = nullptr );

void setModelMatrix( const QMatrix4x4 &modelMatrix );
private:
Qt3DRender::QEffect *mEffect = nullptr;
Qt3DRender::QParameter *mTextureParameter = nullptr;
@@ -62,6 +64,8 @@ class QgsPreviewQuad : public Qt3DCore::QEntity
* \param parent The parent of the quad
*/
QgsPreviewQuad( Qt3DRender::QAbstractTexture *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>(), Qt3DCore::QEntity *parent = nullptr );

void setViewPort( const QPointF &centerNDC, const QSizeF &size );
private:
QgsPreviewQuadMaterial *mMaterial = nullptr;
};
@@ -186,23 +186,28 @@ QgsShadowRenderingFrameGraph::QgsShadowRenderingFrameGraph( QWindow *window, Qt3
Qt3DRender::QFrameGraphNode *postprocessingPass = constructPostprocessingPass();
postprocessingPass->setParent( mLightCameraSelector );


mPostprocessingEntity = new QgsPostprocessingEntity( this, mRootEntity );
mPostprocessingEntity->addComponent( mPostprocessPassLayer );

// textures preview pass
Qt3DRender::QFrameGraphNode *previewPass = constructTexturesPreviewPass();
previewPass->setParent( mMainViewPort );

this->addTexturePreviewOverlay( mForwardDepthTexture, QPointF( 0.8f, 0.8f ), QSizeF( 0.2f, 0.2f ) );

mDebugDepthMapPreviewQuad = this->addTexturePreviewOverlay( mForwardDepthTexture, QPointF( 0.8f, 0.8f ), QSizeF( 0.2f, 0.2f ) );
mDebugShadowMapPreviewQuad = this->addTexturePreviewOverlay( mShadowMapTexture, QPointF( -0.8f, -0.8f ), QSizeF( 0.2f, 0.2f ) );
mDebugDepthMapPreviewQuad->setEnabled( false );
mDebugShadowMapPreviewQuad->setEnabled( false );
// this->addTexturePreviewOverlay( mForwardDepthTexture, QPointF( 0.8f, 0.8f ), QSizeF( 0.2f, 0.2f ) );
}

void QgsShadowRenderingFrameGraph::addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters )
QgsPreviewQuad *QgsShadowRenderingFrameGraph::addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters )
{
QgsPreviewQuad *previewQuad = new QgsPreviewQuad( texture, centerNDC, size, additionalShaderParameters );
previewQuad->addComponent( mPreviewLayer );
previewQuad->setParent( mRootEntity );
mPreviewQuads.push_back( previewQuad );
return previewQuad;
}

QVector3D WorldPosFromDepth( QMatrix4x4 projMatrixInv, QMatrix4x4 viewMatrixInv, float texCoordX, float texCoordY, float depth )
@@ -355,3 +360,35 @@ void QgsShadowRenderingFrameGraph::setupEyeDomeLighting( bool enabled, double st
mPostprocessingEntity->setEyeDomeLightingStrength( strength );
mPostprocessingEntity->setEyeDomeLightingDistance( distance );
}

void QgsShadowRenderingFrameGraph::setupShadowMapDebugging( bool enabled, const QString &corner, double size )
{
mDebugShadowMapPreviewQuad->setEnabled( enabled );
if ( enabled )
{
if ( corner == QStringLiteral( "Top Right" ) )
mDebugShadowMapPreviewQuad->setViewPort( QPointF( 1.0f - size, 1.0f - size ), QSizeF( size, size ) );
else if ( corner == QStringLiteral( "Bottom Right" ) )
mDebugShadowMapPreviewQuad->setViewPort( QPointF( 1.0f - size, -1.0f + size ), QSizeF( size, size ) );
else if ( corner == QStringLiteral( "Top Left" ) )
mDebugShadowMapPreviewQuad->setViewPort( QPointF( -1.0f + size, 1.0f - size ), QSizeF( size, size ) );
else if ( corner == QStringLiteral( "Bottom Left" ) )
mDebugShadowMapPreviewQuad->setViewPort( QPointF( -1.0f + size, -1.0f + size ), QSizeF( size, size ) );
}
}

void QgsShadowRenderingFrameGraph::setupDepthMapDebugging( bool enabled, const QString &corner, double size )
{
mDebugDepthMapPreviewQuad->setEnabled( enabled );
if ( enabled )
{
if ( corner == QStringLiteral( "Top Right" ) )
mDebugDepthMapPreviewQuad->setViewPort( QPointF( 1.0f - size, 1.0f - size ), QSizeF( size, size ) );
else if ( corner == QStringLiteral( "Bottom Right" ) )
mDebugDepthMapPreviewQuad->setViewPort( QPointF( 1.0f - size, -1.0f + size ), QSizeF( size, size ) );
else if ( corner == QStringLiteral( "Top Left" ) )
mDebugDepthMapPreviewQuad->setViewPort( QPointF( -1.0f + size, 1.0f - size ), QSizeF( size, size ) );
else if ( corner == QStringLiteral( "Bottom Left" ) )
mDebugDepthMapPreviewQuad->setViewPort( QPointF( -1.0f + size, -1.0f + size ), QSizeF( size, size ) );
}
}
@@ -113,11 +113,16 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
//! Sets the clear color of the scene (background color)
void setClearColor( const QColor &clearColor );
//! Adds an preview entity that shows a texture in real time for debugging purposes
void addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
QgsPreviewQuad *addTexturePreviewOverlay( Qt3DRender::QTexture2D *texture, const QPointF &centerNDC, const QSizeF &size, QVector<Qt3DRender::QParameter *> additionalShaderParameters = QVector<Qt3DRender::QParameter *>() );
//! Sets shadow rendering to use a directional light
void setupDirectionalLight( const QgsDirectionalLightSettings &light, float maximumShadowRenderingDistance );
//! Sets eye dome lighting shading related settings
void setupEyeDomeLighting( bool enabled, double strength, int distance );
//! Sets the shadow map debugging view port
void setupShadowMapDebugging( bool enabled, const QString &corner, double size );
//! Sets the depth map debugging view port
void setupDepthMapDebugging( bool enabled, const QString &corner, double size );

private:
Qt3DRender::QRenderSurfaceSelector *mRenderSurfaceSelector = nullptr;
Qt3DRender::QViewport *mMainViewPort = nullptr;
@@ -159,6 +164,9 @@ class QgsShadowRenderingFrameGraph : public Qt3DCore::QEntity
double mEyeDomeLightingStrength = 1000.0;
int mEyeDomeLightingDistance = 1;

QgsPreviewQuad *mDebugShadowMapPreviewQuad = nullptr;
QgsPreviewQuad *mDebugDepthMapPreviewQuad = nullptr;

Qt3DRender::QLayerFilter *mShadowSceneEntitiesFilter = nullptr;
Qt3DRender::QRenderStateSet *mShadowRenderStateSet = nullptr;
Qt3DRender::QCullFace *mShadowCullFace = nullptr;

0 comments on commit c3ef5cc

Please sign in to comment.
You can’t perform that action at this time.