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 ) ) );