Thread: Ray Traced Reflections

  1. #1
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640

    Ray Traced Reflections

    Here's an image from my latest ray tracing project. The model reflects its surrounding environment via recursive ray reflections. Im going to add refraction if i have time so the model will look like glass.

  2. #2
    Software Developer jverkoey's Avatar
    Join Date
    Feb 2003
    Location
    New York
    Posts
    1,905
    very awesome anywhere where we can download a demo to see it in action?

  3. #3
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Looks good....I bet that takes quite a bit of time to compute.

  4. #4
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by jverkoey
    very awesome anywhere where we can download a demo to see it in action?
    Im actually just handing it in today and it looks like about %50 of the class couldent build a ray tracer , so posting source right now is a little risky. Perhaps after ive received a mark for it
    Also, there is no input file or anything yet. It just takes a model name as a command line arg and all the lights, postitions, camera. etc. is hard coded (dont ask why, they wanted it that way). If i have time i'll change it so the user can specify a param file with any number of models and lights.

    Quote Originally Posted by Bubba
    Looks good....I bet that takes quite a bit of time to compute.
    yup, over a minute to render that model (~3300 polys, 3 lights) on my lap top. Thats with pretty much no optimization though (just not enough time for something that wasnt required) The only thing im doing to speed it up is dividing the space into 2 half spaces and only checking rays against polys in that half space.


    Thanx for the feedback guys. =]

  5. #5
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    Hey wow, this has not received enough replies. Good friggin work man, it's aesthetically pleasing, and a difficult undertaking.

    Keep it up. i'd love to see the source, because to be honest I have no clue where I'd even begin in writing something like that, because my graphics rendering knowledge is not that advanced.

    EDIT:
    so, like, what's the paradigm here? Are you using an API like OpenGL? If so, are you doing this with fragment programs (erm, pixel/vertex shaders, im not totally sure on the correct terminology here). I'd just like to get a better idea of how you did the project.

  6. #6
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Silvercord
    Hey wow, this has not received enough replies. Good friggin work man, it's aesthetically pleasing, and a difficult undertaking.

    Keep it up. i'd love to see the source, because to be honest I have no clue where I'd even begin in writing something like that, because my graphics rendering knowledge is not that advanced.

    EDIT:
    so, like, what's the paradigm here? Are you using an API like OpenGL? If so, are you doing this with fragment programs (erm, pixel/vertex shaders, im not totally sure on the correct terminology here). I'd just like to get a better idea of how you did the project.
    thanks.

    I am using OpenGL to simply render the raw data after it has been calculated (pixel data) then i save the image to a .ppm file. As far as the actual ray tracing goes, everything is written from scratch, no lib's or api's.

    The idea is to cast a ray (define a vector) from the camera/eye position through each pixel on the raster plane. Then i find where that ray (vector) intersects the model. I then define a new ray (vector) from that point in the reflection direction (vertex normals are interpolated across the triangle and a reflection formula based on actual physics is used). This is done recursuvely until the ray intersects the surrounding evironment. The texture pixel color of intersection is then used as the ambient lighting term in the phong lighting calculation. Phong shading is calculated for each pixel based on the reflected ambient term and the diffuse and specular terms from the light sources (3 in this example).

    Heres a good overview if your interested in some of the finer details of ray tracing.
    http://www.siggraph.org/education/ma...ce/rtrace0.htm

  7. #7
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Awesome - good work. I'd like to see the source too, when those classmates of yours are done failing .
    Do not make direct eye contact with me.

  8. #8
    Banned
    Join Date
    Jan 2003
    Posts
    1,708
    How are the interactions handled when a ray hits a surface in your program? are they simply reflected, or does your program take into account a loss of energy or something like that?

    How long did it take to write, and what program are you in in school? A computer science major?

  9. #9
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Silvercord
    How are the interactions handled when a ray hits a surface in your program? are they simply reflected, or does your program take into account a loss of energy or something like that?

    How long did it take to write, and what program are you in in school? A computer science major?
    There is no energy associated with the rays, they just keep on traveling untill they hit something. What your suggesting with the energy is something called "Radiosity" which is the best way to get a realistic render though it is exceptionally slow. In Ray tracing there are constants defined to weight the ambient, diffuse, and specular components. So basically, ray tracing will "fake" that part of the physics.

    Unfortunaltley i only had a few days (about 5 in total) to write it which means the code is ugly with minimal documentation. Also i realized i basically did the entire thing backwards (kinda hard to explain but Im essentially negating and inverting everything then rendering the image from bottom up to get the same effect as doing it properly) This happend due to a common approach taken in comp. sci. known as the "Crap, i have no time, i just need to make it work..." approach.

    Im a Comp. Sci. major in my third year, though this graphics course is a 4th year course.

  10. #10
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Here's another ray trace of a crappy model i made with an amazing modeling program called "Teddy". Im gonna post something in the GD forum about teddy so everyone can enjoy so check it out there.

  11. #11
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Quote Originally Posted by Perspective
    There is no energy associated with the rays, they just keep on traveling untill they hit something. What your suggesting with the energy is something called "Radiosity" which is the best way to get a realistic render though it is exceptionally slow.
    Radiosity isn't yet truly realtime though, is it?
    Do not make direct eye contact with me.

  12. #12
    Crazy Fool Perspective's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    2,640
    Quote Originally Posted by Lurker
    Radiosity isn't yet truly realtime though, is it?
    No, there isnt fast enough hardware to support realtime radiosity rendering. The resulting images are pretty impressive though.

  13. #13
    The Defective GRAPE Lurker's Avatar
    Join Date
    Feb 2003
    Posts
    949
    Quote Originally Posted by Perspective
    The resulting images are pretty impressive though.
    Very true.
    Do not make direct eye contact with me.

  14. #14
    Registered User
    Join Date
    Mar 2004
    Posts
    180
    Can I see one? :d

  15. #15
    C++ Developer XSquared's Avatar
    Join Date
    Jun 2002
    Location
    Ontario, Canada
    Posts
    2,718
    Dude, don't bump ancient posts.
    Naturally I didn't feel inspired enough to read all the links for you, since I already slaved away for long hours under a blistering sun pressing the search button after typing four whole words! - Quzah

    You. Fetch me my copy of the Wall Street Journal. You two, fight to the death - Stewie

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help designing a recursive function.
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 07-24-2008, 12:45 PM
  2. Ray Tracer
    By CrazyNorman in forum Game Programming
    Replies: 0
    Last Post: 06-18-2008, 10:31 PM
  3. Ray Traced Terrain Self Shadowing Tut
    By Perspective in forum Game Programming
    Replies: 10
    Last Post: 02-12-2006, 12:04 PM
  4. Ray tracer and collision detection
    By hdragon in forum Game Programming
    Replies: 31
    Last Post: 01-19-2006, 11:09 AM
  5. Linked List problem
    By unregistered in forum C Programming
    Replies: 65
    Last Post: 04-16-2002, 10:04 PM