* @see ca.eandb.jmist.framework.material.AbstractMaterial#getScatteringPDF(ca.eandb.jmist.framework.SurfacePoint, ca.eandb.jmist.math.Vector3, ca.eandb.jmist.math.Vector3, boolean, ca.eandb.jmist.framework.color.WavelengthPacket)
*/
@Override
public double getScatteringPDF(SurfacePoint x, Vector3 in, Vector3 out,
boolean adjoint, WavelengthPacket lambda) {
Vector3 n = x.getNormal();
double ndoti = -n.dot(in);
double ndoto = n.dot(out);
boolean reflected = (ndoti / ndoto) > 0.0;
if (reflected) {
Vector3 hr = out.minus(in).times(Math.signum(ndoti)).unit();
hr = hr.dot(n) > 0.0 ? hr : hr.opposite();
double partial = 1.0 / (4.0 * Math.abs(hr.dot(out)));
double d = microfacets.getDistributionPDF(hr, n);
double pm = d * Math.abs(hr.dot(n));
double po = pm * partial;
return po;// / Math.abs(n.dot(out));
} else {
double ni, no;
if (ndoti > 0.0) {
ni = n1;
no = n2;
} else {
ni = n2;
no = n1;
}
//Vector3 ht = out.times(no).minus(in.times(ni)).unit();
Vector3 ht = in.times(ni).minus(out.times(no)).unit();
ht = ht.dot(n) > 0.0 ? ht : ht.opposite();
double hdoti = -ht.dot(in);
double hdoto = ht.dot(out);
double k = Math.abs(hdoti * hdoto / (ndoti * ndoto));
double c = ni * hdoti + no * hdoto;
double partial = no * no * Math.abs(hdoto) / (c * c);
double d = microfacets.getDistributionPDF(ht, n);
double pm = d * Math.abs(ht.dot(n));
double po = pm * partial;
return po;// / Math.abs(n.dot(out));
}
}