1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4#ifndef QSSG_RENDER_PARTICLES_H
5#define QSSG_RENDER_PARTICLES_H
6
7//
8// W A R N I N G
9// -------------
10//
11// This file is not part of the Qt API. It exists purely as an
12// implementation detail. This header file may change from version to
13// version without notice, or even be removed.
14//
15// We mean it.
16//
17
18#include <QtQuick3DRuntimeRender/private/qssgrendernode_p.h>
19#include <QtQuick3DRuntimeRender/private/qssgrendercustommaterial_p.h>
20#include <QtQuick3DRuntimeRender/private/qssgrenderlight_p.h>
21#include <QtQuick3DUtils/private/qssgrenderbasetypes_p.h>
22
23QT_BEGIN_NAMESPACE
24
25struct QSSGRenderImage;
26struct QSSGShaderMaterialAdapter;
27
28struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGParticleSimple
29{
30 QVector3D position;
31 float size;
32 QVector3D rotation;
33 float age;
34 QVector4D color;
35 // total 48 bytes
36};
37
38Q_STATIC_ASSERT_X(sizeof(QSSGParticleSimple) == 48, "size of QSSGParticleSimple must be 48");
39
40struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGParticleAnimated
41{
42 QVector3D position;
43 float size;
44 QVector3D rotation;
45 float age;
46 QVector4D color;
47 float animationFrame;
48 // Padding for full 4 * 16 bytes, take into use as needed.
49 // See particleSize in vertex shader
50 QVector3D unusedPadding;
51 // total 64 bytes
52};
53
54Q_STATIC_ASSERT_X(sizeof(QSSGParticleAnimated) == 64, "size of QSSGParticleAnimated must be 64");
55
56struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGTriangleParticle
57{
58 QVector3D position; // particle position
59 float size;
60 QVector3D rotation;
61 float age;
62 QVector4D color;
63 QVector3D center; // center of the origin triangle
64 float fill;
65 // total 64 bytes
66};
67
68Q_STATIC_ASSERT_X(sizeof(QSSGTriangleParticle) == 64, "size of QSSGTriangleParticle must be 64");
69
70struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGLineParticle
71{
72 QVector3D position;
73 float size;
74 QVector4D color;
75 QVector3D binormal;
76 float animationFrame;
77 float age;
78 float length;
79 QVector2D fill;
80 // total 64 bytes
81};
82
83Q_STATIC_ASSERT_X(sizeof(QSSGLineParticle) == 64, "size of QSSGLineParticle must be 64");
84
85struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGParticleBuffer
86{
87 void resize(int particleCount, int particleSize = sizeof(QSSGParticleSimple));
88 void resizeLine(int particleCount, int segmentCount);
89 void setBounds(const QSSGBounds3& bounds);
90
91 char *pointer();
92 const char *pointer() const;
93 int particlesPerSlice() const;
94 int sliceStride() const;
95 int particleCount() const;
96 int sliceCount() const;
97 QSize size() const;
98 QByteArray data() const;
99 QSSGBounds3 bounds() const;
100 int bufferSize() const;
101 int serial() const;
102 int segments() const;
103
104private:
105 int m_particlesPerSlice = 0;
106 int m_sliceStride = 0;
107 int m_particleCount = 0;
108 int m_serial = 0;
109 int m_segments = 0;
110 QSize m_size;
111 QByteArray m_particleBuffer;
112 QSSGBounds3 m_bounds;
113};
114
115struct Q_QUICK3DRUNTIMERENDER_EXPORT QSSGRenderParticles : public QSSGRenderNode
116{
117 enum class BlendMode : quint8
118 {
119 SourceOver = 0,
120 Screen,
121 Multiply
122 };
123 enum class FeatureLevel : quint8
124 {
125 Simple = 0,
126 Mapped,
127 Animated,
128 SimpleVLight,
129 MappedVLight,
130 AnimatedVLight,
131 Line,
132 LineMapped,
133 LineAnimated,
134 LineVLight,
135 LineMappedVLight,
136 LineAnimatedVLight,
137 };
138
139 Q_DISABLE_COPY(QSSGRenderParticles)
140
141 QSSGParticleBuffer m_particleBuffer;
142
143 QVarLengthArray<QSSGRenderLight *, 4> m_lights;
144
145 QSSGRenderParticles::BlendMode m_blendMode = BlendMode::SourceOver;
146 QSSGRenderImage *m_sprite = nullptr;
147 int m_spriteImageCount = 1;
148 float m_depthBiasSq = 0.0f; // Squared as our sorting is based on the squared distance!
149 float m_sizeModifier = 0.0f;
150 float m_alphaFade = 0.0f;
151 float m_texcoordScale = 1.0f;
152 bool m_blendImages = true;
153 bool m_billboard = true;
154 bool m_hasTransparency = true;
155 bool m_depthSorting = false;
156 QSSGRenderImage *m_colorTable = nullptr;
157 QSSGRenderParticles::FeatureLevel m_featureLevel = FeatureLevel::Simple;
158 bool m_castsReflections = true;
159
160 QSSGRenderParticles();
161 ~QSSGRenderParticles() = default;
162};
163
164
165QT_END_NAMESPACE
166
167#endif
168

source code of qtquick3d/src/runtimerender/graphobjects/qssgrenderparticles_p.h