View Full Version : Raytracing...
09-17-2001, 03:43 AM
As far as i understand, raytracing incolves projecting "lines" from a lightsource, bouncing these lines from surfaces, and the properties of the "line" change depending on the properties of the surface... and the surface colour changes depending on the properties of the line hitting it... Am i right so far??? Well, I now have a really stoopid question to ask... how do i determine _efficiently_ whether a "line" has "hit" a surface?
09-17-2001, 04:06 AM
well i am not "into" raytracing. there are more simple and more complex ways for raytracing.
but for a simple way if a ray hits a plane is the same as e.g. camera hits the plane. so if you got some stuff for collision detection you got at least some stuff for raytracing.
also there are some good books like "advanced aninmation and rendering techniques" out there. also - as usual - there should be stuff on the internet.
try google and teoma to search it.
09-17-2001, 04:35 AM
You are basically searching for the closest polygon that intersect with a line segment.
Of course we can do it brute-force by intersecting with every single polygon.
Or you can organize your data in a structure effective for searching, structures such as tree and heap. For example, a tree in which polygons are spatrialized. You can prune during searching by intersecting line segement with the bounding volumes.
For intesection between line segment and each triangle/polygon, you can try http://www.magic-software.com for some free source code.
09-17-2001, 05:02 AM
the way i would do it -
for each pixel in screen do
pixel_color = trace_ray(near_x_y_z,far_x_y_z);
where trace_ray is a recursive function to return the color of the ray.
Do not do it from the light source as each
light source could have millions of rays
that would never hit the viewport.
[This message has been edited by MButchers (edited 09-17-2001).]
09-17-2001, 04:21 PM
But the rays do not have to hit the viewport, all they do is alter the color of the texture of the surfaces they hit... from there opengl can handle it... all your doing is altering the texture of a surface. I may be wrong...
Raytracing is pretty simple actually assuming point light sources
for each pixel
determine center of pixel and pass ray through it
if you hit an object see if it is lit, if not then add nothing to color otherwise the color is the color of object hit (scaled by distance)
then check along reflection vector and refraction vector to see if hit another object...
if you do see if it is lit and add its color to your color (scaling it according to distance and reflectivity and refractivity level)
repeat recursively to specified depth or until you hit boundries of what can be seen.
if I have any errors or omissions please fix what I said....
now there are many algorithyms to search for a collision and associated data structures...
more info is on the web somewhere or read what I think is the grapic programming bible of sorts
Computer Graphics: Principles and Practice
by Foley, vanDam, Feiner, and Hughes
Also there are other techniques such as passing multiple rays through random areas of the pixel and then doing some scaling operation on the result for the final color, but again you will need more info then I am willing to provide on this board
Also you must scale the lighting by more than just distance, but by its terms, like specular terms etc (if you use phong model) this again is probably on the web and if not in the book.
Powered by vBulletin® Version 4.2.2 Copyright © 2016 vBulletin Solutions, Inc. All rights reserved.