add color to DielectricMaterial
This commit is contained in:
parent
5033cf78c6
commit
235a61f354
@ -31,4 +31,12 @@ java -jar raytracing.jar --samples 50000 --height 1200 CORNELL
|
|||||||
|
|
||||||
```
|
```
|
||||||
java -jar raytracing.jar --samples 50000 --height 600 CORNELL_SMOKE
|
java -jar raytracing.jar --samples 50000 --height 600 CORNELL_SMOKE
|
||||||
|
```
|
||||||
|
|
||||||
|
### diagramm
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
```
|
||||||
|
java -jar raytracing.jar --samples 1000 --height 1080 DIAGRAMM
|
||||||
```
|
```
|
BIN
docs/diagramm.png
Normal file
BIN
docs/diagramm.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 2.3 MiB |
@ -30,6 +30,7 @@ public class Examples {
|
|||||||
register("LIGHT", Examples::getLight);
|
register("LIGHT", Examples::getLight);
|
||||||
register("CORNELL", Examples::getCornellBox);
|
register("CORNELL", Examples::getCornellBox);
|
||||||
register("CORNELL_SMOKE", Examples::getCornellBoxSmoke);
|
register("CORNELL_SMOKE", Examples::getCornellBoxSmoke);
|
||||||
|
register("DIAGRAMM", Examples::getDiagramm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static @NotNull IntFunction<Example> getByName(@NotNull String name) {
|
public static @NotNull IntFunction<Example> getByName(@NotNull String name) {
|
||||||
@ -202,6 +203,54 @@ public class Examples {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static @NotNull Example getDiagramm(int height) {
|
||||||
|
if (height <= 0) height = 450;
|
||||||
|
|
||||||
|
record Partei(String name, Color color, double stimmen) { }
|
||||||
|
var data = List.of(
|
||||||
|
new Partei("CDU", new Color(0x00, 0x4B, 0x76), 18.9),
|
||||||
|
new Partei("SPD", new Color(0xC0, 0x00, 0x3C), 25.7),
|
||||||
|
new Partei("AfD", new Color(0x80, 0xCD, 0xEC), 10.3),
|
||||||
|
new Partei("FDP", new Color(0xF7, 0xBB, 0x3D), 11.5),
|
||||||
|
new Partei("DIE LINKE", new Color(0x5F, 0x31, 0x6E), 4.9),
|
||||||
|
new Partei("GRÜNE", new Color(0x00, 0x85, 0x4A), 14.8),
|
||||||
|
new Partei("CSU", new Color(0x00, 0x77, 0xB6), 5.2)
|
||||||
|
);
|
||||||
|
var white = new LambertianMaterial(new Color(.99, .99, .99));
|
||||||
|
|
||||||
|
var count = data.size();
|
||||||
|
var size = 75d;
|
||||||
|
var spacing = 50d;
|
||||||
|
|
||||||
|
var x = (count + 1) * spacing + count * size + 1000;
|
||||||
|
var y = 500 + 1000;
|
||||||
|
var z = 2 * spacing + size + 1000;
|
||||||
|
|
||||||
|
var objects = new ArrayList<Hittable>();
|
||||||
|
objects.add(new Parallelogram(new Vec3(0, 0, 0), new Vec3(x, 0, 0), new Vec3(0, y, 0), white));
|
||||||
|
objects.add(new Parallelogram(new Vec3(0, 0, 0), new Vec3(0, 0, z), new Vec3(x, 0, 0), white));
|
||||||
|
objects.add(new Parallelogram(new Vec3(0, 0, 0), new Vec3(0, y, 0), new Vec3(0, 0, z), white));
|
||||||
|
|
||||||
|
for (int i = 0; i < data.size(); i++) {
|
||||||
|
var partei = data.get(i);
|
||||||
|
objects.add(Hittables.box(
|
||||||
|
new Vec3((i + 1) * spacing + i * size, 0, spacing),
|
||||||
|
new Vec3((i + 1) * spacing + (i + 1) * size, partei.stimmen() * 15, spacing + size),
|
||||||
|
new DielectricMaterial(1.5, partei.color())
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
return new Example(
|
||||||
|
new Scene(new Color(1.25, 1.25, 1.25), objects),
|
||||||
|
SimpleCamera.builder()
|
||||||
|
.withImage(height * 16 / 9, height)
|
||||||
|
.withPosition(new Vec3(700, 250, 800))
|
||||||
|
.withTarget(new Vec3(500, 200, 0))
|
||||||
|
.withFieldOfView(Math.toRadians(40))
|
||||||
|
.build()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
private static @NotNull SkyBox getSkyBox() {
|
private static @NotNull SkyBox getSkyBox() {
|
||||||
return SkyBox.gradient(new Color(0.5, 0.7, 1.0), Color.WHITE);
|
return SkyBox.gradient(new Color(0.5, 0.7, 1.0), Color.WHITE);
|
||||||
}
|
}
|
||||||
|
@ -6,9 +6,18 @@ import eu.jonahbauer.raytracing.render.Color;
|
|||||||
import eu.jonahbauer.raytracing.scene.HitResult;
|
import eu.jonahbauer.raytracing.scene.HitResult;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public record DielectricMaterial(double refractionIndex) implements Material {
|
public record DielectricMaterial(double refractionIndex, @NotNull Color albedo) implements Material {
|
||||||
|
public DielectricMaterial(double refractionIndex) {
|
||||||
|
this(refractionIndex, Color.WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public DielectricMaterial {
|
||||||
|
Objects.requireNonNull(albedo, "albedo");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public @NotNull Optional<ScatterResult> scatter(@NotNull Ray ray, @NotNull HitResult hit) {
|
public @NotNull Optional<ScatterResult> scatter(@NotNull Ray ray, @NotNull HitResult hit) {
|
||||||
var ri = hit.frontFace() ? (1 / refractionIndex) : refractionIndex;
|
var ri = hit.frontFace() ? (1 / refractionIndex) : refractionIndex;
|
||||||
@ -20,7 +29,7 @@ public record DielectricMaterial(double refractionIndex) implements Material {
|
|||||||
var newDirection = (reflect ? Optional.<Vec3>empty() : Vec3.refract(ray.direction(), hit.normal(), ri))
|
var newDirection = (reflect ? Optional.<Vec3>empty() : Vec3.refract(ray.direction(), hit.normal(), ri))
|
||||||
.orElseGet(() -> Vec3.reflect(ray.direction(), hit.normal()));
|
.orElseGet(() -> Vec3.reflect(ray.direction(), hit.normal()));
|
||||||
|
|
||||||
return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), Color.WHITE));
|
return Optional.of(new ScatterResult(new Ray(hit.position(), newDirection), albedo));
|
||||||
}
|
}
|
||||||
|
|
||||||
private double reflectance(double cos) {
|
private double reflectance(double cos) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user