From dfe80011c90d2ac1e03f318f4349d33013fa01b7 Mon Sep 17 00:00:00 2001 From: jbb01 <32650546+jbb01@users.noreply.github.com> Date: Wed, 7 Aug 2024 15:50:09 +0200 Subject: [PATCH] add "final" scene --- .../eu/jonahbauer/raytracing/Examples.java | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/src/main/java/eu/jonahbauer/raytracing/Examples.java b/src/main/java/eu/jonahbauer/raytracing/Examples.java index 464d5d0..5f38dcb 100644 --- a/src/main/java/eu/jonahbauer/raytracing/Examples.java +++ b/src/main/java/eu/jonahbauer/raytracing/Examples.java @@ -14,6 +14,7 @@ import eu.jonahbauer.raytracing.scene.hittable2d.Parallelogram; import eu.jonahbauer.raytracing.scene.hittable3d.ConstantMedium; import eu.jonahbauer.raytracing.scene.hittable3d.Sphere; import eu.jonahbauer.raytracing.scene.util.Hittables; +import eu.jonahbauer.raytracing.scene.util.HittableBinaryTree; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -36,6 +37,7 @@ public class Examples { register("DIAGRAMM", Examples::getDiagramm); register("EARTH", Examples::getEarth); register("PERLIN", Examples::getPerlin); + register("FINAL", Examples::getFinal); } public static @NotNull IntFunction getByName(@NotNull String name) { @@ -296,6 +298,74 @@ public class Examples { ); } + public static @NotNull Example getFinal(int height) { + if (height <= 0) height = 400; + + var objects = new ArrayList(); + var random = new Random(1); + + // boxes + var boxes = new ArrayList(); + var ground = new LambertianMaterial(new Color(0.48, 0.83, 0.53)); + for (int i = 0; i < 20; i++) { + for (int j = 0; j < 20; j++) { + var w = 100.0; + var x0 = -1000.0 + i * w; + var z0 = -1000.0 + j * w; + var y0 = 0.0; + var x1 = x0 + w; + var y1 = random.nextInt(1, 101); + var z1 = z0 + w; + boxes.add(new Box(new Vec3(x0, y0, z0), new Vec3(x1, y1, z1), ground)); + } + } + objects.add(new HittableBinaryTree(boxes)); + + // light + objects.add(new Parallelogram( + new Vec3(123, 554, 147), new Vec3(300, 0, 0), new Vec3(0, 0, 265), + new DiffuseLight(new Color(7., 7., 7.)) + )); + + // spheres with different materials + objects.add(new Sphere(new Vec3(400, 400, 200), 50, new LambertianMaterial(new Color(0.7, 0.3, 0.1)))); + objects.add(new Sphere(new Vec3(260, 150, 45), 50, new DielectricMaterial(1.5))); + objects.add(new Sphere(new Vec3(0, 150, 145), 50, new MetallicMaterial(new Color(0.8, 0.8, 0.9), 1.0))); + + // glass sphere filled with gas + var boundary = new Sphere(new Vec3(360, 150, 145), 70, new DielectricMaterial(1.5)); + objects.add(boundary); + objects.add(new ConstantMedium(boundary, 0.2, new IsotropicMaterial(new Color(0.2, 0.4, 0.9)))); + + // put the world in a glass sphere + objects.add(new ConstantMedium( + new Sphere(new Vec3(0, 0, 0), 5000, new DielectricMaterial(1.5)), + 0.0001, new IsotropicMaterial(new Color(1., 1., 1.)) + )); + + // textures spheres + objects.add(new Sphere(new Vec3(400, 200, 400), 100, new LambertianMaterial(new ImageTexture("/earthmap.jpg")))); + objects.add(new Sphere(new Vec3(220, 280, 300), 80, new LambertianMaterial(new PerlinTexture(0.2)))); + + // box from spheres + var white = new LambertianMaterial(new Color(.73, .73, .73)); + var spheres = new ArrayList(); + for (int j = 0; j < 1000; j++) { + spheres.add(new Sphere(new Vec3(random.nextDouble(165), random.nextDouble(165), random.nextDouble(165)), 10, white)); + } + objects.add(new HittableBinaryTree(spheres).rotateY(Math.toRadians(15)).translate(new Vec3(-100, 270, 395))); + + return new Example( + new Scene(objects), + SimpleCamera.builder() + .withImage(height, height) + .withFieldOfView(Math.toRadians(40)) + .withPosition(new Vec3(478, 278, -600)) + .withTarget(new Vec3(278, 278, 0)) + .build() + ); + } + private static @NotNull SkyBox getSkyBox() { return SkyBox.gradient(new Color(0.5, 0.7, 1.0), Color.WHITE); }