mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
make particles only use 1 float for inst time again
This commit is contained in:
parent
2ed09a578b
commit
bc436e2c9f
@ -56,7 +56,7 @@ float tick_loop(float period) {
|
|||||||
|
|
||||||
// Only works if t happened within tick_loop_time
|
// Only works if t happened within tick_loop_time
|
||||||
float time_since(float t) {
|
float time_since(float t) {
|
||||||
return tick.x > t ? (tick_loop_time - t + tick.x) : (tick.x - t);
|
return tick.x < t ? (tick_loop_time - t + tick.x) : (tick.x - t);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -20,7 +20,7 @@
|
|||||||
layout(location = 0) in vec3 v_pos;
|
layout(location = 0) in vec3 v_pos;
|
||||||
// in uint v_col;
|
// in uint v_col;
|
||||||
layout(location = 1) in uint v_norm_ao;
|
layout(location = 1) in uint v_norm_ao;
|
||||||
layout(location = 2) in vec3 inst_time;
|
layout(location = 2) in float inst_time;
|
||||||
layout(location = 3) in float inst_lifespan;
|
layout(location = 3) in float inst_lifespan;
|
||||||
layout(location = 4) in float inst_entropy;
|
layout(location = 4) in float inst_entropy;
|
||||||
layout(location = 5) in int inst_mode;
|
layout(location = 5) in int inst_mode;
|
||||||
@ -94,12 +94,14 @@ struct Attr {
|
|||||||
mat4 rot;
|
mat4 rot;
|
||||||
};
|
};
|
||||||
|
|
||||||
float lifetime = max((tick.y - inst_time.y - 1.0), 0.0) * tick_loop_time + (tick.y > inst_time.y ? (tick_loop_time - inst_time.x + tick.x) : (tick.x - inst_time.x));
|
float lifetime = time_since(inst_time);
|
||||||
|
|
||||||
float loop_inst_time(float period) {
|
float loop_inst_time(float period) {
|
||||||
float rest = mod(tick_loop_time, period) * inst_time.y;
|
if (tick.x < inst_time) {
|
||||||
|
return mod(mod(tick_loop_time, period) + inst_time, period);
|
||||||
return mod(rest + inst_time.x, period);
|
} else {
|
||||||
|
return mod(inst_time, period);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vec3 linear_motion(vec3 init_offs, vec3 vel) {
|
vec3 linear_motion(vec3 init_offs, vec3 vel) {
|
||||||
@ -429,7 +431,7 @@ void main() {
|
|||||||
float purple_col = 0.6 + 0.5 * sin(tick_loop(2 * PI, 4, lifetime * 4)) - min(max(green_col - 1, 0), 0.3);
|
float purple_col = 0.6 + 0.5 * sin(tick_loop(2 * PI, 4, lifetime * 4)) - min(max(green_col - 1, 0), 0.3);
|
||||||
float red_col = 1.15 + 0.1 * sin(tick_loop(2 * PI, 3, lifetime * 3)) - min(max(green_col - 1, 0), 0.3) - max(purple_col - 0.5, 0);
|
float red_col = 1.15 + 0.1 * sin(tick_loop(2 * PI, 3, lifetime * 3)) - min(max(green_col - 1, 0), 0.3) - max(purple_col - 0.5, 0);
|
||||||
attr = Attr(
|
attr = Attr(
|
||||||
spiral_motion(inst_dir, 0.3 * (floor(2 * rand0 + 0.5) - 0.5) * min(linear_scale(10), 1), lifetime / inst_lifespan, 10.0, loop_inst_time(PI * 2.0)),
|
spiral_motion(inst_dir, 0.3 * (floor(2 * rand0 + 0.5) - 0.5) * min(linear_scale(10), 1), lifetime / inst_lifespan, 10.0, loop_inst_time(2.0 * PI)),
|
||||||
vec3((1.7 - 0.7 * abs(floor(2 * rand0 - 0.5) + 0.5)) * (1.5 + 0.5 * sin(tick_loop(2 * PI, 10, lifetime * 4)))),
|
vec3((1.7 - 0.7 * abs(floor(2 * rand0 - 0.5) + 0.5)) * (1.5 + 0.5 * sin(tick_loop(2 * PI, 10, lifetime * 4)))),
|
||||||
vec4(vec3(red_col + purple_col * 0.6, green_col + purple_col * 0.35, purple_col), 1),
|
vec4(vec3(red_col + purple_col * 0.6, green_col + purple_col * 0.35, purple_col), 1),
|
||||||
spin_in_axis(inst_dir, tick_loop(2 * PI))
|
spin_in_axis(inst_dir, tick_loop(2 * PI))
|
||||||
|
@ -109,7 +109,7 @@ impl ParticleMode {
|
|||||||
pub struct Instance {
|
pub struct Instance {
|
||||||
// created_at time, so we can calculate time relativity, needed for relative animation.
|
// created_at time, so we can calculate time relativity, needed for relative animation.
|
||||||
// can save 32 bits per instance, for particles that are not relatively animated.
|
// can save 32 bits per instance, for particles that are not relatively animated.
|
||||||
inst_time: [f32; 3],
|
inst_time: f32,
|
||||||
|
|
||||||
// The lifespan in seconds of the particle
|
// The lifespan in seconds of the particle
|
||||||
inst_lifespan: f32,
|
inst_lifespan: f32,
|
||||||
@ -147,11 +147,7 @@ impl Instance {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
Self {
|
Self {
|
||||||
inst_time: [
|
inst_time: (inst_time % super::TIME_PRECISION) as f32,
|
||||||
(inst_time % super::TIME_PRECISION) as f32,
|
|
||||||
(inst_time / super::TIME_PRECISION).floor() as f32,
|
|
||||||
inst_time as f32,
|
|
||||||
],
|
|
||||||
inst_lifespan: lifespan,
|
inst_lifespan: lifespan,
|
||||||
inst_entropy: rand::thread_rng().gen(),
|
inst_entropy: rand::thread_rng().gen(),
|
||||||
inst_mode: inst_mode as i32,
|
inst_mode: inst_mode as i32,
|
||||||
@ -169,11 +165,7 @@ impl Instance {
|
|||||||
) -> Self {
|
) -> Self {
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
Self {
|
Self {
|
||||||
inst_time: [
|
inst_time: (inst_time % super::TIME_PRECISION) as f32,
|
||||||
(inst_time % super::TIME_PRECISION) as f32,
|
|
||||||
(inst_time / super::TIME_PRECISION).floor() as f32,
|
|
||||||
inst_time as f32,
|
|
||||||
],
|
|
||||||
inst_lifespan: lifespan,
|
inst_lifespan: lifespan,
|
||||||
inst_entropy: rand::thread_rng().gen(),
|
inst_entropy: rand::thread_rng().gen(),
|
||||||
inst_mode: inst_mode as i32,
|
inst_mode: inst_mode as i32,
|
||||||
@ -183,7 +175,7 @@ impl Instance {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
|
fn desc<'a>() -> wgpu::VertexBufferLayout<'a> {
|
||||||
const ATTRIBUTES: [wgpu::VertexAttribute; 6] = wgpu::vertex_attr_array![2 => Float32x3, 3 => Float32, 4 => Float32, 5 => Sint32, 6 => Float32x3, 7 => Float32x3];
|
const ATTRIBUTES: [wgpu::VertexAttribute; 6] = wgpu::vertex_attr_array![2 => Float32, 3 => Float32, 4 => Float32, 5 => Sint32, 6 => Float32x3, 7 => Float32x3];
|
||||||
wgpu::VertexBufferLayout {
|
wgpu::VertexBufferLayout {
|
||||||
array_stride: mem::size_of::<Self>() as wgpu::BufferAddress,
|
array_stride: mem::size_of::<Self>() as wgpu::BufferAddress,
|
||||||
step_mode: wgpu::InputStepMode::Instance,
|
step_mode: wgpu::InputStepMode::Instance,
|
||||||
|
Loading…
Reference in New Issue
Block a user