Giter VIP home page Giter VIP logo

raytracer's Introduction

Ray Tracer in a Weekend

Decided to learn more about ray tracing and computer graphics. Implemented this simple ray tracing for spherical objects using C++ from scratch without any additional libraries. Based on Peter Shirley's Ray Tracing in One Weekend

I did this project on my own pace, but I reckon it would take about a weekend if you spend all your time. Amazed with the results that such a simple implementation from scratch can get!

Dependencies

  • g++ >= 7.5
  • CUDA Toolkit >= 9.1
  • ImageMagick (convert PPM to PNG)

Usage

  • Compile using make.
  • If using CUDA, compile with make cuda.
  • Render using make render. The rendered image will be generated at ./output.png.
  • Clean with make clean.

Results

normals sceneA rendomScene

Improvements

  • Conversion to PNG using ImageMagick
  • OpenMP parallel for (if we have multiple cores, why not use them?)
  • CUDA version (let's see how fast this can render!)

CUDA Details

Implemented a CUDA version of the Ray Tracer loosely following the NVIDIA's Ray Tracing Accelerated blog post. I was annoyed at having to use the double pointers camera** cam; hitable** world to instantiate objects on the device. Who uses double pointers in 2020 anyway? First I tried the elegant Managed class operator overloading solution from NVIDIA's blog post on Unified Memory. This solution works fine for the camera class, but fails for hitable and material since both these classes use virtual functions. The problem is that when an instance is created on the host, even though the parameters are shared in the unified memory, the pointer to the virtual function is in the host domain, and thus, not accessible in the device domain. The solution is then to use the unelegant double pointers.

Runtime performance

Rendering a 600x400 image with 100 ray samples per pixel on a Xeon E5-1630 3.7Ghz, GPU NVIDIA Quadro M4000 (8GB RAM).

Device Time
CPU (1 core) 24m
CPU (8 cores) 6m18s
GPU 1m3s
  • Without OpenMP, using a single core, the process took 24min.
  • Using OpenMP with all 8 available cores the same process took 6min 18s. Almost four times as fast!
  • The GPU performance is about ~24 times faster than using a single CPU core!

raytracer's People

Contributors

eduardohenriquearnold avatar

Stargazers

 avatar

Watchers

 avatar  avatar  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.