From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../Modules/SizeByVelocityModule.cpp | 50 ++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Runtime/Graphics/ParticleSystem/Modules/SizeByVelocityModule.cpp (limited to 'Runtime/Graphics/ParticleSystem/Modules/SizeByVelocityModule.cpp') diff --git a/Runtime/Graphics/ParticleSystem/Modules/SizeByVelocityModule.cpp b/Runtime/Graphics/ParticleSystem/Modules/SizeByVelocityModule.cpp new file mode 100644 index 0000000..21cd5df --- /dev/null +++ b/Runtime/Graphics/ParticleSystem/Modules/SizeByVelocityModule.cpp @@ -0,0 +1,50 @@ +#include "UnityPrefix.h" +#include "SizeByVelocityModule.h" +#include "Runtime/BaseClasses/ObjectDefines.h" +#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h" +#include "Runtime/Graphics/ParticleSystem/ParticleSystemUtils.h" + +SizeBySpeedModule::SizeBySpeedModule () : ParticleSystemModule(false) +, m_Range (0.0f, 1.0f) +{} + +template +void UpdateTpl(const MinMaxCurve& curve, const ParticleSystemParticles& ps, float* tempSize, size_t fromIndex, size_t toIndex, const Vector2f offsetScale) +{ + for (size_t q = fromIndex; q < toIndex; ++q) + { + const Vector3f vel = ps.velocity[q] + ps.animatedVelocity[q]; + const float t = InverseLerpFast01 (offsetScale, Magnitude (vel)); + const float random = GenerateRandom(ps.randomSeed[q] + kParticleSystemSizeBySpeedCurveId); + tempSize[q] *= max (0.0f, Evaluate (curve, t, random)); + } +} + +void SizeBySpeedModule::Update (const ParticleSystemParticles& ps, float* tempSize, size_t fromIndex, size_t toIndex) +{ + DebugAssert(toIndex <= ps.array_size ()); + Vector2f offsetScale = CalculateInverseLerpOffsetScale(m_Range); + if (m_Curve.minMaxState == kMMCScalar) + UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); + else if (m_Curve.IsOptimized() && m_Curve.UsesMinMax()) + UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); + else if(m_Curve.IsOptimized()) + UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); + else + UpdateTpl (m_Curve, ps, tempSize, fromIndex, toIndex, offsetScale); +} + +void SizeBySpeedModule::CheckConsistency () +{ + const float MyEpsilon = 0.001f; + m_Range.x = std::min (m_Range.x, m_Range.y - MyEpsilon); +} + +template +void SizeBySpeedModule::Transfer (TransferFunction& transfer) +{ + ParticleSystemModule::Transfer (transfer); + transfer.Transfer (m_Curve, "curve"); + transfer.Transfer (m_Range, "range"); +} +INSTANTIATE_TEMPLATE_TRANSFER(SizeBySpeedModule) -- cgit v1.1-26-g67d0