From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../ParticleSystem/Modules/ColorModule.cpp | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 Runtime/Graphics/ParticleSystem/Modules/ColorModule.cpp (limited to 'Runtime/Graphics/ParticleSystem/Modules/ColorModule.cpp') diff --git a/Runtime/Graphics/ParticleSystem/Modules/ColorModule.cpp b/Runtime/Graphics/ParticleSystem/Modules/ColorModule.cpp new file mode 100644 index 0000000..c9e78c0 --- /dev/null +++ b/Runtime/Graphics/ParticleSystem/Modules/ColorModule.cpp @@ -0,0 +1,51 @@ +#include "UnityPrefix.h" +#include "ColorModule.h" +#include "Runtime/BaseClasses/ObjectDefines.h" +#include "Runtime/Serialize/TransferFunctions/SerializeTransfer.h" +#include "Runtime/Math/Random/Random.h" +#include "Runtime/Graphics/ParticleSystem/ParticleSystemUtils.h" + +template +void UpdateTpl(const ParticleSystemParticles& ps, ColorRGBA32* colorTemp, const MinMaxGradient& gradient, const OptimizedMinMaxGradient& optGradient, size_t fromIndex, size_t toIndex) +{ + for (size_t q = fromIndex; q < toIndex; ++q) + { + const float time = NormalizedTime(ps, q); + const int random = GenerateRandomByte(ps.randomSeed[q] + kParticleSystemColorGradientId); + + ColorRGBA32 value; + if(mode == kGEMGradient) + value = EvaluateGradient (optGradient, time); + else if(mode == kGEMGradientMinMax) + value = EvaluateRandomGradient (optGradient, time, random); + else + value = Evaluate (gradient, time, random); + + colorTemp[q] *= value; + } +} + +ColorModule::ColorModule () : ParticleSystemModule(false) +{} + +void ColorModule::Update (const ParticleSystemParticles& ps, ColorRGBA32* colorTemp, size_t fromIndex, size_t toIndex) +{ + DebugAssert(toIndex <= ps.array_size()); + + OptimizedMinMaxGradient gradient; + m_Gradient.InitializeOptimized(gradient); + if(m_Gradient.minMaxState == kMMGGradient) + UpdateTpl(ps, colorTemp, m_Gradient, gradient, fromIndex, toIndex); + else if(m_Gradient.minMaxState == kMMGRandomBetweenTwoGradients) + UpdateTpl(ps, colorTemp, m_Gradient, gradient, fromIndex, toIndex); + else + UpdateTpl(ps, colorTemp, m_Gradient, gradient, fromIndex, toIndex); +} + +template +void ColorModule::Transfer (TransferFunction& transfer) +{ + ParticleSystemModule::Transfer (transfer); + transfer.Transfer (m_Gradient, "gradient"); +} +INSTANTIATE_TEMPLATE_TRANSFER(ColorModule) -- cgit v1.1-26-g67d0