Jitter expr

This document describes the Jitter expression language syntax. This is the language used for the jit.expr object, as well as the exprfill message to a jit.matrix objects. This expression will be evaluated once for each cell in the input, in order to generate an output matrix with the same matrix dimensions as the input.

You could make a jit.expr that passes through input unchanged.

jit.expr @expr in[0]

Or you could use an expression to add the first and second inputs together:

jit.expr @expr in[0] + in[1]

Or do something more sophisticated, like apply a vignette mask:

jit.expr @expr (1-hypot(snorm[0],snorm[1]))*in[0]*2.

Inputs

Reference the inputs to the expr object with in. Get the first input with in[0], the second with in[1], and so on. Use p to get a specific plane of the input, where in[0].p[0] accesses the first plane of the first input, in[0].p[1] gets the second plane of the first input, and so on.

The jit.expr object defaults to two inputs, but you can increase the number of inputs with the @inputs attribute.

To get the cell coordinates, use either cell, norm, or snorm. The index is used to select the dimension, so cell[0] is the cell coordinate in the x direction (first dimension), cell[1] is the cell coordinate in the y direction, and so on. You can also use dim to get the dimensions of the matrix in any direction.

Finally, it's also possible to access any named matrix by simply using the name of that matrix instead of in. With a matrix named my_matrix, use my_matrix to access the contents of that matrix at the current cell coordinates, or my_matrix.p[0] to access the first plane of that matrix.

NameDescription
in[0-31]Input matrix cell contents, corresponding plane
in[0-31].p[0-31]Input matrix cell contents, specific plane
cell[0-31]Cell coordinates of the current cell
norm[0-31]Normalized (0 to 1) cell coordinates
snorm[0-31]Signed normalized (-1 to 1) cell coordinates
dim[0-31]Matrix dimension size
matrixname[0-31]Named matrix cell contents, corresponding plane
matrixname[0-31].p[0-31]Named matrix cell contents, specific plane

Functions and Operators

Within a Jitter expression, Jitter operators can be applied as functions. For the most part, these are the same operators as are defined for the jit.op object. Some of these can be applied as infix operators, for example in[0] + in[1] for the + operator. Others are called as functions, with commas between arguments, like absdiff(in[0], in[1]).

Instead of the Jitter operators >p and <p, use the function calls gtp(val, test) and ltp(val, test).

Arithmetic

NameDescription
passpass left input, no operator
*multiplication (also mult)
/division (also div)
+addition (also add)
-subtraction (also sub)
+maddition modulo (char only) (also addm)
-msubtraction modulo (char only) (also subm)
%modulo (also mod)
minminimum
maxmaximum
absabsolute value (unary)
avgaverage
absdiffabsolute value of difference
foldfolding/mirrored modulo (float only)
wrapwrapping/positive modulo (float only)
!passpass right input, no operator
!/right input divided by left input (flipped)
!-right input minus left input (flipped)
!%right input modulo left input (flipped)
ignoreleave previous output value

Trigonometric

(float32/float64 only, unary except atan2)

NameDescription
sinsine
coscosine
tantangent
asinarcsine
acosarccosine
atanarctangent
atan2arctangent (binary)
sinhhyperbolic sine
coshhyperbolic cosine
tanhhyperbolic tangent
asinhhyperbolic arcsine
acoshhyperbolic arccosine
atanhhyperbolic arctangent

Bitwise

(long/char only)

NameDescription
&bitwise and
|bitwise or
^bitwise xor
~bitwise compliment (unary)
>>right shift
<<left shift

Logical

NameDescription
&&logical and
||logical or
!logical not (unary)
>greater than
<less than
>=greater than or equal to
<=less than or equal to
==equal
!=not equal
>pgreater than (pass)
<pless than (pass)
>=pgreater than or equal to (pass)
<=pless than or equal to (pass)
==pequal (pass)
!=pnot equal (pass)

Exponential/Logarithmic/Other

(float32/float64 only, unary except hypot and pow)

NameDescription
expe to the x
exp22 to the x
lnlog base e
log2log base 2
log10log base 10
hypothypotenuse (binary)
powx to the y (binary)
sqrtsquare root
ceilinteger ceiling
floorinteger floor
roundround to nearest integer
trunctruncate to integer

Matrix Operators

Many Jitter Matrix Operators can be used inside of a Jitter expression as well. These are the functional equivalent of Jitter objects like jit.clip, objects that perform a simple operation on their matrix inputs. There is no exhaustive list of these, but if there's a simple Jitter object that you'd like to use in an expression, chances are it will work. You could use the following expression to convolve two matrices.

jit.expr @expr "jit.convolve(in[0], in[1])"

If the Jitter matrix operator can be configured with attributes, those can be supplied as an attribute list following the other arguments to the matrix operator. The following would constrain the values in each plane to be between 0.2 and 0.8.

jit.expr @expr "jit.clip(in[0], @min 0.2 @max 0.8)"

Basis Function Generators

The basis function generators from the jit.bfg object can also be used inside of an expression. These work in much the same way as matrix operators.

jit.expr @expr "noise.gradient(norm[0]*2, norm[1]*2, @seed 313)"

Distance functions

NameDescription
distance.chebychevAbsolute maximum difference between two points
distance.euclideanTrue straight line distance in Euclidean space
distance.euclidean.squaredSquared Euclidean distance
distance.manhattanRectilinear distance measured along axes at right angles
distance.manhattan.radialManhattan distance with radius fall-off control
distance.minkovskyExponentially controlled distance

Filter functions

NameDescription
filter.boxSums all samples in the filter area with equal weight
filter.gaussianWeights samples in the filter area using a bell curve
filter.lanczossincWeights samples using a steep windowed sinc curve
filter.mitchellWeights samples using a controllable cubic polynomial
filter.diskSums all samples inside the filter's radius with equal weight
filter.sincWeights samples using an un-windowed sinc curve
filter.catmullromWeights samples using a Catmull-Rom cubic polynomial
filter.besselWeights samples with a linear phase response
filter.triangleWeights samples in the filter area using a pyramid

Transfer functions

NameDescrpition
transfer.stepAlways 0 if value is less than threshold, otherwise always 1
transfer.smoothstepStep function with cubic smoothing at boundaries
transfer.biasPolynomial similar to gamma but remapped to unit interval
transfer.cubicGeneric 3rd order polynomial with controllable coefficients
transfer.sawPeriodic triangle pulse train
transfer.quinticGeneric 5th order polynomial with controllable coefficients
transfer.gainS-Shaped polynomial evaluated inside unit interval
transfer.pulsePeriodic step function
transfer.smoothpulsePeriodic step function with cubic smoothing at boundaries
transfer.sinePeriodic sinusoidal curve
transfer.linearLinear function across unit interval
transfer.solarizeScales given value if threshold is exceeded

Noise functions

NameDescription
noise.cellnoiseCoherent blocky noise
noise.checkerPeriodic checker squares
noise.value.cubicsplinePolynomial smoothed pseudo-random values
noise.value.convolutionConvolution filtered pseudo-random values
noise.sparse.convolutionConvolution filtered pseudo-random feature points
noise.gradientDirectionally weighted polynomially interpolated values
noise.simplexSimplex weighted pseudo-random values
noise.voronoiDistance weighted pseudo-random feature points
noise.distortedDomain distorted combinational noise

Fractal functions

NameDescription
monoAdditive fractal with global simularity across scales
multiMultiplicative fractal with varying simularity across scales
multi.hybridA hybrid additive and multiplicative fractal
multi.heteroHeterogenous multiplicative fractal
multi.ridgedMultiplicative fractal with sharp ridges
turbulenceAdditive mono-fractal with sharp ridges

Constants

There's also a handful of constants ready as well. An expression like in[0] * DEGTORAD would convert a matrix full of degrees to a matrix full of radians.

NameDescription
PIRatio of a circle's circumference to its diameter
TWOPITwice the value of pi
HALFPIHalf the value of pi
INVPIOne over pi
DEGTORADScale factor to convert degrees to radians
RADTODEGScale factor to convert radians to degrees
EBase of the natural logarithm
LN2Natural logarithm evaluated for 2
LN10Natural logarithm evaluated for 10
LOG10ELog base 10 evaluated for e
LOG2ELog base 2 evaluated for e
SQRT2Square root of 2
SQRT1_2One over the square root of 2