Skip to main content

Crate viewport_lib_wind

Crate viewport_lib_wind 

Source
Expand description

Wind field for viewport-lib.

A single global wind vector with gust modulation, driven once per frame on the CPU and pushed into a deformer slot’s slot_params on the GPU. Consumers read the field from two places:

  • The standard mesh shaders apply per-vertex wind through the deformer registry. WindPlugin::install registers the deformer; the GPU half keeps its slot params in sync with the CPU clock.
  • Rust code calls WindField::sample for spring bones, particles, or any other CPU consumer that needs the same vector the renderer sees.

Typical setup:

use viewport_lib::runtime::ViewportRuntime;
use viewport_lib_wind::{WindAuthoring, WindPlugin, WindSwayWeights};

let wind = WindPlugin::new(WindAuthoring::default());
wind.install(&mut resources, &device).expect("register wind deformer");

let runtime = ViewportRuntime::new()
    .with_plugin(wind.cpu_plugin())
    .with_gpu_plugin(wind.gpu_plugin());

// Per wind-affected mesh:
let mask = WindSwayWeights::height_falloff(&positions, 0.0, top_y);
wind.attach_sway_mask(&mut resources, &device, mesh_id, &mask);

The CPU sampler and the WGSL deformer body use the same formula, so a vertex drawn through the deformer and a spring bone tracking the same world position see the same wind to within float precision.

Structs§

WindAuthoring
Authoring knobs for a WindField. These describe what the field looks like at rest; the field itself owns the time clock that ticks forward.
WindField
The CPU-side wind field. Holds the authoring values plus a running clock.
WindGlobals
Per-frame wind state, mirroring the WGSL WindGlobals struct.
WindMaterialParams
Per-mesh material parameters for the wind deformer.
WindPlugin
Wind plugin handle.
WindSwayWeights
Per-vertex sway-mask weights.

Constants§

SHARED_WIND_WGSLDeprecated
VIEWPORT_LIB_WGSL_VERSION
Catalogue version of viewport-lib this crate was built against.
WGSL_VERSION
Catalogue version for WIND_DEFORMER_BODY. Bump on any formula or slot-params layout change.
WIND_DEFORMER_BODY
WGSL body for the wind deformer. Composed into the mesh-family shaders by register_deformer.
WIND_DEFORMER_NAME
Name the wind deformer registers under.
WIND_MATERIAL_PARAMS_STRIDE_BYTES
Per-mesh-instance material-params stride: three f32 (strength, density, speed) = 12 bytes.
WIND_SWAY_STRIDE_BYTES
Per-vertex sway-mask stride: one f32 per vertex (4 bytes).