Raytracing is a Thing

Yesterday I started a new project (not a proper project, just a new folder really) in which to test how quickly I could get a window open and an opengl context ready to mess around with. Turns out that that doesn’t take very long, so I spent the rest of the day just learning about neat D stuff (and being sick). For example I learned that I didn’t have to specify ridiculous command line options in order to get libraries to link. Instead I can just use pragma(lib, "Library"), which is akin to a visual studio vendor extension except standardised and actually part of the language. I also learnt a bit about tuples in D. D tuples are kind of nuts to think about coming from c++ land. They could be very loosely tied to lua’s multiple return types/tuples except that they’re entirely compile time structures. D tuples allow some pretty neat things, like for instance, packing function arguments and repeating arguments. Here is the code that sets up said neat thing:
tupletimesWhich allows me to do this:
argtimesWhich expands to glClearColor(0.7f, 0.7f, 0.7f, 1f). Probably not the most useful example but it’s still cool.

Today I was even more sick than I was yesterday, so I wasted most of my time blowing my nose, drinking orange juice and watching strange and interesting videos on youtube. Then it came to eight o’clock and I thought ‘Hey, I haven’t done anything productive today. To justify my existence I’m going to write a raytracer.’  And then I did.

raytracing

I didn’t do this alone of course. I’ve never touched raytracing before in my life. I HAVE however watched videos on youtube about raytracing while I was supposed to be doing other things. One video I remembered and based most of my code on. This was a video by Iñigo Quilez, a graphics wizard by any standard. Anyway, I modified yesterday’s hacked together ‘project’ to render a quad and compile a shader. For about half an hour after, I watched and copied Iñigo’s code until I got here:
raytraceThe main reason for straight up copying being that my face felt like it was going to explode and sphere intersections looked too hard at the time.

From then on I started getting the jist of things and managed to figure out reflections all on my own! Turns out raytracing makes this really easy. It’s literally just point and shoot. The hardest part was figuring out how to make a recursive function, not recursive. Once that was figured out, this was the result:
acidtraceThe colours are a bit off but the reflections are totally there. One bug I noticed was that the plane appeared noisier as the incidence angle increased, but I ignored it and messed with the colour code instead of trying to figure it out. Adding a multiplier to the colours as they accumulated for each fragment made a big difference in making it look less like an acid trip. After some fiddling I got this:

wormreflectIt’s all animated and running in realtime on the gpu so I’m pretty happy with what I’ve done given how much my face hurts.

manpat

Hello, I’m Patrick Monaghan, a games programmer in training. The purpose of this blog is to track the progress of my various projects relating to game development and various experiments I decide to try.A little bit about myself, I'm fluent in c++. I'm familiar with a few other languages also. I have a working knowledge of blender and gimp, thus can pump out programmer art like it’s going out of style. I’m always willing to learn new things and I always welcome feedback if it means I can improve. Also, here's a youtube channel And my github And my soundcloud Also I'm @_manpat on twitter Finally here's a todo list that I'm putting here so I can't ignore it

Leave a Reply

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