11#include <QtQuick3DRuntimeRender/private/qssgrendertexturedata_p.h>
12#include <QtQuick3DRuntimeRender/private/qssgrenderimage_p.h>
119 scheduleTextureUpdate();
128 return m_skyTopColor;
133 return m_skyHorizonColor;
148 return m_groundBottomColor;
153 return m_groundHorizonColor;
158 return m_groundCurve;
163 return m_groundEnergy;
173 return m_sunLatitude;
178 return m_sunLongitude;
183 return m_sunAngleMin;
188 return m_sunAngleMax;
203 return m_textureQuality;
213 scheduleTextureUpdate();
223 scheduleTextureUpdate();
233 scheduleTextureUpdate();
243 scheduleTextureUpdate();
253 scheduleTextureUpdate();
263 scheduleTextureUpdate();
273 scheduleTextureUpdate();
283 scheduleTextureUpdate();
293 scheduleTextureUpdate();
303 scheduleTextureUpdate();
313 scheduleTextureUpdate();
323 scheduleTextureUpdate();
333 scheduleTextureUpdate();
343 scheduleTextureUpdate();
353 scheduleTextureUpdate();
363 scheduleTextureUpdate();
369 switch (m_textureQuality) {
400 LinearColor skyTopLinear(m_skyTopColor);
401 LinearColor skyHorizonLinear(m_skyHorizonColor);
402 LinearColor groundBottomLinear(m_groundBottomColor);
403 LinearColor groundHorizonLinear(m_groundHorizonColor);
404 LinearColor sunLinear(m_sunColor);
405 sunLinear.r *= m_sunEnergy;
406 sunLinear.g *= m_sunEnergy;
407 sunLinear.b *= m_sunEnergy;
415 auto clamp = [](
float value,
float min,
float max) {
418 else if (
value > max)
423 auto ease = [](
float x,
float c) {
430 return 1.0f -
qPow(1.0f -
x, 1.0f /
c);
434 }
else if (
c < 0.0f) {
436 return qPow(
x * 2.0f, -
c) * 0.5f;
438 return (1.0f -
qPow(1.0f - (
x - 0.5f) * 2.0f, -
c)) * 0.5f + 0.5f;
446 float u = float(
i) / (
width - 1);
447 float phi = u * 2.0 *
M_PI;
451 float theta =
v *
M_PI;
457 float vAngle =
qAcos(
clamp(normal.y(), -1.0, 1.0));
460 if (normal.y() < 0) {
462 float c = (vAngle - (
M_PI * 0.5f)) / (
M_PI * 0.5f);
463 color = groundHorizonLinear.interpolate(groundBottomLinear, ease(
c, m_groundCurve));
464 color.r *= m_groundEnergy;
465 color.g *= m_groundEnergy;
466 color.b *= m_groundEnergy;
469 float c = vAngle / (
M_PI * 0.5f);
470 color = skyHorizonLinear.interpolate(skyTopLinear, ease(1.0 -
c, m_skyCurve));
471 color.r *= m_skyEnergy;
472 color.g *= m_skyEnergy;
473 color.b *= m_skyEnergy;
476 if (sunAngle < m_sunAngleMin) {
478 }
else if (sunAngle < m_sunAngleMax) {
479 float c2 = (sunAngle - m_sunAngleMin) / (m_sunAngleMax - m_sunAngleMin);
480 c2 = ease(
c2, m_sunCurve);
501void ProceduralSkyTextureData::scheduleTextureUpdate()
506ProceduralSkyTextureData::LinearColor::LinearColor(
const QColor &
color)
513 r =
red < 0.04045 ?
red * (1.0 / 12.92) :
qPow((
red + 0.055) * (1.0 / (1 + 0.055)), 2.4),
515 b =
blue < 0.04045 ?
blue * (1.0 / 12.92) :
qPow((
blue + 0.055) * (1.0 / (1 + 0.055)), 2.4),
519ProceduralSkyTextureData::LinearColor ProceduralSkyTextureData::LinearColor::interpolate(
const ProceduralSkyTextureData::LinearColor &
color,
float value)
const
521 LinearColor
copy = *
this;
531ProceduralSkyTextureData::LinearColor ProceduralSkyTextureData::LinearColor::blend(
const ProceduralSkyTextureData::LinearColor &
color)
const
534 float sa = 1.0 -
color.a;
537 return LinearColor();
546quint32 ProceduralSkyTextureData::LinearColor::toRGBA8()
const
548 return (
quint32(lrintf(
r)) & 0xFF) |
549 ((
quint32(lrintf(
g)) & 0xFF) << 8) |
550 ((
quint32(lrintf(
b)) & 0xFF) << 16) |
551 ((
quint32(lrintf(
a)) & 0xFF) << 24);
554quint32 ProceduralSkyTextureData::LinearColor::toRGBE8()
const
565 v = frexp(
v, &exp) * 256.0f /
v;
575quint32 ProceduralSkyTextureData::LinearColor::toRGBE9995()
const
577 const float pow2to9 = 512.0f;
578 const float B = 15.0f;
579 const float N = 9.0f;
581 float sharedExp = 65408.000f;
583 float cRed =
qMax(0.0f,
qMin(sharedExp,
r));
584 float cGreen =
qMax(0.0f,
qMin(sharedExp,
g));
585 float cBlue =
qMax(0.0f,
qMin(sharedExp,
b));
587 float cMax =
qMax(cRed,
qMax(cGreen, cBlue));
589 float expp =
qMax(-
B - 1.0f, floor(std::log(cMax) /
M_LN2)) + 1.0f +
B;
591 float sMax = (float)floor((cMax /
qPow(2.0f, expp -
B - N)) + 0.5f);
593 float exps = expp + 1.0f;
595 if (0.0 <= sMax && sMax < pow2to9) {
599 float sRed =
qFloor((cRed / pow(2.0f, exps -
B - N)) + 0.5f);
600 float sGreen =
qFloor((cGreen / pow(2.0f, exps -
B - N)) + 0.5f);
601 float sBlue =
qFloor((cBlue / pow(2.0f, exps -
B - N)) + 0.5f);
603 return (
quint32(lrintf(sRed)) & 0x1FF) |
604 ((
quint32(lrintf(sGreen)) & 0x1FF) << 9) |
605 ((
quint32(lrintf(sBlue)) & 0x1FF) << 18) |
606 ((
quint32(lrintf(exps)) & 0x1F) << 27);
void groundHorizonColorChanged(QColor groundHorizonColor)
void setGroundHorizonColor(QColor groundHorizonColor)
void sunCurveChanged(float sunCurve)
void setSunColor(QColor sunColor)
void setGroundBottomColor(QColor groundBottomColor)
SkyTextureQuality textureQuality
void setSunAngleMax(float sunAngleMax)
void groundCurveChanged(float groundCurve)
void setGroundEnergy(float groundEnergy)
void groundEnergyChanged(float groundEnergy)
void skyEnergyChanged(float skyEnergy)
void setSkyHorizonColor(QColor skyHorizonColor)
void sunAngleMinChanged(float sunAngleMin)
void sunColorChanged(QColor sunColor)
void sunEnergyChanged(float sunEnergy)
void skyCurveChanged(float skyCurve)
void generateRGBA16FTexture()
void setGroundCurve(float groundCurve)
void sunLatitudeChanged(float sunLatitude)
void setSkyCurve(float skyCurve)
void textureQualityChanged(SkyTextureQuality textureQuality)
~ProceduralSkyTextureData()
void setTextureQuality(SkyTextureQuality textureQuality)
void setSunLatitude(float sunLatitude)
void setSunCurve(float sunCurve)
void sunLongitudeChanged(float sunLongitude)
QColor groundHorizonColor
ProceduralSkyTextureData()
\qmltype ProceduralSkyTextureData \inqmlmodule QtQuick3D.Helpers \inherits TextureData
void setSunAngleMin(float sunAngleMin)
void skyHorizonColorChanged(QColor skyHorizonColor)
@ SkyTextureQualityVeryHigh
@ SkyTextureQualityMedium
void skyTopColorChanged(QColor skyTopColor)
void groundBottomColorChanged(QColor groundBottomColor)
void setSkyEnergy(float skyEnergy)
void setSkyTopColor(QColor skyTopColor)
void setSunEnergy(float sunEnergy)
void setSunLongitude(float sunLongitude)
void sunAngleMaxChanged(float sunAngleMax)
char * data()
\macro QT_NO_CAST_FROM_BYTEARRAY
void resize(qsizetype size)
Sets the size of the byte array to size bytes.
The QColor class provides colors based on RGB, HSV or CMYK values.
void normalize()
Normalizes the current quaternion in place.
static QQuaternion fromAxisAndAngle(const QVector3D &axis, float angle)
Creates a normalized quaternion that corresponds to rotating through angle degrees about the specifie...
void setSize(const QSize &size)
Sets the size of the texture data in pixels.
void setTextureData(const QByteArray &data)
Sets the texture data.
void setHasTransparency(bool hasTransparency)
Set hasTransparency to true if the texture data has an active alpha channel with non-opaque values.
QSize size() const
Returns the size of the texture data in pixels.
void setFormat(Format format)
Sets the format of the texture data.
The QVector3D class represents a vector or vertex in 3D space.
static constexpr float dotProduct(QVector3D v1, QVector3D v2) noexcept
Returns the dot product of v1 and v2.
\keyword 16-bit Floating Point Support\inmodule QtCore \inheaderfile QFloat16
Combined button and popup list for selecting options.
static jboolean copy(JNIEnv *, jobject)
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
bool qFuzzyCompare(qfloat16 p1, qfloat16 p2) noexcept
Q_CORE_EXPORT void qFloatToFloat16(qfloat16 *, const float *, qsizetype length) noexcept
constexpr float qRadiansToDegrees(float radians)
constexpr const T & qMin(const T &a, const T &b)
constexpr const T & qMax(const T &a, const T &b)
GLboolean GLboolean GLboolean b
GLsizei const GLfloat * v
[13]
GLint GLint GLint GLint GLint x
[0]
GLint GLsizei GLsizei height
GLboolean GLboolean GLboolean GLboolean a
[7]
GLint GLenum GLint components
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLint GLsizei GLsizei GLenum GLenum GLsizei void * data
GLenum GLuint GLintptr offset
GLfloat GLfloat GLfloat alpha