Git Product home page Git Product logo

raytracer's Introduction

Basic raytracer

This project is based on the book Ray Tracing in One Weekend by Peter Shirley. I decided to use the code to generate atom-inspired animations. In this first animation, "core" spheres are metal and reflect light from the "electron" spheres. More animations below.

Animation 1

Improvements on the original code

  • New Scene class using variadic templates for controlling the lifetime of Hitables and Materials.
  • Templated vec3 class.
  • Simple Image class for writing the output to disk.
  • PNG output using stb_image_write.h library.
  • Unit testing using Catch2 library (only for vec3 at the moment).
  • Parallel rendering with std::async.
  • Random number generation with <random> header.
  • General refactoring and style changes to my own liking.

Simple performance improvement

Profiling this code on Visual Studio 2017, I realized that the bulk of the computation happens (unsurprisingly) in the first couple of lines of the Sphere.hit() function. Most of the time, the ray does not hit the sphere, the hit() function returns at the first if statement and no expensive color computation is needed with that sphere.

I obtained a significant speedup in Visual Studio 15.0 (close to ~100% in a simple scene) by making Ray.origin() and Ray.direction() return const references, which avoids multiple copy operations in the critical code section.

More animations

In the second animation, the "core" spheres are glass with refractive index 1.5. The center looks strange because the spheres overlap in the middle and the code cannot handle that properly.

Animation 2

In the third animation, I raised refractive index to 2.0, which results in stronger total internal reflection and peculiar symmetrical regions where light passes through the "core".

Animation 3

License

The book's original code by Peter Shirley is in the public domain. This project is licensed under the MIT license. See also DEPENDENCY_LICENSES.txt.

raytracer's People

Contributors

jomiri avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.