novalain / gi-ray

A Monte-Carlo ray tracer from scratch in C++
5 stars 1 forks source link

Implement ray bouncing #72

Closed novalain closed 8 years ago

novalain commented 8 years ago

Carlbaum tree pseudocode:

Render(Scene& scene) {
  for( pixel : pixels ) {
    Ray ray = Ray(current_pixel);
    out_color[pixel] = Raytrace(ray);       
  }
}

ColorDbl Raytrace(Ray& ray) {
  intersection_point = GetClosestIntersectionPoint(ray);
  if (intersection_point) {  
     return Shade(ray, intersection_point); 
  }
  return black;
}

GetClosestIntersectionPoint(ray) {
  for(object : objects) {
      Intersectpoint p = object->RayIntersection(ray);  // new class intersectionpoint?
      // ...
  }
  return p; // holds material and normal
}

ColorDbl Shade(Ray& ray, IntersectionPoint& p) {
  ColorDbl radiance = black;
  for(light : light_sources ) {
    shadow_ray = calc_shadow_ray(point,  light);
    radiance += phong_shading(point, shadow_ray, light);
  }

  // Call recursive until we hit non-reflective or transmissive, need an iteration stop somwhere
  if (p.is_specular_reflective) {
    radiance += specular * Raytrace(reflected_ray(ray, point));
  }
  if(p.is_specular_transmissive) {
     radiance += transmittance * Raytrace(trasmitted_ray(ray, point);
  }
  return radiance;
}

Implement after light source is done and ray works without bounce..