diff --git a/voxygen/src/render/pipelines/trail.rs b/voxygen/src/render/pipelines/trail.rs index aa2bc41c06..73aec545ac 100644 --- a/voxygen/src/render/pipelines/trail.rs +++ b/voxygen/src/render/pipelines/trail.rs @@ -1,6 +1,9 @@ use super::super::{AaMode, GlobalsLayouts, Vertex as VertexTrait}; use bytemuck::{Pod, Zeroable}; -use std::mem; +use std::{ + mem, + ops::{Add, Mul}, +}; #[repr(C)] #[derive(Copy, Clone, Debug, Zeroable, Pod, PartialEq)] @@ -22,6 +25,26 @@ impl Vertex { pub fn zero() -> Self { Self { pos: [0.0; 3] } } } +impl Mul for Vertex { + type Output = Self; + + fn mul(self, val: f32) -> Self::Output { + Self { + pos: self.pos.map(|a| a * val), + } + } +} + +impl Add for Vertex { + type Output = Self; + + fn add(self, other: Self) -> Self::Output { + Self { + pos: self.pos.zip(other.pos).map(|(a, b)| a + b), + } + } +} + impl VertexTrait for Vertex { const QUADS_INDEX: Option = Some(wgpu::IndexFormat::Uint16); const STRIDE: wgpu::BufferAddress = mem::size_of::() as wgpu::BufferAddress; diff --git a/voxygen/src/scene/trail.rs b/voxygen/src/scene/trail.rs index 2dca1fe15b..57c9305a6a 100644 --- a/voxygen/src/scene/trail.rs +++ b/voxygen/src/scene/trail.rs @@ -21,6 +21,7 @@ pub struct TrailMgr { } const TRAIL_DYNAMIC_MODEL_SIZE: usize = 15; +const TRAIL_SHRINKAGE: f32 = 0.8; impl TrailMgr { pub fn new(renderer: &mut Renderer) -> Self { @@ -39,8 +40,18 @@ impl TrailMgr { // Update offset self.offset = (self.offset + 1) % TRAIL_DYNAMIC_MODEL_SIZE; - // Reset quad for each entity mesh at new offset self.entity_meshes.values_mut().for_each(|mesh| { + // Shrink size of each quad over time + let vertices = mesh.vertices_mut_vec(); + for i in 0..TRAIL_DYNAMIC_MODEL_SIZE { + // Verts per quad are in b, c, a, d order + vertices[i * 4 + 2] = vertices[i * 4 + 2] * TRAIL_SHRINKAGE + + vertices[i * 4] * (1.0 - TRAIL_SHRINKAGE); + vertices[i * 4 + 3] = vertices[i * 4 + 3] * TRAIL_SHRINKAGE + + vertices[i * 4 + 1] * (1.0 - TRAIL_SHRINKAGE); + } + + // Reset quad for each entity mesh at new offset let zero = TrailVertex::zero(); mesh.replace_quad(self.offset * 4, Quad::new(zero, zero, zero, zero)); });