add texture support
parent
2c28b10a6e
commit
7c0bc68ab2
@ -0,0 +1,17 @@
|
||||
package eu.jonahbauer.raytracing.render.texture;
|
||||
|
||||
import eu.jonahbauer.raytracing.math.Vec3;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public record CheckerTexture(double scale, @NotNull Texture even, @NotNull Texture odd) implements Texture {
|
||||
|
||||
|
||||
@Override
|
||||
public @NotNull Color get(double u, double v, @NotNull Vec3 p) {
|
||||
var x = (int) Math.floor(p.x() / scale);
|
||||
var y = (int) Math.floor(p.y() / scale);
|
||||
var z = (int) Math.floor(p.z() / scale);
|
||||
var even = (x + y + z) % 2 == 0;
|
||||
return even ? even().get(u, v, p) : odd().get(u, v, p);
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package eu.jonahbauer.raytracing.render.texture;
|
||||
|
||||
import eu.jonahbauer.raytracing.math.Vec3;
|
||||
import eu.jonahbauer.raytracing.scene.HitResult;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface Texture {
|
||||
default @NotNull Color get(@NotNull HitResult hit) {
|
||||
return get(hit.u(), hit.v(), hit.position());
|
||||
}
|
||||
|
||||
@NotNull Color get(double u, double v, @NotNull Vec3 p);
|
||||
}
|
Loading…
Reference in New Issue