|
|
@ -23,6 +23,7 @@ public final class Camera {
|
|
|
|
|
|
|
|
|
|
|
|
// antialiasing
|
|
|
|
// antialiasing
|
|
|
|
private final int samplesPerPixel = 100;
|
|
|
|
private final int samplesPerPixel = 100;
|
|
|
|
|
|
|
|
private final int maxDepth = 10;
|
|
|
|
|
|
|
|
|
|
|
|
// internal properties
|
|
|
|
// internal properties
|
|
|
|
private final @NotNull Vec3 pixelU;
|
|
|
|
private final @NotNull Vec3 pixelU;
|
|
|
@ -123,10 +124,23 @@ public final class Camera {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private @NotNull Color getColor(@NotNull Scene scene, @NotNull Ray ray) {
|
|
|
|
private @NotNull Color getColor(@NotNull Scene scene, @NotNull Ray ray) {
|
|
|
|
var result = scene.hit(ray, Range.NON_NEGATIVE);
|
|
|
|
return getColor(scene, ray, maxDepth);
|
|
|
|
if (result.isPresent()) {
|
|
|
|
}
|
|
|
|
var normal = result.get().normal();
|
|
|
|
|
|
|
|
return getNormalColor(normal);
|
|
|
|
private @NotNull Color getColor(@NotNull Scene scene, @NotNull Ray ray, int depth) {
|
|
|
|
|
|
|
|
if (depth <= 0) return Color.BLACK;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var optional = scene.hit(ray, Range.NON_NEGATIVE);
|
|
|
|
|
|
|
|
if (optional.isPresent()) {
|
|
|
|
|
|
|
|
var result = optional.get();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var newDirection = Vec3.random(true);
|
|
|
|
|
|
|
|
if (result.normal().times(newDirection) < 0) {
|
|
|
|
|
|
|
|
newDirection = newDirection.times(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
var scattered = new Ray(result.position(), newDirection);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return Color.lerp(Color.BLACK, getColor(scene, scattered, depth - 1), 0.5);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return getSkyboxColor(ray);
|
|
|
|
return getSkyboxColor(ray);
|
|
|
|
}
|
|
|
|
}
|
|
|
|