Fixed surface normal calculation bug.
[raymarcher.git] / Primitives.lua
index 88a3849..aafa7cb 100644 (file)
@@ -3,14 +3,23 @@ require "Vector"
 local V = Vector
 
 local function make_sphere(centre, radius, texture)
-      return function(p)
-         return {dist = V.norm(p-centre) - radius,
-                 texture = texture}
-      end
+   local norm = V.norm
+   return function(p)
+      return {dist = V.norm(p-centre) - radius,
+              texture = texture}
+   end
+end
+
+local function make_plane(centre, normal, texture)
+   return function(p)
+      return {dist = normal*(p-centre),
+              texture = texture}
+   end
 end
 
 Primitives = {
-   make_sphere = make_sphere
+   make_sphere = make_sphere,
+   make_plane = make_plane
 }
 
 return Primitives