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


Submitted by Trenkwalder Markus, posted on March 11, 2005




Image Description, by Trenkwalder Markus



Lately I was interested in raytracing. I started writing my own raytracer with C++ in December 2004, utilizing my own math3d++ library for the necessary vector math, and was able to get the first results within less than a week.

I continued development at a much lower pace and added documentation to the source code, so that others, reading my code, could understand what i intended. To be able to test new materials and pixel sampling patterns for antialiasing I created some simple test scenes which you can see in the images.

Most of the scenes feature perfect spheres with different materials applied to them. The checkerboard texture in the images is a procedural texture. In bottom two images there is also a procedural bumpmap applied to it.

The top image and the left image in the second row feature High Dynamic Range (HDR) rendering. All the light in these scenes comes from a HDR cubemap.

Appart from manually unrolling small loops in the my math3d++ library (which speeded things up quite a lot) the raytracer does not use any optimizations! On my computer (Athlon TB 1.2 GHz) it takes 1.19 seconds to render the right scene in the second row at a resolution of 640x480 pixels with 1 sample per pixel (not that fast).

Source code can be downloaded at http://trenki.gippsbiz.com/raytracer/


[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.
 
El Pinto Grande

March 11, 2005, 09:43 AM

At 640x480 that's about 300k primaries and with one light, say, 300k shadow rays; or around 500Kray/s.
For such a simplistic scene, even on your box, that's reeeeal slow.

Anyway there's never enough raytraced IOTDs ;)

 
tetsifly

March 11, 2005, 11:15 AM

El Pinto Grande wrote: At 640x480 that's about 300k primaries and with one light, say, 300k shadow rays; or around 500Kray/s. For such a simplistic scene, even on your box, that's reeeeal slow.

He did say he didn't have any optimisations. :-|

Very nice images though! I especially like the sphere with the bubbles inside. If you are thinking about optimising your ray tracer, first port of call should be an octree. It speeds things up by about 20 times even for small models, and the more objects you include in your scene, the better it performs. Keep up the good work!

 
El Pinto Grande

March 11, 2005, 11:32 AM

tetsifly wrote: He did say he didn't have any optimisations. :-| Very nice images though! I especially like the sphere with the bubbles inside. If you are thinking about optimising your ray tracer, first port of call should be an octree. It speeds things up by about 20 times even for small models, and the more objects you include in your scene, the better it performs. Keep up the good work!


I think that one has crossed the line between non-optimized and slow like molasse.

And for such scenes, any spatial partionning would be a hinderance; not that it matters at that point :)

 
Trenki

March 11, 2005, 02:50 PM

El Pinto Grande wrote: At 640x480 that's about 300k primaries and with one light, say, 300k shadow rays; or around 500Kray/s. For such a simplistic scene, even on your box, that's reeeeal slow.


In this particular scene there are actually no shadow rays, though, it is a quite a complex scene.

All of the white tiles on the floor are reflective and therefore a reflection ray is recursively raytraced. The sphere is reflective and refractive so two rays are generated from which one enters the sphere and when it exits another refracted ray is generated. Behind the refractive sphere there is located a completely reflective sphere which reflects the rays back onto the sphere, so another set of refraction and reflection rays is generated. Then there is also the sphere on the right which reflects the refractive sphere.

With 1.19 seconds on my 1.2 GHz Athlon it is indeed slow but you have to take into account the many reflected and refracted rays.

 
El Pinto Grande

March 11, 2005, 03:28 PM

Ah ok, thought it was the table thing.

Still, i wouldn't qualify 2 spheres and a plane, reflexive/refractive or not, as a complex scene; even with those secondaries that doesn't make it.

IE brute force in action:
http://ompf.org/spgm/gal/first_try/09.jpg
That's an old rtrt attempt, and it's subsampled etc... but you see my point.

 
TobeyThorn

March 11, 2005, 04:10 PM

notice how the image linked to by El Pinto Grande is rather crapulent in quality. whereas Trenki's images are very sharp and artifact free. i'm not saying that it isn't slow, but compare 'insert favorite fruit here' to said favorite fruit. that said, Trenki should seriously consider optimizing/rewriting parts of his raytracer.

 
El Pinto Grande

March 11, 2005, 04:46 PM

Hello?
If you bother reading the text around that link you may notice the use of the term 'subsampled'.

I dug that crapulent shot to show that such a simple scene, even with tons of secondaries, should be rendered way faster by mere brute force.
And subsampling alone cannot explain why on one side a 1600x1200 image is rendered @ 5fps and a 640x480 image @ 0.8 fps on the other.
Remember, 2 spheres and a plane.

Now that you're asking, i can also produce artifact free complex scene in real time, thank you.
But that wasn't the point.

Damn, i hate feeding the troll.

 
tetsifly

March 11, 2005, 04:50 PM

TobeyThorn wrote:that said, Trenki should seriously consider optimizing/rewriting parts of his raytracer.

It would be a complete waste of time heavily optimising sphere and plane intersection code; there's only really one way of doing it anyway. It's when render times start running into hours that optimisation really starts to pay off. It would be a much better idea to implement polygon meshes or global illumination then spend the time improving those aspects of the renderer.

 
TobeyThorn

March 11, 2005, 08:03 PM

don't get so pissy el pinto

 
codeg

March 12, 2005, 05:53 AM

Well done. it looks really cool.
The green sphere in perticular is really nice. I like it.

Keep up the good work

 
Scali

March 13, 2005, 04:04 AM

I don't think you should be comparing rtrt with this.
It looks like this raytracer is trying to go for quality and features, not for the fastest (ugly) hacks to sorta visualize a sphere.
They are two completely different things.

 
Jacco Bikker

March 13, 2005, 05:10 AM

In my opinion it's perfectly OK to focus on features instead of quality. I only started looking at performance once rendering times exceeded several seconds, just because debugging is anoying under these circumstances.

Rendering that green sphere is cool no matter what the speed is. I love that shot. :)

BTW pinto, did you experience something traumatic involving subsampling during your youth? ;)

 
El Pinto Grande

March 13, 2005, 11:16 AM

A rtrt doesn't have to be ugly or hackish (in terms of rendering); Wald proved it.

I dug up that ugly shot because that was the only rendering i had of such an ultra simplistic scene; obviously that was a mistake as it proved too divertive :)

 
El Pinto Grande

March 13, 2005, 11:19 AM

Yes, i think of myself as subsampled sometimes.

 
zOinks

March 13, 2005, 03:30 PM

I agree. I think the two clear spheres are even cooler than the big green one. Anyone can pickup povray in a weekend and generate a few images, but you coded your own engine dude!, nice! Now that's an accomplishment that brings a _great_ deal of satisfaction. Good job.

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