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.