Jump to content
  • Advertisement
Sign in to follow this  
Lode

Realtime raytracing

This topic is 4515 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm following a course called "Computer Graphics". We have to write a raytracer, worth 7 of the 20 points of the exam. Actually we have a choice between two things we can make: a rasterizer (where speed is important) or a raytracer (where speed isn't important but the effects are). So the raytracer doesn't have to be realtime, but I want to amaze the professor by making it realtime. Currently, I can raytrace 4 flat shaded, untextured spheres, at 20fps at 400x300 pixels. Now I still have to add Phong shading and "transformations of objects", and later we will get a second part of the assignment, which will probably add things like reflections and translucency. I'm wondering, if I'd still be able to get it somewhat realtime after all those effects are added. I mean, for example I have to add "transformations of objects", that means I have for every pixel, for every object, to add a multiplication with a 4x4 matrix... Which is maybe more work than everything that's done per pixel right now! Is there a way to do this fast too? Oh yeah, I used to compile my code with "g++ *.cpp -lSDL", and it was 30fps with 1 sphere. Then I compiled it with "g++ *.cpp -lSDL -O3" instead, and it was 65fps with 1 sphere!! Are there other such optimizations that g++ can do, that could make it even faster?

Share this post


Link to post
Share on other sites
Advertisement
I've saw some time ago a real-time raytracer that raytraced 5 reflecting spheres, so I think there's some room left.

What you should really try is to use the vector units of your processor - i.e. SSE/SSE2. There's a compiler switch for GCC for auto-vectorization but you'll probably want to hand-optimize it anyway. Take a look at http://www.openrt.de/, they have some publications on how they optimized their renderer, might give you some helpful hints.

Share this post


Link to post
Share on other sites
And, if you are allowed, then use the GPU Shaders for extra math computational power. With a good video card, this more than doubles the available processing power.

Share this post


Link to post
Share on other sites
Check out the forums on this site.
They have produced some VERY fast raytracers and there's some code floating around there to help you.
Also look up Havran's work, he has done a lot of research on fast raytracing (almost getting realtime global illumination).

Share this post


Link to post
Share on other sites
a few:

-ffast-math
-march=i686

and sometimes

-fexpensive-optimizations

there are others, but I will use the top 2 routinely.

Share this post


Link to post
Share on other sites
Maybe you want to take a look at this library:
http://www.libsh.org/

Basically it allows to use your GPU as a general vector processor, i.e. add pairwise two arrays of numbers and such. You can use it to calculate intersections of rays and spheres in parallel, for instance.

Share this post


Link to post
Share on other sites
one obvious thing is that you dont have to transform every ray...just transform the objects at the beginning of each frame (still keep the matrices and the original coords, but do the transformation only per object per frame). this is especially true with spheres, which are invariant under rotation (unless you start adding surface shaders).

Share this post


Link to post
Share on other sites
Heaven Seven is an old (2000) example of real time ray tracing (in 64k no less).

You'll want some form of space partitioning, to help speed up intersection tests (probably wont help with 4 objects but it becomes very useful very quickly). There where some tricks with using interpolation instead of complete samples, but I not remembering them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!