package pathtracing.bdf;

import basics.math.algebra.Basis;
import basics.math.algebra.Vector;

public class BRDF {

    public static Vector sampleDirection(Vector incoming, Vector normal, double roughness) {
        Vector hemisphereSample = BDF.cosineHemisphere(roughness);

        var direction = incoming.reflect(normal).lerp(normal, 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));
    }
}
