Skip to content

Commit 6748e1b

Browse files
committed
#102 Update particles group struct
1 parent 5e836c0 commit 6748e1b

14 files changed

+140
-33
lines changed

Assets/BuiltIn/Shader/Particle/GLSL/ParticleMeshColorFS.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ void main(void)
7676
float dissolve = n - (1.0 - alpha);
7777
if (dissolve <= 0.0)
7878
discard;
79-
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
8079
float NdotL = max(dot(varWorldNormal, uLightDirection.xyz), 0.0);
8180
vec3 directionalLight = NdotL * sRGB(uLightColor.rgb);
8281
color = directionalLight * color * 0.3;
8382
vec3 ambientLighting = shAmbient(varWorldNormal);
8483
color += sRGB(ambientLighting * texColor.rgb) / PI;
84+
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
8585
FragColor = vec4(color, alpha);
8686
}

Assets/BuiltIn/Shader/Particle/GLSL/ParticleMeshFS.d.glsl

+4-2
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ void main(void)
5757
float dissolve = n - (1.0 - alpha);
5858
if (dissolve <= 0.0)
5959
discard;
60-
61-
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
6260
#endif
6361

6462
#ifdef LIGHTING
@@ -72,5 +70,9 @@ void main(void)
7270
color += sRGB(ambientLighting * texColor.rgb) / PI;
7371
#endif
7472

73+
#ifdef DISSOLVE
74+
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
75+
#endif
76+
7577
FragColor = vec4(color, alpha);
7678
}

Assets/BuiltIn/Shader/Particle/GLSL/ParticleMeshFS.glsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ void main(void)
7676
float dissolve = n - (1.0 - alpha);
7777
if (dissolve <= 0.0)
7878
discard;
79-
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
8079
float NdotL = max(dot(varWorldNormal, uLightDirection.xyz), 0.0);
8180
vec3 directionalLight = NdotL * sRGB(uLightColor.rgb);
8281
color = directionalLight * color * 0.3;
8382
vec3 ambientLighting = shAmbient(varWorldNormal);
8483
color += sRGB(ambientLighting * texColor.rgb) / PI;
84+
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
8585
FragColor = vec4(color, alpha);
8686
}

Assets/BuiltIn/Shader/Particle/HLSL/ParticleMeshColorFS.hlsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ float4 main(PS_INPUT input) : SV_TARGET
8484
float dissolve = n - (1.0 - alpha);
8585
if (dissolve <= 0.0)
8686
discard;
87-
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
8887
float NdotL = max(dot(input.worldNormal, uLightDirection.xyz), 0.0);
8988
float3 directionalLight = NdotL * sRGB(uLightColor.rgb);
9089
color = directionalLight * color * 0.3;
9190
float3 ambientLighting = shAmbient(input.worldNormal);
9291
color += sRGB(ambientLighting * texColor.rgb) / PI;
92+
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
9393
return float4(color, texColor.a * alpha);
9494
}

Assets/BuiltIn/Shader/Particle/HLSL/ParticleMeshFS.d.hlsl

+4-2
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ float4 main(PS_INPUT input) : SV_TARGET
6161
float dissolve = n - (1.0 - alpha);
6262
if (dissolve <= 0.0)
6363
discard;
64-
65-
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
6664
#endif
6765

6866
#ifdef LIGHTING
@@ -76,5 +74,9 @@ float4 main(PS_INPUT input) : SV_TARGET
7674
color += sRGB(ambientLighting * texColor.rgb) / PI;
7775
#endif
7876

77+
#ifdef DISSOLVE
78+
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
79+
#endif
80+
7981
return float4(color, texColor.a * alpha);
8082
}

Assets/BuiltIn/Shader/Particle/HLSL/ParticleMeshFS.hlsl

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,11 @@ float4 main(PS_INPUT input) : SV_TARGET
8484
float dissolve = n - (1.0 - alpha);
8585
if (dissolve <= 0.0)
8686
discard;
87-
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
8887
float NdotL = max(dot(input.worldNormal, uLightDirection.xyz), 0.0);
8988
float3 directionalLight = NdotL * sRGB(uLightColor.rgb);
9089
color = directionalLight * color * 0.3;
9190
float3 ambientLighting = shAmbient(input.worldNormal);
9291
color += sRGB(ambientLighting * texColor.rgb) / PI;
92+
color += sRGB(uDissolveColor.rgb * uColorIntensity.rgb) * step(dissolve, uNoiseScale.w) * n;
9393
return float4(color, texColor.a * alpha);
9494
}

Projects/Skylicht/Components/ParticleSystem/CParticleBufferData.cpp

+54-1
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,30 @@ namespace Skylicht
4646
for (u32 i = 0, n = Groups.size(); i < n; i++)
4747
delete Groups[i];
4848
Groups.clear();
49+
50+
for (u32 i = 0, n = SubGroups.size(); i < n; i++)
51+
delete SubGroups[i];
52+
SubGroups.clear();
53+
54+
AllGroups.clear();
55+
}
56+
57+
void CParticleBufferData::updateListGroup()
58+
{
59+
AllGroups.clear();
60+
61+
for (u32 i = 0, n = Groups.size(); i < n; i++)
62+
AllGroups.push_back(Groups[i]);
63+
64+
for (u32 i = 0, n = SubGroups.size(); i < n; i++)
65+
AllGroups.push_back(SubGroups[i]);
4966
}
5067

5168
CGroup* CParticleBufferData::createGroup()
5269
{
5370
CGroup* g = new CGroup();
5471
Groups.push_back(g);
72+
updateListGroup();
5573
return g;
5674
}
5775

@@ -68,18 +86,51 @@ namespace Skylicht
6886
CSubGroup* CParticleBufferData::createSubGroup(CGroup* group)
6987
{
7088
CSubGroup* g = new CSubGroup(group);
71-
Groups.push_back(g);
89+
SubGroups.push_back(g);
90+
updateListGroup();
7291
return g;
7392
}
7493

94+
std::vector<CSubGroup*> CParticleBufferData::getSubGroup(CGroup* parent)
95+
{
96+
std::vector<CSubGroup*> result;
97+
for (u32 i = 0, n = SubGroups.size(); i < n; i++)
98+
{
99+
CSubGroup* g = SubGroups[i];
100+
if (g && g->getParentGroup() == parent)
101+
{
102+
result.push_back(g);
103+
}
104+
}
105+
return result;
106+
}
107+
75108
void CParticleBufferData::removeGroup(CGroup* group)
76109
{
110+
std::vector<CSubGroup*> subGroups = getSubGroup(group);
111+
for (CSubGroup* g : subGroups)
112+
removeSubGroup(g);
113+
77114
int index = Groups.linear_search(group);
78115
if (index >= 0)
79116
{
80117
Groups.erase(index);
81118
delete group;
119+
120+
updateListGroup();
121+
}
122+
}
123+
124+
void CParticleBufferData::removeSubGroup(CSubGroup* group)
125+
{
126+
int index = SubGroups.linear_search(group);
127+
if (index >= 0)
128+
{
129+
SubGroups.erase(index);
130+
delete group;
82131
}
132+
133+
updateListGroup();
83134
}
84135

85136
void CParticleBufferData::bringToNext(CGroup* group, CGroup* target, bool behind)
@@ -101,6 +152,8 @@ namespace Skylicht
101152
++newIndex;
102153

103154
Groups.insert(group, newIndex);
155+
156+
updateListGroup();
104157
}
105158
}
106159
}

Projects/Skylicht/Components/ParticleSystem/CParticleBufferData.h

+8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ namespace Skylicht
3737
{
3838
public:
3939
core::array<CGroup*> Groups;
40+
core::array<CSubGroup*> SubGroups;
41+
core::array<CGroup*> AllGroups;
4042

4143
public:
4244
CParticleBufferData();
@@ -51,9 +53,15 @@ namespace Skylicht
5153

5254
CSubGroup* createSubGroup(CGroup* group);
5355

56+
std::vector<CSubGroup*> getSubGroup(CGroup* parent);
57+
5458
void removeGroup(CGroup* group);
5559

60+
void removeSubGroup(CSubGroup* group);
61+
5662
void bringToNext(CGroup* group, CGroup* target, bool behind);
63+
64+
void updateListGroup();
5765
};
5866

5967
DECLARE_COMPONENT_DATA_TYPE_INDEX(CParticleBufferData);

Projects/Skylicht/Components/ParticleSystem/CParticleRenderer.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ namespace Skylicht
7070
// use last frame data
7171
CCullingBBoxData* box = GET_ENTITY_DATA(entity, CCullingBBoxData);
7272

73-
CGroup** groups = particleData->Groups.pointer();
74-
for (u32 i = 0, n = particleData->Groups.size(); i < n; i++)
73+
CGroup** groups = particleData->AllGroups.pointer();
74+
for (u32 i = 0, n = particleData->AllGroups.size(); i < n; i++)
7575
{
7676
CGroup* g = groups[i];
7777
if (i == 0)
@@ -132,9 +132,9 @@ namespace Skylicht
132132
CWorldTransformData* transform = GET_ENTITY_DATA(entity, CWorldTransformData);
133133

134134
// update group before render
135-
for (u32 j = 0, m = data->Groups.size(); j < m; j++)
135+
for (u32 j = 0, m = data->AllGroups.size(); j < m; j++)
136136
{
137-
data->Groups[j]->update(culling->Visible);
137+
data->AllGroups[j]->update(culling->Visible);
138138
}
139139

140140
// render
@@ -191,8 +191,8 @@ namespace Skylicht
191191
IVideoDriver* driver = getVideoDriver();
192192
driver->setTransform(video::ETS_WORLD, world);
193193

194-
CGroup** groups = data->Groups.pointer();
195-
for (u32 i = 0, n = data->Groups.size(); i < n; i++)
194+
CGroup** groups = data->AllGroups.pointer();
195+
for (u32 i = 0, n = data->AllGroups.size(); i < n; i++)
196196
{
197197
CGroup* g = groups[i];
198198
if (g->getCurrentParticleCount() > 0 && g->Visible)
@@ -211,8 +211,8 @@ namespace Skylicht
211211
IVideoDriver* driver = getVideoDriver();
212212
driver->setTransform(video::ETS_WORLD, world);
213213

214-
CGroup** groups = data->Groups.pointer();
215-
for (u32 i = 0, n = data->Groups.size(); i < n; i++)
214+
CGroup** groups = data->AllGroups.pointer();
215+
for (u32 i = 0, n = data->AllGroups.size(); i < n; i++)
216216
{
217217
CGroup* g = groups[i];
218218
if (g->getCurrentParticleCount() > 0 && g->Visible)

Projects/Skylicht/Components/ParticleSystem/Particles/CGroup.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -304,10 +304,17 @@ namespace Skylicht
304304
else
305305
p.StartValue[t] = m->getStartValue1();
306306

307-
if (m->isRandomEnd() == true)
308-
p.EndValue[t] = m->getRandomEnd();
307+
if (m->isEnableEndValue())
308+
{
309+
if (m->isRandomEnd() == true)
310+
p.EndValue[t] = m->getRandomEnd();
311+
else
312+
p.EndValue[t] = m->getEndValue1();
313+
}
309314
else
310-
p.EndValue[t] = m->getEndValue1();
315+
{
316+
p.EndValue[t] = p.StartValue[t];
317+
}
311318

312319
if (t == Particle::RotateSpeedX ||
313320
t == Particle::RotateSpeedY ||

Projects/Skylicht/Components/ParticleSystem/Particles/CModel.cpp

+6-3
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ namespace Skylicht
6363
m_end2(0.0f),
6464
m_randomStart(false),
6565
m_randomEnd(false),
66+
m_enableEndValue(true),
6667
m_interpolator(NULL)
6768
{
6869

@@ -91,9 +92,10 @@ namespace Skylicht
9192
object->autoRelease(new CFloatProperty(object, "start1", m_start1));
9293
object->autoRelease(new CFloatProperty(object, "start2", m_start2));
9394

94-
CBoolProperty* randomEnd = new CBoolProperty(object, "randomEnd", m_randomEnd);
95-
randomEnd->setUIHeader("End value");
96-
object->autoRelease(randomEnd);
95+
CBoolProperty* endValue = new CBoolProperty(object, "enableEndValue", m_enableEndValue);
96+
endValue->setUIHeader("End value");
97+
object->autoRelease(endValue);
98+
object->autoRelease(new CBoolProperty(object, "randomEnd", m_randomEnd));
9799
object->autoRelease(new CFloatProperty(object, "end1", m_end1));
98100
object->autoRelease(new CFloatProperty(object, "end2", m_end2));
99101

@@ -114,6 +116,7 @@ namespace Skylicht
114116
m_start1 = object->get<float>("start1", 0.0f);
115117
m_start2 = object->get<float>("start2", 0.0f);
116118

119+
m_enableEndValue = object->get<bool>("enableEndValue", true);
117120
m_randomEnd = object->get<bool>("randomEnd", false);
118121
m_end1 = object->get<float>("end1", 0.0f);
119122
m_end2 = object->get<float>("end2", 0.0f);

Projects/Skylicht/Components/ParticleSystem/Particles/CModel.h

+11
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ namespace Skylicht
4343
float m_start1;
4444
float m_start2;
4545

46+
bool m_enableEndValue;
4647
bool m_randomEnd;
4748
float m_end1;
4849
float m_end2;
@@ -104,6 +105,16 @@ namespace Skylicht
104105
return this;
105106
}
106107

108+
inline bool isEnableEndValue()
109+
{
110+
return m_enableEndValue;
111+
}
112+
113+
inline void enableEndValue(bool b)
114+
{
115+
m_enableEndValue = b;
116+
}
117+
107118
inline bool isRandomStart()
108119
{
109120
return m_randomStart;

0 commit comments

Comments
 (0)