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 "qdirectionallight.h" |
5 | #include "qdirectionallight_p.h" |
6 | |
7 | QT_BEGIN_NAMESPACE |
8 | |
9 | namespace Qt3DRender { |
10 | |
11 | /* |
12 | * |
13 | * Expected Shader struct |
14 | * |
15 | * \code |
16 | * |
17 | * struct DirectionalLight |
18 | * { |
19 | * vec3 position; |
20 | * vec3 worldDirection; |
21 | * vec4 color; |
22 | * float intensity; |
23 | * }; |
24 | * |
25 | * uniform DirectionalLight directionalLights[10]; |
26 | * |
27 | * \endcode |
28 | */ |
29 | |
30 | QDirectionalLightPrivate::QDirectionalLightPrivate() |
31 | : QAbstractLightPrivate(QAbstractLight::DirectionalLight) |
32 | { |
33 | m_shaderData->setProperty(name: "direction" , value: QVector3D(0.0f, -1.0f, 0.0f)); |
34 | } |
35 | |
36 | /*! |
37 | \class Qt3DRender::QDirectionalLight |
38 | \inmodule Qt3DRender |
39 | \since 5.7 |
40 | \brief Encapsulate a Directional Light object in a Qt 3D scene. |
41 | |
42 | A directional light is a light source that behaves similar to sunlight. |
43 | The light from a directional light hits all objects from the same direction |
44 | and with the same intensity, regardless of where they are in the scene. |
45 | */ |
46 | |
47 | /*! |
48 | \qmltype DirectionalLight |
49 | \instantiates Qt3DRender::QDirectionalLight |
50 | \inherits AbstractLight |
51 | \inqmlmodule Qt3D.Render |
52 | \since 5.7 |
53 | \brief Encapsulate a Directional Light object in a Qt 3D scene. |
54 | |
55 | A directional light is a light source that behaves similar to sunlight. |
56 | The light from a directional light hits all objects from the same direction |
57 | and with the same intensity, regardless of where they are in the scene. |
58 | */ |
59 | |
60 | /*! |
61 | \fn Qt3DRender::QDirectionalLight::QDirectionalLight(Qt3DCore::QNode *parent) |
62 | Constructs a new QDirectionalLight with the specified \a parent. |
63 | */ |
64 | QDirectionalLight::QDirectionalLight(QNode *parent) |
65 | : QAbstractLight(*new QDirectionalLightPrivate, parent) |
66 | { |
67 | } |
68 | |
69 | /*! \internal */ |
70 | QDirectionalLight::~QDirectionalLight() |
71 | { |
72 | } |
73 | |
74 | /*! \internal */ |
75 | QDirectionalLight::QDirectionalLight(QDirectionalLightPrivate &dd, QNode *parent) |
76 | : QAbstractLight(dd, parent) |
77 | { |
78 | } |
79 | |
80 | /*! |
81 | \qmlproperty vector3d Qt3D.Render::DirectionalLight::worldDirection |
82 | Specifies the world direction of the directional light. |
83 | |
84 | \note The exact meaning and use of this property is up to the |
85 | material implementation. |
86 | */ |
87 | |
88 | /*! |
89 | \property Qt3DRender::QDirectionalLight::worldDirection |
90 | Specifies the world direction of the directional light. |
91 | |
92 | \note The exact meaning and use of this property is up to the |
93 | material implementation. |
94 | */ |
95 | void QDirectionalLight::setWorldDirection(const QVector3D &direction) |
96 | { |
97 | Q_D(QDirectionalLight); |
98 | if (worldDirection() != direction) { |
99 | d->m_shaderData->setProperty(name: "direction" , value: direction); |
100 | emit worldDirectionChanged(worldDirection: direction); |
101 | } |
102 | } |
103 | |
104 | QVector3D QDirectionalLight::worldDirection() const |
105 | { |
106 | Q_D(const QDirectionalLight); |
107 | return d->m_shaderData->property(name: "direction" ).value<QVector3D>(); |
108 | } |
109 | |
110 | } // namespace Qt3DRender |
111 | |
112 | QT_END_NAMESPACE |
113 | |
114 | #include "moc_qdirectionallight.cpp" |
115 | |