From 08c2f14a986cc281ec2d852b1f335fe0bcbe3361 Mon Sep 17 00:00:00 2001 From: Alan Jian Date: Sat, 20 Jul 2024 19:11:46 +0800 Subject: [PATCH] feat: add scene of random spheres --- scripts/scene.lua | 65 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 49 insertions(+), 16 deletions(-) diff --git a/scripts/scene.lua b/scripts/scene.lua index 01eabf2..5a7e48e 100644 --- a/scripts/scene.lua +++ b/scripts/scene.lua @@ -1,18 +1,51 @@ -camera.pos = {-2.0, 2.0, 1.0} -camera.center = {0.0, 0.0, -1.0} +math.randomseed(os.time()) + +camera.pos = {13.0, 2.0, 3.0} +camera.center = {0.0, 0.0, 0.0} camera.up = {0.0, 1.0, 0.0} camera.fov = math.rad(20.0) -camera.focus_dist = 3.4 -camera.lens_angle = math.rad(10.0) - -material_ground = Lambertian.new({0.8, 0.8, 0.0}) -material_center = Lambertian.new({0.1, 0.2, 0.5}) -material_left = Dielectric.new(1.5) -material_bubble = Dielectric.new(1.0 / 1.5) -material_right = Metal.new({0.8, 0.6, 0.2}, 1.0) - -scene:add(Sphere.new({0.0, -100.5, -1.0}, 100.0, material_ground)) -scene:add(Sphere.new({0.0, 0.0, -1.2}, 0.5, material_center)) -scene:add(Sphere.new({-1.0, 0.0, -1.0}, 0.5, material_left)) -scene:add(Sphere.new({-1.0, 0.0, -1.0}, 0.4, material_bubble)) -scene:add(Sphere.new({1.0, 0.0, -1.0}, 0.5, material_right)) +camera.focus_dist = 10.0 +camera.lens_angle = math.rad(0.6) + +material_ground = Lambertian.new({0.5, 0.5, 0.5}) +scene:add(Sphere.new({0.0, -1000.0, 0.0}, 1000.0, material_ground)) + +for a = -11, 11 do + for b = -11, 11 do + local choose_mat = math.random() + local center = {} + center[1] = a + 0.9 * math.random() + center[2] = 0.2 + center[3] = b + 0.9 * math.random() + + if choose_mat < 0.8 then + local albedo = {} + albedo[1] = math.random() * math.random() + albedo[2] = math.random() * math.random() + albedo[3] = math.random() * math.random() + local material = Lambertian.new(albedo) + scene:add(Sphere.new(center, 0.2, material)) + elseif choose_mat < 0.95 then + local albedo = {} + albedo[1] = 0.5 * math.random() + 0.5 + albedo[2] = 0.5 * math.random() + 0.5 + albedo[3] = 0.5 * math.random() + 0.5 + local fuzz = 0.5 * math.random() + local material = Metal.new(albedo, fuzz) + scene:add(Sphere.new(center, 0.2, material)) + else + local material = Dielectric.new(1.5) + scene:add(Sphere.new(center, 0.2, material)) + end + end +end + +material1 = Dielectric.new(1.5) +scene:add(Sphere.new({0.0, 1.0, 0.0}, 1.0, material1)) + +material2 = Lambertian.new({0.4, 0.2, 0.1}) +scene:add(Sphere.new({-4.0, 1.0, 0.0}, 1.0, material2)) + +material3 = Metal.new({0.7, 0.6, 0.5}, 0.0) +scene:add(Sphere.new({4.0, 1.0, 0.0}, 1.0, material3)) +