mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added lifetime particle parameter
This commit is contained in:
parent
05f4024e1a
commit
7eff8ff0ad
@ -21,6 +21,7 @@ in vec3 v_pos;
|
||||
in uint v_norm_ao;
|
||||
in vec3 inst_pos;
|
||||
in float inst_time;
|
||||
in float inst_lifespan;
|
||||
in float inst_entropy;
|
||||
in int inst_mode;
|
||||
|
||||
@ -73,6 +74,10 @@ float linear_scale(float factor) {
|
||||
return lifetime * factor;
|
||||
}
|
||||
|
||||
float start_end(float from, float to) {
|
||||
return mix(from, to, lifetime / inst_lifespan);
|
||||
}
|
||||
|
||||
mat4 rotationMatrix(vec3 axis, float angle)
|
||||
{
|
||||
axis = normalize(axis);
|
||||
@ -104,10 +109,10 @@ void main() {
|
||||
attr = Attr(
|
||||
linear_motion(
|
||||
vec3(0.0, 0.0, 0.0),
|
||||
vec3(rand2 * 0.02, rand3 * 0.02, 1.0 + rand4 * 0.1)// + vec3(sin(lifetime), sin(lifetime + 1.5), sin(lifetime * 4) * 0.25)
|
||||
vec3(rand2 * 0.02, rand3 * 0.02, 1.0 + rand4 * 0.1)
|
||||
),
|
||||
linear_scale(0.5),
|
||||
vec4(1, 1, 1, 0.3),
|
||||
vec4(1, 1, 1, start_end(1.0, 0.0)),
|
||||
rotationMatrix(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 0.5)
|
||||
);
|
||||
} else if (inst_mode == FIRE) {
|
||||
@ -221,7 +226,6 @@ void main() {
|
||||
// inst_pos *
|
||||
((normals[(v_norm_ao >> 0) & 0x7u]) * attr.rot).xyz;
|
||||
|
||||
|
||||
//vec3 col = vec3((uvec3(v_col) >> uvec3(0, 8, 16)) & uvec3(0xFFu)) / 255.0;
|
||||
f_col = vec4(srgb_to_linear(attr.col.rgb), attr.col.a);
|
||||
|
||||
|
@ -24,6 +24,9 @@ gfx_defines! {
|
||||
// can save 32 bits per instance, for particles that are not relatively animated.
|
||||
inst_time: f32 = "inst_time",
|
||||
|
||||
// The lifespan in seconds of the particle
|
||||
inst_lifespan: f32 = "inst_lifespan",
|
||||
|
||||
// a seed value for randomness
|
||||
// can save 32 bits per instance, for particles that don't need randomness/uniqueness.
|
||||
inst_entropy: f32 = "inst_entropy",
|
||||
@ -107,10 +110,16 @@ impl ParticleMode {
|
||||
}
|
||||
|
||||
impl Instance {
|
||||
pub fn new(inst_time: f64, inst_mode: ParticleMode, inst_pos: Vec3<f32>) -> Self {
|
||||
pub fn new(
|
||||
inst_time: f64,
|
||||
lifespan: f32,
|
||||
inst_mode: ParticleMode,
|
||||
inst_pos: Vec3<f32>,
|
||||
) -> Self {
|
||||
use rand::Rng;
|
||||
Self {
|
||||
inst_time: inst_time as f32,
|
||||
inst_lifespan: lifespan,
|
||||
inst_entropy: rand::thread_rng().gen(),
|
||||
inst_mode: inst_mode as i32,
|
||||
inst_pos: inst_pos.into_array(),
|
||||
@ -119,7 +128,7 @@ impl Instance {
|
||||
}
|
||||
|
||||
impl Default for Instance {
|
||||
fn default() -> Self { Self::new(0.0, ParticleMode::CampfireSmoke, Vec3::zero()) }
|
||||
fn default() -> Self { Self::new(0.0, 0.0, ParticleMode::CampfireSmoke, Vec3::zero()) }
|
||||
}
|
||||
|
||||
pub struct ParticlePipeline;
|
||||
|
@ -157,7 +157,7 @@ impl ParticleMgr {
|
||||
Duration::from_secs(10),
|
||||
time,
|
||||
ParticleMode::CampfireSmoke,
|
||||
pos.0.map(|e| e + thread_rng().gen_range(-0.5, 0.5)),
|
||||
pos.0.map(|e| e + thread_rng().gen_range(-0.25, 0.25)),
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -276,7 +276,7 @@ impl ParticleMgr {
|
||||
let particles: &[(BoiFn, usize, f32, f32, ParticleMode)] = &[
|
||||
(|boi| &boi.leaves, 4, 0.001, 30.0, ParticleMode::Leaf),
|
||||
(|boi| &boi.embers, 2, 20.0, 0.25, ParticleMode::CampfireFire),
|
||||
(|boi| &boi.embers, 8, 6.0, 30.0, ParticleMode::CampfireSmoke),
|
||||
(|boi| &boi.embers, 8, 3.0, 40.0, ParticleMode::CampfireSmoke),
|
||||
];
|
||||
|
||||
for (get_blocks, range, rate, dur, mode) in particles.iter() {
|
||||
@ -461,7 +461,7 @@ impl Particle {
|
||||
fn new(lifespan: Duration, time: f64, mode: ParticleMode, pos: Vec3<f32>) -> Self {
|
||||
Particle {
|
||||
alive_until: time + lifespan.as_secs_f64(),
|
||||
instance: ParticleInstance::new(time, mode, pos),
|
||||
instance: ParticleInstance::new(time, lifespan.as_secs_f32(), mode, pos),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user