int l1 = RandomUtil.discrete(0, ka - 1, rnd);
int m1 = ka - 1 - l1;
if (newLightTail == null && l1 > 0) {
PathInfo pi = x.getPathInfo();
Light light = pi.getScene().getLight();
newLightTail = light.sample(pi, rnd.next(), rnd.next(), rnd.next());
l1--;
}
while (l1-- > 0) {
newLightTail = newLightTail.expand(rnd.next(), rnd.next(), rnd.next());
if (newLightTail == null || newLightTail.isAtInfinity()) {
return null;
}
}
if (newEyeTail == null && m1 > 0) {
PathInfo pi = x.getPathInfo();
Lens lens = pi.getScene().getLens();
Point2 p = RandomUtil.canonical2(rnd);
newEyeTail = lens.sample(p, pi, rnd.next(), rnd.next(), rnd.next());
m1--;
}
while (m1-- > 0) {