Create SpectrumTest scene
This commit is contained in:
parent
f2e20940bc
commit
03f6f14c7c
|
@ -24,7 +24,7 @@ public class SplineSpectrum implements Spectrum {
|
||||||
double h = samples[i].getKey() - samples[i - 1].getKey();
|
double h = samples[i].getKey() - samples[i - 1].getKey();
|
||||||
if (h <= 0.0)
|
if (h <= 0.0)
|
||||||
throw new IllegalArgumentException("Samples must have strictly increasing x coordinates.");
|
throw new IllegalArgumentException("Samples must have strictly increasing x coordinates.");
|
||||||
d[i] = (samples[i].getValue() - samples[i - 1].getValue());
|
d[i - 1] = (samples[i].getValue() - samples[i - 1].getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
m[0] = d[0];
|
m[0] = d[0];
|
||||||
|
@ -56,14 +56,13 @@ public class SplineSpectrum implements Spectrum {
|
||||||
return samples[n-1].getValue();
|
return samples[n-1].getValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
Double.valueOf(wavelength);
|
|
||||||
int i = Arrays.binarySearch(samples,
|
int i = Arrays.binarySearch(samples,
|
||||||
new Pair<Double, Double>(Double.valueOf(wavelength), null),
|
new Pair<Double, Double>(Double.valueOf(wavelength), null),
|
||||||
new DoublePairKeyComparator());
|
new DoublePairKeyComparator());
|
||||||
if (i >= 0) {
|
if (i >= 0) {
|
||||||
return samples[i].getValue();
|
return samples[i].getValue();
|
||||||
}
|
}
|
||||||
i = -(i+1);
|
i = -(i+2); // Invert negative result and get index of previous element
|
||||||
double h = samples[i+1].getKey() - samples[i].getKey();
|
double h = samples[i+1].getKey() - samples[i].getKey();
|
||||||
double t = (wavelength - samples[i].getKey()) / h;
|
double t = (wavelength - samples[i].getKey()) / h;
|
||||||
return (samples[i].getValue() * (1 + 2*t) + h*m[i]*t) * (1 - t) * (1 - t)
|
return (samples[i].getValue() * (1 + 2*t) + h*m[i]*t) * (1 - t) * (1 - t)
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package xyz.marsavic.gfxlab.graphics3d;
|
package xyz.marsavic.gfxlab.graphics3d;
|
||||||
|
|
||||||
import xyz.marsavic.gfxlab.Color;
|
|
||||||
import xyz.marsavic.gfxlab.Spectrum;
|
import xyz.marsavic.gfxlab.Spectrum;
|
||||||
import xyz.marsavic.gfxlab.Vec3;
|
import xyz.marsavic.gfxlab.Vec3;
|
||||||
|
|
||||||
|
@ -10,12 +9,12 @@ public record Light(
|
||||||
Spectrum s
|
Spectrum s
|
||||||
) {
|
) {
|
||||||
|
|
||||||
public static Light pc(Vec3 p, Spectrum s) {
|
public static Light ps(Vec3 p, Spectrum s) {
|
||||||
return new Light(p, s);
|
return new Light(p, s);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Light p(Vec3 p) {
|
public static Light p(Vec3 p) {
|
||||||
return pc(p, wavelength -> 0);
|
return ps(p, wavelength -> 1.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,11 +30,11 @@ public record Material(
|
||||||
public static final Material MATTE = matte();
|
public static final Material MATTE = matte();
|
||||||
|
|
||||||
public static final Material MIRROR = BLACK.reflective(new SplineSpectrum(new Pair[]{
|
public static final Material MIRROR = BLACK.reflective(new SplineSpectrum(new Pair[]{
|
||||||
new Pair<Double, Double>(248.0, 92.6),
|
new Pair<Double, Double>(248.0, 0.926),
|
||||||
new Pair<Double, Double>(400.0, 92.0),
|
new Pair<Double, Double>(400.0, 0.920),
|
||||||
new Pair<Double, Double>(532.0, 91.6),
|
new Pair<Double, Double>(532.0, 0.916),
|
||||||
new Pair<Double, Double>(633.0, 90.7),
|
new Pair<Double, Double>(633.0, 0.907),
|
||||||
new Pair<Double, Double>(800.0, 86.8)
|
new Pair<Double, Double>(800.0, 0.868)
|
||||||
}));
|
}));
|
||||||
public static final Material GLASS = BLACK.refractive(w -> 1.0)
|
public static final Material GLASS = BLACK.refractive(w -> 1.0)
|
||||||
.refractiveIndex(w -> 1.6 + (w-400)/(800-400) * (1.55 - 1.6)); /* Made to roughly resemble refractive index
|
.refractiveIndex(w -> 1.6 + (w-400)/(800-400) * (1.55 - 1.6)); /* Made to roughly resemble refractive index
|
||||||
|
|
|
@ -7,9 +7,20 @@ import xyz.marsavic.gfxlab.graphics3d.*;
|
||||||
public class RayTracerSimple extends RayTracer {
|
public class RayTracerSimple extends RayTracer {
|
||||||
|
|
||||||
private static final int spectrumSamples = 20;
|
private static final int spectrumSamples = 20;
|
||||||
static final double minWavelength = 380;
|
private static final double minWavelength = 380;
|
||||||
static final double maxWavelength = 780;
|
private static final double maxWavelength = 780;
|
||||||
private static final double EPSILON = 1e-9;
|
private static final double EPSILON = 1e-9;
|
||||||
|
private static final double maxXYZ;
|
||||||
|
|
||||||
|
static {
|
||||||
|
double max = 0.0;
|
||||||
|
for (int i = 0; i < spectrumSamples; i++) {
|
||||||
|
double wavelength = minWavelength + (((double) i)/spectrumSamples)*(maxWavelength - minWavelength);
|
||||||
|
max += Xyz.x[(int) wavelength] + Xyz.y[(int) wavelength] + Xyz.z[(int) wavelength];
|
||||||
|
}
|
||||||
|
maxXYZ = max;
|
||||||
|
}
|
||||||
|
|
||||||
public RayTracerSimple(Scene scene, Camera camera) {
|
public RayTracerSimple(Scene scene, Camera camera) {
|
||||||
super(scene, camera);
|
super(scene, camera);
|
||||||
}
|
}
|
||||||
|
@ -29,7 +40,10 @@ public class RayTracerSimple extends RayTracer {
|
||||||
y += intensity * Xyz.y[(int) wavelength];
|
y += intensity * Xyz.y[(int) wavelength];
|
||||||
z += intensity * Xyz.z[(int) wavelength];
|
z += intensity * Xyz.z[(int) wavelength];
|
||||||
}
|
}
|
||||||
return Color.xyz(x,y,z);
|
|
||||||
|
Color result = Color.xyz(x,y,z);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected double sample(Ray ray, int depthRemaining, double wavelength) {
|
protected double sample(Ray ray, int depthRemaining, double wavelength) {
|
||||||
|
|
|
@ -22,15 +22,18 @@ public class SpectrumTest extends Scene.Base {
|
||||||
|
|
||||||
public SpectrumTest() {
|
public SpectrumTest() {
|
||||||
var materialUVWalls = Grid.standard(Spectrum.WHITE);
|
var materialUVWalls = Grid.standard(Spectrum.WHITE);
|
||||||
var materialUVWallsL = Grid.standard(new SplineSpectrum(new Pair[]{
|
SplineSpectrum s;
|
||||||
|
var materialUVWallsL = Grid.standard(s = new SplineSpectrum(new Pair[]{
|
||||||
new Pair<Double, Double>(450.0, 0.2),
|
new Pair<Double, Double>(450.0, 0.2),
|
||||||
|
new Pair<Double, Double>(500.0, 0.27),
|
||||||
new Pair<Double, Double>(550.0, 0.35),
|
new Pair<Double, Double>(550.0, 0.35),
|
||||||
new Pair<Double, Double>(650.0, 0.8),
|
new Pair<Double, Double>(700.0, 0.8),
|
||||||
}));
|
}));
|
||||||
var materialUVWallsR = Grid.standard(new SplineSpectrum(new Pair[]{
|
var materialUVWallsR = Grid.standard(new SplineSpectrum(new Pair[]{
|
||||||
new Pair<Double, Double>(450.0, 0.3),
|
new Pair<Double, Double>(450.0, 0.1),
|
||||||
new Pair<Double, Double>(550.0, 0.75),
|
new Pair<Double, Double>(500.0, 0.25),
|
||||||
new Pair<Double, Double>(650.0, 0.3),
|
new Pair<Double, Double>(550.0, 0.2),
|
||||||
|
new Pair<Double, Double>(650.0, 0.1),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
Collection<Solid> solids = new ArrayList<>();
|
Collection<Solid> solids = new ArrayList<>();
|
||||||
|
@ -41,23 +44,17 @@ public class SpectrumTest extends Scene.Base {
|
||||||
HalfSpace.pn(Vec3.xyz( 0, 1, 0), Vec3.xyz( 0, -1, 0), materialUVWalls),
|
HalfSpace.pn(Vec3.xyz( 0, 1, 0), Vec3.xyz( 0, -1, 0), materialUVWalls),
|
||||||
HalfSpace.pn(Vec3.xyz( 0, 0, 1), Vec3.xyz( 0, 0, -1), materialUVWalls),
|
HalfSpace.pn(Vec3.xyz( 0, 0, 1), Vec3.xyz( 0, 0, -1), materialUVWalls),
|
||||||
|
|
||||||
Ball.cr(Vec3.xyz(-0.3, 0.3, 0.0), 0.4, uv -> Material.GLASS.refractive(new SplineSpectrum(
|
Ball.cr(Vec3.xyz(-0.3, 0.3, 0.0), 0.4, uv -> Material.GLASS.refractive(w->0.5)),
|
||||||
new Pair[]{
|
Ball.cr(Vec3.xyz( 0.4, -0.4, 0.0), 0.4, uv -> Material.GLASS)
|
||||||
new Pair<Double, Double>(450.0, 0.8),
|
// Ball.cr(Vec3.xyz(-0.3, -0.4, -0.6), 0.4, uv -> Material.GLASS.refractiveIndex(w -> 2.5)),
|
||||||
new Pair<Double, Double>(550.0, 0.35),
|
// Ball.cr(Vec3.xyz( 0.4, 0.3, 0.6), 0.4, uv -> Material.GLASS.refractiveIndex(w -> 0.6))
|
||||||
new Pair<Double, Double>(650.0, 0.2),
|
|
||||||
}
|
|
||||||
))),
|
|
||||||
Ball.cr(Vec3.xyz( 0.4, -0.4, 0.0), 0.4, uv -> Material.GLASS),
|
|
||||||
Ball.cr(Vec3.xyz(-0.3, -0.4, -0.6), 0.4, uv -> Material.GLASS.refractiveIndex(w -> 2.5)),
|
|
||||||
Ball.cr(Vec3.xyz( 0.4, 0.3, 0.6), 0.4, uv -> Material.GLASS.refractiveIndex(w -> 0.6))
|
|
||||||
);
|
);
|
||||||
|
|
||||||
Collections.addAll(lights,
|
Collections.addAll(lights,
|
||||||
Light.pc(Vec3.xyz(-0.7, 0.7, -0.7), Spectrum.WHITE),
|
Light.ps(Vec3.xyz(-0.7, 0.7, -0.7), Spectrum.WHITE),
|
||||||
Light.pc(Vec3.xyz(-0.7, 0.7, 0.7), Spectrum.WHITE),
|
Light.ps(Vec3.xyz(-0.7, 0.7, 0.7), Spectrum.WHITE),
|
||||||
Light.pc(Vec3.xyz( 0.7, 0.7, -0.7), Spectrum.WHITE),
|
Light.ps(Vec3.xyz( 0.7, 0.7, -0.7), Spectrum.WHITE),
|
||||||
Light.pc(Vec3.xyz( 0.7, 0.7, 0.7), Spectrum.WHITE)
|
Light.ps(Vec3.xyz( 0.7, 0.7, 0.7), Spectrum.WHITE)
|
||||||
);
|
);
|
||||||
|
|
||||||
solid = Group.of(solids);
|
solid = Group.of(solids);
|
||||||
|
|
Loading…
Reference in a new issue