Skip to main content
gamedev.net
🔒 Locked

Raytracing tutorials?

Started by Peter Svensson Jan 28, 2004 at 5:31 AM 7 replies 1.6k views
Original Post
Peter Svensson
Peter Svensson
Hello! I''m looking for simple and advanced raytracing tutorials. Maybe you know of one that has been usefull to you? //Thanx, Peter... Ps. And yes, i have searched at google, gamedev and flipcode... Ds.
davepermen
davepermen
well.. i''ve learned most from the first results in google if i plug in raytracing tutorial.. one is for mac, wich is quite a nice one.. there are others, too.. just browse the first .. say.. 20 results.. its about the best i know for beginners..

i''ve learned that way (and with pen and paper, and much too less math knowledge (means i worked at start without vector math:D))




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud
IainC
IainC
Actually, AP, my best raytracing links didn''t come from the (quite broken these days) Google.

I personally found the wonderful FuzzyPhoton very helpful. I also have a small collection of raytracing links, and a small fairly well-commented raytracer available.

Good luck - I had a lot of fun implementing my little rt as a side-project.



www.coldcity.com
code, pics, life
[size="2"]www.coldcity.com code, art, life
The Reindeer Effect
The Reindeer Effect
If you have any specific questions, you can just ask here and I will try and help you. Not that I know tons about it, but I could definitely try and help out with any beginner issues.


Still, since it might help, I will toss out some psuedocode:

load model descriptions and move them into position

apply viewing transformation

for all rows, j, in the raster {

for all columns, i, in the raster {

initialize color value, s (RGB)

for pixel (i,j) calculate direction vector, d

set ray origin, p, to camera position

doRay(p, d, s)

set the pixel at (i,j) to s

}

}



function doRay(p, d, s) {

find the identity of the polygon, K, that intersects the ray

p + u*d at point p1 and is closest to p

calculate the surface color s, for polygon k at point p1

if k is reflective {

set reflective direction dr

doRay(p1,dr,sr)

}

if k is transparent {

get transparent direction dt

doRay(p1,dt,st)

}

get surface normal, n, for polygon k at point p1

from p1 send rays to each light source

test every polygon in model to see if the light ray intersects it

if it does, then the surface is in shadow from that light source

combine s, with sr and st, and apply lighting using n to get the

final s value

}
The Reindeer Effect
The Reindeer Effect
Since I am in a good mood, and when I first wrote my raytracer I got a bit stuck with the whole "calculate direction vector" thing, I figured I should post an example.

The part about finding the direction vector ... well my camera consisted of two parts. A position, and a "window". Here is a little drawing


(-12,9,0) (12,9,0)
.__________________.
| |
| |
| (0,0,0) |
| . | the camera origin is (0,0,10)
| |
| |
|__________________|
(-12,-9,0) (12,-9,0)

this is a right hand coordinate system, so a positive z value implies towards the viewer, while a negative z value is deeper into the scene


The window keeps a 4:3 aspect ratio, because I want the final image to have a 4:3 ratio. The window is a total of 24 units wide, and 18 units tall. Say we are rendering a 800x600 image. The change in x per pixel would be 24/800 = 0.03, and the change in y per pixel would be 18/600 = 0.03 (this is assuming a sampling of one ray per pixel). To find the point on the window that corresponds with a pixel in the raster, we can just use this little calculation:
quote:

x = xleft + (0.5 + i)dx
y = ytop - (0.5 + j)dy


xleft for us is -12, ytop is 9. dx is the change in x per pixel, dy is the change in y per pixel. i and j are the coordinates in the raster.

Our first pixel (0,0) would be at the point (-12 + 0.5*0.03, 9 - 0.5*0.03, 0), or simply (-11.985, 8.985, 0).

Yay! We now have 2 points on the ray. We can determine a direction now! Time to subtract the origin from the 2nd point:

(-11.985, 8.985, 0) - (0,0,10) = (-11.985, 8.985, -10)

Now since this is the value for direction, we should normalize it:

norm = sqrt(-11.985^2 + 8.985^2 + -10^2) = ~18.01
(-11.985, 8.985, -10) / 18.01 = (-0.665, 0.499, 0.555)

There, now you have your origin (0,0,10) AND your direction (-0.665, 0.499, 0.555). Now time to test for intersections.
AxoDosS
AxoDosS
Hello, here is a link for you.
http://www.2tothex.com/raytracing/index.html
davepermen
davepermen
quote:
Original post by IainC
Actually, AP, my best raytracing links didn''t come from the (quite broken these days) Google.


I know these links from google btw.. :D

btw, a nice small collection in here.




If that''s not the help you''re after then you''re going to have to explain the problem better than what you have. - joanusdmentia

davepermen.net
If that's not the help you're after then you're going to have to explain the problem better than what you have. - joanusdmentia
My Page davepermen.net | My Music on Bandcamp and on Soundcloud

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.