Archive: Raytracing


6th August 2002 04:30 UTC

Raytracing
Hey there. It has occured to me that while some AVSers use simple rotations around 3 planes to obtain our 3d SSs and DMs, UnConeD and others use a mystical force called "raytracing." I did a search on Google, and I came up with a lot of programs, but not a lot of information on how this works.
From what I gather, raytracing traces a line from the observer out to the world until it hits something. Well that's all fine and dandy, but how do you actually DO that?
AVS-Masters, if you don't mind sharing your secrets of success, or at least posting a link that has some good material to read, it'd be much appriciated!

Thanks,
~Keaton


6th August 2002 07:39 UTC

The basic concept of raytracing is not hard...

First you need a way to describe a ray that starts at the point (ox, oy, oz) and points in the direction (dx, dy, dz). Then you can describe any point on this ray by:

(k*dx+ox, k*dy+oy, k*dz+oz) where k is any positive real number.

By filling this is in equations for shapes (plane, sphere, cylinder, ...) and solving for k, you can find the intersection point. Then you need to calculate a texture coordinate based on that point.

Raytracing works nicely for DM's, but for a superscope it's much too slow. You can get pretty complex shapes like this, but the problem is that a DM has a very low resolution, so edges will look very weird. Oh and of course a DM doesn't do perspective correction, so at low grid sizes you'll get distortions.


7th August 2002 10:19 UTC

Wow...NOW I understand it! I've just been trying to go about it the hard way (sort of like long division by counting on your fingers)

BTW - you're a major dude now, if you haven't noticed ;)
But as Nic01 pointed out to me, you've been a major dude since Whacko AVS :D


12th August 2002 09:35 UTC

Another method, although harder, is reverse engineering SSC equations.

For example:
y=mx+c becomes x=(y-c)/m
y=x^2 becomes x=sqrt(y)
etc.


17th August 2002 08:54 UTC

Now that I actually understand raytracing, I need to understand it :P

I assume ox/oy/oz is the 'camera' and dx/dy/dz are the points on the texture. But what do you mean by filling in equations for shapes and solving for k?


17th August 2002 14:20 UTC

Dx,dy,dz are the direction-coordinations of the ray. Initially these are set to (x,y,1). If you draw these for the entire grid of the DM, you get a rectangular pyramid of rays: this is the 'view'. Then, we rotate this view-pyramid to get the correct direction.

So in the end we have the ray (ox+dx*k, oy+dy*k, oz+dz*k).
Now suppose we want to raytrace the plane z=1. We replace 'z' with its parametric coordinate and solve for k:

    oz+dz*k=1
<=> dz*k=1-oz
<=> k=(1-oz)/dz


And this is the solution to the problem. We now know that the ray intersects the plane at:

(ox+dx*k, oy+dy*k, oz+dz*k)

Now you need to calculate the (x,y) coordinates based on those. Optionally you can do fog using alphablending.

Of course for complicated arrangements (lots of planes) or higher order surfaces (cylinder, sphere, ...) the code gets a lot more complicated, but the idea stays the same.