diff --git a/README.md b/README.md index 1a78814..dd63538 100644 --- a/README.md +++ b/README.md @@ -31,4 +31,12 @@ java -jar raytracing.jar --samples 50000 --height 1200 CORNELL ``` java -jar raytracing.jar --samples 50000 --height 600 CORNELL_SMOKE +``` + +### diagramm + +![](./docs/diagramm.png) + +``` +java -jar raytracing.jar --samples 1000 --height 1080 DIAGRAMM ``` \ No newline at end of file diff --git a/docs/diagramm.png b/docs/diagramm.png new file mode 100644 index 0000000..76290c1 Binary files /dev/null and b/docs/diagramm.png differ diff --git a/src/main/java/eu/jonahbauer/raytracing/Examples.java b/src/main/java/eu/jonahbauer/raytracing/Examples.java index 58f58c9..ffeb8ae 100644 --- a/src/main/java/eu/jonahbauer/raytracing/Examples.java +++ b/src/main/java/eu/jonahbauer/raytracing/Examples.java @@ -30,6 +30,7 @@ public class Examples { register("LIGHT", Examples::getLight); register("CORNELL", Examples::getCornellBox); register("CORNELL_SMOKE", Examples::getCornellBoxSmoke); + register("DIAGRAMM", Examples::getDiagramm); } public static @NotNull IntFunction getByName(@NotNull String name) { @@ -202,6 +203,54 @@ public class Examples { ); } + public static @NotNull Example getDiagramm(int height) { + if (height <= 0) height = 450; + + record Partei(String name, Color color, double stimmen) { } + var data = List.of( + new Partei("CDU", new Color(0x00, 0x4B, 0x76), 18.9), + new Partei("SPD", new Color(0xC0, 0x00, 0x3C), 25.7), + new Partei("AfD", new Color(0x80, 0xCD, 0xEC), 10.3), + new Partei("FDP", new Color(0xF7, 0xBB, 0x3D), 11.5), + new Partei("DIE LINKE", new Color(0x5F, 0x31, 0x6E), 4.9), + new Partei("GRÜNE", new Color(0x00, 0x85, 0x4A), 14.8), + new Partei("CSU", new Color(0x00, 0x77, 0xB6), 5.2) + ); + var white = new LambertianMaterial(new Color(.99, .99, .99)); + + var count = data.size(); + var size = 75d; + var spacing = 50d; + + var x = (count + 1) * spacing + count * size + 1000; + var y = 500 + 1000; + var z = 2 * spacing + size + 1000; + + var objects = new ArrayList(); + objects.add(new Parallelogram(new Vec3(0, 0, 0), new Vec3(x, 0, 0), new Vec3(0, y, 0), white)); + objects.add(new Parallelogram(new Vec3(0, 0, 0), new Vec3(0, 0, z), new Vec3(x, 0, 0), white)); + objects.add(new Parallelogram(new Vec3(0, 0, 0), new Vec3(0, y, 0), new Vec3(0, 0, z), white)); + + for (int i = 0; i < data.size(); i++) { + var partei = data.get(i); + objects.add(Hittables.box( + new Vec3((i + 1) * spacing + i * size, 0, spacing), + new Vec3((i + 1) * spacing + (i + 1) * size, partei.stimmen() * 15, spacing + size), + new DielectricMaterial(1.5, partei.color()) + )); + } + + return new Example( + new Scene(new Color(1.25, 1.25, 1.25), objects), + SimpleCamera.builder() + .withImage(height * 16 / 9, height) + .withPosition(new Vec3(700, 250, 800)) + .withTarget(new Vec3(500, 200, 0)) + .withFieldOfView(Math.toRadians(40)) + .build() + ); + } + private static @NotNull SkyBox getSkyBox() { return SkyBox.gradient(new Color(0.5, 0.7, 1.0), Color.WHITE); } diff --git a/src/main/java/eu/jonahbauer/raytracing/render/material/DielectricMaterial.java b/src/main/java/eu/jonahbauer/raytracing/render/material/DielectricMaterial.java index 3c554ed..8e22c6f 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/DielectricMaterial.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/DielectricMaterial.java @@ -6,9 +6,18 @@ import eu.jonahbauer.raytracing.render.Color; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; +import java.util.Objects; import java.util.Optional; -public record DielectricMaterial(double refractionIndex) implements Material { +public record DielectricMaterial(double refractionIndex, @NotNull Color albedo) implements Material { + public DielectricMaterial(double refractionIndex) { + this(refractionIndex, Color.WHITE); + } + + public DielectricMaterial { + Objects.requireNonNull(albedo, "albedo"); + } + @Override public @NotNull Optional scatter(@NotNull Ray ray, @NotNull HitResult hit) { var ri = hit.frontFace() ? (1 / refractionIndex) : refractionIndex; @@ -20,7 +29,7 @@ public record DielectricMaterial(double refractionIndex) implements Material { var newDirection = (reflect ? Optional.empty() : Vec3.refract(ray.direction(), hit.normal(), ri)) .orElseGet(() -> Vec3.reflect(ray.direction(), hit.normal())); - return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), Color.WHITE)); + return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), albedo)); } private double reflectance(double cos) {