18#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
19#include <Qt3DRender/QAttribute>
20#include <Qt3DRender/QBuffer>
21#include <Qt3DRender/QGeometry>
27#include <Qt3DCore/QAttribute>
28#include <Qt3DCore/QBuffer>
29#include <Qt3DCore/QGeometry>
36#include <Qt3DRender/QGeometryRenderer>
37#include <Qt3DRender/QParameter>
38#include <Qt3DRender/QTechnique>
39#include <Qt3DRender/QGraphicsApiFilter>
40#include <Qt3DRender/QDepthTest>
47 , mFrameGraph( frameGraph )
49 mColorTextureParameter =
new Qt3DRender::QParameter( QStringLiteral(
"colorTexture" ), frameGraph->
forwardRenderColorTexture() );
50 mDepthTextureParameter =
new Qt3DRender::QParameter( QStringLiteral(
"depthTexture" ), frameGraph->
forwardRenderDepthTexture() );
51 mShadowMapParameter =
new Qt3DRender::QParameter( QStringLiteral(
"shadowTexture" ), frameGraph->
shadowMapTexture() );
53 mMaterial->addParameter( mColorTextureParameter );
54 mMaterial->addParameter( mDepthTextureParameter );
55 mMaterial->addParameter( mShadowMapParameter );
56 mMaterial->addParameter( mAmbientOcclusionTextureParameter );
61 mFarPlaneParameter =
new Qt3DRender::QParameter( QStringLiteral(
"farPlane" ), mMainCamera->farPlane() );
62 mMaterial->addParameter( mFarPlaneParameter );
63 connect( mMainCamera, &Qt3DRender::QCamera::farPlaneChanged, mFarPlaneParameter, [&](
float farPlane )
65 mFarPlaneParameter->setValue( farPlane );
67 mNearPlaneParameter =
new Qt3DRender::QParameter( QStringLiteral(
"nearPlane" ), mMainCamera->nearPlane() );
68 mMaterial->addParameter( mNearPlaneParameter );
69 connect( mMainCamera, &Qt3DRender::QCamera::nearPlaneChanged, mNearPlaneParameter, [&](
float nearPlane )
71 mNearPlaneParameter->setValue( nearPlane );
74 mLightFarPlaneParameter =
new Qt3DRender::QParameter( QStringLiteral(
"lightFarPlane" ), mLightCamera->farPlane() );
75 mMaterial->addParameter( mLightFarPlaneParameter );
76 connect( mLightCamera, &Qt3DRender::QCamera::farPlaneChanged, mLightFarPlaneParameter, [&](
float farPlane )
78 mLightFarPlaneParameter->setValue( farPlane );
80 mLightNearPlaneParameter =
new Qt3DRender::QParameter( QStringLiteral(
"lightNearPlane" ), mLightCamera->nearPlane() );
81 mMaterial->addParameter( mLightNearPlaneParameter );
82 connect( mLightCamera, &Qt3DRender::QCamera::nearPlaneChanged, mLightNearPlaneParameter, [&](
float nearPlane )
84 mLightNearPlaneParameter->setValue( nearPlane );
87 mMainCameraInvViewMatrixParameter =
new Qt3DRender::QParameter( QStringLiteral(
"invertedCameraView" ), mMainCamera->viewMatrix().inverted() );
88 mMaterial->addParameter( mMainCameraInvViewMatrixParameter );
89 mMainCameraInvProjMatrixParameter =
new Qt3DRender::QParameter( QStringLiteral(
"invertedCameraProj" ), mMainCamera->projectionMatrix().inverted() );
90 mMaterial->addParameter( mMainCameraInvProjMatrixParameter );
91 connect( mMainCamera, &Qt3DRender::QCamera::projectionMatrixChanged, mMainCameraInvProjMatrixParameter, [&](
const QMatrix4x4 & projectionMatrix )
93 mMainCameraInvProjMatrixParameter->setValue( projectionMatrix.inverted() );
95 connect( mMainCamera, &Qt3DRender::QCamera::viewMatrixChanged, mMainCameraInvViewMatrixParameter, [&]()
97 mMainCameraInvViewMatrixParameter->setValue( mMainCamera->viewMatrix().inverted() );
100 mShadowMinX =
new Qt3DRender::QParameter( QStringLiteral(
"shadowMinX" ), QVariant::fromValue( 0.0f ) );
101 mShadowMaxX =
new Qt3DRender::QParameter( QStringLiteral(
"shadowMaxX" ), QVariant::fromValue( 0.0f ) );
102 mShadowMinZ =
new Qt3DRender::QParameter( QStringLiteral(
"shadowMinZ" ), QVariant::fromValue( 0.0f ) );
103 mShadowMaxZ =
new Qt3DRender::QParameter( QStringLiteral(
"shadowMaxZ" ), QVariant::fromValue( 0.0f ) );
109 mRenderShadowsParameter =
new Qt3DRender::QParameter( QStringLiteral(
"renderShadows" ), QVariant::fromValue( 0 ) );
110 mMaterial->addParameter( mRenderShadowsParameter );
112 mShadowBiasParameter =
new Qt3DRender::QParameter( QStringLiteral(
"shadowBias" ), QVariant::fromValue( 0.00001f ) );
113 mMaterial->addParameter( mShadowBiasParameter );
115 mEyeDomeLightingEnabledParameter =
new Qt3DRender::QParameter( QStringLiteral(
"edlEnabled" ), QVariant::fromValue( 0 ) );
116 mEyeDomeLightingStrengthParameter =
new Qt3DRender::QParameter( QStringLiteral(
"edlStrength" ), QVariant::fromValue( 1000.0f ) );
117 mEyeDomeLightingDistanceParameter =
new Qt3DRender::QParameter( QStringLiteral(
"edlDistance" ), QVariant::fromValue( 2.0f ) );
118 mMaterial->addParameter( mEyeDomeLightingEnabledParameter );
119 mMaterial->addParameter( mEyeDomeLightingStrengthParameter );
120 mMaterial->addParameter( mEyeDomeLightingDistanceParameter );
122 mAmbientOcclusionEnabledParameter =
new Qt3DRender::QParameter( QStringLiteral(
"ssaoEnabled" ), QVariant::fromValue( 0 ) );
123 mMaterial->addParameter( mAmbientOcclusionEnabledParameter );
125 mLightPosition =
new Qt3DRender::QParameter( QStringLiteral(
"lightPosition" ), QVariant::fromValue( QVector3D() ) );
126 mLightDirection =
new Qt3DRender::QParameter( QStringLiteral(
"lightDirection" ), QVariant::fromValue( QVector3D() ) );
127 mMaterial->addParameter( mLightPosition );
128 mMaterial->addParameter( mLightDirection );
130 const QString vertexShaderPath = QStringLiteral(
"qrc:/shaders/postprocess.vert" );
131 const QString fragmentShaderPath = QStringLiteral(
"qrc:/shaders/postprocess.frag" );
133 mShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( vertexShaderPath ) ) );
134 mShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( fragmentShaderPath ) ) );
139 mShadowMinX->setValue( minX );
140 mShadowMaxX->setValue( maxX );
141 mShadowMinZ->setValue( minZ );
142 mShadowMaxZ->setValue( maxZ );
147 mLightPosition->setValue( QVariant::fromValue( position ) );
148 mLightDirection->setValue( QVariant::fromValue( direction.normalized() ) );
153 mRenderShadowsParameter->setValue( QVariant::fromValue( enabled ? 1 : 0 ) );
158 mShadowBiasParameter->setValue( QVariant::fromValue( shadowBias ) );
163 mEyeDomeLightingEnabledParameter->setValue( QVariant::fromValue( enabled ? 1 : 0 ) );
168 mEyeDomeLightingStrengthParameter->setValue( QVariant::fromValue( strength ) );
173 mEyeDomeLightingDistanceParameter->setValue( QVariant::fromValue( distance ) );
178 mAmbientOcclusionEnabledParameter->setValue( enabled );
void setupShadowRenderingExtent(float minX, float maxX, float minZ, float maxZ)
Sets the parts of the scene where objects cast shadows.
QgsPostprocessingEntity(QgsShadowRenderingFrameGraph *frameGraph, QNode *parent=nullptr)
Constructor.
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.
Qt3DRender::QShaderProgram * mShader
Qt3DRender::QMaterial * mMaterial
Qt3DRender::QTexture2D * shadowMapTexture()
Returns the shadow map (a depth texture for the shadow rendering pass)
Qt3DRender::QCamera * lightCamera()
Returns the light camera.
Qt3DRender::QTexture2D * forwardRenderColorTexture()
Returns the color texture of the forward rendering pass.
Qt3DRender::QTexture2D * forwardRenderDepthTexture()
Returns the depth texture of the forward rendering pass.
Qt3DRender::QCamera * mainCamera()
Returns the main camera.
Qt3DRender::QTexture2D * blurredAmbientOcclusionFactorMap()
Returns blurred ambient occlusion factor values texture.
Qt3DCore::QAttribute Qt3DQAttribute
Qt3DCore::QBuffer Qt3DQBuffer
Qt3DCore::QGeometry Qt3DQGeometry