update particles randomizer
This commit is contained in:
@@ -39,7 +39,7 @@ void Emitter::update(float delta, std::vector<Particle>& particles) {
|
|||||||
// spawn particle
|
// spawn particle
|
||||||
Particle particle = prototype;
|
Particle particle = prototype;
|
||||||
particle.emitter = this;
|
particle.emitter = this;
|
||||||
particle.random = rand();
|
particle.random = random.rand32();
|
||||||
particle.position = position;
|
particle.position = position;
|
||||||
particle.velocity += glm::ballRand(1.0f) * explosion;
|
particle.velocity += glm::ballRand(1.0f) * explosion;
|
||||||
particles.push_back(std::move(particle));
|
particles.push_back(std::move(particle));
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
#include "typedefs.hpp"
|
#include "typedefs.hpp"
|
||||||
|
|
||||||
#include "maths/UVRegion.hpp"
|
#include "maths/UVRegion.hpp"
|
||||||
|
#include "maths/util.hpp"
|
||||||
|
|
||||||
class Emitter;
|
class Emitter;
|
||||||
|
|
||||||
@@ -50,6 +51,8 @@ class Emitter {
|
|||||||
float timer = 0.0f;
|
float timer = 0.0f;
|
||||||
/// @brief Random velocity magnitude applying to spawned particles
|
/// @brief Random velocity magnitude applying to spawned particles
|
||||||
glm::vec3 explosion {8.0f};
|
glm::vec3 explosion {8.0f};
|
||||||
|
|
||||||
|
util::PseudoRandom random;
|
||||||
public:
|
public:
|
||||||
ParticleBehaviour behaviour;
|
ParticleBehaviour behaviour;
|
||||||
|
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ ParticlesRenderer::ParticlesRenderer(
|
|||||||
auto region = util::get_texture_region(assets, "blocks:grass_top", "");
|
auto region = util::get_texture_region(assets, "blocks:grass_top", "");
|
||||||
emitters.push_back(std::make_unique<Emitter>(glm::vec3(0, 80, 0), Particle {
|
emitters.push_back(std::make_unique<Emitter>(glm::vec3(0, 80, 0), Particle {
|
||||||
nullptr, 0, glm::vec3(), glm::vec3(), 5.0f, region.region
|
nullptr, 0, glm::vec3(), glm::vec3(), 5.0f, region.region
|
||||||
},region.texture, 0.002f, -1));
|
}, region.texture, 0.002f, -1));
|
||||||
}
|
}
|
||||||
|
|
||||||
ParticlesRenderer::~ParticlesRenderer() = default;
|
ParticlesRenderer::~ParticlesRenderer() = default;
|
||||||
@@ -71,7 +71,7 @@ void ParticlesRenderer::renderParticles(const Camera& camera, float delta) {
|
|||||||
light = MainBatch::sampleLight(
|
light = MainBatch::sampleLight(
|
||||||
particle.position, chunks, backlight
|
particle.position, chunks, backlight
|
||||||
);
|
);
|
||||||
light *= 0.7f + (particle.random % 300) * 0.001f;
|
light *= 0.8f + (particle.random % 200) * 0.001f;
|
||||||
}
|
}
|
||||||
batch->quad(
|
batch->quad(
|
||||||
particle.position,
|
particle.position,
|
||||||
|
|||||||
Reference in New Issue
Block a user