Added mandelbrot pigment.
[raymarcher.git] / Operations.lua
1 -- Package of geometric operations on SDF objects
2
3 local function union(s1, s2)
4    return function (location)
5       local p1 = s1(location)
6       local p2 = s2(location)
7
8       if p1.dist < p2.dist then
9          return {dist = p1.dist, texture = p1.texture}
10       else
11          return {dist = p2.dist, texture = p2.texture}
12       end
13    end
14 end
15
16 local function diff(s1, s2)
17    return function (location)
18       local p1 = s1(location)
19       local p2 = s2(location)
20
21       return {dist = math.max(p1.dist, -p2.dist),
22               texture = p1.texture}
23    end
24 end
25
26
27 Operations = {
28    union = union,
29    diff = diff
30 }
31
32 return Operations