add metal
parent
2e5659a04a
commit
a41b14da48
@ -0,0 +1,23 @@
|
|||||||
|
package eu.jonahbauer.raytracing.material;
|
||||||
|
|
||||||
|
import eu.jonahbauer.raytracing.math.Ray;
|
||||||
|
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 MetallicMaterial(@NotNull Color albedo) implements Material {
|
||||||
|
public MetallicMaterial {
|
||||||
|
Objects.requireNonNull(albedo, "albedo");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<ScatterResult> scatter(@NotNull Ray ray, @NotNull HitResult hit) {
|
||||||
|
var direction = ray.direction();
|
||||||
|
var normal = hit.normal();
|
||||||
|
var newDirection = direction.minus(normal.times(2 * normal.times(direction)));
|
||||||
|
return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), albedo));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue