Skip to content

ronnieholm/Ray-tracing-in-one-weekend-CSharp

Repository files navigation

Ray-tracing-in-one-weekend-CSharp

A C# port of Peter Shirley's Ray Tracing in One Weekend (book, version 1.55 and C++ code available for free).

Running the application generates a random scene:

Random scene If you feel a bit rusty on the math, you may want to start with a few posts I wrote while working through the book:

Getting started

$ git clone https://github.com/ronnieholm/Ray-tracing-in-one-weekend-CSharp.git
$ dotnet run -c release > out.ppm
$ display out.ppm

On my Intel Core i7-7560U CPU @ 2.40GHz laptop running Linux and .NET, ray tracing takes about two minutes.

Benchmarking

For benchmarking, writing to standard output should be disabled in Program.cs:

.NET 6 (Linux)

real    1m34.189s
user    1m34.720s
sys     0m0.222s

Peter Shirley's C++ version:

% git clone https://github.com/RayTracing/raytracinginoneweekend.git
% cd raytracinginoneweekend/src/

Comment out the last std::cout statement in main.cc.

% g++ -O2 main.cc 
% time ./a.out > /dev/null 

real    1m13.045s
user    1m12.789s
sys     0m0.056s

In terms of raw computation power, .NET doesn't come close to C++. At least not while staying true to the C++ code structure.

See also

  • Live coding implementation in C++ (part 1, part 2, part 3, part 4). Adds commentary and derives equations that the books glosses over.

About

C# implementation of Ray Tracing in One Weekend by Peter Shirley.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages