this
texture for a hit}
+ */
default @NotNull Color get(@NotNull HitResult hit) {
return get(hit.u(), hit.v(), hit.position());
}
+ /**
+ * {@return the color of this
texture at the specified position}
+ * @param u the texture u coordinate
+ * @param v the texture v coordinate
+ * @param p the position
+ */
@NotNull Color get(double u, double v, @NotNull Vec3 p);
+ /**
+ * Returns whether {@link #get(double, double, Vec3)} uses the {@code u} and/or {@code v} parameters.
+ * When a texture indicates that the {@code u} and {@code v} coordinates are not required, the calculation may be
+ * skipped and {@link Double#NaN} will be passed.
+ * @return whether {@link #get(double, double, Vec3)} uses the {@code u} and/or {@code v} parameters
+ */
default boolean isUVRequired() {
return true;
}
diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java b/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java
index cf21baf..83f4a00 100644
--- a/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java
+++ b/src/main/java/eu/jonahbauer/raytracing/scene/HitResult.java
@@ -1,11 +1,25 @@
package eu.jonahbauer.raytracing.scene;
+import eu.jonahbauer.raytracing.math.Range;
+import eu.jonahbauer.raytracing.math.Ray;
import eu.jonahbauer.raytracing.math.Vec3;
import eu.jonahbauer.raytracing.render.material.Material;
+import eu.jonahbauer.raytracing.render.texture.Texture;
import org.jetbrains.annotations.NotNull;
import java.util.Objects;
+/**
+ * The result of a {@linkplain Hittable#hit(Ray, Range) hit}.
+ * @param t the {@code t} value at which the hit occurs
+ * @param position the position of the hit
+ * @param normal the surface normal at the hit position
+ * @param target the hit target (for debug purposes only)
+ * @param material the material of the surface
+ * @param u the texture u coordinate (or {@code Double.NaN} if the {@linkplain Material#texture() material's texture} does {@linkplain Texture#isUVRequired() not depend} on the uv-coordinates)
+ * @param v the texture v coordinate (or {@code Double.NaN} if the {@linkplain Material#texture() material's texture} does {@linkplain Texture#isUVRequired() not depend} on the uv-coordinates)
+ * @param isFrontFace whether the front or the back of the surface was it
+ */
public record HitResult(
double t, @NotNull Vec3 position, @NotNull Vec3 normal, @NotNull Hittable target,
@NotNull Material material, double u, double v, boolean isFrontFace
diff --git a/src/main/java/eu/jonahbauer/raytracing/scene/Hittable.java b/src/main/java/eu/jonahbauer/raytracing/scene/Hittable.java
index 6f841a1..6df3617 100644
--- a/src/main/java/eu/jonahbauer/raytracing/scene/Hittable.java
+++ b/src/main/java/eu/jonahbauer/raytracing/scene/Hittable.java
@@ -13,9 +13,22 @@ import java.util.Optional;
public interface Hittable {
/**
- * {@return the value t
such that ray.at(t)
is the intersection of this shaped closest to
- * the ray origin, or Double.NaN
if the ray does not intersect this shape}
+ * @see #hit(Ray, Range)
+ */
+ default @NotNull Optional
+ * The second parameter {@code range} allows the implementation to skip unnecessary calculations if it can
+ * determine that a hit (if any) will fall outside the valid range of {@code t}s. The returned hit may still be
+ * outside the valid range and has to be checked by the caller.
* @param ray a ray
+ * @param range the range of valid {@code t}s
+ * @return the result of the hit test, containing (among others) the value {@code t} such that {@code ray.at(t)} is
+ * a point on {@code this} hittable
*/
@NotNull Optional