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:
Which allows me to do this:
Which 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.
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:
The 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:
The 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: