1// Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qpointlight.h"
5#include "qpointlight_p.h"
6
7QT_BEGIN_NAMESPACE
8
9namespace Qt3DRender {
10
11/*
12 Expected Shader struct
13
14 \code
15
16 struct PointLight
17 {
18 vec3 position;
19 vec4 color;
20 float intensity;
21 };
22
23 uniform PointLight pointLights[10];
24
25 \endcode
26 */
27
28QPointLightPrivate::QPointLightPrivate()
29 : QAbstractLightPrivate(QAbstractLight::PointLight)
30{
31 m_shaderData->setProperty(name: "constantAttenuation", value: 1.0f);
32 m_shaderData->setProperty(name: "linearAttenuation", value: 0.0f);
33 m_shaderData->setProperty(name: "quadraticAttenuation", value: 0.0f);
34}
35
36/*!
37 \class Qt3DRender::QPointLight
38 \inmodule Qt3DRender
39 \since 5.5
40 \brief Encapsulate a Point Light object in a Qt 3D scene.
41
42 A point light is a light source that emits light in all directions, from a single point.
43 Conceptually, this is similar to light given off by a standard light bulb.
44
45 A point light uses three attenuation factors to describe how the intensity of the light
46 decreases over distance. These factors are designed to be used together in calcuating total
47 attenuation. For the materials in Qt3D Extras the following formula is used, where distance
48 is the distance from the light to the surface being rendered:
49
50 \code
51 totalAttenuation = 1.0 / (constantAttenuation + (linearAttenuation * distance) + (quadraticAttenuation * distance * distance));
52 \endcode
53
54 Custom materials may choose to interpret these factors differently.
55 */
56
57/*!
58 \qmltype PointLight
59 \instantiates Qt3DRender::QPointLight
60 \inherits AbstractLight
61 \inqmlmodule Qt3D.Render
62 \since 5.5
63 \brief Encapsulate a Point Light object in a Qt 3D scene.
64
65 A point light is a light source that emits light in all directions, from a single point.
66 Conceptually, this is similar to light given off by a standard light bulb.
67
68 A point light uses three attenuation factors to describe how the intensity of the light
69 decreases over distance. These factors are designed to be used together in calcuating total
70 attenuation. For the materials in Qt3D Extras the following formula is used, where distance
71 is the distance from the light to the surface being rendered:
72
73 \code
74 totalAttenuation = 1.0 / (constantAttenuation + (linearAttenuation * distance) + (quadraticAttenuation * distance * distance));
75 \endcode
76
77 Custom materials may choose to interpret these factors differently.
78*/
79
80/*!
81 \fn Qt3DRender::QPointLight::QPointLight(Qt3DCore::QNode *parent)
82 Constructs a new QPointLight with the specified \a parent.
83 */
84QPointLight::QPointLight(QNode *parent)
85 : QAbstractLight(*new QPointLightPrivate, parent)
86{
87}
88
89/*! \internal */
90QPointLight::~QPointLight()
91{
92}
93
94/*! \internal */
95QPointLight::QPointLight(QPointLightPrivate &dd, QNode *parent)
96 : QAbstractLight(dd, parent)
97{
98}
99
100/*!
101 \qmlproperty float Qt3D.Render::PointLight::constantAttenuation
102 Specifies the constant attenuation of the point light.
103
104 \note The exact meaning and use of this property is up to the
105 material implementation.
106*/
107
108/*!
109 \property Qt3DRender::QPointLight::constantAttenuation
110 Specifies the constant attenuation of the point light.
111
112 \note The exact meaning and use of this property is up to the
113 material implementation.
114 */
115float QPointLight::constantAttenuation() const
116{
117 Q_D(const QPointLight);
118 return d->m_shaderData->property(name: "constantAttenuation").toFloat();
119}
120
121void QPointLight::setConstantAttenuation(float value)
122{
123 Q_D(QPointLight);
124 if (constantAttenuation() != value) {
125 d->m_shaderData->setProperty(name: "constantAttenuation", value);
126 emit constantAttenuationChanged(constantAttenuation: value);
127 }
128}
129
130/*!
131 \qmlproperty float Qt3D.Render::PointLight::linearAttenuation
132 Specifies the linear attenuation of the point light.
133
134 \note The exact meaning and use of this property is up to the
135 material implementation.
136*/
137
138/*!
139 \property Qt3DRender::QPointLight::linearAttenuation
140 Specifies the linear attenuation of the point light.
141
142 \note The exact meaning and use of this property is up to the
143 material implementation.
144 */
145float QPointLight::linearAttenuation() const
146{
147 Q_D(const QPointLight);
148 return d->m_shaderData->property(name: "linearAttenuation").toFloat();
149}
150
151void QPointLight::setLinearAttenuation(float value)
152{
153 Q_D(QPointLight);
154 if (linearAttenuation() != value) {
155 d->m_shaderData->setProperty(name: "linearAttenuation", value);
156 emit linearAttenuationChanged(linearAttenuation: value);
157 }
158}
159
160/*!
161 \qmlproperty float Qt3D.Render::PointLight::quadraticAttenuation
162 Specifies the quadratic attenuation of the point light.
163
164 \note The exact meaning and use of this property is up to the
165 material implementation.
166*/
167
168/*!
169 \property Qt3DRender::QPointLight::quadraticAttenuation
170 Specifies the quadratic attenuation of the point light.
171
172 \note The exact meaning and use of this property is up to the
173 material implementation.
174 */
175float QPointLight::quadraticAttenuation() const
176{
177 Q_D(const QPointLight);
178 return d->m_shaderData->property(name: "quadraticAttenuation").toFloat();
179}
180
181void QPointLight::setQuadraticAttenuation(float value)
182{
183 Q_D(QPointLight);
184 if (quadraticAttenuation() != value) {
185 d->m_shaderData->setProperty(name: "quadraticAttenuation", value);
186 emit quadraticAttenuationChanged(quadraticAttenuation: value);
187 }
188}
189
190} // namespace Qt3DRender
191
192QT_END_NAMESPACE
193
194#include "moc_qpointlight.cpp"
195

source code of qt3d/src/render/lights/qpointlight.cpp