1 | /**************************************************************************** |
2 | ** |
3 | ** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB). |
4 | ** Contact: https://www.qt.io/licensing/ |
5 | ** |
6 | ** This file is part of the Qt3D module of the Qt Toolkit. |
7 | ** |
8 | ** $QT_BEGIN_LICENSE:LGPL$ |
9 | ** Commercial License Usage |
10 | ** Licensees holding valid commercial Qt licenses may use this file in |
11 | ** accordance with the commercial license agreement provided with the |
12 | ** Software or, alternatively, in accordance with the terms contained in |
13 | ** a written agreement between you and The Qt Company. For licensing terms |
14 | ** and conditions see https://www.qt.io/terms-conditions. For further |
15 | ** information use the contact form at https://www.qt.io/contact-us. |
16 | ** |
17 | ** GNU Lesser General Public License Usage |
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser |
19 | ** General Public License version 3 as published by the Free Software |
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the |
21 | ** packaging of this file. Please review the following information to |
22 | ** ensure the GNU Lesser General Public License version 3 requirements |
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. |
24 | ** |
25 | ** GNU General Public License Usage |
26 | ** Alternatively, this file may be used under the terms of the GNU |
27 | ** General Public License version 2.0 or (at your option) the GNU General |
28 | ** Public license version 3 or any later version approved by the KDE Free |
29 | ** Qt Foundation. The licenses are as published by the Free Software |
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 |
31 | ** included in the packaging of this file. Please review the following |
32 | ** information to ensure the GNU General Public License requirements will |
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and |
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. |
35 | ** |
36 | ** $QT_END_LICENSE$ |
37 | ** |
38 | ****************************************************************************/ |
39 | |
40 | #include "qdirectionallight.h" |
41 | #include "qdirectionallight_p.h" |
42 | |
43 | QT_BEGIN_NAMESPACE |
44 | |
45 | namespace Qt3DRender { |
46 | |
47 | /* |
48 | * |
49 | * Expected Shader struct |
50 | * |
51 | * \code |
52 | * |
53 | * struct DirectionalLight |
54 | * { |
55 | * vec3 position; |
56 | * vec3 worldDirection; |
57 | * vec4 color; |
58 | * float intensity; |
59 | * }; |
60 | * |
61 | * uniform DirectionalLight directionalLights[10]; |
62 | * |
63 | * \endcode |
64 | */ |
65 | |
66 | QDirectionalLightPrivate::QDirectionalLightPrivate() |
67 | : QAbstractLightPrivate(QAbstractLight::DirectionalLight) |
68 | { |
69 | m_shaderData->setProperty(name: "direction" , value: QVector3D(0.0f, -1.0f, 0.0f)); |
70 | } |
71 | |
72 | /*! |
73 | \class Qt3DRender::QDirectionalLight |
74 | \inmodule Qt3DRender |
75 | \since 5.7 |
76 | \brief Encapsulate a Directional Light object in a Qt 3D scene. |
77 | |
78 | A directional light is a light source that behaves similar to sunlight. |
79 | The light from a directional light hits all objects from the same direction |
80 | and with the same intensity, regardless of where they are in the scene. |
81 | */ |
82 | |
83 | /*! |
84 | \qmltype DirectionalLight |
85 | \instantiates Qt3DRender::QDirectionalLight |
86 | \inherits AbstractLight |
87 | \inqmlmodule Qt3D.Render |
88 | \since 5.7 |
89 | \brief Encapsulate a Directional Light object in a Qt 3D scene. |
90 | |
91 | A directional light is a light source that behaves similar to sunlight. |
92 | The light from a directional light hits all objects from the same direction |
93 | and with the same intensity, regardless of where they are in the scene. |
94 | */ |
95 | |
96 | /*! |
97 | \fn Qt3DRender::QDirectionalLight::QDirectionalLight(Qt3DCore::QNode *parent) |
98 | Constructs a new QDirectionalLight with the specified \a parent. |
99 | */ |
100 | QDirectionalLight::QDirectionalLight(QNode *parent) |
101 | : QAbstractLight(*new QDirectionalLightPrivate, parent) |
102 | { |
103 | } |
104 | |
105 | /*! \internal */ |
106 | QDirectionalLight::~QDirectionalLight() |
107 | { |
108 | } |
109 | |
110 | /*! \internal */ |
111 | QDirectionalLight::QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent) |
112 | : QAbstractLight(dd, parent) |
113 | { |
114 | } |
115 | |
116 | /*! |
117 | \qmlproperty vector3d Qt3D.Render::DirectionalLight::worldDirection |
118 | Specifies the world direction of the directional light. |
119 | |
120 | \note The exact meaning and use of this property is up to the |
121 | material implementation. |
122 | */ |
123 | |
124 | /*! |
125 | \property Qt3DRender::QDirectionalLight::worldDirection |
126 | Specifies the world direction of the directional light. |
127 | |
128 | \note The exact meaning and use of this property is up to the |
129 | material implementation. |
130 | */ |
131 | void QDirectionalLight::setWorldDirection(const QVector3D &direction) |
132 | { |
133 | Q_D(QDirectionalLight); |
134 | if (worldDirection() != direction) { |
135 | d->m_shaderData->setProperty(name: "direction" , value: direction); |
136 | emit worldDirectionChanged(worldDirection: direction); |
137 | } |
138 | } |
139 | |
140 | QVector3D QDirectionalLight::worldDirection() const |
141 | { |
142 | Q_D(const QDirectionalLight); |
143 | return d->m_shaderData->property(name: "direction" ).value<QVector3D>(); |
144 | } |
145 | |
146 | } // namespace Qt3DRender |
147 | |
148 | QT_END_NAMESPACE |
149 | |