add metal

main
jbb01 6 months ago
parent 2e5659a04a
commit a41b14da48

@ -1,6 +1,7 @@
package eu.jonahbauer.raytracing;
import eu.jonahbauer.raytracing.material.LambertianMaterial;
import eu.jonahbauer.raytracing.material.MetallicMaterial;
import eu.jonahbauer.raytracing.render.Camera;
import eu.jonahbauer.raytracing.render.Color;
import eu.jonahbauer.raytracing.render.ImageFormat;
@ -13,8 +14,10 @@ import java.nio.file.Path;
public class Main {
public static void main(String[] args) throws IOException {
var scene = new Scene(
new Sphere(0, 0, 1, 0.5, new LambertianMaterial(Color.RED)),
new Sphere(0, -100.5, 1, 100, new LambertianMaterial(Color.BLUE))
new Sphere(0, -100.5, 1, 100, new LambertianMaterial(new Color(0.8, 0.8, 0.0))),
new Sphere(0, 0, 1.2, 0.5, new LambertianMaterial(new Color(0.1, 0.2, 0.5))),
new Sphere(-1, 0, 1, 0.5, new MetallicMaterial(new Color(0.8, 0.8, 0.8))),
new Sphere(1, 0, 1, 0.5, new MetallicMaterial(new Color(0.8, 0.6, 0.2)))
);
var camera = new Camera(512, 2, 16 / 9d);

@ -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…
Cancel
Save