--- Some pre-defined colours
+require "Vector"
+local V = Vector
+
Colours = {
- red = {1,0,0},
- green = {0,1,0},
- blue = {0,0,1},
- yellow = {1,1,0},
- magenta = {1,0,1},
- cyan = {0,1,1}
+ red = V.new{1,0,0},
+ green = V.new{0,1,0},
+ blue = V.new{0,0,1},
+ yellow = V.new{1,1,0},
+ magenta = V.new{1,0,1},
+ cyan = V.new{0,1,1}
}
return Colours
Primitives = {
make_sphere = make_sphere,
make_plane = make_plane,
- make_pipe = make_pipe
+ make_pipe = make_pipe,
+ make_mandelbulb = make_mandelbulb
}
return Primitives
require "Vector"
local V = Vector
+require "Colours"
+local C = Colours
+
local function make_phong_texture(lights, mapped_pigment, amb, diff, spec, shiny)
local normalize = V.normalize
end
end
+local function make_rainbow_pigment(scale)
+ return function (x,y)
+
+ local Ired = math.sin(x/math.pi/scale)^2 * math.sin(y/math.pi/scale)^2
+ local Igreen = math.cos(x/math.pi/scale)^2 * math.sin(y/math.pi/scale)^2
+ local Iblue = math.sin(x/math.pi/scale)^2 * math.cos(y/math.pi/scale)^2
+
+ return C.red*Ired + C.green*Igreen + C.blue*Iblue
+ end
+end
+
+
-- Mapping functions
-- These functions define mappings from 3D world coordinates to 2D
make_solid_pigment = make_solid_pigment,
make_checkered_pigment = make_checkered_pigment,
make_image_pigment = make_image_pigment,
+ make_rainbow_pigment = make_rainbow_pigment,
make_mandelbrot_pigment = make_mandelbrot_pigment,
map_rectangular = map_rectangular,
map_spherical = map_spherical
sdf = P.make_mandelbulb(V.origin, 100, 8,
T.make_phong_texture(
{V.new{3,-5,3}},
- T.make_solid_pigment{0,0.5,1.0},
+ -- T.make_solid_pigment{0,0.5,1.0},
+ T.map_spherical(T.make_rainbow_pigment(0.1), V.origin, 1, 1),
0.1, 1.0, 0.0, 30)),
camera = {location = V.new{0,-5,0},
Render.eps = 0.001
Render.bg_col = {0,0,0}
-Render.render(scene, 2560, 1440, "out/mandelbulb.ppm")
+Render.render(scene, 2560, 1440, "out/mandelbulb_rainbow.ppm")
+-- Render.render(scene, 2560, 1440, "out/mandelbulb_rainbow.ppm")
--- /dev/null
+require "Vector"
+local V = Vector
+
+require "Primitives"
+local P = Primitives
+
+require "Operations"
+local O = Operations
+
+require "Textures"
+local T = Textures
+
+require "Render"
+
+local lights = {V.new{1,-1,1}}
+
+local plane_normal = V.normalize(V.new{0.0,-1,0.0})
+local texture_y = V.normalize(V.cross(plane_normal,V.x))
+local texture_x = V.cross(texture_y,plane_normal)
+
+local scene = {
+ sdf = P.make_plane(V.new{0,0,0}, plane_normal,
+ T.make_phong_texture(lights,
+ T.map_rectangular(
+ T.make_rainbow_pigment(0.1),
+ texture_x, texture_y),
+ 0.2, 1.0, 0, 1)),
+
+ camera = {location = V.new{-0.5,-5,0},
+ point_at = V.new{-0.5,0,0},
+ right = V.x,
+ fov = 1}}
+
+Render.render(scene, 320, 200, "out/rainbow_wall.ppm")