for some reason in my ray tracer if I try to limit the number of recursive calls in my ray tracer my reflectance doesn't work.
Here is my reflectance code:
public static int recursionLevel;
public int maxRecursionLevel;
public Colour shade(Intersection intersection, ArrayList<Light> lights, Ray incidenceRay) {
recursionLevel++;
if(recursionLevel<maxRecursionLevel){
Vector3D reflectedDirection = incidenceRay.direction.subtractNormal(intersection.normal.multiply(2).multiply(incidenceRay.direction.dot(intersection.normal)));
Ray reflectiveRay = new Ray(intersection.point, reflectedDirection);
double min = Double.MAX_VALUE;
Colour tempColour = new Colour();
for(int i = 0; i<RayTracer.world.worldObjects.size(); i++){
Intersection reflectiveRayIntersection = RayTracer.world.worldObjects.get(i).intersect(reflectiveRay);
if (reflectiveRayIntersection != null && reflectiveRayIntersection.distance<min){
min = reflectiveRayIntersection.distance;
recursionLevel++;
tempColour = RayTracer.world.worldObjects.get(i).material.shade(reflectiveRayIntersection, lights, reflectiveRay);
recursionLevel--;
}
}
return tempColour;
}else{
return new Colour(1.0f,1.0f,1.0f);
}
}
If I get rid of the if statement it works, though I run out of memory if I place too many reflective objects. I'm not sure what could be causing this.
Aucun commentaire:
Enregistrer un commentaire