Beam particles fixed/tweaked.

This commit is contained in:
Sam 2020-09-28 20:59:58 -05:00
parent 5f889773b5
commit 207586cfab
3 changed files with 13 additions and 15 deletions

View File

@ -23,7 +23,7 @@ in vec3 inst_pos;
in float inst_time;
in float inst_lifespan;
in float inst_entropy;
in float inst_misc;
in vec3 inst_pos2;
in int inst_mode;
out vec3 f_pos;
@ -106,10 +106,6 @@ mat4 identity() {
);
}
vec3 beam_pos2() {
return vec3(inst_lifespan, inst_entropy, inst_misc);
}
vec3 perp_axis1(vec3 axis) {
return normalize(vec3(axis.y + axis.z, -axis.x + axis.z, -axis.x - axis.y));
}
@ -275,10 +271,10 @@ void main() {
);
} else if (inst_mode == HEALING_BEAM) {
attr = Attr(
spiral_motion(beam_pos2() - inst_pos, 0.3 * (floor(2 * hash(vec4(inst_time)) + 0.5) - 0.5) * min(linear_scale(10), 1), lifetime / 1), // The 1 that lifetime is divided by is the duration of the beam. It is currently hardcoded here due to limitations in passing in variables.
vec3((1.7 - 0.7 * abs(floor(2 * hash(vec4(inst_time)) - 0.5) + 0.5)) * (1.5 + 0.5 * sin(tick.x * 10 - lifetime * 4))),
spiral_motion(inst_pos2 - inst_pos, 0.3 * (floor(2 * rand0 + 0.5) - 0.5) * min(linear_scale(10), 1), lifetime / inst_lifespan),
vec3((1.7 - 0.7 * abs(floor(2 * rand0 - 0.5) + 0.5)) * (1.5 + 0.5 * sin(tick.x * 10 - lifetime * 4))),
vec4(vec3(0.3, 0.7 + 0.4 * sin(tick.x * 8 - lifetime * 3), 0.3 + 0.1 * sin (tick.x * 2)), 0.3),
spin_in_axis(vec3(inst_entropy, inst_misc, inst_lifespan), tick.z)
spin_in_axis(inst_pos2, tick.z)
);
} else if (inst_mode == ENERGY_NATURE) {
attr = Attr(

View File

@ -35,8 +35,8 @@ gfx_defines! {
// can save 32 bits per instance, and have cleaner tailor made code.
inst_mode: i32 = "inst_mode",
// an extra value for particles that need it
inst_misc: f32 = "inst_misc",
// an extra position for particles that need it
inst_pos2: [f32; 3] = "inst_pos2",
// a triangle is: f32 x 3 x 3 x 1 = 288 bits
// a quad is: f32 x 3 x 3 x 2 = 576 bits
@ -131,23 +131,25 @@ impl Instance {
inst_entropy: rand::thread_rng().gen(),
inst_mode: inst_mode as i32,
inst_pos: inst_pos.into_array(),
inst_misc: 0.0,
inst_pos2: [0.0, 0.0, 0.0],
}
}
pub fn new_beam(
inst_time: f64,
lifespan: f32,
inst_mode: ParticleMode,
inst_pos: Vec3<f32>,
inst_pos2: 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(),
inst_lifespan: inst_pos2.x,
inst_entropy: inst_pos2.y,
inst_misc: inst_pos2.z,
inst_pos2: inst_pos2.into_array(),
}
}
}

View File

@ -726,7 +726,7 @@ impl Particle {
) -> Self {
Particle {
alive_until: time + lifespan.as_secs_f64(),
instance: ParticleInstance::new_beam(time, mode, pos1, pos2),
instance: ParticleInstance::new_beam(time, lifespan.as_secs_f32(), mode, pos1, pos2),
}
}
}