1 -- Geometric primitives for raymarching
5 local function make_sphere(centre, radius, texture)
8 return {dist = V.norm(p-centre) - radius,
13 local function make_plane(centre, normal, texture)
15 return {dist = normal*(p-centre),
20 local function make_pipe(centre, radius, axis, texture)
22 return {dist = V.norm(V.cross(p-centre, axis)) - radius,
27 local function make_mandelbulb(centre, max_iter, power, texture)
39 -- convert to polar coordinates
40 theta = math.acos(z[3]/r)
41 phi = math.atan(z[2],z[1])
42 dr = math.pow(r, power-1.0)*power*dr + 1.0
44 -- scale and rotate the point
45 zr = math.pow(r, power)
49 -- convert back to cartesian coordinates
50 z = V.new{math.sin(theta)*math.cos(phi),
51 math.sin(phi)*math.sin(theta),
56 return {dist = 0.5*math.log(r)*r/dr,
64 make_sphere = make_sphere,
65 make_plane = make_plane,
66 make_pipe = make_pipe,
67 make_mandelbulb = make_mandelbulb