link to this article

mkheightmap

Height-Slang Reference

2008-06-25

Abstract

Height-Slang is a language for the definition of heightmaps [0]. It is used in mkheightmap, itself being a powerfull tool (a part of the puzzle of picogen [1]) to generate heightmaps on the command-line.

Height-Slang Reference

The next sections show the currently supported instructions of height-slang, following this convention:

  • A greek letter (\alpha, \beta, \gamma, etc.) indicates an arbitrary expression
  • Each item looks like

    <function-syntax> \equiv <math~notation>

    or

    <function-syntax> = <equivalent~expression> \equiv <math~notation>

Note that there is only one data type in Height-Slang: real. This means we have to introduce kludges to anyway be able to solve boolean expressions:

A real-value \alpha is considered true, if and only if \alpha\ge0.5, else it is considered false

This rule applies to the first parameter of the "?"-function, and to any parameter of the logical functions "and", "or", "xor", "not". Additionaly, a value of either 1.0 (true) or 0.0 (false) is returned by the comparison functions, so they can safely be used for the "?"-function as the first parameter, but also as a "on/off"-factor in general expressions (that leads to a kind of branch free code).

comparison

  • (<~\alpha~\beta) \equiv {\alpha}<{\beta}
  • (<=~\alpha~\beta) \equiv {\alpha}\le{\beta}
  • (>~\alpha~\beta) \equiv {\alpha}>{\beta}
  • (>=~\alpha~\beta) \equiv {\alpha}\ge{\beta}
  • (=~\alpha~\beta) \equiv {\alpha}={\beta}
  • (<>~\alpha~\beta) \equiv {\alpha}\ne{\beta}

basic

  • (+~\alpha~\beta) \equiv \alpha+\beta
  • (-~\alpha~\beta) \equiv \alpha-\beta
  • (*~\alpha~\beta) \equiv \alpha\cdot\beta
  • (/~\alpha~\beta) \equiv \alpha \div \beta

functions with one parameter

  • (inv~\alpha) = (/~1~\alpha) \equiv 1 \div \alpha
  • (sin~\alpha) \equiv \sin(\alpha)
  • (cos~\alpha) \equiv \cos(\alpha)
  • (floor~\alpha) \equiv floor(\alpha)
  • (abs~\alpha) \equiv abs(\alpha)
  • (trunc~\alpha) \equiv trunc(\alpha)
  • (frac~\alpha) = (-~\alpha~(floor~\alpha)) \equiv \alpha - floor(\alpha)
  • (neg~\alpha) = (-~0~\alpha) \equiv -\alpha
  • (sqrt~\alpha) \equiv \sqrt{\alpha}
  • (not~\alpha) \equiv ?

functions with two parameters

  • (\wedge~\alpha~\beta) \equiv \alpha^{\beta}(note that \wedge is meant to be "^" on your keyboard)
  • (and~\alpha~\beta) \equiv \alpha \texttt{ and }\beta
  • (or~\alpha~\beta) \equiv \alpha \texttt{ or }\beta
  • (xor~\alpha~\beta) \equiv \alpha \texttt{ xor }\beta

functions with three parameters

  • (?~\alpha~\beta~\gamma) = \beta ~~if~\alpha,~~else~\gamma
  • (lerp~\alpha~\beta~\gamma) = (+~(*~\alpha~(-~1~\gamma))~(*~\beta~\gamma))  \equiv \alpha\cdot(1-\gamma) + \beta\cdot \gamma

configurable functions with two parameters

LayeredNoise


([2 LayeredNoise
seed(<positive integer>) <default: 42>
frequency(<positive integer>) <default: 2>
layercount(<positive integer>) <default: 4>
noisemapfilter(<nearest|bilinear>) <default: bilinear>
persistence(<1-dimensional HS expression>) <default: 0.5>
levelEvaluationFunction(<1-dimensional HS expression>)) <default: x>
] parameter_a parameter_b
)