def random_scene(aspect_ratio: float, time0: float, time1: float) \ -> Tuple[BVHNode, Camera]: world = HittableList() # ground_material = Lambertian(SolidColor(0.5, 0.5, 0.5)) ground_material = Lambertian( CheckerTexture(SolidColor(0.2, 0.3, 0.1), SolidColor(0.9, 0.9, 0.9))) world.add(Sphere(Point3(0, -1000, 0), 1000, ground_material)) for a in range(-11, 11): for b in range(-11, 11): choose_mat = random_float() center = Point3(a + 0.9 * random_float(), 0.2, b + 0.9 * random_float()) if (center - Vec3(4, 0.2, 0)).length() > 0.9: if choose_mat < 0.6: # Diffuse albedo = Color.random() * Color.random() sphere_material_diffuse = Lambertian(SolidColor(albedo)) center2 = center + Vec3(0, random_float(0, 0.5), 0) world.add( MovingSphere(center, center2, 0, 1, 0.2, sphere_material_diffuse)) elif choose_mat < 0.8: # Metal albedo = Color.random(0.5, 1) fuzz = random_float(0, 0.5) sphere_material_metal = Metal(albedo, fuzz) world.add(Sphere(center, 0.2, sphere_material_metal)) else: # Glass sphere_material_glass = Dielectric(1.5) world.add(Sphere(center, 0.2, sphere_material_glass)) material_1 = Dielectric(1.5) world.add(Sphere(Point3(0, 1, 0), 1, material_1)) material_2 = Lambertian(SolidColor(0.4, 0.2, 0.1)) world.add(Sphere(Point3(-4, 1, 0), 1, material_2)) material_3 = Metal(Color(0.7, 0.6, 0.5), 0) world.add(Sphere(Point3(4, 1, 0), 1, material_3)) world_bvh = BVHNode(world.objects, time0, time1) lookfrom = Point3(13, 2, 3) lookat = Point3(0, 0, 0) vup = Vec3(0, 1, 0) vfov = 20 dist_to_focus: float = 10 aperture: float = 0.1 cam = Camera(lookfrom, lookat, vup, vfov, aspect_ratio, aperture, dist_to_focus, time0, time1) return world_bvh, cam
def random_scene() -> HittableList: world = HittableList() ground_material = Lambertian(Color(0.5, 0.5, 0.5), 1) world.add(Sphere(Point3(0, -1000, 0), 1000, ground_material)) sphere_material_glass = Dielectric(1.5, 2) for a in range(-11, 11): for b in range(-11, 11): choose_mat = random_float() center = Point3(a + 0.9 * random_float(), 0.2, b + 0.9 * random_float()) if (center - Vec3(4, 0.2, 0)).length() > 0.9: idx = (a * 22 + b) + (11 * 22 + 11) + 6 if choose_mat < 0.6: # Diffuse albedo = Color.random() * Color.random() sphere_material_diffuse = Lambertian(albedo, idx) world.add(Sphere(center, 0.2, sphere_material_diffuse)) elif choose_mat < 0.8: # Metal albedo = Color.random(0.5, 1) fuzz = random_float(0, 0.5) sphere_material_metal = Metal(albedo, fuzz, idx) world.add(Sphere(center, 0.2, sphere_material_metal)) else: # Glass world.add(Sphere(center, 0.2, sphere_material_glass)) material_1 = Dielectric(1.5, 3) world.add(Sphere(Point3(0, 1, 0), 1, material_1)) material_2 = Lambertian(Color(0.4, 0.2, 0.1), 4) world.add(Sphere(Point3(-4, 1, 0), 1, material_2)) material_3 = Metal(Color(0.7, 0.6, 0.5), 0, 5) world.add(Sphere(Point3(4, 1, 0), 1, material_3)) return world