Image Generation (Raytrace 2)
Image Generation (Raytrace 2)
Last time we got a basic raytracer working that could handle colours, planes and spheres. Which made for some ok but dull images. I wanted to expand to new shapes but first decided a bit of a re-architecture was in order.
Previously everything was in the entity now I have separated out geometry and materials. An entity is now a instance of geometry with a transform and material applied. I also separeated the geometry tracing and materials out into there own files away from the tracer itself. This simpilifes things a lot and makes adding new types easier as the entity itself doesnt need the transformation logic ( we just transform the ray into local coordinates)
I then added a new box type and plumbed it in. The ray/box intersection logic was a bit tricky – Rust is aggressive about trapping on overflow and comparing floating point numbers so we have to be a bit more careful and branchy rather than just assuming Inf will sort after everything else.
While getting the logic for this correct I looked into adding some unittests just to make my life easier – rendering a scene with millions of rays isnt the easiest way of debugging ray box intersection. Rust’s unittest framework was excellent for adding small test cases – I dont know how well it scales adding cases to the bottom of the file but for now it is going well.
To show of the new rnage of colours, geometry and transformations I make the following scene which looks a lot more promising.
We are still missing lighting, proper materials and performance but it makes something pretty! On to the other things in the future. It was made with the new style json input