23using namespace Qt::StringLiterals;
65 return *
this == *otherPhong;
70 const double avgDiffuseFactor = 0.5;
71 const double avgSpecularFactor = 0.1;
73 double red = mAmbientCoefficient * mAmbient.redF() + mDiffuseCoefficient * avgDiffuseFactor * mDiffuse.redF() + mSpecularCoefficient * avgSpecularFactor * mSpecular.redF();
75 double green = mAmbientCoefficient * mAmbient.greenF() + mDiffuseCoefficient * avgDiffuseFactor * mDiffuse.greenF() + mSpecularCoefficient * avgSpecularFactor * mSpecular.greenF();
77 double blue = mAmbientCoefficient * mAmbient.blueF() + mDiffuseCoefficient * avgDiffuseFactor * mDiffuse.blueF() + mSpecularCoefficient * avgSpecularFactor * mSpecular.blueF();
79 red = std::clamp( red, 0.0, 1.0 );
80 green = std::clamp( green, 0.0, 1.0 );
81 blue = std::clamp( blue, 0.0, 1.0 );
83 return QColor::fromRgbF(
static_cast<float>( red ),
static_cast<float>( green ),
static_cast<float>( blue ),
static_cast<float>( mOpacity ) );
88 metallic = std::clamp( metallic, 0.0f, 1.0f );
90 const float baseR = baseColor.redF();
91 const float baseG = baseColor.greenF();
92 const float baseB = baseColor.blueF();
95 constexpr float AMBIENT_FACTOR = 0.2f;
96 mAmbient = QColor::fromRgbF( baseR * AMBIENT_FACTOR, baseG * AMBIENT_FACTOR, baseB * AMBIENT_FACTOR );
99 constexpr float F0_DIELECTRIC = 0.04f;
100 constexpr float F0_METALLIC = 0.6f;
101 const float ks = F0_DIELECTRIC * ( 1.0f - metallic ) + F0_METALLIC * metallic;
102 const float kd = 1.0f - ks;
105 mDiffuse = QColor::fromRgbF( kd * baseR, kd * baseG, kd * baseB );
112 mSpecular = QColor::fromRgbF( ( 1.0f - metallic ) * F0_DIELECTRIC + metallic * baseR, ( 1.0f - metallic ) * F0_DIELECTRIC + metallic * baseG, ( 1.0f - metallic ) * F0_DIELECTRIC + metallic * baseB );
114 constexpr float MIN_SHININESS = 32.0f;
115 constexpr float MAX_SHININESS = 200.0f;
116 mShininess = MIN_SHININESS + metallic * ( MAX_SHININESS - MIN_SHININESS );
129 mShininess = elem.attribute( u
"shininess"_s ).toDouble();
130 mOpacity = elem.attribute( u
"opacity"_s, u
"1.0"_s ).toDouble();
131 mAmbientCoefficient = elem.attribute( u
"ka"_s, u
"1.0"_s ).toDouble();
132 mDiffuseCoefficient = elem.attribute( u
"kd"_s, u
"1.0"_s ).toDouble();
133 mSpecularCoefficient = elem.attribute( u
"ks"_s, u
"1.0"_s ).toDouble();
143 elem.setAttribute( u
"shininess"_s, mShininess );
144 elem.setAttribute( u
"opacity"_s, mOpacity );
145 elem.setAttribute( u
"ka"_s, mAmbientCoefficient );
146 elem.setAttribute( u
"kd"_s, mDiffuseCoefficient );
147 elem.setAttribute( u
"ks"_s, mSpecularCoefficient );
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.
QColor averageColor() const override
Returns an approximate color representing the blended material color.
bool equals(const QgsAbstractMaterialSettings *other) const override
Returns true if this settings exactly matches an other settings.
void setColorsFromBase(const QColor &baseColor, float metallic)
Decomposes a base color into Phong material components, and sets the material's colors accordingly.
QString type() const override
Returns the unique type name for the material.
static bool supportsTechnique(Qgis::MaterialRenderingTechnique technique)
Returns true if the specified technique is supported by the Phong material.
static QgsAbstractMaterialSettings * create()
Returns a new instance of QgsPhongMaterialSettings.
void writeXml(QDomElement &elem, const QgsReadWriteContext &context) const override
Writes settings to a DOM element.
QgsPhongMaterialSettings * clone() const override
Clones the material settings.
QgsPhongMaterialSettings()=default
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.