This is my C# implementation of Peter Shirley's Ray Tracing in One Weekend and Ray Tracing: The Next Week
Some notable changes:
- Code split in two projects:
RTLib
containing the renderer, materials, textures, hittables and other supporting codeRTConsole
containing the console runner and scene definitions
- Support for PNG output using ImageSharp
- Support for single-faced rectangles. For example they can be used to "close" a Cornell Box while still being able to see inside.
- Implemented two renderers:
ParallelRenderer
works very similarly to the original from the book, with the main change being that it usesParallel.For
to allow rendering lines in parallel.IncrementalRenderer
uses a slightly tweaked loop to render one sample for every pixel at a time, and saving the image every 10 samples. This allows you to see results very quickly, and spot any obvious problem without having to wait for a full render.
Other changes include some performance tweaks, and using more idiomatic C# coding structures. I wouldn't consider this code to be highly optimized, but I've done my best to remove the main bottlenecks.
You can render images using this command line:
cd RTConsole
dotnet run -c Release -- [output_file_name].png [scene_number_from_1_to_8]
# For example
dotnet run -c Release -- image.png 1
If you have Just, you can also use just render SCENE_NUMBER
to do the same.
Available scenes:
- The random scene from the end of book 1
- Two spheres with a checkered texture
- Two speres with a noise "marble-like" texture
- A sphere with the earth texture
- A scene with a sphere and a couple light sources
- Cornell Box, with glass and metal boxes
- Cornell Box, with "smoky" materials for the boxes
- The final scene from book 2