ScatteredRay sr = strategy.scatter(x, v, adjoint, lambda, ru, rv, ref.seed);
if (sr != null) {
if (sr.getType() == Type.SPECULAR) {
return ScatteredRay.select(sr, w);
} else {
Ray3 ray = sr.getRay();
Vector3 r = ray.direction();
Vector3 in = adjoint ? r.opposite() : v;
Vector3 out = adjoint ? v.opposite() : r;
double pdf = w * sr.getPDF() + (1.0 - w) * inner.getScatteringPDF(x, v, r, adjoint, lambda);
Color bsdf = inner.bsdf(x, in, out, lambda);
return new ScatteredRay(ray, bsdf.divide(pdf), sr.getType(), pdf, sr.isTransmitted());
}
}
} else {
ScatteredRay sr = inner.scatter(x, v, adjoint, lambda, ru, rv, ref.seed);
if (sr != null) {
if (sr.getType() == Type.SPECULAR) {
return ScatteredRay.select(sr, 1.0 - w);
} else {
Ray3 ray = sr.getRay();
Vector3 r = ray.direction();
Vector3 in = adjoint ? r.opposite() : v;
Vector3 out = adjoint ? v.opposite() : r;
double pdf = w * strategy.getScatteringPDF(x, v, r, adjoint, lambda) + (1.0 - w) * sr.getPDF();
Color bsdf = inner.bsdf(x, in, out, lambda);
return new ScatteredRay(ray, bsdf.divide(pdf), sr.getType(), pdf, sr.isTransmitted());