|
|
@ -1,5 +1,6 @@
|
|
|
|
package eu.jonahbauer.raytracing;
|
|
|
|
package eu.jonahbauer.raytracing;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import eu.jonahbauer.raytracing.render.camera.Camera;
|
|
|
|
import eu.jonahbauer.raytracing.render.material.DielectricMaterial;
|
|
|
|
import eu.jonahbauer.raytracing.render.material.DielectricMaterial;
|
|
|
|
import eu.jonahbauer.raytracing.render.material.LambertianMaterial;
|
|
|
|
import eu.jonahbauer.raytracing.render.material.LambertianMaterial;
|
|
|
|
import eu.jonahbauer.raytracing.render.material.Material;
|
|
|
|
import eu.jonahbauer.raytracing.render.material.Material;
|
|
|
@ -12,8 +13,11 @@ import eu.jonahbauer.raytracing.render.canvas.LiveCanvas;
|
|
|
|
import eu.jonahbauer.raytracing.render.canvas.Image;
|
|
|
|
import eu.jonahbauer.raytracing.render.canvas.Image;
|
|
|
|
import eu.jonahbauer.raytracing.render.renderer.SimpleRenderer;
|
|
|
|
import eu.jonahbauer.raytracing.render.renderer.SimpleRenderer;
|
|
|
|
import eu.jonahbauer.raytracing.scene.Hittable;
|
|
|
|
import eu.jonahbauer.raytracing.scene.Hittable;
|
|
|
|
|
|
|
|
import eu.jonahbauer.raytracing.scene.flat.Ellipse;
|
|
|
|
|
|
|
|
import eu.jonahbauer.raytracing.scene.flat.Parallelogram;
|
|
|
|
import eu.jonahbauer.raytracing.scene.Scene;
|
|
|
|
import eu.jonahbauer.raytracing.scene.Scene;
|
|
|
|
import eu.jonahbauer.raytracing.scene.Sphere;
|
|
|
|
import eu.jonahbauer.raytracing.scene.Sphere;
|
|
|
|
|
|
|
|
import eu.jonahbauer.raytracing.scene.flat.Triangle;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
|
|
|
|
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
@ -24,16 +28,9 @@ import java.util.Random;
|
|
|
|
|
|
|
|
|
|
|
|
public class Main {
|
|
|
|
public class Main {
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
public static void main(String[] args) throws IOException {
|
|
|
|
var scene = getScene();
|
|
|
|
var example = getSquares();
|
|
|
|
|
|
|
|
var scene = example.scene();
|
|
|
|
var camera = SimpleCamera.builder()
|
|
|
|
var camera = example.camera();
|
|
|
|
.withImage(1200, 675)
|
|
|
|
|
|
|
|
.withPosition(new Vec3(13, 2, 3))
|
|
|
|
|
|
|
|
.withTarget(new Vec3(0, 0, 0))
|
|
|
|
|
|
|
|
.withFieldOfView(Math.toRadians(20))
|
|
|
|
|
|
|
|
.withFocusDistance(10.0)
|
|
|
|
|
|
|
|
.withBlurAngle(Math.toRadians(0.6))
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var renderer = SimpleRenderer.builder()
|
|
|
|
var renderer = SimpleRenderer.builder()
|
|
|
|
.withSamplesPerPixel(500)
|
|
|
|
.withSamplesPerPixel(500)
|
|
|
@ -51,7 +48,7 @@ public class Main {
|
|
|
|
ImageFormat.PNG.write(image, Path.of("scene-" + System.currentTimeMillis() + ".png"));
|
|
|
|
ImageFormat.PNG.write(image, Path.of("scene-" + System.currentTimeMillis() + ".png"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static @NotNull Scene getScene() {
|
|
|
|
private static @NotNull Example getSpheres() {
|
|
|
|
var rng = new Random(1);
|
|
|
|
var rng = new Random(1);
|
|
|
|
var objects = new ArrayList<Hittable>();
|
|
|
|
var objects = new ArrayList<Hittable>();
|
|
|
|
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 Color(0.5, 0.5, 0.5))));
|
|
|
@ -85,7 +82,34 @@ public class Main {
|
|
|
|
objects.add(new Sphere(new Vec3(-4, 1, 0), 1.0, new LambertianMaterial(new Color(0.4, 0.2, 0.1))));
|
|
|
|
objects.add(new Sphere(new Vec3(-4, 1, 0), 1.0, new LambertianMaterial(new Color(0.4, 0.2, 0.1))));
|
|
|
|
objects.add(new Sphere(new Vec3(4, 1, 0), 1.0, new MetallicMaterial(new Color(0.7, 0.6, 0.5))));
|
|
|
|
objects.add(new Sphere(new Vec3(4, 1, 0), 1.0, new MetallicMaterial(new Color(0.7, 0.6, 0.5))));
|
|
|
|
|
|
|
|
|
|
|
|
return new Scene(objects);
|
|
|
|
var camera = SimpleCamera.builder()
|
|
|
|
|
|
|
|
.withImage(1200, 675)
|
|
|
|
|
|
|
|
.withPosition(new Vec3(13, 2, 3))
|
|
|
|
|
|
|
|
.withTarget(new Vec3(0, 0, 0))
|
|
|
|
|
|
|
|
.withFieldOfView(Math.toRadians(20))
|
|
|
|
|
|
|
|
.withFocusDistance(10.0)
|
|
|
|
|
|
|
|
.withBlurAngle(Math.toRadians(0.6))
|
|
|
|
|
|
|
|
.build();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return new Example(new Scene(objects), camera);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private static @NotNull Example getSquares() {
|
|
|
|
|
|
|
|
return new Example(
|
|
|
|
|
|
|
|
new Scene(List.of(
|
|
|
|
|
|
|
|
new Parallelogram(new Vec3(-3, -2, 5), new Vec3(0, 0, -4), new Vec3(0, 4, 0), new LambertianMaterial(new Color(1.0, 0.2, 0.2))),
|
|
|
|
|
|
|
|
new Parallelogram(new Vec3(-2, -2, 0), new Vec3(4, 0, 0), new Vec3(0, 4, 0), new LambertianMaterial(new Color(0.2, 1.0, 0.2))),
|
|
|
|
|
|
|
|
new Parallelogram(new Vec3(3, -2, 1), new Vec3(0, 0, 4), new Vec3(0, 4, 0), new LambertianMaterial(new Color(0.2, 0.2, 1.0))),
|
|
|
|
|
|
|
|
new Parallelogram(new Vec3(-2, 3, 1), new Vec3(4, 0, 0), new Vec3(0, 0, 4), new LambertianMaterial(new Color(1.0, 0.5, 0.0))),
|
|
|
|
|
|
|
|
new Parallelogram(new Vec3(-2, -3, 5), new Vec3(4, 0, 0), new Vec3(0, 0, -4), new LambertianMaterial(new Color(0.2, 0.8, 0.8)))
|
|
|
|
|
|
|
|
)),
|
|
|
|
|
|
|
|
SimpleCamera.builder()
|
|
|
|
|
|
|
|
.withImage(400, 400)
|
|
|
|
|
|
|
|
.withFieldOfView(Math.toRadians(80))
|
|
|
|
|
|
|
|
.withPosition(new Vec3(0, 0, 9))
|
|
|
|
|
|
|
|
.withTarget(new Vec3(0, 0, 0))
|
|
|
|
|
|
|
|
.build()
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static @NotNull Scene getSimpleScene() {
|
|
|
|
private static @NotNull Scene getSimpleScene() {
|
|
|
@ -97,4 +121,6 @@ public class Main {
|
|
|
|
new Sphere(new Vec3(1.0, 0, -1.2), 0.5, new MetallicMaterial(new Color(0.8, 0.6, 0.2), 0.0))
|
|
|
|
new Sphere(new Vec3(1.0, 0, -1.2), 0.5, new MetallicMaterial(new Color(0.8, 0.6, 0.2), 0.0))
|
|
|
|
));
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private record Example(@NotNull Scene scene, @NotNull Camera camera) {}
|
|
|
|
}
|
|
|
|
}
|