From be353c9fe05950937951a5867863af6a912f0348 Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 28 Sep 2020 20:59:58 -0500 Subject: [PATCH] Beam particles fixed/tweaked. --- assets/voxygen/shaders/particle-vert.glsl | 12 ++++-------- voxygen/src/render/pipelines/particle.rs | 14 ++++++++------ voxygen/src/scene/particle.rs | 2 +- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index 35a60a9840..0a2e020ca4 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -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( diff --git a/voxygen/src/render/pipelines/particle.rs b/voxygen/src/render/pipelines/particle.rs index 2bd17548cf..8968a96554 100644 --- a/voxygen/src/render/pipelines/particle.rs +++ b/voxygen/src/render/pipelines/particle.rs @@ -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, inst_pos2: Vec3, ) -> 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(), } } } diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 704ad843d1..55b22e4787 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -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), } } }