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


Submitted by Devon Zachary, posted on May 30, 2001




Image Description, by Devon Zachary



I started work on this raytracer project a while ago, but just recently purchased 'Computer Graphics -Principles and Practice' - stonking good book (if not slightly overwhelming!!) But I had heard that raytracers were easy to program and looked nice, so I dove in. The book had the intersection formulas for a couple primitives (plane+sphere+polygon) and so I coded those in.

Lighting is just basic phong lighting (N dot D + specular) and in the big purple picture you can see and example of a bug I was experiencing, in which the negative values (Resulting from the phong equation) were creating a very bright bump in the centre, which was odd, because I only had two lights!! But I solved the problem, and the picture looked good, so I saved it. Lights can have linear, quadratic, and constant attenuation...(although wrong values of linear+quadratic attenuation cause wierd colors alongside the border of the attenuation area)

Shadows are calculated using normal raytracing prodcedures (no shadow volumes or maps, although I would like to use shadow maps for softer shadows) The only interesting feature is a 'soft shadow sphere' feature, which creates a group of lights with low intensities to fake area lights.

There is reflection- no refraction. (need more time to wrap my head around it!) And support for basic surfaces, using perlin noise (which I am currently doing very wrong... the noise is not band limited!) as well as a checker function.

Looking at the POV- source has been very helpful, at least in terms of structuring the program....

Output is just to RAW files, it also outputs a depth map channel, based on T from the ray equation, I'm not sure if this is more, or less accurate for making stereograms then basic Z-buffers. (can someone who knows tell me?)

Anyway, if you have any questions, just ask!


[prev]
Image of the Day Gallery
www.flipcode.com

[next]

 
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.
 
Bart Coppens

May 30, 2001, 04:02 PM

That looks good! I especially like the big one in the middle because of the great reflections.

 
Lion V

May 30, 2001, 04:11 PM

I like it !
good work !

 
Mournblade

May 30, 2001, 04:22 PM

How long does it take to calculate the image - for a fullscreen image - 800x600x32. There was supposed to be a Raytracing in Realtime article but I haven't seen hide nor hair of it.

 
Clemens Hofreither

May 30, 2001, 04:36 PM

Looks pretty cool. (Especially the bugged one ;))
I have done something similar just some weeks ago, however I didn't spend a lot of time on it; but it's true, these raytracers are very fun and rewarding to write!
Question: Did you implement an input file format, or do you (just as I did) simply add the primitives in the source code?

 
EGreg

May 30, 2001, 05:45 PM

Very nice.
Why does everyone like making spheres? Hehehehe...

-Greg

 
David Olsson

May 30, 2001, 05:53 PM

Sphere is the most perect shape there is in three dimensionals, that and because spheres are the easiest object to intersect.

 
Jaap Suter

May 30, 2001, 05:57 PM

Sorry, but these kind of statements make my hair grow :). Since when is a sphere the most perfect shape in three dimensions? On what arguments are you basing that conclusion?

Grz,

Japio

 
dom

May 30, 2001, 06:06 PM

top work!

 
Sebastian Sylvan

May 30, 2001, 06:11 PM

Probably that it is symmetrical no matter from which direction you look at it.

 
David Olsson

May 30, 2001, 06:42 PM

Exactly, should be pretty obvious.

 
David Olsson

May 30, 2001, 06:43 PM

"Sorry, but these kind of statements make my hair grow". Good for you, then wont get bald ! :)

 
Jaap Suter

May 30, 2001, 06:44 PM

Symmetry defines the amount of perfectness?

Mmmmmm, :).
By the way, it's not that I entirely disagree with your statement. It's just that it's an interesting statement.

Grz,

Japio

 
David Olsson

May 30, 2001, 06:59 PM

At least in euclidean(?) geometry.

Another reason is that I'm thinking of basing my next raytracer entirly on microscopic spheres (used boxes before), I have good reasons for this.
My intention is to make this raytracer realtime. I have some pretty good ideas how to do this.

 
Derek Simkowiak

May 30, 2001, 07:12 PM

Regarding symmetry and geometrical "perfection"...

I saw ones of those "Human Sexuality" shows on The Learning Channel (or was it Discovery? whatever...) where they talked about brain chemistry, social development, Darwinistic tendencies, etc. Not exactly porn but interesting stuff nonetheless :)

Point is, some college did a huge social study and found that people most prefer members of the opposite sex whose face is symmetrical. That is, people with asymmetrical faces are considered "ugly", statistically speaking. (Another study used computers to composite hundreds of "attractive" women's faces into one face -- the result was quite a cutie.)

I guess I'm trying to say that people subconsciously want to hump spheres... or something...


 
malkia

May 30, 2001, 07:16 PM

so how you gonna handle the antialiasing at the end - I've read some papers about casting rays going through the same grid point but little bit jittered and then collecting the results for one pixel form several rays.. But as i never wrote real raytracer - i can't judge if this is efficient. Another idea is to cast 4 rays for the corners of each pixels and if you hit one and same object to accumulate all the pixels which are hit into one - the grid texture for example.

A friend of my gave me time ago to read some EWA filtering method - but it was very slow - Elliptical Weighted Average Filter -

I've tried to search it, hoping that it was only one document describing this technique - but it seems there are lots of them (including the one only refferencing)

search on google for >

 
malkia

May 30, 2001, 07:21 PM

funny, i've watched the same film time ago.

But human is kind of mono-symmetrical (hehe new-term?). He is not symmetrical from everywhere (like the ball).

Most creatures are like this - actually the snake is multi-one-axis symmetrical (one more :)...

but i really can't find the point in all this. Well I can't but women can - whoo >> It's good to be SYMMETRICAL

 
DragonWorx

May 30, 2001, 07:53 PM

This looks great.

I am studying RayTracing next semester at univerity, and i can't wait to make something as nice as this...

;)

 
RezDZ

May 30, 2001, 08:08 PM

Hello again! Thank's for your comments and/or questions....

Interesting theory on why we like sphere :)

How fast it renders is based on the complexity of the scene, obviously, but a scene with thousands of spheres calculates just as quickly as one with four spheres, because it does rudimentary vista calculation. Of course there is a bit of over head for looping through four thousand vistas, but....

To render the purple one, without shadows, at 640x480x16 (not 32..and no dithering...) is about 1.6 minutes.... but the actual ray count is very high, too high. somewhere around 160000 for the scene, because I need to do more calcs to determine when a ray's contribution is not very much (adaptive ray discarding....i think?)

The antialiasing question:

JITTER! Or possibly take a more distributed approach, for soft shadows etc. Maybe it will become a monte carlo tracer....I'm not sure. It's very easy to experiment, because everything is object oriented. So to try out a new way of rendering, I just rewrite the 'RayTracer' class, and it doesn't effect my vector,matrix,ray, etc. calculation.

Currently, it just renders four points for each grid pixel, and averages..... slow, but then again very easy.

Input file format: These pictures were just in the source, so:

Primitive Prim1;
Prim1.CreateAsSphere(Vector(wherever),Radius,(surface));
Scene.AddPrimitive(Prim1)

But I'm working on a 'compiled format', sort of like assembly language:

.scn
creatsurf 0
surftype 0 perlin
sphr 0,0,0 10
surf 0
plan 0,1,0 10

not very intuitive, but it will be okay when i use it with other apps (like converting a truespace mesh or something).

Spheres: They are easy to code! that is why I like them.

Anyone got any resources for cone tracing? Could one use cone tracing to do radiosity?

 
Alex Taylor

May 30, 2001, 08:38 PM

Don't be stupid. Everyone knows the most perfect shape in three dimensions is a 5ft pink elephant - duh. ;-)

 
LacrosseGoalie

May 30, 2001, 09:46 PM

Call me an idiot, but I never touched raytracing...I am now sort of intrigued with it. With raytracing, I understand that the number of spheres has little effect because the rays bounce off of them. This means that realtime raytracing is a possibility, if the room was built up of primitives, and there were some effecient algorithms and such. What I don't get is at what point does the ray start?

 
disableddan

May 30, 2001, 10:09 PM

It looks really cool! Those mirror and lighting effects never fail to impress.

 
Hemp

May 30, 2001, 10:09 PM

Um no, I absolutely have no desire to have sex with a sphere.

Although, I have had many women tell me that they like my balls.

Hmmm....

 
_Mike_

May 30, 2001, 11:06 PM


I leave for one weekend and you guys are talking about having sex with spheres! Nice pic, though

 
iMalc

May 30, 2001, 11:11 PM

>What I don't get is at what point does the ray start?
The ray usually starts from the camera/eye location and points towards the point on the near clip plane for the pixel to be rendered.
Rays can also start from the light sources (as is more natural) but this IMHO is more difficult but allows you to do effects known as caustics - shadows from refraction I think.

I myself have written a raytracer and have combined it with my Polygon Scan Converter such that the two can produce virtually identical pictures. But of course I can more easily add shadows and reflections in the ray-tracer, but it has to be fairly small (160*120) to run in realtime.

I have raytracing code for an arbitrary oriented cylinder, sphere, cone, parabola etc which I derived/optimised myself, if anyone is interested. Oh, and also polygon subdivision code for the PSC equivalents.

I am having trouble deriving the torus intersection equation, can someone help, or tell me where to find the code?

 
Bobris

May 31, 2001, 12:32 AM

POVRAY POVRAY and once again POVRAY
www.povray.org :-) Look at sources there is everything what you need ...

 
DirtyPunk

May 31, 2001, 12:38 AM

Ray tracing is most dependant on secondary rays in terms of time anyway :) The lower the maximum bounces per ray, the lower the rendering time :)

 
tom

May 31, 2001, 02:23 AM

imagine you have just one eye, which is located somewhere in front of your monitor :)
now you shoot a ray from the position of your eye through each pixel.
you must find the closest intersection of this ray with an object.
when you've found it, you can do your lighting calculations, and if the object reflects, start a new ray from the intersection (in this case you have to mirror the ray on the object's surface normal).

well, that's maybe a bit simplified, but actually, raytracing IS simple...the problem is, how to make it fast :)

 
Sdw

May 31, 2001, 03:04 AM

Nice pics! Actually I have also written a simple tracer a short while ago (screenshot). I was going for realtime performance, but if you check the screenshot you see a '0' in the fps counter! :) I had to drop down to really lowres to (128x64 or something) to get atleast somewhat decent framerates. I didn't have any profiling program so I never figured out exactly WHAT was taking too much time = what needed optimizing..

 
tom

May 31, 2001, 03:27 AM

>I never figured out exactly WHAT was taking too much time = what needed optimizing..

well, the intersection calculations, i'd say. solving quadratic equations (for spheres, cylinders etc) is quite expensive.
at least this was the performance killer #1 in the raytracer
i wrote some time ago.

 
gimp

May 31, 2001, 04:27 AM

"Symmetry defines the amount of perfectness? "

I saw an article a while back, "New Scientist" I think, that showed that people with more symmetrical faces were better looking(percieved anyway).

Plastic surgery is normally make a person more symmertical. People who resemble spheres however aren't normally seen as good looking in society though :)

Chris
(Not quite as symmetrical as he would like to be)

 
This thread contains 79 messages.
First Previous ( To view more messages, select a page: 0 1 2 ... out of 2) Next Last
 
 
Hosting by Solid Eight Studios, maker of PhotoTangler Collage Maker.