Particle system improvements + Emissive materials

Added option for Global particle positions
Added material property for particles
Added Emissive rendering
This commit is contained in:
Antoine Pilote
2023-09-23 20:31:50 -04:00
parent 50bc020f6e
commit 2cb0ca4f29
17 changed files with 242 additions and 26 deletions

View File

@@ -6,12 +6,17 @@ namespace Nuake
{
BEGIN_SERIALIZE();
SERIALIZE_VEC4(ParticleColor);
SERIALIZE_VEC3(ParticleScale);
SERIALIZE_VAL(Amount);
SERIALIZE_VAL(Life);
SERIALIZE_VAL(Rate);
SERIALIZE_VEC3(Gravity);
SERIALIZE_VAL(GravityRandom);
SERIALIZE_VAL(Radius);
SERIALIZE_VAL(GlobalSpace);
SERIALIZE_OBJECT(ParticleMaterial);
END_SERIALIZE();
}
@@ -25,6 +30,20 @@ namespace Nuake
Rate = j["Rate"];
}
DESERIALIZE_VEC3(j["Gravity"], Gravity);
if (j.contains("ParticleScale"))
{
DESERIALIZE_VEC3(j["ParticleScale"], ParticleScale);
}
if (j.contains("GlobalSpace"))
{
DESERIALIZE_VAL(GlobalSpace);
}
if (j.contains("ParticleMaterial"))
{
Ref<Material> newMaterial = CreateRef<Material>();
newMaterial->Deserialize(j["ParticleMaterial"]);
ParticleMaterial = newMaterial;
}
GravityRandom = j["GravityRandom"];
Radius = j["Radius"];
return true;

View File

@@ -14,10 +14,15 @@ namespace Nuake
ParticleEmitterComponent() = default;
~ParticleEmitterComponent() = default;
Ref<Material> ParticleMaterial = CreateRef<Material>();
Color ParticleColor;
float Amount;
float Life = 1.0f;
float Rate = 0.0f;
Vector3 ParticleScale = Vector3(0.1, 0.1, 0.1);
bool GlobalSpace = false;
Vector3 Gravity;
float GravityRandom;

View File

@@ -31,7 +31,7 @@ namespace Nuake
SpriteMesh = CreateRef<Mesh>();
SpriteMesh->AddSurface(quadVertices, { 0, 1, 2, 3, 4, 5 });
auto& material = MaterialManager::Get()->GetMaterial(FileSystem::Root + SpritePath);
auto material = MaterialManager::Get()->GetMaterial(FileSystem::Root + SpritePath);
SpriteMesh->SetMaterial(material);
return true;

View File

@@ -13,6 +13,11 @@ namespace Nuake
}
void ParticleEmitter::SetGlobalOrigin(const Vector3& origin)
{
GlobalOrigin = origin;
}
void ParticleEmitter::SpawnParticle()
{
const bool canSpawnParticle = Particles.size() < Amount;
@@ -23,11 +28,16 @@ namespace Nuake
if (Rate == 0.0f || RateTimer > Rate)
{
const auto initialPosition = Vector3(m_Random(m_MT), m_Random(m_MT), m_Random(m_MT));
auto initialPosition = Vector3(m_Random(m_MT), m_Random(m_MT), m_Random(m_MT));
const auto initialVelocity = Vector3();
const auto initialColor = ParticleColor;
const float initialLife = Life;
if (IsGlobalSpace)
{
initialPosition = initialPosition + GlobalOrigin;
}
Particles.push_back({
initialPosition,
initialVelocity,

View File

@@ -22,6 +22,9 @@ namespace Nuake
float Rate = 0.0f;
Color ParticleColor;
bool IsGlobalSpace = false;
Vector3 GlobalOrigin;
private:
float RateTimer = 0.0f;
std::mt19937 m_MT;
@@ -33,6 +36,8 @@ namespace Nuake
ParticleEmitter();
~ParticleEmitter() = default;
void SetGlobalOrigin(const Vector3& origin);
void SpawnParticle();
void Update(Timestep ts);

View File

@@ -34,6 +34,8 @@ namespace Nuake
emitter.SetRadius(emitterComponent.Radius);
emitter.Life = emitterComponent.Life;
emitter.Rate = emitterComponent.Rate;
emitter.IsGlobalSpace = emitterComponent.GlobalSpace;
emitter.GlobalOrigin = transformComponent.GetGlobalTransform()[3];
// Spawn particle if possible
emitterComponent.Emitter.SpawnParticle();