23using namespace Qt::StringLiterals;
65 return *
this == *otherGooch;
70 const double kDiffuse = 0.8;
71 const double kSpecular = 0.2;
73 double red = 0.5 * kDiffuse * ( ( mCool.redF() + mAlpha * mDiffuse.redF() ) + ( mWarm.redF() + mBeta * mDiffuse.redF() ) ) + kSpecular * mSpecular.redF();
74 double green = 0.5 * kDiffuse * ( ( mCool.greenF() + mAlpha * mDiffuse.greenF() ) + ( mWarm.greenF() + mBeta * mDiffuse.greenF() ) ) + kSpecular * mSpecular.greenF();
75 double blue = 0.5 * kDiffuse * ( ( mCool.blueF() + mAlpha * mDiffuse.blueF() ) + ( mWarm.blueF() + mBeta * mDiffuse.blueF() ) ) + kSpecular * mSpecular.blueF();
77 red = std::clamp( red, 0.0, 1.0 );
78 green = std::clamp( green, 0.0, 1.0 );
79 blue = std::clamp( blue, 0.0, 1.0 );
81 return QColor::fromRgbF(
static_cast<float>( red ),
static_cast<float>( green ),
static_cast<float>( blue ) );
86 mAlpha = std::clamp(
alpha, 0.0, 1.0 );
87 mBeta = std::clamp(
beta, 0.0, 1.0 );
89 const float alphaF =
static_cast<float>( mAlpha );
90 const float betaF =
static_cast<float>( mBeta );
94 mCool.setRedF( baseColor.redF() * ( 1.0f - alphaF ) );
95 mCool.setGreenF( baseColor.greenF() * ( 1.0f - alphaF ) );
96 mCool.setBlueF( baseColor.blueF() * ( 1.0f - alphaF ) + alphaF );
100 mWarm.setRedF( baseColor.redF() * ( 1.0f - betaF ) + betaF );
101 mWarm.setGreenF( baseColor.greenF() * ( 1.0f - betaF ) + betaF );
102 mWarm.setBlueF( baseColor.blueF() * ( 1.0f - betaF ) );
105 mDiffuse.setRedF( 0.5f * ( mWarm.redF() + mCool.redF() ) );
106 mDiffuse.setGreenF( 0.5f * ( mWarm.greenF() + mCool.greenF() ) );
107 mDiffuse.setBlueF( 0.5f * ( mWarm.blueF() + mCool.blueF() ) );
110 mSpecular = QColor::fromRgbF( 0.4f, 0.4f, 0.4f );
124 mShininess = elem.attribute( u
"shininess2"_s, u
"100"_s ).toDouble();
125 mAlpha = elem.attribute( u
"alpha"_s, u
"0.25"_s ).toDouble();
126 mBeta = elem.attribute( u
"beta"_s, u
"0.5"_s ).toDouble();
137 elem.setAttribute( u
"shininess2"_s, mShininess );
138 elem.setAttribute( u
"alpha"_s, mAlpha );
139 elem.setAttribute( u
"beta"_s, mBeta );
MaterialRenderingTechnique
Material rendering techniques.
@ Points
Point based rendering, requires point data.
@ Triangles
Triangle based rendering (default).
@ TrianglesFromModel
Triangle based rendering, using a model object source.
@ Lines
Line based rendering, requires line data.
@ Billboards
Flat billboard rendering.
@ TrianglesDataDefined
Triangle based rendering with possibility of datadefined color.
@ InstancedPoints
Instanced based rendering, requiring triangles and point data.
@ TrianglesWithFixedTexture
Triangle based rendering, using a fixed, non-user-configurable texture (e.g. for terrain rendering).
Abstract base class for material settings.
virtual void writeXml(QDomElement &element, const QgsReadWriteContext &) const
Writes settings to a DOM element.
virtual void readXml(const QDomElement &element, const QgsReadWriteContext &)
Reads settings from a DOM element.
static QColor colorFromString(const QString &string)
Decodes a string into a color value.
static QString colorToString(const QColor &color)
Encodes a color into a string value.
QgsGoochMaterialSettings * clone() const override
Clones the material settings.
QColor averageColor() const override
Returns an approximate color representing the blended material color.
double alpha() const
Returns the alpha value.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
bool equals(const QgsAbstractMaterialSettings *other) const override
Returns true if this settings exactly matches an other settings.
void setColorsFromBase(const QColor &baseColor, double alpha, double beta)
Decomposes an average color into Gooch material components, and sets the material colors accordingly.
QString type() const override
Returns the unique type name for the material.
double beta() const
Returns the beta value.
QgsGoochMaterialSettings()=default
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Gooch material.
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsGoochMaterialSettings.
void readXml(const QDomElement &elem, const QgsReadWriteContext &context) override
Reads settings from a DOM element.
A container for the context for various read/write operations on objects.