Ray Tracing 016Random Spheres

Summary

  • Updated raytracer to generate a scene with randomly placed spheres and random materials.
  • Updated engine class to support two new render loop types: Multipass and MultipassInc.

Loading...

One major change was the introduction of two new render loop types: Multipass and MultipassInc.

Multipass is essentially my first implementation, which simply divided the image height and width by a number of pseudo-"threads". The resulting section width and height is then used as an offset for the x- and y-loops. This produces a nice effect where the image is filled incrementally with multiple scan lines and sections. It looks as if there are separate threads at work and uncovers several sections of the image incrementally so I get an overall preview without having to wait from the top left corner moving downwards before I get to see anything in the center or lower section of the image.

MultipassInc is similar to Multipass, but it doesn't attempt to calculate all samples for a pixel at once. If I calculate the image without anti-aliasing or with only one sample, I get a rather grainy but very fast complete image. I very quickly get an idea what the final image looks like. If I calculated 500 samples for each pixel before I move on to the next, it would take much longer before I get to see anything meaningful.

In MultipassInc, I calculate only one sample per iteration, then start over and redraw the image with the second sample applied to the first, then starting over again to refine the image further, and repeat until all samples are completed.

This takes quite a long time, longer than calculating all random samples for a pixel, but the advantage is that I get a very fast first image, and I can decide whether I want to stick around for the rendering to finish. I like this approach better than the other render loops I experimented with earlier. I might still use this approach later after adding other acceleration techniques.

Links