*/
public Color shade(ShadingContext sc) {
if (firstBounceRays > 0 && sc.getPathDepth() < 1) {
Random sampler = firstBounceSampler.get();
WavelengthPacket lambda = sc.getWavelengthPacket();
Color shade = sc.getColorModel().getBlack(lambda);
for (int i = 0; i < firstBounceRays; i++) {
ScatteredRay ray = sc.getMaterial().scatter(sc, sc.getIncident(), true, sc.getWavelengthPacket(), sampler.next(), sampler.next(), sampler.next());
if (ray != null) {
shade = shade.plus(sc.castRay(ray).times(ray.getColor()));
}
}
return shade.divide(firstBounceRays);
} else if (sc.getPathDepth() < maxDepth) {
ScatteredRay ray = sc.getScatteredRay();
if (ray != null) {
double prob = ColorUtil.getMeanChannelValue(ray.getColor());
if (prob < 1.0) {
if (RandomUtil.bernoulli(prob, rnd.get())) {
ray = ScatteredRay.select(ray, prob);
} else {
ray = null;
}
}
if (ray != null) {
return sc.castRay(ray).times(ray.getColor());
}
}
}
WavelengthPacket lambda = sc.getWavelengthPacket();
return sc.getColorModel().getBlack(lambda);
}