Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
proceduralskytexturedata_p.h
Go to the documentation of this file.
1// Copyright (C) 2022 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4//
5// W A R N I N G
6// -------------
7//
8// This file is not part of the Qt API. It exists purely as an
9// implementation detail. This header file may change from version to
10// version without notice, or even be removed.
11//
12// We mean it.
13//
14
15
16#ifndef PROCEDURALSKYTEXTURE_H
17#define PROCEDURALSKYTEXTURE_H
18
19#include <QtQuick3DHelpers/qtquick3dhelpersexports.h>
20#include <QtQuick3D/QQuick3DTextureData>
21#include <QtQml/QQmlEngine>
22
23#include <QtGui/QColor>
24#include <QtCore/QByteArray>
25
27
28class Q_QUICK3DHELPERS_EXPORT ProceduralSkyTextureData : public QQuick3DTextureData
29{
30 Q_OBJECT
31 Q_PROPERTY(QColor skyTopColor READ skyTopColor WRITE setSkyTopColor NOTIFY skyTopColorChanged)
32 Q_PROPERTY(QColor skyHorizonColor READ skyHorizonColor WRITE setSkyHorizonColor NOTIFY skyHorizonColorChanged)
33 Q_PROPERTY(float skyCurve READ skyCurve WRITE setSkyCurve NOTIFY skyCurveChanged)
34 Q_PROPERTY(float skyEnergy READ skyEnergy WRITE setSkyEnergy NOTIFY skyEnergyChanged)
35
36 Q_PROPERTY(QColor groundBottomColor READ groundBottomColor WRITE setGroundBottomColor NOTIFY groundBottomColorChanged)
37 Q_PROPERTY(QColor groundHorizonColor READ groundHorizonColor WRITE setGroundHorizonColor NOTIFY groundHorizonColorChanged)
38 Q_PROPERTY(float groundCurve READ groundCurve WRITE setGroundCurve NOTIFY groundCurveChanged)
39 Q_PROPERTY(float groundEnergy READ groundEnergy WRITE setGroundEnergy NOTIFY groundEnergyChanged)
40
41 Q_PROPERTY(QColor sunColor READ sunColor WRITE setSunColor NOTIFY sunColorChanged)
42 Q_PROPERTY(float sunLatitude READ sunLatitude WRITE setSunLatitude NOTIFY sunLatitudeChanged)
43 Q_PROPERTY(float sunLongitude READ sunLongitude WRITE setSunLongitude NOTIFY sunLongitudeChanged)
44 Q_PROPERTY(float sunAngleMin READ sunAngleMin WRITE setSunAngleMin NOTIFY sunAngleMinChanged)
45 Q_PROPERTY(float sunAngleMax READ sunAngleMax WRITE setSunAngleMax NOTIFY sunAngleMaxChanged)
46 Q_PROPERTY(float sunCurve READ sunCurve WRITE setSunCurve NOTIFY sunCurveChanged)
47 Q_PROPERTY(float sunEnergy READ sunEnergy WRITE setSunEnergy NOTIFY sunEnergyChanged)
48 Q_PROPERTY(SkyTextureQuality textureQuality READ textureQuality WRITE setTextureQuality NOTIFY textureQualityChanged)
49 QML_ELEMENT
50
51public:
52 enum class SkyTextureQuality {
53 SkyTextureQualityLow, // 512
54 SkyTextureQualityMedium, // 1024
55 SkyTextureQualityHigh, // 2048
56 SkyTextureQualityVeryHigh, // 4096
57 };
58 Q_ENUM(SkyTextureQuality)
59
60 ProceduralSkyTextureData();
61 ~ProceduralSkyTextureData();
62
63 QColor skyTopColor() const;
64 QColor skyHorizonColor() const;
65 float skyCurve() const;
66 float skyEnergy() const;
67
68 QColor groundBottomColor() const;
69 QColor groundHorizonColor() const;
70 float groundCurve() const;
71 float groundEnergy() const;
72
73 QColor sunColor() const;
74 float sunLatitude() const;
75 float sunLongitude() const;
76 float sunAngleMin() const;
77 float sunAngleMax() const;
78 float sunCurve() const;
79 float sunEnergy() const;
80
81 SkyTextureQuality textureQuality() const;
82
83public Q_SLOTS:
84 void setSkyTopColor(QColor skyTopColor);
85 void setSkyHorizonColor(QColor skyHorizonColor);
86 void setSkyCurve(float skyCurve);
87 void setSkyEnergy(float skyEnergy);
88
89 void setGroundBottomColor(QColor groundBottomColor);
90 void setGroundHorizonColor(QColor groundHorizonColor);
91 void setGroundCurve(float groundCurve);
92 void setGroundEnergy(float groundEnergy);
93
94 void setSunColor(QColor sunColor);
95 void setSunLatitude(float sunLatitude);
96 void setSunLongitude(float sunLongitude);
97 void setSunAngleMin(float sunAngleMin);
98 void setSunAngleMax(float sunAngleMax);
99 void setSunCurve(float sunCurve);
100 void setSunEnergy(float sunEnergy);
101
102 void setTextureQuality(SkyTextureQuality textureQuality);
103
104 void generateRGBA16FTexture();
105
106Q_SIGNALS:
107 void skyTopColorChanged(QColor skyTopColor);
108 void skyHorizonColorChanged(QColor skyHorizonColor);
109 void skyCurveChanged(float skyCurve);
110 void skyEnergyChanged(float skyEnergy);
111
112 void groundBottomColorChanged(QColor groundBottomColor);
113 void groundHorizonColorChanged(QColor groundHorizonColor);
114 void groundCurveChanged(float groundCurve);
115 void groundEnergyChanged(float groundEnergy);
116
117 void sunColorChanged(QColor sunColor);
118
119 void sunLatitudeChanged(float sunLatitude);
120 void sunLongitudeChanged(float sunLongitude);
121 void sunAngleMinChanged(float sunAngleMin);
122 void sunAngleMaxChanged(float sunAngleMax);
123 void sunCurveChanged(float sunCurve);
124 void sunEnergyChanged(float sunEnergy);
125
126 void textureQualityChanged(SkyTextureQuality textureQuality);
127
128private:
129
130 struct LinearColor {
131 float r = 0.0f;
132 float g = 0.0f;
133 float b = 0.0f;
134 float a = 0.0f;
135 LinearColor(const QColor &color);
136 LinearColor() {}
137
138 LinearColor interpolate(const LinearColor &color, float value) const;
139 LinearColor blend(const LinearColor &color) const;
140 quint32 toRGBE9995() const;
141 quint32 toRGBA8() const;
142 quint32 toRGBE8() const;
143 };
144
145 QByteArray generateSkyTexture(int width, int height, QByteArray &imageData, bool isRGBE) const;
146 void scheduleTextureUpdate();
147 QColor m_skyTopColor = QColor(165, 214, 241);
148 QColor m_skyHorizonColor = QColor(214, 234, 250);
149 float m_skyCurve = 0.09f;
150 float m_skyEnergy = 1.0f;
151
152 QColor m_groundBottomColor = QColor(40, 47, 54);
153 QColor m_groundHorizonColor = QColor(108, 101, 95);
154 float m_groundCurve = 0.02f;
155 float m_groundEnergy = 1.0f;
156
157 QColor m_sunColor = QColor(255, 255, 255);
158 float m_sunLatitude = 35.0f;
159 float m_sunLongitude = 0.0f;
160 float m_sunAngleMin = 1.0f;
161 float m_sunAngleMax = 100.0f;
162 float m_sunCurve = 0.05f;
163 float m_sunEnergy = 1.0f;
164
165 SkyTextureQuality m_textureQuality = SkyTextureQuality::SkyTextureQualityMedium;
166};
167
168QT_END_NAMESPACE
169
170#endif // PROCEDURALSKYTEXTURE_H