// Implementation of Path Tracing Vector3f Scene::castRay(const Ray &ray, int depth)…
- User
// Implementation of Path Tracing Vector3f Scene::castRay(const Ray &ray, int depth) const { // TO DO Implement Path Tracing Algorithm here Intersection intersection = intersect(ray); Vector3f hitcolor = Vector3f(0);
//deal with light source if(intersection.emit.norm()>0) hitcolor = Vector3f(1); else if(intersection.happened) { Vector3f wo = normalize(-ray.direction); Vector3f p = intersection.coords; Vector3f N = normalize(intersection.normal); float pdf_light = 0.0f; Intersection inter; sampleLight(inter,pdf_light); Vector3f x = inter.coords; Vector3f ws = normalize(x-p); Vector3f NN = normalize(inter.normal); Vector3f L_dir = Vector3f(0); //direct light if((intersect(Ray(p,ws)).coords - x).norm() < 0.01) { L_dir = inter.emit * intersection.m->eval(wo,ws,N)*dotProduct(ws,N) * dotProduct(-ws,NN) / (((x-p).norm()* (x-p).norm()) * pdf_light); } Vector3f L_indir = Vector3f(0); float P_RR = get_random_float(); //indirect light if(P_RR < Scene::RussianRoulette) { Vector3f wi = intersection.m->sample(wo,N); L_indir = castRay(Ray(p,wi),depth) *intersection.m->eval(wi,wo,N) * dotProduct(wi,N) / (intersection.m->pdf(wi,wo,N)*Scene::RussianRoulette); } hitcolor = L_indir + L_dir; } return hitcolor;
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.