From d129e30f519960ad85975511aba4cb256cf2efb8 Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Wed, 18 Nov 2020 13:22:05 +0000 Subject: [PATCH] Fixed various particle issues --- assets/voxygen/shaders/particle-frag.glsl | 9 ++--- assets/voxygen/shaders/particle-vert.glsl | 42 +++++++++++++++-------- voxygen/src/scene/particle.rs | 10 ++++-- 3 files changed, 39 insertions(+), 22 deletions(-) diff --git a/assets/voxygen/shaders/particle-frag.glsl b/assets/voxygen/shaders/particle-frag.glsl index c4a66e6cd1..8849598bf9 100644 --- a/assets/voxygen/shaders/particle-frag.glsl +++ b/assets/voxygen/shaders/particle-frag.glsl @@ -19,6 +19,7 @@ in vec3 f_pos; flat in vec3 f_norm; in vec4 f_col; +in float f_reflect; out vec4 tgt_color; @@ -59,9 +60,9 @@ void main() { const float R_s1s2 = pow((1.3325 - 1.0) / (1.3325 + 1.0), 2); float R_s = (f_pos.z < f_alt) ? mix(R_s2s1 * R_s1s0, R_s1s0, medium.x) : mix(R_s2s0, R_s1s2 * R_s2s0, medium.x); - vec3 k_a = vec3(1.0); - vec3 k_d = vec3(1.0); - vec3 k_s = vec3(R_s); + vec3 k_a = vec3(1.0) * f_reflect; + vec3 k_d = vec3(1.0) * f_reflect; + vec3 k_s = vec3(R_s) * f_reflect; vec3 emitted_light, reflected_light; @@ -75,7 +76,7 @@ void main() { // TODO: Not this emitted_light += max(f_col.rgb - 1.0, vec3(0)); - surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light); + surf_color = illuminate(max_light, view_dir, surf_color * emitted_light, surf_color * reflected_light * f_reflect); tgt_color = vec4(surf_color, f_col.a); } diff --git a/assets/voxygen/shaders/particle-vert.glsl b/assets/voxygen/shaders/particle-vert.glsl index 39a1d3ddfe..09920976e6 100644 --- a/assets/voxygen/shaders/particle-vert.glsl +++ b/assets/voxygen/shaders/particle-vert.glsl @@ -31,6 +31,7 @@ flat out vec3 f_norm; out vec4 f_col; out float f_ao; out float f_light; +out float f_reflect; const float SCALE = 1.0 / 11.0; @@ -139,6 +140,7 @@ void main() { float rand9 = hash(vec4(inst_entropy + 9)); Attr attr; + f_reflect = 1.0; if (inst_mode == SMOKE) { attr = Attr( @@ -151,20 +153,21 @@ void main() { spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3 + lifetime * 0.5) ); } else if (inst_mode == FIRE) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( linear_motion( - vec3(rand0 * 0.25, rand1 * 0.25, 0.3), + vec3(normalize(vec2(rand0, rand1)) * 0.25, 0.3), vec3(rand2 * 0.1, rand3 * 0.1, 2.0 + rand4 * 1.0) ), vec3(1.0), - vec4(2, 0.8 + rand5 * 0.3, 0, 1), + vec4(2, 1.5 + rand5 * 0.5, 0, 1), spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3) ); } else if (inst_mode == GUN_POWDER_SPARK) { attr = Attr( linear_motion( - vec3(rand0, rand1, rand3) * 0.3, - vec3(rand4, rand5, rand6) * 2.0 + grav_vel(earth_gravity) + normalize(vec3(rand0, rand1, rand3)) * 0.3, + normalize(vec3(rand4, rand5, rand6)) * 2.0 + grav_vel(earth_gravity) ), vec3(1.0), vec4(3.5, 3 + rand7, 0, 1), @@ -174,57 +177,62 @@ void main() { attr = Attr( linear_motion( vec3(0), - vec3(rand4, rand5, rand6) * 30.0 + grav_vel(earth_gravity) + normalize(vec3(rand4, rand5, rand6)) * 30.0 + grav_vel(earth_gravity) ), vec3(2.0 + rand0), vec4(vec3(0.6 + rand7 * 0.4), 1), spin_in_axis(vec3(1,0,0),0) ); } else if (inst_mode == FIREWORK_BLUE) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( linear_motion( vec3(0), - vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity) + normalize(vec3(rand1, rand2, rand3)) * 40.0 + grav_vel(earth_gravity) ), vec3(3.0 + rand0), vec4(0.15, 0.4, 1, 1), identity() ); } else if (inst_mode == FIREWORK_GREEN) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( linear_motion( vec3(0), - vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity) + normalize(vec3(rand1, rand2, rand3)) * 40.0 + grav_vel(earth_gravity) ), vec3(3.0 + rand0), vec4(0, 1, 0, 1), identity() ); } else if (inst_mode == FIREWORK_PURPLE) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( linear_motion( vec3(0), - vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity) + normalize(vec3(rand1, rand2, rand3)) * 40.0 + grav_vel(earth_gravity) ), vec3(3.0 + rand0), vec4(0.7, 0.0, 1.0, 1.0), identity() ); } else if (inst_mode == FIREWORK_RED) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( linear_motion( vec3(0), - vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity) + normalize(vec3(rand1, rand2, rand3)) * 40.0 + grav_vel(earth_gravity) ), vec3(3.0 + rand0), vec4(1, 0, 0, 1), identity() ); } else if (inst_mode == FIREWORK_YELLOW) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( linear_motion( vec3(0), - vec3(rand1, rand2, rand3) * 40.0 + grav_vel(earth_gravity) + normalize(vec3(rand1, rand2, rand3)) * 40.0 + grav_vel(earth_gravity) ), vec3(3.0 + rand0), vec4(1, 1, 0, 1), @@ -272,34 +280,38 @@ void main() { spin_in_axis(vec3(1,0,0),0) ); } else if (inst_mode == HEALING_BEAM) { + f_reflect = 0.0; attr = Attr( spiral_motion(inst_dir, 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), + vec4(vec3(0.4, 2.7 + 0.4 * sin(tick.x * 8 - lifetime * 3 + 4), 0.5 + 0.6 * sin(tick.x * 7)), 0.3), spin_in_axis(inst_dir, tick.z) ); } else if (inst_mode == ENERGY_NATURE) { + f_reflect = 0.0; attr = Attr( linear_motion( vec3(rand0 * 1, rand1 * 1, rand2 * 1), vec3(rand3 * 2, rand4 * 2, rand5 * 2) ), vec3(0.8), - vec4(vec3(0, 1, 0), 1), + vec4(vec3(0, 2.5, 1.5 + rand7 * 0.7), 1), spin_in_axis(vec3(rand6, rand7, rand8), rand9 * 3) ); } else if (inst_mode == FLAMETHROWER) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( (inst_dir * lifetime / inst_lifespan) + vec3(rand0, rand1, rand2) * (lifetime * 5 + 0.25), vec3(0.6 + rand3 * 0.5 + lifetime / inst_lifespan * 5), - vec4(1, 0.6 + rand5 * 0.3 - 0.6 * lifetime / inst_lifespan, 0, 0.8 - 0.6 * lifetime / inst_lifespan), + vec4(3, 1.6 + rand5 * 0.3 - 0.6 * lifetime / inst_lifespan, 0.2, 0.8 - 0.6 * lifetime / inst_lifespan), spin_in_axis(vec3(rand6, rand7, rand8), lifetime / inst_lifespan * 10 + 3 * rand9) ); } else if (inst_mode == FIRE_SHOCKWAVE) { + f_reflect = 0.0; // Fire doesn't reflect light, it emits it attr = Attr( vec3(rand0, rand1, lifetime * 10 + rand2), vec3(1.6 + rand3 * 1.5 + 10 * (lifetime + inst_lifespan)), - vec4(1, 0.6 + rand7 * 0.3 - 5 * inst_lifespan + 2 * lifetime, 0, 0.8 - 3.5 * inst_lifespan), + vec4(3, 1.6 + rand7 * 0.3 - 5 * inst_lifespan + 2 * lifetime, 0.2, 0.8 - 3.5 * inst_lifespan), spin_in_axis(vec3(rand3, rand4, rand5), rand6) ); } else { @@ -324,7 +336,7 @@ void main() { ((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); + f_col = vec4(attr.col.rgb, attr.col.a); gl_Position = all_mat * diff --git a/voxygen/src/scene/particle.rs b/voxygen/src/scene/particle.rs index 215b1d17e5..572618c75d 100644 --- a/voxygen/src/scene/particle.rs +++ b/voxygen/src/scene/particle.rs @@ -72,7 +72,8 @@ impl ParticleMgr { time, ParticleMode::EnergyNature, *pos + Vec3::::zero() - .map(|_| rng.gen_range(-radius, radius)), + .map(|_| rng.gen_range(-1.0, 1.0)) + .normalized() * *radius, ) }, ); @@ -85,7 +86,8 @@ impl ParticleMgr { time, ParticleMode::CampfireFire, *pos + Vec3::::zero() - .map(|_| rng.gen_range(-radius, radius)), + .map(|_| rng.gen_range(-1.0, 1.0)) + .normalized() * *radius, ) }, ); @@ -117,7 +119,9 @@ impl ParticleMgr { Duration::from_secs(4), time, ParticleMode::CampfireSmoke, - *pos + Vec2::::zero().map(|_| rng.gen_range(-radius, radius)), + *pos + Vec3::::zero() + .map(|_| rng.gen_range(-1.0, 1.0)) + .normalized() * *radius, ) }, );