Writing a ray-tracer

As mentioned in this previous post – in-between bouts of preparation for AU2013 and my other work responsibilities – I've been spending time following an edX class on computer graphics. It's been really beneficial: I've shored up some of the basics I'd missed out on studying formally at university and it was a great continuation of many of the concepts gleaned from the linear algebra class on Coursera.

The final assignment in the class has been a challenge: I've had to write a ray-racer from the ground up. It's been really interesting, though: there are various steps to go through, such as loading a scene from a (text) file, implementing a camera model, the ability to test for intersections between rays and the elements of your scene and then lighting and shadow calculations. I knew that ray-tracers cast per-pixel rays to determine colouring – and followed reflections in the model to determine the effect of light bouncing off other objects in the scene – but I didn't realise they also cast rays towards light sources to determine whether the pixel was in shade (with respect to that particular light). In many ways obvious, but going through the whole process has been very instructive.

And I'm really happy I had this opportunity to dust off my C++ skills: I'd actually forgotten how much I enjoy the language, despite hassles such as class declarations and multiple inclusion of header files.

For fun I decided to save out the results I received from my evolving application and create an animated GIF showing some of the progress. Lots of the early issues – such as the black and white images – ended up relating to the image output code, but I eventually progressed to being able to deal with geometry, transformations and – towards the end – shading and lighting effects. I'm still not quite done but I won't post any further images – at least not of the scenes provided in the course – as these images are actually used to submit the homework and the deadline isn't for another couple of weeks.

 

Raytracer bloopers

3 responses to “Writing a ray-tracer”

  1. why not do it in .net? Is C++ necessary?

  2. I looked up that class. Had not seen edx site before.
    When will the Kean mind meld be invented??
    On same subject, I would think you have access to world class 3d gurus given Adesk's ownership of Maya and max. I wish I had that as I would ask them how they can simplify a civil engineering type surface with emphasis on keeping the sharper edges (walls, curbs...) I bet they have a few ideas.

  3. Yes - C++ was required. Even Microsoft recommends C++ for DirectX work (as far as I recall), even though there are 3rd party bindings to C# (such as SharpDX).

    There are incredibly talented 3D gurus in the company - most of whom I don't know - who I'm sure could solve all manner of problems. But they often have tough problems they're working through in their own domains, of course, even if more of them are focused on cross-product problems than before.

    Kean

Leave a Reply to Kean Walmsley Cancel reply

Your email address will not be published. Required fields are marked *