From: Tim Vaughan Date: Thu, 23 Feb 2023 10:54:09 +0000 (+0100) Subject: Render is now its own package. X-Git-Url: https://thelambdalab.xyz/gitweb/index.cgi?p=raymarcher.git;a=commitdiff_plain;h=ef4dde6203d251741131f06824200c3d7f01f56d Render is now its own package. --- diff --git a/raymarch.lua b/Render.lua similarity index 64% rename from raymarch.lua rename to Render.lua index 594645e..17f244d 100644 --- a/raymarch.lua +++ b/Render.lua @@ -1,3 +1,5 @@ +-- Main rendering functions + require "Vector" local V = Vector @@ -77,33 +79,11 @@ local function render(scene, width, height, filename) print("done") end +Render = { + eps = eps, + max_dist2 = max_dist2, + bg_col = bg_col, + render = render +} -local lights = {V.new{3,-3,1}} - -local scene = { - sdf = - O.union( - O.diff( - O.diff( - O.diff( - P.make_sphere(V.new{0,0,0}, 1, - T.make_phong_texture(lights, - T.make_solid_pigment({0,1,0}), - 0.2, 0.7, 1.0, 100)), - P.make_sphere(V.new{0,0,0}, 0.8)), - P.make_pipe(V.new{0,0,0}, 0.5, V.new{0,1,0})), - P.make_pipe(V.new{0,0,0}, 0.5, V.new{1,0,0})), - - P.make_plane(V.new{0,0,-1.0}, V.new{0,0,1}, - T.make_phong_texture(lights, - T.make_checkered_pigment({0.5,0,0.2}, {1,1,1}), - 0.2, 1.0, 0, 1))), - -- T.make_flat_texture(T.make_checkered_pigment({0,0,1}, {1,1,1})))), - - camera = {location = V.new{2,-5,1}, - point_at = V.new{0,0,0}, - right = V.x, - fov = 1}} - --- render(scene, 320, 200, "test.ppm") -render(scene, 640, 480, "test.ppm") +return Render diff --git a/holy_sphere.lua b/holy_sphere.lua new file mode 100644 index 0000000..b26f67e --- /dev/null +++ b/holy_sphere.lua @@ -0,0 +1,41 @@ +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{3,-3,1}} + +local scene = { + sdf = + O.union( + O.diff( + O.diff( + O.diff( + P.make_sphere(V.new{0,0,0}, 1, + T.make_phong_texture(lights, + T.make_solid_pigment({0,1,0}), + 0.2, 0.7, 1.0, 100)), + P.make_sphere(V.new{0,0,0}, 0.8)), + P.make_pipe(V.new{0,0,0}, 0.5, V.new{0,1,0})), + P.make_pipe(V.new{0,0,0}, 0.5, V.new{1,0,0})), + + P.make_plane(V.new{0,0,-1.0}, V.new{0,0,1}, + T.make_phong_texture(lights, + T.make_checkered_pigment({0.5,0,0.2}, {1,1,1}), + 0.2, 1.0, 0, 1))), + + camera = {location = V.new{2,-5,1}, + point_at = V.new{0,0,0}, + right = V.x, + fov = 1}} + +Render.render(scene, 1280, 960, "holy_sphere.ppm")