Not logged in, Join Here! or Log In Below:  
News Articles Search    

Submitted by Buddy Betts, posted on February 26, 2002

Image Description, by Buddy Betts

So here's my first IOTD submission -- my "it's been done millions of times before" ray-tracer! It contains the standard features:
  • spheres
  • planes
  • polygons (well, only triangles, but easy to convert to any convex polygon)
  • cylinders
  • ambient light
  • point lights
  • spot lights
  • soft shadows
  • reflections (can set level of diffusion)
  • texture mapping
  • bump mapping
  • multi-texturing
  • It's written in C++ and uses OpenGL. Wrote it under Windows, but since it uses OpenGL don't see why it wouldn't work under other OSes. In fact, if you're so inclined you can pick up a copy of the code at If you've ever wanted to write cool ray-tracer effects but are too lazy to do the basics, now's your chance!

    -Buddy Betts

    Image of the Day Gallery


    Message Center / Reader Comments: ( To Participate in the Discussion, Join the Community )
    Archive Notice: This thread is old and no longer active. It is here for reference purposes. This thread was created on an older version of the flipcode forums, before the site closed in 2005. Please keep that in mind as you view this thread, as many of the topics and opinions may be outdated.

    February 26, 2002, 02:38 PM

    Nice work, the mirror effect looks neat. But I fail to see the reflected middle ball in the red and blue speheres, I just see a black shadow. Maybe I need a pair of new glasses.. :)

    Navreet Gill

    February 26, 2002, 02:46 PM

    haha, the site already exceeded it's data transfer for the day

    Ron Frazier

    February 26, 2002, 02:48 PM

    I think I see it (could be my imagination), but the tricky thing is that you are looking for a mirrored object in a hazy reflection. Its a lot harder to find detect something like that in a still image.


    February 26, 2002, 03:10 PM

    No. It isn't there. this is what occurred to me when i looked at the pic for the first time. Pretty annoying...

    Pieter Anemaet

    February 26, 2002, 03:18 PM

    /me looks at the IOTD

    "Hubba hubba"

    Nice work!


    February 26, 2002, 03:35 PM

    Hasta los cojones!

    Very nice.


    February 26, 2002, 03:37 PM

    How is raytracing done in OpenGL?

    I've heard of using hardware to render masks for first-shoot optimization, but what else?

    Nate Miller

    February 26, 2002, 03:51 PM

    You render the permutated mutex of the lateral tangential line to the sphere of complexity and you gain 10 FPS. You can also try accessing the off-screen hyperbolic ray that is circumscribed to the on-screen halo monitor, which gives you a 10.1 FPS increase.


    February 26, 2002, 04:05 PM

    you forgot to mention the feeding pie!


    February 26, 2002, 04:13 PM

    Nah.. it's there, but really hard to see.. I had to zoom in on the image, then you can see the outline of the middle sphere..

    Palsy Palooka

    February 26, 2002, 04:28 PM

    I'm sure you can see it. Just watch the reflection in the red and the blue sphere of the reflection of the groundtiles in the middle sphere. It should all be clear now...

    Palsy Palooka

    February 26, 2002, 04:31 PM

    Nice work, how long does it take to render such a scene?


    February 26, 2002, 04:32 PM

    He never actually said it was hardware accelerated, just that it uses OpenGL. I have a funny feeling he's just using OpenGL to access the frame buffer.


    February 26, 2002, 04:51 PM

    You're all crazy. The red and blue spheres are significantly behind the centre one.. and you can see the reflections of the red and blue spheres in the centre sphere, where you would expect to find them.


    February 26, 2002, 05:37 PM

    I guess I was kinda confusing.. I'm just using OpenGL to open a window and use orthographic projection to draw a 2d image.. so it just barely uses OpenGL.


    February 26, 2002, 05:40 PM

    Well, on my slow PII-366 it generally takes a few minutes to render the scene at 1024x768. It's not optimized in any way.. when I'm working on it I just render to a nice 320x200 just so I can see if my changes are working without taking forever. Of course, the more objects/reflections you have the slower it is..


    February 26, 2002, 06:52 PM

    it is there, you can't see it cus the middle sphere is gray :P

    Ben Gosney


    February 26, 2002, 07:41 PM

    very nice work :) i'm a sucker for ray tracing indeed :)

    i just finished updating my realtime ray tracer, check

    what sampling method are you using for your area lights? what kind of area lights are you using?

    it's nice that you're also releasing the code, i'm going to have a look at it later today...


    February 26, 2002, 07:53 PM

    hmm, i put the sentence referring to my site in plug and /plug tags, which are missing. oh well.


    February 27, 2002, 04:07 AM

    I think the reflections are quite messed up. I dont see the middle ball in the red or blue balls BUT I might see the blue ball reflection in the BLUE ball (and red refl in the red ball) odd...? Or then perhaps I'm too tired to see anything.



    February 27, 2002, 07:15 AM

    hope I can see other shape or objects done with ray tracing other than sphere such as dodecahedron, torus etc...
    erm..anyway, the green guy on the first pic sure looks nice..:)


    February 27, 2002, 09:28 AM

    Not only can you see the reflection of the grey ball on the blue ball, but you can even see the reflection of the red ball on the back of the grey ball on the blue ball.

    It's a raytracer... assume that it worked first, and if you really really can't find something, THEN get skeptical :)


    February 27, 2002, 09:33 AM

    Actually, I may have gone a little too far with what I just said... I suppose it is possible that for whatever reason, the grey ball isn't lit in the reflections... though you can clearly see the reflective component of the grey ball in the other balls.


    February 27, 2002, 09:38 AM

    (sorry, long thread)

    yeah, I think that's actually it. The back of the grey ball doesn't look as you would expect it to in real life, because the light it's receiving from the floor behind it isn't lighting it in the same manner as a light source.. and since the back is in the shade as well, you don't see any diffuse shading on the back of it at all (?).. and so all you're seeing is the reflection off the grey ball.
    .. but I think that's what raytracers typically do before implementing more features.. so screw it.


    February 27, 2002, 11:09 AM

    Your bump mapping looks slick in the top picture!



    February 28, 2002, 06:17 AM

    It must be possible to render this scene in real-time if you want. At least some frames per second at a good resolution. Use as much subsampling and early out as possible, and you'll get there ... It ain't that hard ...



    March 01, 2002, 02:39 PM

    Why is it that people are either complaining that the reflections don't look right, or go on about how many fps he could be getting.
    Usually it's pretty obvious from the description and completity of the image how competent they are in the field of raytracing.

    You know what I'd like to see in raytracers? Discs... part of a plane that is bounded by a sphere. And not made out of triangles either. I've got a very nice simple optimised disc intersection routine that I derived myself.


    March 08, 2002, 02:42 AM

    just a note...

    that i know of, the easiest/fastest way to calculate a disc intersection (which i recall from the book Photorealism and Ray Tracing in C) is to:

    1. assuming the disc is infinitely flat, define it as a plane with a given normal and origin (or offset).

    2. calculate the intersection between the ray and the disc's plane using the standard ray-plane intersection method.

    3. find the square of the distance from the point of intersection to the origin of the disc. if this result is less than the square of the radius of the disc, the ray intersects the disc.

    of course, (3) can be done using the actual distance and actual radius (instead of the squares), but it's easier to just find (P-Q)^2 (where P = disc origin and Q = intersection point).

    optionally, an "inner" radius can also be used; an intersection occurs only where the [square of the distance from the point of plane-intersection to the disc origin] is between the square of the disc outer radius and the disc inner radius. this allows for rendering of a disc with a hole in it (i.e. a flat toroid).

    - algofoogle

    This thread contains 28 messages.
    Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.