A weekend past and some new updates: * The raytracer is now parallelized. * I have found a parallel RNG scheme that allows reproducible multithreaded result for those who wants to do parallel reproducible Monte-Carlo simulations: * writeup [https://github.com/mratsim/weave/issues/147#issuecomment-633198832](https://github.com/mratsim/weave/issues/147#issuecomment-633198832) * the magic: [https://github.com/mratsim/trace-of-radiance/blob/26ef9ed5/trace_of_radiance/support/rng.nim#L21-L29](https://github.com/mratsim/trace-of-radiance/blob/26ef9ed5/trace_of_radiance/support/rng.nim#L21-L29) a `pair` function that can take 2 integers (for example one produced by a "master RNG" and one from a loop variable, or 2 from nested loop variables) and that can be used to reseed RNGs across threads to: * ensure different RNG streams * ensure reproducibility * I departed a bit from the book to add an animation:
* For this I have added: * a mini physics engine that can simulate gravity and bounce * the output can now be a series of PPM images * the output can be a mp4 video in H.264 format * The H264 encoder is lossless and less than 300 lines of pure Nim: * [https://github.com/mratsim/trace-of-radiance/blob/26ef9ed5/trace_of_radiance/io/h264.nim](https://github.com/mratsim/trace-of-radiance/blob/26ef9ed5/trace_of_radiance/io/h264.nim) * When passed to FFMPEG, it will complain about corrupted frames but ssshhhh, don't let it say otherwise, it's spec compliant and can be read by media players ;) * I've added a MP4 muxer (this one is full-featured via the minimp4 header-only library) * color conversion for RGB to Y'CbCr 420 (also known as YUV420 i.e. with chroma subsampling). Limitations: * It's very very slow, ~3 hours of rendering on 18 cores for a 576x324 image with 400+ spheres and 300 rays per pixels. The reason why is that each ray must test if it encounters any of the sphere, and redo that after each bounce, a ray can bounce up to 50 times (artificial limit otherwise compute never finishes). * Solution is in the volume 2 "Raytracing the next week", via Bounding Volume Hierarchy (BVH), which will make the time needed logarithmic (and assuming 10000 seconds of initial rendering time ln(10000) == 9) * No Motion blur, I added animation but no motion blur. * Solution is in the volume 2 "Raytracing the next week", as well. But the book simulates motion blur but has no animation code ;). Note: Feel free to reuse the video code to record the NimConf but 6 seconds of size 576x324 took 53MB ;)