Ray Tracing 010: Metal


Continuing with materials, this chapter will introduce a generic materials class and two first material child classes for diffuse (Lambertian) and reflective/metallic materials.

@TODO: add write-up

Updated Files


  • added material class and mat_ptr


  • added material.h
  • addd random.h
  • replaced drand48() with random_double()
  • moved random_in_unit_sphere() to material.h
  • added depth parameter to color() function
  • in color(), update to use new material with depth of 50 calls, moved previous target for diffuse material to class
  • replaced MAXFLOAT with INFINITY
  • in main(), added depth parameter to color(), added material to spheres, added two spheres to list


  • added material pointer


  • new file with base material class and two child classes for diffuse and reflective materials

Here’s also the link to the Javascript implementation:

Please see my repository at github.com/celeph/ray-tracing for the complete code. For more details, check out Peter Shirley’s excellent book that inspired this episode: “Ray Tracing in One Weekend” and his original book and code repo.

Credits and Further Reading

Next Steps