Threaded rendering
Shaved another 30% off rendering time by inlining and some more caching, but it seems like I’m reaching the limit of what I can get out of a single thread.
[1] pry(#<GlisteningRuby::DSL::Scene>)> render verbose:true
Setup time: 0.532384 s
Render time: 259.392946 s
Total time: 259.92533 s
There’s quite a bit of overhead, because Ruby doesn’t run its native threads in parallel, so we have to fork and return the result serialized via a file to the parent. This could probably be further optimized by not serializing as YAML, and reusing the render threads, but anyway.
[2] pry(#<GlisteningRuby::DSL::Scene>)> render verbose:true, threads:2
Setup time: 0.522643 s
Render time: 149.411224 s
Total time: 149.933867 s
This is the number of real CPU cores in my workstation.
[3] pry(#<GlisteningRuby::DSL::Scene>)> render verbose:true, threads:4
Setup time: 0.580056 s
Render time: 85.895065 s
Total time: 86.475121 s
Using hyperthreading quickly loses efficiency, but gets the CPU fan going.
[3] pry(#<GlisteningRuby::DSL::Scene>)> render verbose:true, threads:8
Setup time: 0.560456 s
Render time: 77.613168 s
Total time: 78.173624 s
Next related
Super Sampling Anti-Aliasing
Remember the smoothly shaded teapot? Still looks pretty rough with all the jaggies and speckles. Well, with the shiny new multi threading support it’s actually feasible to add some image quality improvements.
Previous related
Light and Magic
Made some refinements to lighting. Originially there was only a point light without distance falloff, which is not an accurate light model in any case. The light inside the room lights the entire world, all the way to the horizon.
Cache is King
Cut teapot rendering time in half with some clever caching.
Day 36, Constructive Solid Geometry
The final pre-defined feature of the project is done, Constructive Solid Geometry, implementing the boolean set operations union, intersection, and difference for solid geometries. This way we can use the basic geometric surface shapes to create more advanced shapes, without resorting to approximating by thousands of triangles.