Ray Casting and Ray Tracing

Tue Nov 17 2009Programming

Having spent a lot of time on rasterizer based rendering, I've wanted to learn more about ray tracing, if only for the sake of curiosity. I also wanted to revisit ray casting, as it had been some time and I took some of the finer details for granted the first time around, so this time, I went through it with a fine toothcomb to make sure I got all of the details down.

Given that the majority of speed is lost in blitting the columns to the screen in traditional ray casters, I decided to render each vertical strip as line primitives in XNA. It's not a shabby use of the hardware, although I'd love to take a crack at writing a shader based ray caster sometime down the road.

I gave a quick performance test, although nothing too extensive but I did run it at 2048x1152 (amongst other oversized resolutions) and it managed to fulfil the synced 60fps, which was nice to see.

Here's a look at the basic ray caster in XNA:

Very simple ray caster in XNA

As for the ray tracing, I've not made too much progress and for the moment, I'm just performing intersections with a plane. I hear it only gets harder from there :)

Another detail; given that I'm working with a plane extending in just the X and Z directions (Facing +Y), I'm also hacking this slightly for test purposes due to the fact that I'm clamping its size at 64 units in the X (-32 to 32), and 64 units in the Z (-32 to 32) in order to give the plane some shape.

And also a look at the basic ray tracer in XNA:

Very simple ray traced plane

Again, I'm using XNA and except this time, I'm doing something a little different to the ray caster and I'm modifying the content of a texture and just drawing that texture to the screen with a SpriteBatch. I never said I was after performance.. At least not just yet anyway!

GatsbyNetlifyReactTypeScriptTailwind CSS
© Copyright 2008-2022 Terry Butler