From 7c0bc68ab28726172f6409c56fd3ed3c3e043b2b 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 texture support --- .../java/eu/jonahbauer/raytracing/Examples.java | 8 ++++++-- .../raytracing/render/canvas/Canvas.java | 2 +- .../raytracing/render/canvas/Image.java | 2 +- .../raytracing/render/canvas/LiveCanvas.java | 2 +- .../render/material/DielectricMaterial.java | 10 ++++++---- .../render/material/DiffuseLight.java | 7 ++++--- .../render/material/IsotropicMaterial.java | 4 ++-- .../render/material/LambertianMaterial.java | 9 +++++---- .../raytracing/render/material/Material.java | 2 +- .../render/material/MetallicMaterial.java | 13 +++++++------ .../render/renderer/SimpleRenderer.java | 2 +- .../render/texture/CheckerTexture.java | 17 +++++++++++++++++ .../raytracing/render/{ => texture}/Color.java | 16 ++++++++++++---- .../raytracing/render/texture/Texture.java | 13 +++++++++++++ .../jonahbauer/raytracing/scene/HitResult.java | 11 ++++++----- .../eu/jonahbauer/raytracing/scene/Scene.java | 2 +- .../eu/jonahbauer/raytracing/scene/SkyBox.java | 2 +- .../raytracing/scene/hittable2d/Hittable2D.java | 5 ++++- .../scene/hittable3d/ConstantMedium.java | 2 +- .../raytracing/scene/hittable3d/Sphere.java | 14 ++++++++++++-- .../raytracing/scene/transform/RotateY.java | 2 +- .../raytracing/scene/transform/Translate.java | 8 +------- .../raytracing/render/canvas/ImageTest.java | 2 +- .../raytracing/scene/hittable3d/SphereTest.java | 2 +- 24 files changed, 106 insertions(+), 51 deletions(-) create mode 100644 src/main/java/eu/jonahbauer/raytracing/render/texture/CheckerTexture.java rename src/main/java/eu/jonahbauer/raytracing/render/{ => texture}/Color.java (86%) create mode 100644 src/main/java/eu/jonahbauer/raytracing/render/texture/Texture.java diff --git a/src/main/java/eu/jonahbauer/raytracing/Examples.java b/src/main/java/eu/jonahbauer/raytracing/Examples.java index ffeb8ae..5c044af 100644 --- a/src/main/java/eu/jonahbauer/raytracing/Examples.java +++ b/src/main/java/eu/jonahbauer/raytracing/Examples.java @@ -1,7 +1,8 @@ package eu.jonahbauer.raytracing; import eu.jonahbauer.raytracing.math.Vec3; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.CheckerTexture; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.render.camera.SimpleCamera; import eu.jonahbauer.raytracing.render.material.*; import eu.jonahbauer.raytracing.scene.Hittable; @@ -61,7 +62,10 @@ public class Examples { var rng = new Random(1); var objects = new ArrayList(); - objects.add(new Sphere(new Vec3(0, -1000, 0), 1000, new LambertianMaterial(new Color(0.5, 0.5, 0.5)))); + objects.add(new Sphere( + new Vec3(0, -1000, 0), 1000, + new LambertianMaterial(new CheckerTexture(0.32, new Color(.2, .3, .1), new Color(.9, .9, .9))) + )); for (int a = -11; a < 11; a++) { for (int b = -11; b < 11; b++) { diff --git a/src/main/java/eu/jonahbauer/raytracing/render/canvas/Canvas.java b/src/main/java/eu/jonahbauer/raytracing/render/canvas/Canvas.java index c81ab7d..0919996 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/canvas/Canvas.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/canvas/Canvas.java @@ -1,6 +1,6 @@ package eu.jonahbauer.raytracing.render.canvas; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import org.jetbrains.annotations.NotNull; import java.util.function.Function; diff --git a/src/main/java/eu/jonahbauer/raytracing/render/canvas/Image.java b/src/main/java/eu/jonahbauer/raytracing/render/canvas/Image.java index 5f93eca..4ee3ee9 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/canvas/Image.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/canvas/Image.java @@ -1,6 +1,6 @@ package eu.jonahbauer.raytracing.render.canvas; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import org.jetbrains.annotations.NotNull; import java.util.Objects; diff --git a/src/main/java/eu/jonahbauer/raytracing/render/canvas/LiveCanvas.java b/src/main/java/eu/jonahbauer/raytracing/render/canvas/LiveCanvas.java index bfc5fc0..2839f2b 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/canvas/LiveCanvas.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/canvas/LiveCanvas.java @@ -1,6 +1,6 @@ package eu.jonahbauer.raytracing.render.canvas; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import org.jetbrains.annotations.NotNull; import javax.swing.*; 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 03b3502..c452e09 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/DielectricMaterial.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/DielectricMaterial.java @@ -2,7 +2,8 @@ package eu.jonahbauer.raytracing.render.material; import eu.jonahbauer.raytracing.math.Ray; import eu.jonahbauer.raytracing.math.Vec3; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; +import eu.jonahbauer.raytracing.render.texture.Texture; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; @@ -10,13 +11,13 @@ import java.util.Objects; import java.util.Optional; import java.util.random.RandomGenerator; -public record DielectricMaterial(double refractionIndex, @NotNull Color albedo) implements Material { +public record DielectricMaterial(double refractionIndex, @NotNull Texture texture) implements Material { public DielectricMaterial(double refractionIndex) { this(refractionIndex, Color.WHITE); } public DielectricMaterial { - Objects.requireNonNull(albedo, "albedo"); + Objects.requireNonNull(texture, "texture"); } @Override @@ -30,7 +31,8 @@ public record DielectricMaterial(double refractionIndex, @NotNull Color albedo) 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), albedo)); + var attenuation = texture.get(hit); + return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), attenuation)); } private double reflectance(double cos) { diff --git a/src/main/java/eu/jonahbauer/raytracing/render/material/DiffuseLight.java b/src/main/java/eu/jonahbauer/raytracing/render/material/DiffuseLight.java index f89e348..c4996ad 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/DiffuseLight.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/DiffuseLight.java @@ -1,14 +1,15 @@ package eu.jonahbauer.raytracing.render.material; import eu.jonahbauer.raytracing.math.Ray; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; +import eu.jonahbauer.raytracing.render.texture.Texture; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; import java.util.Optional; import java.util.random.RandomGenerator; -public record DiffuseLight(@NotNull Color emit) implements Material { +public record DiffuseLight(@NotNull Texture texture) implements Material { @Override public @NotNull Optional scatter(@NotNull Ray ray, @NotNull HitResult hit, @NotNull RandomGenerator random) { return Optional.empty(); @@ -16,6 +17,6 @@ public record DiffuseLight(@NotNull Color emit) implements Material { @Override public @NotNull Color emitted(@NotNull HitResult hit) { - return emit; + return texture.get(hit); } } diff --git a/src/main/java/eu/jonahbauer/raytracing/render/material/IsotropicMaterial.java b/src/main/java/eu/jonahbauer/raytracing/render/material/IsotropicMaterial.java index 74e0ecf..1f4b4af 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/IsotropicMaterial.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/IsotropicMaterial.java @@ -2,14 +2,14 @@ package eu.jonahbauer.raytracing.render.material; import eu.jonahbauer.raytracing.math.Ray; import eu.jonahbauer.raytracing.math.Vec3; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; import java.util.Optional; import java.util.random.RandomGenerator; -public record IsotropicMaterial(@NotNull Color albedo) implements Material{ +public record IsotropicMaterial(@NotNull Color albedo) implements Material { @Override public @NotNull Optional scatter(@NotNull Ray ray, @NotNull HitResult hit, @NotNull RandomGenerator random) { return Optional.of(new ScatterResult(new Ray(hit.position(), Vec3.random(random, true)), albedo())); diff --git a/src/main/java/eu/jonahbauer/raytracing/render/material/LambertianMaterial.java b/src/main/java/eu/jonahbauer/raytracing/render/material/LambertianMaterial.java index ded69c7..cd701d7 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/LambertianMaterial.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/LambertianMaterial.java @@ -2,7 +2,7 @@ package eu.jonahbauer.raytracing.render.material; import eu.jonahbauer.raytracing.math.Ray; import eu.jonahbauer.raytracing.math.Vec3; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Texture; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; @@ -10,9 +10,9 @@ import java.util.Objects; import java.util.Optional; import java.util.random.RandomGenerator; -public record LambertianMaterial(@NotNull Color albedo) implements Material { +public record LambertianMaterial(@NotNull Texture texture) implements Material { public LambertianMaterial { - Objects.requireNonNull(albedo, "albedo"); + Objects.requireNonNull(texture, "texture"); } @Override @@ -20,7 +20,8 @@ public record LambertianMaterial(@NotNull Color albedo) implements Material { var newDirection = hit.normal().plus(Vec3.random(random, true)); if (newDirection.isNearZero()) newDirection = hit.normal(); + var attenuation = texture.get(hit); var scattered = new Ray(hit.position(), newDirection); - return Optional.of(new ScatterResult(scattered, albedo)); + return Optional.of(new ScatterResult(scattered, attenuation)); } } diff --git a/src/main/java/eu/jonahbauer/raytracing/render/material/Material.java b/src/main/java/eu/jonahbauer/raytracing/render/material/Material.java index 85f46c8..4f430f0 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/Material.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/Material.java @@ -1,7 +1,7 @@ package eu.jonahbauer.raytracing.render.material; import eu.jonahbauer.raytracing.math.Ray; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/eu/jonahbauer/raytracing/render/material/MetallicMaterial.java b/src/main/java/eu/jonahbauer/raytracing/render/material/MetallicMaterial.java index 2ff15ee..a89b0a0 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/material/MetallicMaterial.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/material/MetallicMaterial.java @@ -2,7 +2,7 @@ package eu.jonahbauer.raytracing.render.material; import eu.jonahbauer.raytracing.math.Ray; import eu.jonahbauer.raytracing.math.Vec3; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Texture; import eu.jonahbauer.raytracing.scene.HitResult; import org.jetbrains.annotations.NotNull; @@ -10,14 +10,14 @@ import java.util.Objects; import java.util.Optional; import java.util.random.RandomGenerator; -public record MetallicMaterial(@NotNull Color albedo, double fuzz) implements Material { +public record MetallicMaterial(@NotNull Texture texture, double fuzz) implements Material { - public MetallicMaterial(@NotNull Color albedo) { - this(albedo, 0); + public MetallicMaterial(@NotNull Texture texture) { + this(texture, 0); } public MetallicMaterial { - Objects.requireNonNull(albedo, "albedo"); + Objects.requireNonNull(texture, "texture"); if (fuzz < 0 || !Double.isFinite(fuzz)) throw new IllegalArgumentException("fuzz must be non-negative"); } @@ -27,6 +27,7 @@ public record MetallicMaterial(@NotNull Color albedo, double fuzz) implements Ma if (fuzz > 0) { newDirection = newDirection.unit().plus(Vec3.random(random, true).times(fuzz)); } - return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), albedo)); + var attenuation = texture.get(hit); + return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), attenuation)); } } diff --git a/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java b/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java index d503194..7c90722 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/renderer/SimpleRenderer.java @@ -2,7 +2,7 @@ package eu.jonahbauer.raytracing.render.renderer; import eu.jonahbauer.raytracing.math.Range; import eu.jonahbauer.raytracing.math.Ray; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.render.camera.Camera; import eu.jonahbauer.raytracing.render.canvas.Canvas; import eu.jonahbauer.raytracing.scene.Scene; diff --git a/src/main/java/eu/jonahbauer/raytracing/render/texture/CheckerTexture.java b/src/main/java/eu/jonahbauer/raytracing/render/texture/CheckerTexture.java new file mode 100644 index 0000000..70b832d --- /dev/null +++ b/src/main/java/eu/jonahbauer/raytracing/render/texture/CheckerTexture.java @@ -0,0 +1,17 @@ +package eu.jonahbauer.raytracing.render.texture; + +import eu.jonahbauer.raytracing.math.Vec3; +import org.jetbrains.annotations.NotNull; + +public record CheckerTexture(double scale, @NotNull Texture even, @NotNull Texture odd) implements Texture { + + + @Override + public @NotNull Color get(double u, double v, @NotNull Vec3 p) { + var x = (int) Math.floor(p.x() / scale); + var y = (int) Math.floor(p.y() / scale); + var z = (int) Math.floor(p.z() / scale); + var even = (x + y + z) % 2 == 0; + return even ? even().get(u, v, p) : odd().get(u, v, p); + } +} diff --git a/src/main/java/eu/jonahbauer/raytracing/render/Color.java b/src/main/java/eu/jonahbauer/raytracing/render/texture/Color.java similarity index 86% rename from src/main/java/eu/jonahbauer/raytracing/render/Color.java rename to src/main/java/eu/jonahbauer/raytracing/render/texture/Color.java index b33388b..bf08111 100644 --- a/src/main/java/eu/jonahbauer/raytracing/render/Color.java +++ b/src/main/java/eu/jonahbauer/raytracing/render/texture/Color.java @@ -1,10 +1,11 @@ -package eu.jonahbauer.raytracing.render; +package eu.jonahbauer.raytracing.render.texture; +import eu.jonahbauer.raytracing.math.Vec3; import org.jetbrains.annotations.NotNull; import java.util.Random; -public record Color(double r, double g, double b) { +public record Color(double r, double g, double b) implements Texture { public static final @NotNull Color BLACK = new Color(0.0, 0.0, 0.0); public static final @NotNull Color WHITE = new Color(1.0, 1.0, 1.0); public static final @NotNull Color RED = new Color(1.0, 0.0, 0.0); @@ -68,7 +69,9 @@ public record Color(double r, double g, double b) { } } - public Color {} + public Color(int rgb) { + this((rgb >> 16) & 0xFF, (rgb >> 8) & 0xFF, rgb & 0xFF); + } public Color(int red, int green, int blue) { this(red / 255f, green / 255f, blue / 255f); @@ -86,7 +89,12 @@ public record Color(double r, double g, double b) { return toInt(b); } + @Override + public @NotNull Color get(double u, double v, @NotNull Vec3 p) { + return this; + } + private static int toInt(double value) { - return Math.max(0, Math.min(255, (int) (255.99 * value))); + return Math.clamp((int) (255.99 * value), 0, 255); } } diff --git a/src/main/java/eu/jonahbauer/raytracing/render/texture/Texture.java b/src/main/java/eu/jonahbauer/raytracing/render/texture/Texture.java new file mode 100644 index 0000000..ab01c5b --- /dev/null +++ b/src/main/java/eu/jonahbauer/raytracing/render/texture/Texture.java @@ -0,0 +1,13 @@ +package eu.jonahbauer.raytracing.render.texture; + +import eu.jonahbauer.raytracing.math.Vec3; +import eu.jonahbauer.raytracing.scene.HitResult; +import org.jetbrains.annotations.NotNull; + +public interface Texture { + default @NotNull Color get(@NotNull HitResult hit) { + return get(hit.u(), hit.v(), hit.position()); + } + + @NotNull Color get(double u, double v, @NotNull Vec3 p); +} diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java b/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java index 2d06ff0..c4a82a5 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java @@ -7,17 +7,18 @@ import org.jetbrains.annotations.NotNull; import java.util.Objects; public record HitResult( - double t, - @NotNull Vec3 position, - @NotNull Vec3 normal, - @NotNull Material material, - boolean frontFace + double t, @NotNull Vec3 position, @NotNull Vec3 normal, + @NotNull Material material, double u, double v, boolean frontFace ) implements Comparable { public HitResult { Objects.requireNonNull(position, "position"); normal = normal.unit(); } + public @NotNull HitResult withPositionAndNormal(@NotNull Vec3 position, @NotNull Vec3 normal) { + return new HitResult(t, position, normal, material, u, v, frontFace); + } + @Override public int compareTo(@NotNull HitResult o) { return Double.compare(t, o.t); diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/Scene.java b/src/main/java/eu/jonahbauer/raytracing/scene/Scene.java index a987a7a..79a5101 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/Scene.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/Scene.java @@ -2,7 +2,7 @@ package eu.jonahbauer.raytracing.scene; import eu.jonahbauer.raytracing.math.AABB; import eu.jonahbauer.raytracing.math.Ray; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.scene.util.HittableBinaryTree; import eu.jonahbauer.raytracing.scene.util.HittableCollection; import org.jetbrains.annotations.NotNull; diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/SkyBox.java b/src/main/java/eu/jonahbauer/raytracing/scene/SkyBox.java index c08dc4a..58cbf8e 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/SkyBox.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/SkyBox.java @@ -1,7 +1,7 @@ package eu.jonahbauer.raytracing.scene; import eu.jonahbauer.raytracing.math.Ray; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import org.jetbrains.annotations.NotNull; @FunctionalInterface diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/hittable2d/Hittable2D.java b/src/main/java/eu/jonahbauer/raytracing/scene/hittable2d/Hittable2D.java index df10e97..74bb50a 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/hittable2d/Hittable2D.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/hittable2d/Hittable2D.java @@ -51,7 +51,10 @@ public abstract class Hittable2D implements Hittable { if (!isInterior(alpha, beta)) return Optional.empty(); var frontFace = denominator < 0; - return Optional.of(new HitResult(t, position, frontFace ? normal : normal.neg(), material, frontFace)); + return Optional.of(new HitResult( + t, position, frontFace ? normal : normal.neg(), + material, alpha, beta, frontFace + )); } protected abstract boolean isInterior(double alpha, double beta); diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/ConstantMedium.java b/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/ConstantMedium.java index ba72b50..3c03d8a 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/ConstantMedium.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/ConstantMedium.java @@ -32,7 +32,7 @@ public record ConstantMedium(@NotNull Hittable boundary, double density, @NotNul if (hitDistance > distance) return Optional.empty(); var t = tmin + hitDistance / length; - return Optional.of(new HitResult(t, ray.at(t), Vec3.UNIT_X, material, true)); // arbitrary normal and frontFace + return Optional.of(new HitResult(t, ray.at(t), Vec3.UNIT_X, material, 0, 0, true)); // arbitrary normal and frontFace } @Override diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/Sphere.java b/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/Sphere.java index ea1b990..66437b1 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/Sphere.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/hittable3d/Sphere.java @@ -49,9 +49,19 @@ public final class Sphere implements Hittable { if (!range.surrounds(t)) return Optional.empty(); var position = ray.at(t); - var normal = position.minus(center); + var normal = position.minus(center).div(radius); var frontFace = normal.times(ray.direction()) < 0; - return Optional.of(new HitResult(t, position, frontFace ? normal : normal.times(-1), material, frontFace)); + + var theta = Math.acos(- normal.y()); + var phi = Math.atan2(- normal.z(), normal.x()) + Math.PI; + + var u = phi / (2 * Math.PI); + var v = theta / Math.PI; + + return Optional.of(new HitResult( + t, position, frontFace ? normal : normal.neg(), + material, u, v, frontFace + )); } @Override diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/transform/RotateY.java b/src/main/java/eu/jonahbauer/raytracing/scene/transform/RotateY.java index fa675c8..b6f8ffd 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/transform/RotateY.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/transform/RotateY.java @@ -79,7 +79,7 @@ public final class RotateY extends Transform { -sin * normal.x() + cos * normal.z() ); - return new HitResult(result.t(), newPosition, newNormal, result.material(), result.frontFace()); + return result.withPositionAndNormal(newPosition, newNormal); } @Override diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/transform/Translate.java b/src/main/java/eu/jonahbauer/raytracing/scene/transform/Translate.java index 0e72282..edc2921 100644 --- a/src/main/java/eu/jonahbauer/raytracing/scene/transform/Translate.java +++ b/src/main/java/eu/jonahbauer/raytracing/scene/transform/Translate.java @@ -29,13 +29,7 @@ public final class Translate extends Transform { @Override protected @NotNull HitResult transform(@NotNull HitResult result) { - return new HitResult( - result.t(), - result.position().plus(offset), - result.normal(), - result.material(), - result.frontFace() - ); + return result.withPositionAndNormal(result.position().plus(offset), result.normal()); } @Override diff --git a/src/test/java/eu/jonahbauer/raytracing/render/canvas/ImageTest.java b/src/test/java/eu/jonahbauer/raytracing/render/canvas/ImageTest.java index 9396f96..ed360e6 100644 --- a/src/test/java/eu/jonahbauer/raytracing/render/canvas/ImageTest.java +++ b/src/test/java/eu/jonahbauer/raytracing/render/canvas/ImageTest.java @@ -1,6 +1,6 @@ package eu.jonahbauer.raytracing.render.canvas; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.render.ImageFormat; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; diff --git a/src/test/java/eu/jonahbauer/raytracing/scene/hittable3d/SphereTest.java b/src/test/java/eu/jonahbauer/raytracing/scene/hittable3d/SphereTest.java index 0898d58..e4a4ac7 100644 --- a/src/test/java/eu/jonahbauer/raytracing/scene/hittable3d/SphereTest.java +++ b/src/test/java/eu/jonahbauer/raytracing/scene/hittable3d/SphereTest.java @@ -3,7 +3,7 @@ package eu.jonahbauer.raytracing.scene.hittable3d; import eu.jonahbauer.raytracing.math.Range; import eu.jonahbauer.raytracing.math.Ray; import eu.jonahbauer.raytracing.math.Vec3; -import eu.jonahbauer.raytracing.render.Color; +import eu.jonahbauer.raytracing.render.texture.Color; import eu.jonahbauer.raytracing.render.material.LambertianMaterial; import org.junit.jupiter.api.Test;