[][src]Function terr::heightmap::midpoint_displacement

pub fn midpoint_displacement<F, R: Rng, D: Distribution<F>>(
    m: &mut Heightmap<F>,
    n0: u32,
    rng: &mut R,
    distr: D
) -> Result<(), Error> where
    F: RealField + Copy

Perform mid-point displacement on the given height-map.

Mid-point displacement is a simple fractal-based procedural generation algorithm for height-maps.

Applicable to square height-maps with side-length 2n + 1. (TODO: generalise to non-square and non-power-of-2 sizes?)

The four corners of the heightmap should be initialised before performing mid-point displacement.

Parameters:

  • m the heightmap (restricted to squares with side-length of 2n + 1)
  • n0 (normally 0) is the number of midpoint displacement steps to skip
  • distr is the displacement distribution; for example one may use Uniform::new(-scale, scale) or Normal::new(0.0, scale) where scale is a scaling factor. Note that samples are multiplied by half the side length of the current quad.