21 lines
706 B
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));
|
|
}
|
|
}
|