summaryrefslogtreecommitdiff
path: root/Runtime/Graphics/ParticleSystem/Modules/ColorModule.cpp
blob: c9e78c07f07b773457ec9d7200f2d9df3057645a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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<MinMaxGradientEvalMode mode>
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<kGEMGradient>(ps, colorTemp, m_Gradient, gradient, fromIndex, toIndex);
	else if(m_Gradient.minMaxState == kMMGRandomBetweenTwoGradients)
		UpdateTpl<kGEMGradientMinMax>(ps, colorTemp, m_Gradient, gradient, fromIndex, toIndex);
	else
		UpdateTpl<kGEMSlow>(ps, colorTemp, m_Gradient, gradient, fromIndex, toIndex);
}

template<class TransferFunction>
void ColorModule::Transfer (TransferFunction& transfer)
{
	ParticleSystemModule::Transfer (transfer);
	transfer.Transfer (m_Gradient, "gradient");
}
INSTANTIATE_TEMPLATE_TRANSFER(ColorModule)