Skip to content

Commit

Permalink
qgsmesh3dmaterial: Add support for gl_ClipDistance
Browse files Browse the repository at this point in the history
This is achieved with two changes:
1. define the plane equation as uniform with the
`Qgs3DUtils::addBoundingBoxParametersToEffect` call
2. include `clipplane.inc` file in the vertex shader file and call
setClipDistance()

With these changes, the planes defined in the framegraph are used.
  • Loading branch information
ptitjano committed Jul 12, 2024
1 parent e58c189 commit 0bb1e81
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 9 deletions.
6 changes: 3 additions & 3 deletions src/3d/mesh/qgsmesh3dentity_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void QgsMeshDataset3DEntity::applyMaterial()
if ( datasetGroupIndex >= 0 )
mSymbol->setColorRampShader( rendererSettings.scalarSettings( datasetGroupIndex ).colorRampShader() );
}
QgsMesh3DMaterial *material = new QgsMesh3DMaterial( layer(), mMapSettings.temporalRange(), mMapSettings.origin(), mSymbol.get(), QgsMesh3DMaterial::ScalarDataSet );
QgsMesh3DMaterial *material = new QgsMesh3DMaterial( layer(), mMapSettings, mSymbol.get(), QgsMesh3DMaterial::ScalarDataSet );
addComponent( material );
}

Expand Down Expand Up @@ -96,8 +96,8 @@ void QgsMesh3DTerrainTileEntity::buildGeometry()
void QgsMesh3DTerrainTileEntity::applyMaterial()
{
QgsMesh3DMaterial *material = new QgsMesh3DMaterial(
nullptr, QgsDateTimeRange(),
mMapSettings.origin(),
nullptr,
mMapSettings,
mSymbol.get(),
QgsMesh3DMaterial::ZValue );
addComponent( material );
Expand Down
10 changes: 6 additions & 4 deletions src/3d/mesh/qgsmesh3dmaterial_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
***************************************************************************/

#include "qgsmesh3dmaterial_p.h"
#include "qgs3dmapsettings.h"

#include <Qt3DRender/QEffect>
#include <Qt3DRender/QGraphicsApiFilter>
Expand Down Expand Up @@ -110,21 +111,22 @@ class ArrowsTextureGenerator: public Qt3DRender::QTextureImageDataGenerator


QgsMesh3DMaterial::QgsMesh3DMaterial( QgsMeshLayer *layer,
const QgsDateTimeRange &timeRange,
const QgsVector3D &origin,
const Qgs3DMapSettings &mapSettings,
const QgsMesh3DSymbol *symbol,
MagnitudeType magnitudeType )
: mSymbol( symbol->clone() )
, mMagnitudeType( magnitudeType )
, mOrigin( origin )
, mOrigin( mapSettings.origin() )
{
Qt3DRender::QEffect *eff = new Qt3DRender::QEffect( this );

configure();

// this method has to be called even if there isn't arrows (terrain) because it configures the parameter of shaders
// If all the parameters ("uniform" in shaders) are not defined in QGIS, the shaders sometimes don't work (depends on hardware?)
configureArrows( layer, timeRange );
configureArrows( layer, mapSettings.temporalRange() );

Qgs3DUtils::addBoundingBoxParametersToEffect( eff, mapSettings );

eff->addTechnique( mTechnique );
setEffect( eff );
Expand Down
5 changes: 3 additions & 2 deletions src/3d/mesh/qgsmesh3dmaterial_p.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include <Qt3DRender/QTechnique>
#include <Qt3DRender/QAbstractTextureImage>

#include "qgs3dmapsettings.h"
#include "qgsmesh3dsymbol.h"
#include "qgsvector3d.h"

Expand All @@ -41,6 +42,7 @@
#define SIP_NO_FILE

class QgsMeshLayer;
class Qgs3DMapSettings;

/**
* \ingroup 3d
Expand Down Expand Up @@ -71,8 +73,7 @@ class QgsMesh3DMaterial : public Qt3DRender::QMaterial

//! Constructor
QgsMesh3DMaterial( QgsMeshLayer *layer,
const QgsDateTimeRange &timeRange,
const QgsVector3D &origin,
const Qgs3DMapSettings &mapSettings,
const QgsMesh3DSymbol *symbol,
MagnitudeType magnitudeType = ZValue );

Expand Down
4 changes: 4 additions & 0 deletions src/3d/shaders/mesh/mesh.vert
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ out MeshVertex {
float magnitude;
} vs_out;

#pragma include ../clipplane.inc

void main()
{
gl_Position = mvp * vec4( vertexPosition, 1.0 );
Expand All @@ -28,4 +30,6 @@ void main()
vs_out.magnitude=scalarMagnitude;
else
vs_out.magnitude=worldPosition.y;

setClipDistance(worldPosition);
}

0 comments on commit 0bb1e81

Please sign in to comment.