QGIS API Documentation
4.3.0-Master (1c7cf7431bd)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
3d
qgsenvironmentlight.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsenvironmentlight.cpp
3
--------------------------------------
4
Date : May 2026
5
Copyright : (C) 2026 by Nyall Dawson
6
Email : nyall dot dawson at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsenvironmentlight.h
"
17
18
#include "
qgsframegraph.h
"
19
20
#include <QString>
21
#include <QVector3D>
22
#include <Qt3DRender/QParameter>
23
#include <Qt3DRender/QTexture>
24
25
#include "moc_qgsenvironmentlight.cpp"
26
27
using namespace
Qt::StringLiterals;
28
29
QgsEnvironmentLight::QgsEnvironmentLight
(
QgsFrameGraph
*frameGraph, QNode *parent )
30
:
Qt3DCore
::QEntity( parent )
31
{
32
const
QVariantList sh( 9, QVector3D( 0, 0, 0 ) );
33
mShParam =
new
Qt3DRender::QParameter( u
"envLightSh[0]"
_s, QVariant::fromValue( sh ),
this
);
34
35
mDummyCubeMap =
new
Qt3DRender::QTextureCubeMap(
this
);
36
mDummyCubeMap->setFormat( Qt3DRender::QAbstractTexture::RGBA8_UNorm );
37
mDummyCubeMap->setWidth( 1 );
38
mDummyCubeMap->setHeight( 1 );
39
mDummyCubeMap->setGenerateMipMaps(
false
);
40
mDummyCubeMap->setMagnificationFilter( Qt3DRender::QAbstractTexture::Nearest );
41
mDummyCubeMap->setMinificationFilter( Qt3DRender::QAbstractTexture::Nearest );
42
43
mSpecularMapParam =
new
Qt3DRender::QParameter( u
"globalSpecularMap"
_s, QVariant::fromValue( mDummyCubeMap ),
this
);
44
mMipLevelsParam =
new
Qt3DRender::QParameter( u
"globalSpecularMipLevels"
_s, 1,
this
);
45
46
mEnvironmentLightModeParam =
new
Qt3DRender::QParameter( u
"envLightMode"
_s, 0,
this
);
47
mEnvironmentLightStrengthParam =
new
Qt3DRender::QParameter( u
"envLightStrength"
_s, 1,
this
);
48
frameGraph->
addGlobalParameters
( { mShParam, mSpecularMapParam, mMipLevelsParam, mEnvironmentLightModeParam, mEnvironmentLightStrengthParam } );
49
}
50
51
void
QgsEnvironmentLight::setMode
(
Mode
mode )
52
{
53
switch
( mode )
54
{
55
case
Mode::Disabled
:
56
mEnvironmentLightModeParam->setValue( 0 );
57
break
;
58
case
Mode::SpecularMapWithSphericalHarmonics
:
59
mEnvironmentLightModeParam->setValue( 1 );
60
break
;
61
}
62
}
63
64
void
QgsEnvironmentLight::setStrength
(
float
strength )
65
{
66
mEnvironmentLightStrengthParam->setValue( strength );
67
}
68
69
void
QgsEnvironmentLight::setSphericalHarmonics
(
const
QVector<QVector3D> &harmonics )
70
{
71
Q_ASSERT( harmonics.size() == 9 );
72
QVariantList value;
73
value.reserve( 9 );
74
for
(
const
QVector3D &vector : harmonics )
75
{
76
value << vector;
77
}
78
mShParam->setValue( QVariant::fromValue( value ) );
79
}
80
81
void
QgsEnvironmentLight::setSpecularMap
( Qt3DRender::QTextureCubeMap *specularTexture,
int
mipLevels )
82
{
83
mSpecularMapParam->setValue( specularTexture ? QVariant::fromValue( specularTexture ) : QVariant::fromValue( mDummyCubeMap ) );
84
mMipLevelsParam->setValue( mipLevels );
85
}
QgsEnvironmentLight::QgsEnvironmentLight
QgsEnvironmentLight(QgsFrameGraph *frameGraph, QNode *parent=nullptr)
Constructor.
Definition
qgsenvironmentlight.cpp:29
QgsEnvironmentLight::setStrength
void setStrength(float strength)
Sets the strength of the environmental light, as a factor between 0 and 1.
Definition
qgsenvironmentlight.cpp:64
QgsEnvironmentLight::Mode
Mode
Environmental lighting modes.
Definition
qgsenvironmentlight.h:52
QgsEnvironmentLight::Mode::SpecularMapWithSphericalHarmonics
@ SpecularMapWithSphericalHarmonics
Specular map, using spherical harmonics for irradiance.
Definition
qgsenvironmentlight.h:54
QgsEnvironmentLight::Mode::Disabled
@ Disabled
No environment lighting.
Definition
qgsenvironmentlight.h:53
QgsEnvironmentLight::setMode
void setMode(Mode mode)
Sets the environment light mode.
Definition
qgsenvironmentlight.cpp:51
QgsEnvironmentLight::setSpecularMap
void setSpecularMap(Qt3DRender::QTextureCubeMap *specularTexture, int mipLevels)
Sets the specular map texture and available mip levels.
Definition
qgsenvironmentlight.cpp:81
QgsEnvironmentLight::setSphericalHarmonics
void setSphericalHarmonics(const QVector< QVector3D > &harmonics)
Sets the spherical harmonics for irradiant light.
Definition
qgsenvironmentlight.cpp:69
QgsFrameGraph
Container class that holds different objects related to frame graphs of 3D scenes.
Definition
qgsframegraph.h:86
QgsFrameGraph::addGlobalParameters
void addGlobalParameters(const QList< Qt3DRender::QParameter * > ¶meters)
Adds additional global parameters to the graph.
Definition
qgsframegraph.cpp:205
Qt3DCore
Definition
qgsabstract3drenderer.h:33
qgsenvironmentlight.h
qgsframegraph.h
Generated on
for QGIS API Documentation by
1.17.0