add dielectric material
parent
ca769c56b2
commit
088263b344
@ -0,0 +1,18 @@
|
|||||||
|
package eu.jonahbauer.raytracing.material;
|
||||||
|
|
||||||
|
import eu.jonahbauer.raytracing.math.Ray;
|
||||||
|
import eu.jonahbauer.raytracing.math.Vec3;
|
||||||
|
import eu.jonahbauer.raytracing.render.Color;
|
||||||
|
import eu.jonahbauer.raytracing.scene.HitResult;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public record DielectricMaterial(double refractionIndex) implements Material {
|
||||||
|
@Override
|
||||||
|
public @NotNull Optional<ScatterResult> scatter(@NotNull Ray ray, @NotNull HitResult hit) {
|
||||||
|
var ri = hit.frontFace() ? (1 / refractionIndex) : refractionIndex;
|
||||||
|
var refracted = Vec3.refract(ray.direction(), hit.normal(), ri);
|
||||||
|
return Optional.of(new ScatterResult(new Ray(hit.position(), refracted), Color.WHITE));
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue