This repository has been archived on 2024-01-12. You can view files and clone it, but cannot push or open issues or pull requests.
jpath/src/main/java/pathtracing/bdf/BTDF.java

21 lines
706 B
Java

package pathtracing.bdf;
import basics.math.algebra.Basis;
import basics.math.algebra.Vector;
public class BTDF {
public static Vector sampleDirection(Vector incoming, Vector normal, double roughness, double ior) {
Vector hemisphereSample = BDF.cosineHemisphere(roughness);
var direction = Vector.refract(normal, incoming, ior)
.lerp(normal.negate(), roughness);
var orthnormalBasis = Basis.constructOrthonormalBasis(direction);
return orthnormalBasis.vectors[0].scale(hemisphereSample.z)
.add(orthnormalBasis.vectors[1].scale(hemisphereSample.x))
.add(orthnormalBasis.vectors[2].scale(hemisphereSample.y));
}
}