18 #include <Qt3DCore/QEntity>
19 #include <Qt3DExtras/QCuboidMesh>
20 #include <Qt3DRender/QEffect>
21 #include <Qt3DRender/QMaterial>
22 #include <Qt3DRender/QShaderProgram>
23 #include <Qt3DRender/QFilterKey>
24 #include <Qt3DRender/QRenderPass>
25 #include <Qt3DRender/QTechnique>
26 #include <Qt3DRender/QGraphicsApiFilter>
27 #include <Qt3DRender/QCullFace>
28 #include <Qt3DRender/QDepthTest>
29 #include <Qt3DRender/QSeamlessCubemap>
30 #include <Qt3DRender/QParameter>
31 #include <Qt3DRender/QTextureImage>
41 , mMaterial( new
Qt3DRender::QMaterial( this ) )
42 , mGl3Technique( new
Qt3DRender::QTechnique( this ) )
43 , mFilterKey( new
Qt3DRender::QFilterKey( this ) )
44 , mGl3RenderPass( new
Qt3DRender::QRenderPass( this ) )
46 , mGammaStrengthParameter( new
Qt3DRender::QParameter( QStringLiteral(
"gammaStrength" ), 0.0f ) )
47 , mTextureParameter( new
Qt3DRender::QParameter( this ) )
49 mGl3Technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
52 mGl3Technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
55 mFilterKey->setName( QStringLiteral(
"renderingStyle" ) );
56 mFilterKey->setValue( QStringLiteral(
"forward" ) );
60 Qt3DRender::QCullFace *cullFront =
new Qt3DRender::QCullFace();
61 cullFront->setMode( Qt3DRender::QCullFace::Front );
62 Qt3DRender::QDepthTest *depthTest =
new Qt3DRender::QDepthTest();
63 depthTest->setDepthFunction( Qt3DRender::QDepthTest::LessOrEqual );
64 Qt3DRender::QSeamlessCubemap *seamlessCubemap =
new Qt3DRender::QSeamlessCubemap();
78 mMesh->setXYMeshResolution( QSize( 2, 2 ) );
79 mMesh->setXZMeshResolution( QSize( 2, 2 ) );
80 mMesh->setYZMeshResolution( QSize( 2, 2 ) );
82 addComponent(
mMesh );
90 , mTexturePath( texturePath )
91 , mLoadedTexture( new
Qt3DRender::QTextureLoader( parent ) )
92 , mGlShader( new
Qt3DRender::QShaderProgram( this ) )
94 mLoadedTexture->setGenerateMipMaps(
false );
95 mGlShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.vert" ) ) ) );
96 mGlShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/hdr_skybox.frag" ) ) ) );
105 void QgsPanoramicSkyboxEntity::reloadTexture()
107 mLoadedTexture->setSource( QUrl::fromUserInput( mTexturePath ) );
114 , mGlShader( new
Qt3DRender::QShaderProgram() )
115 , mCubeMap( new
Qt3DRender::QTextureCubeMap( this ) )
118 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveX] = posX;
119 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveY] = posY;
120 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveZ] = posZ;
121 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeX] = negX;
122 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeY] = negY;
123 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeZ] = negZ;
127 void QgsCubeFacesSkyboxEntity::init()
129 mGlShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.vert" ) ) ) );
130 mGlShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.frag" ) ) ) );
133 mCubeMap->setMagnificationFilter( Qt3DRender::QTextureCubeMap::Linear );
134 mCubeMap->setMinificationFilter( Qt3DRender::QTextureCubeMap::Linear );
135 mCubeMap->setGenerateMipMaps(
false );
136 mCubeMap->setWrapMode( Qt3DRender::QTextureWrapMode( Qt3DRender::QTextureWrapMode::Repeat ) );
138 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveX] = QString();
139 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveY] = QString();
140 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveZ] = QString();
141 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeX] = QString();
142 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeY] = QString();
143 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeZ] = QString();
149 void QgsCubeFacesSkyboxEntity::reloadTexture()
151 for ( Qt3DRender::QAbstractTextureImage *textureImage : mFacesTextureImages )
153 mCubeMap->removeTextureImage( textureImage );
156 mFacesTextureImages.clear();
158 for (
auto it = mCubeFacesPaths.begin(); it != mCubeFacesPaths.end(); ++it )
160 Qt3DRender::QTextureCubeMap::CubeMapFace face = it.key();
161 QString texturePath = it.value();
162 Qt3DRender::QTextureImage *image =
new Qt3DRender::QTextureImage(
this );
163 image->setFace( face );
164 image->setMirrored(
false );
165 image->setSource( QUrl::fromUserInput( texturePath ) );
166 mCubeMap->addTextureImage( image );
167 mFacesTextureImages.push_back( image );
QgsCubeFacesSkyboxEntity(const QString &posX, const QString &posY, const QString &posZ, const QString &negX, const QString &negY, const QString &negZ, Qt3DCore::QNode *parent=nullptr)
Constructs a skybox from 6 different images.
QgsPanoramicSkyboxEntity(const QString &texturePath, Qt3DCore::QNode *parent=nullptr)
Construct a skybox from a panoramic 360 image.
Base class for all skybox types.
QgsSkyboxEntity(QNode *parent=nullptr)
Constructor.
Qt3DRender::QRenderPass * mGl3RenderPass
Qt3DRender::QParameter * mGammaStrengthParameter
Qt3DRender::QFilterKey * mFilterKey
Qt3DRender::QEffect * mEffect
Qt3DExtras::QCuboidMesh * mMesh
Qt3DRender::QParameter * mTextureParameter
Qt3DRender::QMaterial * mMaterial
Qt3DRender::QTechnique * mGl3Technique