forked from cocos/cocos-engine
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
20 changed files
with
270 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
31 changes: 31 additions & 0 deletions
31
native/cocos/particle/modules/CurlNoiseForceOverLifetime.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,40 @@ | ||
#pragma once | ||
|
||
#include "particle/ParticleSystemModule.h" | ||
#include "particle/CurveRange.h" | ||
#include "math/Vec3.h" | ||
|
||
namespace cc { | ||
class CurlNoiseForceOverLifetime : public ParticleSystemModule { | ||
public: | ||
enum { | ||
MAX_NUM_OCTAVE = 4, | ||
}; | ||
|
||
CurlNoiseForceOverLifetime() = default; | ||
virtual ~CurlNoiseForceOverLifetime() override = default; | ||
|
||
virtual void update(ModuleUpdateContext& context) const override; | ||
|
||
private: | ||
template <bool separateAxes, bool remap> | ||
void updateForce(ModuleUpdateContext& context) const; | ||
|
||
template<bool multiOctaves, NoiseQuality quality, NoiseAlgorithm algorithm> | ||
Vec2 accumulateNoiseSum(Vec3 sample, float frequency); | ||
|
||
CurveRange _strength[3]{1, 1, 1}; | ||
CurveRange _scrollSpeed{0}; | ||
CurveRange _remapCurve[3]{{1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}, {1.F, OptimizedCurve::ZERO_TO_ONE}}; | ||
float _octaveMultiplier{0.5}; | ||
float _octaveScale{2.F}; | ||
float _frequency{0.5}; | ||
NoiseQuality _quality{NoiseQuality::HIGH}; | ||
NoiseAlgorithm _algorithm{NoiseAlgorithm::PERLIN}; | ||
bool _damping{true}; | ||
bool _separateAxes{false}; | ||
bool _remap{false}; | ||
uint8_t _octaves{1}; | ||
|
||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,39 @@ | ||
#include "particle/modules/EmissionByBurst.h" | ||
#include "math/MathUtil.h" | ||
|
||
namespace cc { | ||
void EmissionByBurst::update(ModuleUpdateContext& context) const { | ||
if (context.emitter.loopedAge < 0) { | ||
return; | ||
} | ||
|
||
} | ||
|
||
void EmissionByBurst::updateEmissionInfo(ModuleUpdateContext& context, float prevLoopedAge, float loopedAge, float normalizedLoopAge, float prevNormalizedLoopAge, float subFrame) const { | ||
float dt = loopedAge - prevLoopedAge; | ||
for (size_t i = 0; i < _burstCount; i++) { | ||
const Burst& burst = _bursts[i]; | ||
if (burst.time > loopedAge) continue; | ||
|
||
float interval = std::max(burst.interval, math::EPSILON); | ||
float count = dt / interval; | ||
float emittedCycle = (prevLoopedAge - burst.time) / interval; | ||
float toEmitCycle = (loopedAge - burst.time) / interval; | ||
uint32_t newBurst = (int32_t)toEmitCycle - (int32_t)emittedCycle; | ||
|
||
if (newBurst > 0) { | ||
float burstInterval = dt / count; | ||
float normalizedInterval = (normalizedLoopAge - prevNormalizedLoopAge) / count; | ||
float remainder = toEmitCycle - (int32_t)toEmitCycle; | ||
for (size_t cycle = 0; cycle < newBurst; cycle++) { | ||
float interpStartNormalizedT = normalizedLoopAge - normalizedInterval * remainder; | ||
float alpha = Rand::rand1(context.emitter.tickCount, context.emitter.randomSeed, 0x7277c); | ||
float count = burst.count.evaluateSlow(interpStartNormalizedT, alpha); | ||
|
||
float interpStartDt = remainder * burstInterval + (context.deltaTime - dt - subFrame); | ||
context.emissionInfos.emplace_back(count, 0.F, 0.F, interpStartDt, interpStartNormalizedT); | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
36 changes: 36 additions & 0 deletions
36
native/cocos/particle/modules/InheritVelocityOverLifetime.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include "particle/modules/InheritVelocityOverLifetime.h" | ||
|
||
namespace cc { | ||
void InheritVelocityOverLifetime::update(ModuleUpdateContext& context) const { | ||
if (_multiplier.mode == CurveRangeMode::CONSTANT) { | ||
updateVelocity<CurveRangeMode::CONSTANT>(context); | ||
} else if (_multiplier.mode == CurveRangeMode::CURVE) { | ||
updateVelocity<CurveRangeMode::CURVE>(context); | ||
} else if (_multiplier.mode == CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS) { | ||
updateVelocity<CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS>(context); | ||
} else { | ||
updateVelocity<CurveRangeMode::RANDOM_BETWEEN_TWO_CURVES>(context); | ||
} | ||
} | ||
|
||
template <CurveRangeMode mode> | ||
void InheritVelocityOverLifetime::updateVelocity(ModuleUpdateContext& context) const { | ||
if (context.emitter.simulationSpace == CoordinateSpace::LOCAL) return; | ||
|
||
ParticleVec3Array& dest = context.particles.velocity[context.particles.currentVelocityIndex]; | ||
Vec3 emitterVelocity = context.emitter.velocity; | ||
for (uint32_t i = context.fromIndex; i < context.toIndex; i++) { | ||
float alpha{1.F}; | ||
float time{1.F}; | ||
if constexpr (CurveRange::needsRandomAlpha<mode>()) { | ||
alpha = Rand::rand1(context.particles.id.load(i), context.emitter.randomSeed, 0x6517bc); | ||
} | ||
|
||
if constexpr (CurveRange::needsTime<mode>()) { | ||
time = context.particles.normalizedAge.load(i); | ||
}; | ||
float scale = _multiplier.evaluate<mode>(time, alpha); | ||
dest.store(i, dest.load(i) + emitterVelocity * scale); | ||
} | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
native/cocos/particle/modules/InheritVelocityOverLifetime.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#pragma once | ||
|
||
#include "particle/ParticleSystemModule.h" | ||
#include "particle/CurveRange.h" | ||
|
||
namespace cc { | ||
class InheritVelocityOverLifetime : public ParticleSystemModule { | ||
public: | ||
InheritVelocityOverLifetime() = default; | ||
virtual ~InheritVelocityOverLifetime() override = default; | ||
virtual void update(ModuleUpdateContext& context) const override; | ||
|
||
private: | ||
template<CurveRangeMode mode> | ||
void updateVelocity(ModuleUpdateContext& context) const; | ||
|
||
CurveRange _multiplier{0}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
native/cocos/particle/modules/OrbitalVelocityOverLifetime.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#include "particle/modules/OrbitalVelocityOverLifetime.h" | ||
|
||
namespace cc { | ||
void OrbitalVelocityOverLifetime::update(ModuleUpdateContext& context) const { | ||
if (_orbital[0].mode == CurveRangeMode::CONSTANT) { | ||
updateOrbital<CurveRangeMode::CONSTANT>(context); | ||
} else if (_orbital[0].mode == CurveRangeMode::CURVE) { | ||
updateOrbital<CurveRangeMode::CURVE>(context); | ||
} else if (_orbital[0].mode == CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS) { | ||
updateOrbital<CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS>(context); | ||
} else { | ||
updateOrbital<CurveRangeMode::RANDOM_BETWEEN_TWO_CURVES>(context); | ||
} | ||
} | ||
|
||
template <CurveRangeMode orbitalMode> | ||
void OrbitalVelocityOverLifetime::updateOrbital(ModuleUpdateContext& context) const { | ||
if (_offset[0].mode == CurveRangeMode::CONSTANT) { | ||
updateOffset<orbitalMode, CurveRangeMode::CONSTANT>(context); | ||
} else if (_offset[0].mode == CurveRangeMode::CURVE) { | ||
updateOffset<orbitalMode, CurveRangeMode::CURVE>(context); | ||
} else if (_offset[0].mode == CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS) { | ||
updateOffset<orbitalMode, CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS>(context); | ||
} else { | ||
updateOffset<orbitalMode, CurveRangeMode::RANDOM_BETWEEN_TWO_CURVES>(context); | ||
} | ||
} | ||
|
||
template <CurveRangeMode orbitalMode, CurveRangeMode offsetMode> | ||
void OrbitalVelocityOverLifetime::updateOffset(ModuleUpdateContext& context) const { | ||
if (_radial.mode == CurveRangeMode::CONSTANT) { | ||
updateVelocity<orbitalMode, offsetMode, CurveRangeMode::CONSTANT>(context); | ||
} else if (_radial.mode == CurveRangeMode::CURVE) { | ||
updateVelocity<orbitalMode, offsetMode, CurveRangeMode::CURVE>(context); | ||
} else if (_radial.mode == CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS) { | ||
updateVelocity<orbitalMode, offsetMode, CurveRangeMode::RANDOM_BETWEEN_TWO_CONSTANTS>(context); | ||
} else { | ||
updateVelocity<orbitalMode, offsetMode, CurveRangeMode::RANDOM_BETWEEN_TWO_CURVES>(context); | ||
} | ||
} | ||
|
||
template <CurveRangeMode orbitalMode, CurveRangeMode offsetMode, CurveRangeMode radialMode> | ||
void OrbitalVelocityOverLifetime::updateVelocity(ModuleUpdateContext& context) const { | ||
for (size_t i = context.fromIndex; i < context.toIndex; i++) { | ||
Vec3 alpha{}; | ||
float time{1.F}; | ||
|
||
if constexpr (CurveRange::needsTime<orbitalMode>() || CurveRange::needsTime<offsetMode>() || CurveRange::needsTime<radialMode>()) { | ||
time = context.particles.normalizedAge.load(i); | ||
} | ||
|
||
if constexpr (CurveRange::needsRandomAlpha<orbitalMode>()) { | ||
alpha = Rand::rand3(context.particles.id.load(i), context.emitter.randomSeed, 0xef728c); | ||
} | ||
|
||
Vec3 oritalVelocity { | ||
_orbital[0].evaluate<orbitalMode>(time, alpha.x); | ||
_orbital[1].evaluate<orbitalMode>(time, alpha.y); | ||
_orbital[2].evaluate<orbitalMode>(time, alpha.z); | ||
}; | ||
|
||
if constexpr (CurveRange::needsRandomAlpha<offsetMode>()) { | ||
alpha = Rand::rand3(context.particles.id.load(i), context.emitter.randomSeed, 0x117ca); | ||
} | ||
|
||
Vec3 offset { | ||
_offset[0].evaluate<offsetMode>(time, alpha.x); | ||
_offset[1].evaluate<offsetMode>(time, alpha.y); | ||
_offset[2].evaluate<offsetMode>(time, alpha.z); | ||
}; | ||
|
||
if constexpr (CurveRange::needsRandomAlpha<radialMode>()) { | ||
alpha.x = Rand::rand1(context.particles.id.load(i), context.emitter.randomSeed, 0x67182bc); | ||
} | ||
|
||
float radialVel = _radial.evaluate<radialMode>(time, alpha.x); | ||
} | ||
} | ||
} |
Oops, something went wrong.