17#include "moc_qgsskyboxentity.cpp"
19#include <Qt3DCore/QEntity>
20#include <Qt3DExtras/QCuboidMesh>
21#include <Qt3DRender/QEffect>
22#include <Qt3DRender/QMaterial>
23#include <Qt3DRender/QShaderProgram>
24#include <Qt3DRender/QFilterKey>
25#include <Qt3DRender/QRenderPass>
26#include <Qt3DRender/QTechnique>
27#include <Qt3DRender/QGraphicsApiFilter>
28#include <Qt3DRender/QCullFace>
29#include <Qt3DRender/QDepthTest>
30#include <Qt3DRender/QSeamlessCubemap>
31#include <Qt3DRender/QParameter>
32#include <Qt3DRender/QTextureImage>
42 , mMaterial( new
Qt3DRender::QMaterial( this ) )
43 , mGl3Technique( new
Qt3DRender::QTechnique( this ) )
44 , mFilterKey( new
Qt3DRender::QFilterKey( this ) )
45 , mGl3RenderPass( new
Qt3DRender::QRenderPass( this ) )
47 , mGammaStrengthParameter( new
Qt3DRender::QParameter( QStringLiteral(
"gammaStrength" ), 0.0f ) )
48 , mTextureParameter( new
Qt3DRender::QParameter( this ) )
50 mGl3Technique->graphicsApiFilter()->setApi( Qt3DRender::QGraphicsApiFilter::OpenGL );
53 mGl3Technique->graphicsApiFilter()->setProfile( Qt3DRender::QGraphicsApiFilter::CoreProfile );
56 mFilterKey->setName( QStringLiteral(
"renderingStyle" ) );
57 mFilterKey->setValue( QStringLiteral(
"forward" ) );
61 Qt3DRender::QCullFace *cullFront =
new Qt3DRender::QCullFace();
62 cullFront->setMode( Qt3DRender::QCullFace::Front );
63 Qt3DRender::QDepthTest *depthTest =
new Qt3DRender::QDepthTest();
64 depthTest->setDepthFunction( Qt3DRender::QDepthTest::LessOrEqual );
65 Qt3DRender::QSeamlessCubemap *seamlessCubemap =
new Qt3DRender::QSeamlessCubemap();
79 mMesh->setXYMeshResolution( QSize( 2, 2 ) );
80 mMesh->setXZMeshResolution( QSize( 2, 2 ) );
81 mMesh->setYZMeshResolution( QSize( 2, 2 ) );
83 addComponent(
mMesh );
91 , mTexturePath( texturePath )
92 , mLoadedTexture( new
Qt3DRender::QTextureLoader( parent ) )
93 , mGlShader( new
Qt3DRender::QShaderProgram( this ) )
95 mLoadedTexture->setGenerateMipMaps(
false );
96 mGlShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.vert" ) ) ) );
97 mGlShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/hdr_skybox.frag" ) ) ) );
106void QgsPanoramicSkyboxEntity::reloadTexture()
108 mLoadedTexture->setSource( QUrl::fromUserInput( mTexturePath ) );
115 , mGlShader( new
Qt3DRender::QShaderProgram() )
116 , mCubeMap( new
Qt3DRender::QTextureCubeMap( this ) )
119 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveX] = posX;
120 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveY] = posY;
121 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveZ] = posZ;
122 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeX] = negX;
123 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeY] = negY;
124 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeZ] = negZ;
128void QgsCubeFacesSkyboxEntity::init()
130 mGlShader->setVertexShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.vert" ) ) ) );
131 mGlShader->setFragmentShaderCode( Qt3DRender::QShaderProgram::loadSource( QUrl( QStringLiteral(
"qrc:/shaders/skybox.frag" ) ) ) );
134 mCubeMap->setMagnificationFilter( Qt3DRender::QTextureCubeMap::Linear );
135 mCubeMap->setMinificationFilter( Qt3DRender::QTextureCubeMap::Linear );
136 mCubeMap->setGenerateMipMaps(
false );
137 mCubeMap->setWrapMode( Qt3DRender::QTextureWrapMode( Qt3DRender::QTextureWrapMode::Repeat ) );
139 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveX] = QString();
140 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveY] = QString();
141 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapPositiveZ] = QString();
142 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeX] = QString();
143 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeY] = QString();
144 mCubeFacesPaths[Qt3DRender::QTextureCubeMap::CubeMapNegativeZ] = QString();
150void QgsCubeFacesSkyboxEntity::reloadTexture()
152 for ( Qt3DRender::QAbstractTextureImage *textureImage : mFacesTextureImages )
154 mCubeMap->removeTextureImage( textureImage );
157 mFacesTextureImages.clear();
159 for (
auto it = mCubeFacesPaths.begin(); it != mCubeFacesPaths.end(); ++it )
161 const Qt3DRender::QTextureCubeMap::CubeMapFace face = it.key();
162 const QString texturePath = it.value();
163 Qt3DRender::QTextureImage *image =
new Qt3DRender::QTextureImage(
this );
164 image->setFace( face );
165 image->setMirrored(
false );
166 image->setSource( QUrl::fromUserInput( texturePath ) );
167 mCubeMap->addTextureImage( image );
168 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