mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Improve airflow particles
This commit is contained in:
parent
16c41109d3
commit
1dee12af85
@ -164,10 +164,24 @@ mat4 spin_in_axis(vec3 axis, float angle)
|
||||
float c = cos(angle);
|
||||
float oc = 1.0 - c;
|
||||
|
||||
return mat4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0,
|
||||
oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0,
|
||||
oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0,
|
||||
0, 0, 0, 1);
|
||||
return mat4(
|
||||
oc * axis.x * axis.x + c,
|
||||
oc * axis.x * axis.y - axis.z * s,
|
||||
oc * axis.z * axis.x + axis.y * s,
|
||||
0,
|
||||
|
||||
oc * axis.x * axis.y + axis.z * s,
|
||||
oc * axis.y * axis.y + c,
|
||||
oc * axis.y * axis.z - axis.x * s,
|
||||
0,
|
||||
|
||||
oc * axis.z * axis.x - axis.y * s,
|
||||
oc * axis.y * axis.z + axis.x * s,
|
||||
oc * axis.z * axis.z + c,
|
||||
0,
|
||||
|
||||
0, 0, 0, 1
|
||||
);
|
||||
}
|
||||
|
||||
mat4 identity() {
|
||||
@ -986,11 +1000,19 @@ void main() {
|
||||
);
|
||||
break;
|
||||
case AIRFLOW:
|
||||
perp_axis = normalize(cross(inst_dir, vec3(0.0, 0.0, 1.0)));
|
||||
perp_axis = normalize(cross(inst_dir, vec3(1.0, 0.0, 0.0)));
|
||||
attr = Attr(
|
||||
// offsets
|
||||
inst_dir * 0.2 * length(inst_dir) * percent() + inst_dir * percent() * 0.08,
|
||||
vec3(0.03 * length(inst_dir), 0.03 * length(inst_dir), 20.0 * length(inst_dir) * percent() * (1 - percent())),
|
||||
// scale
|
||||
vec3(
|
||||
0.3 * length(inst_dir),
|
||||
0.3 * length(inst_dir),
|
||||
3.0 * length(inst_dir) * percent() * (1 - percent())
|
||||
),
|
||||
// color
|
||||
vec4(1.1, 1.1, 1.1, 0.3),
|
||||
// rotation
|
||||
spin_in_axis(perp_axis, asin(inst_dir.z / length(inst_dir)) + PI / 2.0)
|
||||
);
|
||||
break;
|
||||
@ -1018,7 +1040,14 @@ void main() {
|
||||
|
||||
// First 3 normals are negative, next 3 are positive
|
||||
// TODO: Make particle normals match orientation
|
||||
vec4 normals[6] = vec4[](vec4(-1,0,0,0), vec4(1,0,0,0), vec4(0,-1,0,0), vec4(0,1,0,0), vec4(0,0,-1,0), vec4(0,0,1,0));
|
||||
vec4 normals[6] = vec4[](
|
||||
vec4(-1,0,0,0),
|
||||
vec4(1,0,0,0),
|
||||
vec4(0,-1,0,0),
|
||||
vec4(0,1,0,0),
|
||||
vec4(0,0,-1,0),
|
||||
vec4(0,0,1,0)
|
||||
);
|
||||
f_norm =
|
||||
// inst_pos *
|
||||
normalize(((normals[(v_norm_ao >> 0) & 0x7u]) * attr.rot).xyz);
|
||||
|
@ -26,7 +26,8 @@ impl Animation for GlidingAnimation {
|
||||
) -> Self::Skeleton {
|
||||
let mut next = (*skeleton).clone();
|
||||
|
||||
next.glider_trails = true;
|
||||
// TODO: remove glider trails completely
|
||||
next.glider_trails = false;
|
||||
|
||||
let speednorm = velocity.magnitude().min(50.0) / 50.0;
|
||||
let slow = (acc_vel * 0.1).sin();
|
||||
|
@ -1326,26 +1326,53 @@ impl ParticleMgr {
|
||||
elevation: _,
|
||||
}) = physics.in_fluid
|
||||
{
|
||||
self.particles.resize_with(
|
||||
self.particles.len()
|
||||
+ usize::from(self.scheduler.heartbeats(Duration::from_millis(10))), // scale with wind speed
|
||||
|| {
|
||||
let start_pos = interpolated.pos
|
||||
+ Vec3::new(
|
||||
body.max_radius(),
|
||||
body.max_radius(),
|
||||
body.height() / 2.0,
|
||||
)
|
||||
.map(|d| d * rng.gen_range(-10.0..10.0));
|
||||
Particle::new_directed(
|
||||
Duration::from_millis(300), // scale with wind speed
|
||||
time,
|
||||
ParticleMode::Airflow,
|
||||
start_pos,
|
||||
start_pos + air_vel.0,
|
||||
)
|
||||
},
|
||||
// Empirical observation is that air_vel is somewhere
|
||||
// between 0.0 and 13.0, but we are extending to be sure
|
||||
const MAX_AIR_VEL: f32 = 15.0;
|
||||
const MIN_AIR_VEL: f32 = -2.0;
|
||||
|
||||
let minmax_norm = |val, min, max| (val - min) / (max - min);
|
||||
|
||||
let wind_speed = air_vel.0.magnitude();
|
||||
|
||||
// Less means more frequent particles
|
||||
let heartbeat = 200
|
||||
- Lerp::lerp(
|
||||
50u64,
|
||||
150,
|
||||
minmax_norm(wind_speed, MIN_AIR_VEL, MAX_AIR_VEL),
|
||||
);
|
||||
|
||||
let new_count = self.particles.len()
|
||||
+ usize::from(
|
||||
self.scheduler.heartbeats(Duration::from_millis(heartbeat)),
|
||||
);
|
||||
|
||||
// More number, longer particles
|
||||
let duration = Lerp::lerp(
|
||||
0u64,
|
||||
1000,
|
||||
minmax_norm(wind_speed, MIN_AIR_VEL, MAX_AIR_VEL),
|
||||
);
|
||||
let duration = Duration::from_millis(duration);
|
||||
|
||||
self.particles.resize_with(new_count, || {
|
||||
let start_pos = interpolated.pos
|
||||
+ Vec3::new(
|
||||
body.max_radius(),
|
||||
body.max_radius(),
|
||||
body.height() / 2.0,
|
||||
)
|
||||
.map(|d| d * rng.gen_range(-10.0..10.0));
|
||||
|
||||
Particle::new_directed(
|
||||
duration,
|
||||
time,
|
||||
ParticleMode::Airflow,
|
||||
start_pos,
|
||||
start_pos + air_vel.0,
|
||||
)
|
||||
});
|
||||
}
|
||||
},
|
||||
_ => {},
|
||||
|
Loading…
Reference in New Issue
Block a user