#ifndef _WHITTED_INTEGRATOR_H_ #define _WHITTED_INTEGRATOR_H_ #include "Integrator.h" #include "Scene.h" class WhittedIntegrator : public Integrator { public: float3 /*getColor*/ Li(Ray *ray, const Scene *scene, Sample *sample, int depth = 0) { float3 color = 0.0f; if(depth > 6) {return color;} if(!scene->accelerator->Trace(*ray)) {return 0.0f;} Intersection i; ray->object->GetIntersection(*ray, i); // ambient color += i.material->ka; // direct lighting LightList::const_iterator light; for(light = scene->lights.begin(); light != scene->lights.end(); light++) { color += (*light)->computeDirectContribution(i, scene, sample); } // reflection if(i.material->kr > 0.0f) { Ray refl(i.p + i.n * 1e-3f, Ray::reflect(-ray->direction, i.n)); color += /*getColor*/ Li(&refl, scene, sample, depth + 1) * i.material->kr; } // transmission if(i.material->kt > 0.0f) { float3 sourceIOR = float3(1.f); float3 targetIOR = i.material->nt; if(dot(i.n, ray->direction) > 0) { sourceIOR = i.material->nt; targetIOR = float3(1.f); } for(int c = 0; c < 3; c++) { Ray refr(i.p, Ray::refract(-ray->direction, i.n, sourceIOR[c], targetIOR[c])); refr.origin += 1e-3f * refr.direction; float3 filter(0.f); filter[c] = 1.f; color += /*getColor*/Li(&refr, scene, sample, depth + 1) * filter * i.material->kt; } } /* absorption from the material between ray.origin and i.p */ color *= ray->absorb(i); return color; } }; #endif