Skip to content

Latest commit

 

History

History
104 lines (83 loc) · 4.99 KB

README.md

File metadata and controls

104 lines (83 loc) · 4.99 KB

Chapters on GPU Ray Tracing

This repository hosts a new book series that walks you through building your own GPU path tracer. It is intended for readers of the Ray Tracing In One Weekend series who are curious about implementing the same concepts on a GPU using a modern graphics API.

The book will guide you through the building blocks of a GPU-based renderer using the same step-by-step approach in Ray Tracing In One Weekend. The goal is not to build a fully-featured and highly optimized real-time renderer; rather, it is to show you how to translate the concepts introduced in Ray Tracing In One Weekend into a design that is practical to port to all modern GPU platforms while paying attention to some of the common pitfalls of GPU programming.

I hope that, by completing this book, you will have built a renderer that serves as a foundation for future learning and experimentation. It won't be the most-efficient renderer but it will be able to draw the scenes from Ray Tracing In One Weekend at near-interactive rates.

Project Status

This book is a work-in-progress and has not been released yet. I'll update this README as soon as there is a first draft!

Directory Structure

TODO

Source Code

Ray Tracing In One Weekend deliberately avoids the use of APIs and special-purpose libraries. However, programming a GPU requires you to develop against an API that supports the particular piece of hardware that you want to target.

My goal with this book is for all of the concepts to easily map to any graphics framework and programming environment. GPU programming can naturally involve a lot of boilerplate and I want to keep the barrier for entry as low as possible for someone who wants to get started with building a ray tracer right away without having to learn all the intricacies of window management and engine infrastructure.

To that end, I decided to provide some support code to keep some of that friction low. I made the following API and programming language choices for the code examples:

  1. WebGPU is a new API that defines a good abstraction for all baseline features one can find in a modern graphics API. A reader that wants to use a different API can translate the concepts fairly easily. In particular, WebGPU has native implementations that are easily portable to any OS and GPU that supports Vulkan, Metal, and D3D. The code examples will specifically use the wgpu library which supports Vulkan, Metal, D3D11, D3D12, OpenGL ES, and WebGPU via WebAssembly.

  2. I chose Rust as the programming language for both its safety and ease of use. I've found that Rust has often made my development faster as it resolves many potential memory bugs and data races at compile time while staying fairly low-level. Another advantage of Rust is that it takes virtually no effort to get the examples to run on different operating systems as the package manager takes care of this automatically.

I'm cognizant of the fact Rust may feel unfamiliar to some readers. I will strive to keep the code examples free of esoteric Rust-isms to keep the code understandable to a reader who is familiar with C.

That said, none of this should prevent you from implementing this book in your favorite language, on your favorite OS, using your favorite API. In fact, wgpu (the library used by the code examples) has native bindings for several programming languages.

Building and Running

You can use the standard Rust package manager cargo to compile and run the code. First, make sure you have installed the latest version of the Rust toolchain (see instructions). Then run the following in your terminal (inside the directory containing the source code):

To run a debug build:

$ cargo run

To run an optimized build:

$ cargo run --release

If you want to run this on macOS with Apple Silicon, you may want to consider running without x86-64 emulation:

$ rustup target add aarch64-apple-darwin
$ cargo run --release --target aarch64-apple-darwin

Corrections & Contributions

If you spot errors, have suggested corrections, or would like to help out with the project, please review the CONTRIBUTING document for the most effective way to proceed.

This work is licensed under a Creative Commons Attribution 4.0 International License. You can find a copy of the license text at LICENSE

CC BY 4.0