Skip to main content

FlowMap

Struct FlowMap 

Source
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: usize

Width of the flow map.

§height: usize

Height of the flow map.

§speed: f32

Flow speed multiplier.

§strength: f32

Flow strength multiplier.

§time: f32

Current cycle time.

§cycle_duration: f32

Duration of one flow cycle (UV offset resets to avoid extreme distortion).

Implementations§

Source§

impl FlowMap

Source

pub fn new(width: usize, height: usize) -> Self

Create a new flow map with the given dimensions.

Source

pub fn uniform(width: usize, height: usize, direction: Vec2) -> Self

Create a flow map with a uniform direction.

Source

pub fn vortex(width: usize, height: usize, strength: f32) -> Self

Create a circular flow map (vortex).

Source

pub fn divergent(width: usize, height: usize, strength: f32) -> Self

Create a divergent flow map (expanding from center).

Source

pub fn with_speed(self, speed: f32) -> Self

Set flow speed.

Source

pub fn with_strength(self, strength: f32) -> Self

Set flow strength.

Source

pub fn with_cycle(self, duration: f32) -> Self

Set cycle duration.

Source

pub fn tick(&mut self, dt: f32)

Advance time.

Source

pub fn sample(&self, uv: Vec2) -> Vec2

Sample the flow vector at a UV coordinate using bilinear interpolation.

Source

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.

Source

pub fn distort_array(&self, uvs: &mut [[f32; 2]])

Distort an array of UVs.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<S> FromSample<S> for S

Source§

fn from_sample_(s: S) -> S

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

Source§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,