How-To

GLSL

Things

mat3 getRotationMatrix(vec3 r)

returns a rotation matrix corresponding to, in order,
a rotation about the x-axis with 'r.x' radians,
a rotation about the y-axis with 'r.y' radians,
a rotation about the z-axis with 'r.z' radians,
and is therefore vulnerable to gimbal lock.

Sampling

float hash( uint n )

returns a ``random'' number between [0,1] given a 'n'

vec3 getHemiSphereSample(vec3 n, uint seed)

returns a random, cos-weighted, hemisphere sample in the direction of 'n'

vec3 getConeSample(vec3 dir, float extent, uint seed)

returns a random cone sample in the direction of 'dir' where 'extent' represents the hemisphere area ratio of the cone. (so between [0,1] where 1 represents the whole hemisphere)

Distance Functions

The following functions give the distance to a select primitive from the point 'p'.

float distancePlane(vec3 p, vec3 n)
float distanceHalfSpacce(vec3 p, vec3 n)
float distanceBox( vec3 p, vec3 b )
float distanceCube( vec3 p, float b )
float distanceSphere( vec3 p, float s )
float distanceOctahedronExact( in vec3 p, in float s)
float distanceOctahedronInexact( in vec3 p, in float s)
float distanceTetrahedron(vec3 p)
float distanceTorus( vec3 p, vec2 t )
float distanceCylinder( vec3 p, float r)
float distanceCappedCylinder( vec3 p, float h, float r )
return distances to a lot of primitives.
all primitives are centered at the origin.

All other parameters define the shape of the primitive.

Fractals

The following functions have to do with making fractals. 's' always keeps track of the current scaling which is important in keeping the distance fields proper.

Operations

void planeFold(inout vec3 p, vec3 n)

Reflect 'p' conditionally (i.e. a fold), about the plane with normal 'n'.

void boxFold(inout vec3 p, vec3 min, vec3 max)

Performs a boxfold where the box is defined by 'min' and 'max'

void sphereInversion(inout vec3 p, inout float s, float r)

Performs a sphere inversion.

Fractals

Menger Sponge

void mengerSpongeIteration(inout vec3 p, inout float s)

Performs an iteration of the Menger Sponge IFS. Uniforms included.

float distanceMengerSponge(vec3 p)

Returns the distance to the Menger Sponge fractal. Basically performs mengerSpongeIteration multiple times after which the distance to a cube is taken. Uniforms included.

float orbitMengerSponge(vec3 p)

Kleinian

void kleinianIteration(inout vec3 p, inout float s)

Performs an iteration of the Kleinian IFS. Uniforms included.

float distanceKleinian(vec3 p)

Returns the distance to the Kleinian fractal. Basically performs kleinianIteration multiple times after which the distance to a plane(with normal [0,1,0]) is taken. Uniforms included.

Mandelbox

void mandelboxIteration(inout vec3 p, inout float s, vec3 p0)

float distanceMandelbox(vec3 p)

Kalibox

float distanceKalibox(vec3 p)

float orbitKalibox(vec3 p)

float orbitKalibox(vec3 p)

sierpinski Octahedron

void sierpinskiOctahedronIteration(inout vec3 p, inout float s)

distanceSierpinskiOctahedron(vec3 p)