All Projects → ypujante → ray-tracing

ypujante / ray-tracing

Licence: Apache-2.0 license
This is a go implementation of the "Ray Tracing in One Weekend" book

Programming Languages

go
31211 projects - #10 most used programming language

Projects that are alternatives of or similar to ray-tracing

MinecraftC
A Raytraced Minecraft Classic 0.0.30a port to C
Stars: ✭ 250 (+575.68%)
Mutual labels:  sdl2, raytracing
C Ray
C-Ray is a small, simple path tracer written in C
Stars: ✭ 323 (+772.97%)
Mutual labels:  sdl2, raytracing
Embree viewer
Embree viewer is a simple implementation of a progressive renderer, based on Intel's Embree raytracing kernels. Its UI is written in SDL2, and it supports Alembic, OBJ file formats, with a JSON file to describe a scene.
Stars: ✭ 19 (-48.65%)
Mutual labels:  sdl2, raytracing
Moonlight Qt
GameStream client for PCs (Windows, Mac, Linux, and Steam Link)
Stars: ✭ 2,796 (+7456.76%)
Mutual labels:  sdl2
Dino Rush
🌋 Endless runner game
Stars: ✭ 173 (+367.57%)
Mutual labels:  sdl2
42 cheatsheet
Also referred to as "The C Man"
Stars: ✭ 204 (+451.35%)
Mutual labels:  sdl2
Super-Mario-Bros-game
The remake of Super Mario Bros (1985) made with C++ and SDL2 library.
Stars: ✭ 39 (+5.41%)
Mutual labels:  sdl2
Plutonium
An easy-to-use UI framework for Nintendo Switch homebrew
Stars: ✭ 166 (+348.65%)
Mutual labels:  sdl2
Tmxlite
lightweight C++14 parser for Tiled tmx files
Stars: ✭ 248 (+570.27%)
Mutual labels:  sdl2
Freej2me
A free J2ME emulator with libretro, awt and sdl2 frontends.
Stars: ✭ 203 (+448.65%)
Mutual labels:  sdl2
Jitboy
A Game Boy emulator with dynamic recompilation (JIT)
Stars: ✭ 190 (+413.51%)
Mutual labels:  sdl2
Civone
An open source implementation of Sid Meier's Civilization.
Stars: ✭ 176 (+375.68%)
Mutual labels:  sdl2
Engine
A basic cross-platform 3D game engine
Stars: ✭ 208 (+462.16%)
Mutual labels:  sdl2
Bstone
Unofficial source port for Blake Stone series
Stars: ✭ 170 (+359.46%)
Mutual labels:  sdl2
Dome
A lightweight game development environment where games can be written in Wren
Stars: ✭ 251 (+578.38%)
Mutual labels:  sdl2
Div Games Studio
Complete cross platform games development package, originally for DOS but now available on modern platforms.
Stars: ✭ 168 (+354.05%)
Mutual labels:  sdl2
Nothing
A simple platformer about nothing
Stars: ✭ 249 (+572.97%)
Mutual labels:  sdl2
Ck2dll
Crusader Kings II double byte patch /production : 3.3.4 /dev : 3.3.4
Stars: ✭ 186 (+402.7%)
Mutual labels:  sdl2
Flextgl
OpenGL and Vulkan header and loader generator.
Stars: ✭ 180 (+386.49%)
Mutual labels:  sdl2
Vcmi
Open-source engine for Heroes of Might and Magic III
Stars: ✭ 2,514 (+6694.59%)
Mutual labels:  sdl2

ray-tracing

This is a go implementation of the Ray Tracing in One Weekend book.

Ray Tracing in Action

Motivation

After following the book in C++ and wanting to learn go, I decided to use it at my first real hands on project with go. I wanted to make the code parallel and display the progress.

Enhancements

  • displays the image as it is being rendered (uses SDL)
  • processes the image in multiple goroutines and multiple passes (for example, a first pass with 1 ray per pixel so that the rendering happens very quickly, and then further passes with more rays per pixel to enhance the result)
  • choose the seed so that the end result is reproducible

Installation

go get -v github.com/ypujante/ray-tracing

The only dependency is on the SDL2 Binding for Go library which also requires that you install SDL for your system.

Compiling

go install

Love the simplicity...

Running

  • ray-tracing will render the final scene in 800x400 pixels in 2 passes (a quick 1 ray per pixel pass and a 99 rays per pixel pass) using all the cores on your machine and a seed of 2017

  • ray-tracing -r 1 -r 10 -r 50 -r 100 -w 1600 -h 800 -cpu 4 -seed 12345 will use 4 passes (1/10/50/100 rays each so a total of 161 rays per pixel) using 4 cores and a width/height of 1600x800 and a seed of 12345

Lessons learned

  • rand.Float64() is (in hindsight for obvious reasons) synchronized and really killed the performances of the program since it is heavily used by each computation. Abstracted it into a Rnd interface (see model.go) and each goroutine creates its own non synchronized version to fix the issue.

  • using goroutines and channels really rocks. A few very powerful set of primitives are all it takes to make asynchronous programming a joy again :).

  • goroutines are fast... try -cpu 200... which will create 200 goroutines and, although you obviously do not gain by having more goroutines than the number of cores (since it is 100% CPU bound), it is pretty fascinating to also see that it is not dramatically slowing it down by having to time slice all those goroutines

  • go implements interface/object orientation in a very different manner than any other language. Although it takes some time to get used to it, I really enjoyed it after a while. My Rnd interface is a good example, since I could make the rnd.Rand class magically implement it even if it is a type not defined by me.

  • I do miss generics :( As far as I can tell there is no way to implement the split function I wrote in a generic fashion which is a shame.

Dependencies

License

Apache 2.0

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].