Over the weekend I had some more fun with the ray-tracing application I’m writing for my BerkeleyX homework. This time, though, I ended up using AutoCAD to do some debugging (which was an interesting twist).
The big problem with debugging an app such as a ray-tracer is that it’s hard to picture a complex 3D scene in your mind – especially when there are lots of transformations being applied to the various objects in the model. At least it’s not something my mind is at all good at.
AutoCAD, on the other hand, is very good at helping you think about 3D geometry. I started off creating some of the base model by hand, but then ended up dropping that and using a couple of handy techniques which seemed to be worth sharing.
The first was to write out simple points – in my case the intersection points between the rays I’m casting towards the lights to determine which pixels should be in shadow and the geometry in the scene – to the standard output (my ray-tracer is actually a console application). This output could then be piped into a text file and imported into AutoCAD using the POINTCLOUDINDEX command (followed by the POINTCLOUDATTACH command to bring in the indexes PCG – which can also be done by clicking on the bubble notification when indexing is complete).
This resulted in a nice visual representation of the points I’m interested in checking for correctness in 3D:
The other approach I used was to write out an AutoCAD script – which again can be piped to an .scr file – and then executed inside AutoCAD. I did this to create lines going between the intersections of the original rays being cast from the camera position to the model and the intersections made by the “shadow” rays being cast from those locations towards the lights hitting the model. Phew.
It was pretty interesting to see the results, although it resulted in a lot of geometry to sift through (10K lines for the shadow rays alone). It helped to see that extending the rays through to their intersection happened at the light source – which is just as it should be.
I still have at least a few evenings of work left before I’m done, but I am getting closer (and have plenty more blooper shots for an updated animated GIF :-).
This one now implements attenuation of point lights (which admittedly still needs a bit of tweaking), and hopefully I’ll soon have shadows working, too.
I ended up bringing in a point cloud of the points that were meant to be visible but were falsely shadowed in my code (something you can’t see above, but this was one of the issues I was struggling with). I could then step through the code in the debugger (obviously outside of AutoCAD) and then copy and paste values across, which helped me identify that I was missing a check on the direction of the distance along the ray when it intersected a triangle:
AutoCAD really ended up helping me get to the bottom of some gnarly issues I’d been struggling with.