2 * Copyright (c) 2023 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 #include "sparkles-effect-modifier.h"
19 #include "sparkles-effect-source.h"
21 namespace Dali::ParticleEffect
23 static float LIFETIME = 3.0f;
24 SparklesModifier::SparklesModifier(ParticleEmitter& emitter)
29 bool SparklesModifier::IsMultiThreaded()
34 void SparklesModifier::Update(ParticleList& particleList, uint32_t first, uint32_t count)
36 // If no acive particles return
37 if(!particleList.GetActiveParticleCount())
42 mAngle = ((mAngle + 2) % 360);
44 // Retrieve the Source and get the stream
47 mStreamBasePos = static_cast<SparklesSource*>(&mEmitter.GetSource().GetSourceCallback())->mStreamBasePos;
51 mStreamBaseAngle = static_cast<SparklesSource*>(&mEmitter.GetSource().GetSourceCallback())->mStreamBaseAngle;
54 // Missing stream, return!
60 auto& activeParticles = particleList.GetActiveParticles();
62 auto it = activeParticles.begin();
63 std::advance(it, first);
65 for(; count; ++it, count--)
67 // Acquire stream data
69 auto& position = particle.Get<Vector3>(ParticleStream::POSITION_STREAM_BIT);
70 auto& velocity = particle.Get<Vector3>(ParticleStream::VELOCITY_STREAM_BIT);
71 auto& color = particle.Get<Vector4>(ParticleStream::COLOR_STREAM_BIT);
72 auto& scale = particle.Get<Vector3>(ParticleStream::SCALE_STREAM_BIT);
75 [[maybe_unused]] auto& basePos = particle.GetByIndex<Vector3>(mStreamBasePos);
77 auto angle = particle.GetByIndex<float>(mStreamBaseAngle);
78 auto radians = ((angle * M_PI)/180.f);
79 float lifetime = particle.Get<float>(ParticleStream::LIFETIME_STREAM_BIT);
80 position.y += velocity.y *sin(radians);
81 position.x += velocity.x * cos(radians);
84 float normalizedTime = (lifetime / LIFETIME);
85 color.a = normalizedTime;
86 scale = Vector3(64.0f*(normalizedTime * normalizedTime * normalizedTime * normalizedTime), 64.0f*(normalizedTime * normalizedTime * normalizedTime * normalizedTime), 1.0);