1 | // Copyright (C) 2008-2012 NVIDIA Corporation. |
2 | // Copyright (C) 2019 The Qt Company Ltd. |
3 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only |
4 | |
5 | #ifndef QSSG_RENDER_LIGHT_H |
6 | #define QSSG_RENDER_LIGHT_H |
7 | |
8 | // |
9 | // W A R N I N G |
10 | // ------------- |
11 | // |
12 | // This file is not part of the Qt API. It exists purely as an |
13 | // implementation detail. This header file may change from version to |
14 | // version without notice, or even be removed. |
15 | // |
16 | // We mean it. |
17 | // |
18 | |
19 | #include <QtQuick3DRuntimeRender/private/qssgrendernode_p.h> |
20 | |
21 | QT_BEGIN_NAMESPACE |
22 | |
23 | struct QSSGRenderImage; |
24 | |
25 | struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderLight : public QSSGRenderNode |
26 | { |
27 | enum class DirtyFlag : quint8 |
28 | { |
29 | LightDirty = 0x1 |
30 | }; |
31 | using FlagT = std::underlying_type_t<DirtyFlag>; |
32 | |
33 | // Must match QQuick3DAbstractLight::QSSGSoftShadowQuality |
34 | enum class SoftShadowQuality { |
35 | Hard = 0, |
36 | PCF4, |
37 | PCF8, |
38 | PCF16, |
39 | PCF32, |
40 | PCF64, |
41 | }; |
42 | |
43 | static constexpr DirtyFlag DirtyMask { std::numeric_limits<FlagT>::max() }; |
44 | |
45 | QSSGRenderNode *m_scope; |
46 | QVector3D m_diffuseColor; // colors are 0-1 normalized |
47 | QVector3D m_specularColor; // colors are 0-1 normalized |
48 | QVector3D m_ambientColor; // colors are 0-1 normalized |
49 | |
50 | // The variables below are in the same range as Studio |
51 | // Only valid if node is a point light |
52 | float m_brightness; |
53 | float m_constantFade; |
54 | float m_linearFade; |
55 | float m_quadraticFade; |
56 | |
57 | float m_coneAngle; // 0-180 |
58 | float m_innerConeAngle; // 0-180 |
59 | |
60 | FlagT m_lightDirtyFlags = 0; |
61 | bool m_castShadow; // true if this light produce shadows |
62 | float m_shadowBias; // depth shift to avoid self-shadowing artifacts |
63 | float m_shadowFactor; // Darkening factor for ESMs |
64 | quint32 m_shadowMapRes; // Resolution of shadow map |
65 | float m_shadowMapFar; // Far clip plane for the shadow map |
66 | float m_shadowFilter; // Shadow map filter step size |
67 | SoftShadowQuality m_softShadowQuality = SoftShadowQuality::PCF4; |
68 | |
69 | float m_pcfFactor = 2.0f; |
70 | |
71 | bool m_bakingEnabled; |
72 | bool m_fullyBaked; // direct+indirect |
73 | |
74 | // Cascading shadow map options |
75 | float m_csmSplit1 = 0.0f; |
76 | float m_csmSplit2 = 0.25f; |
77 | float m_csmSplit3 = 0.5f; |
78 | int m_csmNumSplits = 0; |
79 | float m_csmBlendRatio = 0.05f; |
80 | |
81 | // Defaults to directional light |
82 | explicit QSSGRenderLight(Type type = Type::DirectionalLight); |
83 | |
84 | [[nodiscard]] inline bool isEnabled() const { return (m_brightness > 0.0f); } |
85 | |
86 | [[nodiscard]] inline bool isDirty(DirtyFlag dirtyFlag = DirtyMask) const |
87 | { |
88 | return ((m_lightDirtyFlags & FlagT(dirtyFlag)) != 0) |
89 | || ((dirtyFlag == DirtyMask) && QSSGRenderNode::isDirty()); |
90 | } |
91 | void markDirty(DirtyFlag dirtyFlag); |
92 | void clearDirty(DirtyFlag dirtyFlag); |
93 | }; |
94 | QT_END_NAMESPACE |
95 | |
96 | #endif |
97 | |