|
|
@ -19,6 +19,7 @@ import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.nio.file.Path;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
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 {
|
|
|
@ -47,24 +48,25 @@ public class Main {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private static @NotNull Scene getScene() {
|
|
|
|
private static @NotNull Scene getScene() {
|
|
|
|
|
|
|
|
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))));
|
|
|
|
|
|
|
|
|
|
|
|
for (int a = -11; a < 11; a++) {
|
|
|
|
for (int a = -11; a < 11; a++) {
|
|
|
|
for (int b = -11; b < 11; b++) {
|
|
|
|
for (int b = -11; b < 11; b++) {
|
|
|
|
var center = new Vec3(a + 0.9 * Math.random(), 0.2, b + 0.9 * Math.random());
|
|
|
|
var center = new Vec3(a + 0.9 * rng.nextDouble(), 0.2, b + 0.9 * rng.nextDouble());
|
|
|
|
if (Vec3.distance(center, new Vec3(4, 0.2, 0)) <= 0.9) continue;
|
|
|
|
if (Vec3.distance(center, new Vec3(4, 0.2, 0)) <= 0.9) continue;
|
|
|
|
|
|
|
|
|
|
|
|
Material material;
|
|
|
|
Material material;
|
|
|
|
var rnd = Math.random();
|
|
|
|
var rnd = rng.nextDouble();
|
|
|
|
if (rnd < 0.8) {
|
|
|
|
if (rnd < 0.8) {
|
|
|
|
// diffuse
|
|
|
|
// diffuse
|
|
|
|
var albedo = Color.multiply(Color.random(), Color.random());
|
|
|
|
var albedo = Color.multiply(Color.random(rng), Color.random(rng));
|
|
|
|
material = new LambertianMaterial(albedo);
|
|
|
|
material = new LambertianMaterial(albedo);
|
|
|
|
} else if (rnd < 0.95) {
|
|
|
|
} else if (rnd < 0.95) {
|
|
|
|
// metal
|
|
|
|
// metal
|
|
|
|
var albedo = Color.random(0.5, 1.0);
|
|
|
|
var albedo = Color.random(rng, 0.5, 1.0);
|
|
|
|
var fuzz = Math.random() * 0.5;
|
|
|
|
var fuzz = rng.nextDouble() * 0.5;
|
|
|
|
material = new MetallicMaterial(albedo, fuzz);
|
|
|
|
material = new MetallicMaterial(albedo, fuzz);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// glass
|
|
|
|
// glass
|
|
|
|