Added missing export of mandel pigment.
[raymarcher.git] / Textures.lua
index 1e919c7..3a4abaf 100644 (file)
@@ -68,13 +68,34 @@ local function make_checkered_pigment(colour1, colour2)
       end
    end
 end
+
+local function make_mandelbrot_pigment(set_colour, max_iter)
+
+   local function get_col(x,y,cx,cy,iter)
+      if iter == 0 then
+         return set_colour
+      elseif x^2 + y^2 > 4 then
+         local I = iter/max_iter
+         return {I,I,1-I}
+      else
+         return get_col(x^2 - y^2 + cx,
+                        2*x*y + cy,
+                        cx, cy, iter-1)
+      end
+   end
+
+   return function (x,y)
+      get_col(0,0,x,y,max_iter)
+   end
+end
    
 Textures = {
    make_phong_texture = make_phong_texture,
    make_flat_texture = make_flat_texture,
    make_count_texture = make_count_texture,
    make_solid_pigment = make_solid_pigment,
-   make_checkered_pigment = make_checkered_pigment
+   make_checkered_pigment = make_checkered_pigment,
+   make_mandelbrot_pigment = make_mandelbrot_pigment
 }
 
 return Textures