Gauntlets of Recursion (+3)

Times, trials, and turbulence.

Trace my rays, baby.

One Pixel at a Time

Side projects sure are sinister, aren’t they? Well, lucky this one isn’t anything large like a full-fledged game, so it serves as just enough to keep my mind feeling fresh at thought when I’m all Gloomed out. What is this project of which I speak?

Why, a Raytracer, of course. If you aren’t familiar with exactly what raytracing is, then I strongly recommend you take a read-through on the aforementioned link. The idea is that the user’s screen represents a ‘meta-screen’ that exists in the 3D environment, from which a metaphorical camera behind it casts out rays of light through each of the tiny pixels that make up the screen you’re looking at. Each ray finds out which object it intersects with, and does a number of calculations to determine its colour — things like reflection, refraction, diffuse and specular lighting, and likely many other things. Through much computation (you can guess why raytracing is slow) the final image can be quite realistic. This is the technique that folks like Pixar use to render their fancy CG movies.

Writing a raytracer has always been a huge ambition of mine — it’s just so cool to think that such a simple algorithm can produce incredibly realistic 3D images with such ease. Not to mention the utter awesomeness of being able to define this world using shapes composed of raw mathematical equations. Here’s an image generated by my (small) raytracer at a juicily-high 1280×960 resolution (clicky):


(Shiiiiny.)

What we have here is pretty simple by the standards set by the numerous kick-arse raytracers out there. So far I’ve implemented: Phong lighting (diffuse+specular), reflections, shadows, spheres, planes, and textures (for planes only). A short list, but I’m eager to try and get refraction and more shapes in there for some cooler scenes. I’m also quite interested in the notion of real-time raytracing, which mine is reasonably far away from. If I run at 160×140 I can manage a little over 10 FPS (anyone interested in seeing this?). However, I didn’t write this with speed in mind. Perhaps a project for a rainy day. πŸ™‚

I’m also really tempted to start writing some articles on the topic — I’ve noticed that the current ‘best’ resources glaze over a lot of important material (like intersection detection, explaining the math for the effects, and the general ‘structure’ of the raytracer, objects, and the scene). If anyone has any non-trivial interest in this, please speak up!

More Gloom

Not much programming done lately. The focus currently is getting a rough draft of the design document completed, so I have a more solid idea of what the game is going to look and feel like. I’m really trying to hard to avoid make-it-up-as-you-go syndrome (aka. MIUAYGS), so following the “measure twice, cut once” methodology feels like the wisest move. I won’t blather about the half-baked rough draft material I have so far, since most of it will either change or get cut out. πŸ™‚ But, as the document progresses, I get more and more eager to develop forward, as the final image of the game grows clearer and clearer in my mind. Onward! πŸ™‚

Advertisements

12 responses to “Trace my rays, baby.

  1. The Visible Man August 11, 2007 at 10:28 pm

    That Raytracer looks awesome! I’ve only played with raytracing once (in fact, it was based off of a demo you made!) and unfortunately was stopped dead in my tracks, since it was back before I knew Trig. As far as side projects go, this one definitely looks like it was worth the time!

    Glad to hear you’re planning out Gloom, too! Hopefully thinking through the whole design first will lead to better game play and atmosphere πŸ™‚

    Good luck!

  2. David a.k.a "Trapper Zoid" August 12, 2007 at 1:11 am

    Raytacers are fun; I’ve also only tried making one once for university, but it was one of the better projects I had to do. If you’re interested in speed, make sure you’re using faster version of the trig. functions, or even just use lookup tables.

  3. Todo August 12, 2007 at 7:14 am

    Pixar’s PRMan isn’t a raytracer by nature. I just thought I’d set you straight on this fact. Since you have built up a genuine interest in raytracing, I don’t think you mind learning something new :-). http://en.wikipedia.org/wiki/PhotoRealistic_RenderMan

    Cheers!

  4. Stephen August 12, 2007 at 8:34 am

    @TVM: Thanks! Actually, the tutorial/demo I wrote way-back-when was for Raycasting, which is a rather different technique. Raytracing doesn’t actually use trigonometry (by nature). The main maths involved are the intersections of rays and mathematical shapes, and some vector math.

    @David: I’d be interested in seeing some shots from yours. What kind of features did you have implemented?

    @Todo: I stand mightily corrected. They say you learn something new every day. πŸ™‚

  5. LachlanL August 12, 2007 at 6:01 pm

    Very nice! RTRT’s always been of interest to me, but I’ve never actually gotten around to trying to make anything. I’m sure you’ll be deep into SIMD soon if you’re interested in that stuff.

  6. ravuya August 13, 2007 at 11:46 am

    Nice raytracer. I did one for my computer graphics course, but didn’t have time to really finish it and do all the features I wanted in amongst my other course load.

    I’ll have to find some screenshots some time, and maybe run it two or three times. I won second place in the “prettiest image” competition we had, which netted me some extra marks.

  7. Stephen August 13, 2007 at 1:29 pm

    @Lachlan: SIMD looks very promising in terms of optimizing vector routines. I’ll keep it in mind when I delve deeper into the low-level world.

    @Ravuya: Very cool — what kinds of features does it have? How long did it take to write? And what year is your CG course in? Mine isn’t until 4th year, so I’m probably going to already have learned most of the material by then. 😦

  8. ravuya August 20, 2007 at 11:44 am

    Uhmhum.

    IIRC, it had reflections, translucency, texture mapping, and triangle, infinite plane, sphere and MD2 primitives (yeah, it could load quake models and animate them into an MPEG as well).

    It was in third year, but I should’ve taken it ahead of time had I the requisite courses like I was supposed to.

  9. ravuya August 20, 2007 at 11:45 am

    I should state that the features I *wanted* were multithreading, cubes and progressive refinement (so at least you could get a preview of what’s going on).

    I could’ve sworn I posted about it in my journal over the last few months.

  10. ravuya August 20, 2007 at 11:45 am

    Oh, shit, yes. Also, I should state it was done in a month (it was the third of three assignments, and the first two were realtime rendering and image manipulation using OpenGL).

  11. ravuya August 20, 2007 at 11:46 am

    Oh, finally, while it took a whole month, if I had gotten to work on it for more than five minutes a week, I probably would’ve been done sooner πŸ™‚

    You need an edit function

  12. Stephen August 20, 2007 at 2:03 pm

    Agreed. It seems like the what-should-be-commonplace feature of editting one’s comments is surprisingly missing. I’ll look into this.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: