# physics/response.md

Moving media (a rotor's wash, a fan, a jet, a river, a fall into water, hot exhaust) act on the things they meet by the **physical properties** of those things. It is the engine's default for models that declare propulsors; a game overrides any part. Nothing is switched on for a model that declares none, so old scenes are unchanged.

## The chain

1. A model declares `physics.propulsors` (`.fmdl`: kind `rotor`, `ducted-fan` or `jet`, `position`, `axis`, `diameter`, `hoverShare`, `medium`). `bindPropulsors(actor, { field, actuator?, surface?, scale? })` (`@ferret/levels`) gives a `PropulsorSet`; call `update()` once a step after the actuators.
2. Each propulsor publishes a **jet** into the flow field (`@ferret/flow`, publisher `physics-response`): thrust from the running actuator, else the declared share of the weight; exit speed by momentum theory (a rotor's wake is twice the induced velocity over half the disc). Over a surface it adds an impinging wall jet and, in ground effect, an extra thrust.
3. Consumers read the field. Nothing that feeds the physics step reads GPU results.

| Consumer | What it does | Where |
|---|---|---|
| plants | grass and foliage lean and shiver in the local air | `FlowMap` (CPU raster, 64 x 64, two height layers); `GrassView` of `@ferret/terrain` and `@ferret/weather` and the foliage-wind plugin take `flowMap`; without it the shaders are as before |
| water | dent by the jet's pressure q / (rho g), wind stress ripples, spray, drops into water | `airOnWater` -> `WaterSurface.forcing`, `SprayEmitter` -> `water.splash`, `impactOnWater` |
| bed | Shields, Meyer-Peter-Muller bed load, Exner balance, Isbash for stones, Stokes drift of floats | `BedWash`, `stoneMoves`, `floatDrift` |
| ground | Bagnold threshold (cohesion, moisture), saltation flux, Exner balance, dust events | `GroundWash` |
| flakes | cut grass, leaves, paper: lift-off, flutter or tumble, carriage, settling, lee piles | `FlakePool` |
| bodies, cloth, heat | physics-media drag and sliding; cloth wind; melt by the heat balance | `physics-media` (already reads the field), `physics-stretch` (published sources only), `jetFlux`, `snowMelted` |

## Laws and their three forms

Each law has a TypeScript reference (`src/laws/*`), a GLSL ES 3.00 form and a WGSL form (`src/shaders.ts`); `tools/physics-response/gpu-check.mjs` runs both on the video card against the CPU. The classes are `rigid`, `elastic`, `membrane`, `granular`, `flake`, `liquid-surface`, `bed`, `stone`, `floating`, `heat`; a material's `response` block names one (or `false`), and `deriveResponse` makes one from the fields the material already has.

## Budgets

`ResponseBudget` (a world service) offers four quality knobs: `response.water`, `response.ground`, `response.flakes`, `response.map` (least visible given up first). Read its values (`mapEvery`, `mapStride`, `waterStride`, `groundEvery`, `flakeShare`) where you run the parts. Measured in `examples/response`: the map raster costs 12.5 ms at the richest step and 1.1 ms at the cheapest.

## Overrides

- `PropulsorSet.scale` multiplies every jet (0 switches them off); a propulsor of a model may be `null` in an overlay to remove it.
- A material's `response: false` leaves it alone; any response parameter is data.
- `FlowMap`, `airOnWater`, `GroundWash` take their own sources, grains and heights; a game feeds them what its ground and water really are.

## Platform

WebGL2 is the reference; the WebGPU engine of Babylon runs the same scenes (`createGameAsync({ gpu: 'webgpu' })`, needs the full Chromium on Windows). Ferret's own GLSL shaders go through Babylon's GLSL-to-WGSL path. The GPU compute execution of the map and the grids is not built yet; the CPU execution is the reduced path.

## Try it

`node tools/build.mjs response`, then open `response/` (`?over=sand` puts the Squirrel above a sand patch, `?lv=N` pins the budget knobs, `?h=` sets its height). `tools/physics-response/sample-shot.mjs` takes a shot and the numbers on the NVIDIA card.
