QGIS API Documentation 4.1.0-Master (ca2ac17535b)
Loading...
Searching...
No Matches
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
27using namespace Qt::StringLiterals;
28
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
52{
53 switch ( mode )
54 {
55 case Mode::Disabled:
56 mEnvironmentLightModeParam->setValue( 0 );
57 break;
59 mEnvironmentLightModeParam->setValue( 1 );
60 break;
61 }
62}
63
65{
66 mEnvironmentLightStrengthParam->setValue( strength );
67}
68
69void 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
81void QgsEnvironmentLight::setSpecularMap( Qt3DRender::QTextureCubeMap *specularTexture, int mipLevels )
82{
83 mSpecularMapParam->setValue( specularTexture ? QVariant::fromValue( specularTexture ) : QVariant::fromValue( mDummyCubeMap ) );
84 mMipLevelsParam->setValue( mipLevels );
85}
QgsEnvironmentLight(QgsFrameGraph *frameGraph, QNode *parent=nullptr)
Constructor.
void setStrength(float strength)
Sets the strength of the environmental light, as a factor between 0 and 1.
Mode
Environmental lighting modes.
@ SpecularMapWithSphericalHarmonics
Specular map, using spherical harmonics for irradiance.
@ Disabled
No environment lighting.
void setMode(Mode mode)
Sets the environment light mode.
void setSpecularMap(Qt3DRender::QTextureCubeMap *specularTexture, int mipLevels)
Sets the specular map texture and available mip levels.
void setSphericalHarmonics(const QVector< QVector3D > &harmonics)
Sets the spherical harmonics for irradiant light.
Container class that holds different objects related to frame graphs of 3D scenes.
void addGlobalParameters(const QList< Qt3DRender::QParameter * > &parameters)
Adds additional global parameters to the graph.