c(a)
: constant (for instance: c(1.5)
, c(time)
)a + b
: additiona - b
: subtractionmul(a, b)
: multiplication (element wise)div(a, b)
: division (element wise)recip(b)
: reciprocal (1/b)d_sq(a)
: squared (a*a)d_sqrt(a)
: square rootd_sin(a)
d_cos(a)
d_exp(a)
d_log(a)
dc_mul(a, b)
dc_sq(z)
dc_conj(z)
: conjugatedc_absSq(z)
: Re(z)^2 + Im(z)^2dc_recip(z)
: 1/zd_lenSq(v)
: x^2 + y*2 + z^2d_cross(a, b)
: cross productVAL
: number (replaces float)VAL2
: 2 dimensional vector (replaces vec2)VAL3
: 3 dimensional vector (replaces vec3)VAL3 surface(VAL2 ts)
- the parametric functionbool inRange(vec2 ts)
- return true if inside the parameter domainvec3 shading(vec3 normal, vec2 ts, vec3 pos)
time
: time in seconds#define DEFAULT_SHADING
- the shading function will be vec3 shading(vec3 normal, vec2 ts, vec3 pos) { return vec3(dot(normal, vec3(1, 0, 0)) / 2. + 0.5); }
#define DISABLE_STOCHASTIC
: runs slower but more accuratelyNOTE: don't add float
s with VAL
s.
You can however multiply float
s with VAL
s (or with VAL2
or VAL3
)
The VAL
type and the custom functions are used in order to calculate the surface function derivatives (Jacobian) efficiently and accurately, using AutoDiff.
AutoDiff requires every variable to contain the value and the derivatives, and each operation/function to calculate both the value and the derivatives based on the previous ones.
Therefore VAL
is a glsl vec3
under the hood, where the x component is the value, the y component is the derivative in terms of the first parameter (parameter to the surface
function), and z component is the derivative in terms of the second parameter.
VAL2
and VAL3
are mat2x3
and mat3x3
respectively.
VAL d_cosh(VAL a) { return VAL(cosh(a.x), a.yz * sinh(a.x)); } VAL d_sinh(VAL a) { return VAL(sinh(a.x), a.yz * cosh(a.x)); }