Reduced Render.eps.
[raymarcher.git] / Operations.lua
index d606d39..db9b9a7 100644 (file)
@@ -1,20 +1,39 @@
 -- Package of geometric operations on SDF objects
 
-local function union(s1, s2)
+local function union(sdfs)
    return function (location)
-      local p1 = s1(location)
-      local p2 = s2(location)
+      local p = sdfs[1](location)
+      local pp = nil
 
-      if p1.dist < p2.dist then
-         return {dist = p1.dist, texture = p1.texture}
-      else
-         return {dist = p2.dist, texture = p2.texture}
+      for i=2,#sdfs do
+         pp = sdfs[i](location)
+         if pp.dist < p.dist then
+            p = pp
+         end
       end
+
+      return p
+   end
+end
+
+local function diff(sdfs)
+   return function (location)
+      local p = sdfs[1](location)
+      local pp = nil
+
+      for i=2,#sdfs do
+         pp = sdfs[i](location)
+         p.dist = math.max(p.dist, -pp.dist)
+      end
+      
+      return p
    end
 end
 
+
 Operations = {
-   union = union
+   union = union,
+   diff = diff
 }
 
 return Operations