add 'random_sub_uv' particle setting
This commit is contained in:
parent
c8187c5f25
commit
86b83a5377
@ -1,8 +1,9 @@
|
||||
function on_block_broken(id, x, y, z, playerid)
|
||||
particles.emit({x+0.5, y+0.5, z+0.5}, 100, {
|
||||
lifetime=1.0,
|
||||
lifetime=2.0,
|
||||
spawn_interval=0.0001,
|
||||
explosion={4, 4, 4},
|
||||
texture="blocks:"..block.get_textures(id)[1]
|
||||
texture="blocks:"..block.get_textures(id)[1],
|
||||
random_sub_uv=0.1
|
||||
})
|
||||
end
|
||||
|
||||
@ -67,7 +67,16 @@ void Emitter::update(
|
||||
particle.emitter = this;
|
||||
particle.random = random.rand32();
|
||||
particle.position = position;
|
||||
particle.lifetime *= 1.0f - preset.lifetimeSpread * random.randFloat();
|
||||
particle.velocity += glm::ballRand(1.0f) * preset.explosion;
|
||||
if (preset.randomSubUV < 1.0f) {
|
||||
particle.region.autoSub(
|
||||
preset.randomSubUV,
|
||||
preset.randomSubUV,
|
||||
random.randFloat(),
|
||||
random.randFloat()
|
||||
);
|
||||
}
|
||||
particles.push_back(std::move(particle));
|
||||
timer -= spawnInterval;
|
||||
if (count > 0) {
|
||||
|
||||
@ -22,4 +22,15 @@ struct UVRegion {
|
||||
inline float getHeight() const {
|
||||
return fabs(v2 - v1);
|
||||
}
|
||||
|
||||
void autoSub(float w, float h, float x, float y) {
|
||||
x *= 1.0f - w;
|
||||
y *= 1.0f - h;
|
||||
float uvw = getWidth();
|
||||
float uvh = getHeight();
|
||||
u1 = u1 + uvw * x;
|
||||
v1 = v1 + uvh * y;
|
||||
u2 = u1 + uvw * w;
|
||||
v2 = v1 + uvh * h;
|
||||
}
|
||||
};
|
||||
|
||||
@ -10,9 +10,11 @@ dv::value ParticlesPreset::serialize() const {
|
||||
root["max_distance"] = maxDistance;
|
||||
root["spawn_interval"] = spawnInterval;
|
||||
root["lifetime"] = lifetime;
|
||||
root["lifetime_spread"] = lifetimeSpread;
|
||||
root["acceleration"] = dv::to_value(acceleration);
|
||||
root["explosion"] = dv::to_value(explosion);
|
||||
root["size"] = dv::to_value(size);
|
||||
root["random_sub_uv"] = randomSubUV;
|
||||
return root;
|
||||
}
|
||||
|
||||
@ -23,6 +25,8 @@ void ParticlesPreset::deserialize(const dv::value& src) {
|
||||
src.at("max_distance").get(maxDistance);
|
||||
src.at("spawn_interval").get(spawnInterval);
|
||||
src.at("lifetime").get(lifetime);
|
||||
src.at("lifetime_spread").get(lifetimeSpread);
|
||||
src.at("random_sub_uv").get(randomSubUV);
|
||||
if (src.has("acceleration")) {
|
||||
dv::get_vec(src["acceleration"], acceleration);
|
||||
}
|
||||
|
||||
@ -15,6 +15,8 @@ struct ParticlesPreset : public Serializable {
|
||||
float spawnInterval = 0.1f;
|
||||
/// @brief Particle life time
|
||||
float lifetime = 5.0f;
|
||||
/// @brief Life time spread divided by lifetime
|
||||
float lifetimeSpread = 0.2f;
|
||||
/// @brief Initial velocity
|
||||
glm::vec3 velocity {};
|
||||
/// @brief Velocity acceleration
|
||||
@ -25,6 +27,8 @@ struct ParticlesPreset : public Serializable {
|
||||
glm::vec3 size {0.1f};
|
||||
/// @brief Texture name
|
||||
std::string texture = "";
|
||||
/// @brief Size of random sub-uv region
|
||||
float randomSubUV = 1.0f;
|
||||
|
||||
dv::value serialize() const override;
|
||||
void deserialize(const dv::value& src) override;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user