if (level == MAX_RECURSION_DEPTH) {
return 0xFFFF00FF00000000L;
}
//Find nearest Hit
CollisionDetails c = findNearestHit(ray);
//No hit
if (c.o == null) {
return 0xFFFF00FF00FF00FFL;
}
//Calculate hit position
Vect3 hitPoint = new Vect3();
Vect.addMultiple(ray.getOrigin(), ray.getDirection(), c.d, hitPoint);
//Get color and normal at hitpoint
long color = IntColors.toLong(c.o.getColorAt(hitPoint));
Vect3 normal = new Vect3();
c.o.getNormalAt(hitPoint, normal);
//Check if anything is blocking direct sunlight (go where the sunlight comes from)
Vect3 lrDir = new Vect3();
Vect.scale(LIGHT_DIRECTION, -1, lrDir);
Ray lightRay = new Ray(hitPoint, lrDir);
CollisionDetails lc = findNearestHit(lightRay);
//if nothing blocks the sun's light, add ambient and diffuse light, otherwise ambient only
double lightScale = 0;
if(lc.o==null)
lightScale = Vect.dotProduct(normal, LIGHT_DIRECTION);