pub struct FlowMap {
pub vectors: Vec<Vec2>,
pub width: usize,
pub height: usize,
pub speed: f32,
pub strength: f32,
pub time: f32,
pub cycle_duration: f32,
}Expand description
A flow map for UV distortion.
A flow map stores 2D velocity vectors at each texel. At render time, UVs are offset by the flow direction, creating the illusion of flowing liquid, lava, etc.
Fields§
§vectors: Vec<Vec2>Flow vectors stored row-major. Each entry is a 2D direction.
width: usizeWidth of the flow map.
height: usizeHeight of the flow map.
speed: f32Flow speed multiplier.
strength: f32Flow strength multiplier.
time: f32Current cycle time.
cycle_duration: f32Duration of one flow cycle (UV offset resets to avoid extreme distortion).
Implementations§
Source§impl FlowMap
impl FlowMap
Sourcepub fn new(width: usize, height: usize) -> Self
pub fn new(width: usize, height: usize) -> Self
Create a new flow map with the given dimensions.
Sourcepub fn uniform(width: usize, height: usize, direction: Vec2) -> Self
pub fn uniform(width: usize, height: usize, direction: Vec2) -> Self
Create a flow map with a uniform direction.
Sourcepub fn vortex(width: usize, height: usize, strength: f32) -> Self
pub fn vortex(width: usize, height: usize, strength: f32) -> Self
Create a circular flow map (vortex).
Sourcepub fn divergent(width: usize, height: usize, strength: f32) -> Self
pub fn divergent(width: usize, height: usize, strength: f32) -> Self
Create a divergent flow map (expanding from center).
Sourcepub fn with_speed(self, speed: f32) -> Self
pub fn with_speed(self, speed: f32) -> Self
Set flow speed.
Sourcepub fn with_strength(self, strength: f32) -> Self
pub fn with_strength(self, strength: f32) -> Self
Set flow strength.
Sourcepub fn with_cycle(self, duration: f32) -> Self
pub fn with_cycle(self, duration: f32) -> Self
Set cycle duration.
Sourcepub fn sample(&self, uv: Vec2) -> Vec2
pub fn sample(&self, uv: Vec2) -> Vec2
Sample the flow vector at a UV coordinate using bilinear interpolation.
Sourcepub fn distort(&self, uv: Vec2) -> Vec2
pub fn distort(&self, uv: Vec2) -> Vec2
Apply flow distortion to a UV coordinate.
Uses dual-phase approach to avoid visual discontinuities when the flow cycle resets.
Sourcepub fn distort_array(&self, uvs: &mut [[f32; 2]])
pub fn distort_array(&self, uvs: &mut [[f32; 2]])
Distort an array of UVs.
Auto Trait Implementations§
impl Freeze for FlowMap
impl RefUnwindSafe for FlowMap
impl Send for FlowMap
impl Sync for FlowMap
impl Unpin for FlowMap
impl UnsafeUnpin for FlowMap
impl UnwindSafe for FlowMap
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.