Tweeks to mandel_wall.lua example.
[raymarcher.git] / Primitives.lua
1 -- Geometric primitives for raymarching
2 require "Vector"
3 local V = Vector
4
5 local function make_sphere(centre, radius, texture)
6    local norm = V.norm
7    return function(p)
8       return {dist = V.norm(p-centre) - radius,
9               texture = texture}
10    end
11 end
12
13 local function make_plane(centre, normal, texture)
14    return function(p)
15       return {dist = normal*(p-centre),
16               texture = texture}
17    end
18 end
19
20 local function make_pipe(centre, radius, axis, texture)
21    return function(p)
22       return {dist = V.norm(V.cross(p-centre, axis)) - radius,
23               texture = texture}
24    end
25 end
26
27
28 Primitives = {
29    make_sphere = make_sphere,
30    make_plane = make_plane,
31    make_pipe = make_pipe
32 }
33
34 return Primitives