Skip to content

Latest commit

 

History

History
55 lines (41 loc) · 2.05 KB

README.md

File metadata and controls

55 lines (41 loc) · 2.05 KB

3d-raytracer-lua

A simple 3D raytracer written in Lua over a couple of weekends.

Some time ago I wanted to learn more about 3D raytracers, so I read these two books by Peter Shirley and then translated the C++ code from the books into Lua:

Note

I read version 3 of the books. There are newer versions now.

This raytracer is obviously not production-ready or really anything to be taken seriously, but I had a lot of fun writing it!
I decided to use Lua because it's a very minimal and limited language, which makes it even more fun, but it's obviously not the fastest language out there so if you want to try it you'll have to clear your schedule. 😅
The final render seen below took almost a week to render... Don't ask. Sorry Planet Earth!

All the code is written by me, but I added a MIT license so feel free to use it however you like.

Results

Result - Final Result - Random Result - Cornell Box Smoke Result - Simple Light Result - Three Spheres

Requirements

  • LuaJIT 2.1 (highly recommended) or Lua 5.1 (newer Lua versions might work but not tested)
  • If you use standard Lua you will also need the Lua BitOp extension, which is included in LuaJIT

How to try

Download the repository and then run any of the scenes using LuaJIT:

$ luajit ./scenes/<scene>.lua

For example, random.lua is reasonably fast and showcases many of the features:

$ luajit ./scenes/random.lua

After the rendering is finished, you can find the resulting PPM file in ./results/.
To convert the PPM file to a PNG/JPEG file, I recommend using GIMP or ImageMagick.