project: Global illumination pathtracer

Details

A simple pathtracer program, capable of producing renderings of simple bodies. The program computes global illumination, by intersecting scene objects, such as luminaries and solid bodies, with idealised surface properies.

  • last updated: August, 2018
Download source

Screenshots

scene_3smpls.bmp scene_1smpl_dark.bmp scene_30smpls.bmp

src > color.hpp

View raw
#ifndef RAYTRACER_COLOR_HPP
#define RAYTRACER_COLOR_HPP

#include<math.h>

namespace raytracer
{
class color
{
 public:    
  //color(): red(0.0f), green(0.0f), blue(0.0f), special(0.0f) {}
  color(const double red= 0.0f, const double green= 0.0f, const double blue= 0.0f, const double special= 0.0f): red(red), green(green), blue(blue), special(special) {}
    
  inline double brightness() const { return (red+green+blue)/3; }
  inline color add(const color& c) const { return color(red+c.red, green+c.green, blue+c.blue, special); }
  inline color mult(const color& c) const { return color(red*c.red, green*c.green, blue*c.blue, special); }
  inline color scale(const double s) const { return color(red*s, green*s, blue*s, special); }
  inline color average(const color& c) const { return color((red+c.red)/2.0f, (green+c.green)/2.0f, (blue+c.blue)/2.0f, special); }
  inline color clamp() {
    //red= fabs(red);
    //green= fabs(green);
    //blue= fabs(blue);
    red= (red< 0.0f)? 0.0f: red;
    green= (green< 0.0f)? 0.0f: green;
    blue= (blue< 0.0f)? 0.0f: blue;
    red= (red> 1.0f)? 1.0f: red;     
    green= (green> 1.0f)? 1.0f: green;
    blue= (blue> 1.0f)? 1.0f: blue;
    return color(red, green, blue);
  }
    
  double red, green, blue, special;
};

}

#endif