10

I've been wanting to write my own multithreaded realtime raytracer in C++, but I don't want to implement all the vector and matrix logic that comes with it. I figured I'd do some research to find a good library for this, but I haven't had much success...

It's important that the implementation is fast, and preferably that it comes with some friendly licensing. I've read that boost has basic algebra, but I couldn't find anything on how good it was regarding its speed.

For the rest, Google gave me Armadillo, which claims to be very fast, and compares itself to certain other libraries that I haven't heard of.
Then I got Seldon, which also claims to be efficient and convenient, although I couldn't find out where exactly they are on the scale.
Lastly I read about Eigen, which I've also seen mentioned here on StackOverflow while searching here.

In the CG lecture at my university, they use HLSL for the algebra (making the students implement/optimise parts of the raytracer), which got me thinking whether or not I could use GLSL for this. Again, I have no idea what option is most efficient, or what the general consensus is on algebra libraries. I was hoping SO could help me out here, so I can get started with some real development :)

PS: I tried linking to sites, but I don't have enough rep yet

robrene
  • 359
  • 3
  • 14
  • 2
    I'd highly recommend ompf.org (http://ompf.org) their forums are filled with some of the fastest raytracers in existence. And many of them include detailed information about how they work. – Timothy Baldridge Jan 13 '11 at 15:12

5 Answers5

12

I'd recommend writing your own routines. When I wrote my raytracer, I found that most of the algebra used the same small collection of methods. Basically all you need is a vector class that supports addition, subtraction, etc. And from there all you really need is Dot and Cross.

And to be honest using GLSL isn't going to give you much more than that anyways (they only support dot, cross and simple vector math, everything else must be hand coded). I'd also recommend prototyping in C++ then moving to CUDA afterwards. It's rather difficult to debug a GPU code, so you can get it working in the CPU then recode it a bit to work in CUDA.

In reality raytracers are fairly simple. It's making them fast that is hard. It's the acceleration structures that are going to take most of your time and optimization. At least it did for me.

Timothy Baldridge
  • 10,455
  • 1
  • 44
  • 80
  • Did you write your own ray-object intersection routines, or is there a library can handle this? – Daniel Farrell Jan 12 '11 at 22:33
  • This is exactly the type of answer I was looking for, thanks! – robrene Jan 12 '11 at 23:28
  • I wrote my own. And it's not hard. I started with a brute force, triangle only raytracer. I wrote an exporter from Blender that would export any object as a list of triangles. Then v1 of the raytracer only needs to do ray->triangle intersection. After that I implemented a BVH tree. Basically you take groups of triangles and wrap them into cubes. Cubes are wrapped into more cubes. From there you simply do a ray->cube intersection test and keep walking down the tree till you hit a triangle. – Timothy Baldridge Jan 13 '11 at 15:09
  • In the final version the tree was created in CPU, and then flattened into a memory block that was fed into the GPU (via CUDA) where the collision detection was performed. – Timothy Baldridge Jan 13 '11 at 15:10
  • This is long after the OP but new things happen: the http://en.wikipedia.org/wiki/OpenRL library does most of the acceleration structuring (and provides the base types you would need) -- consider it to be like OpenGL, in that you don't need (or want) to have to implement poly-filling and Bresenham lines. Just let the library manage the ugly bits while you focus on content – bjorke Jun 24 '13 at 18:55
2

You should take look at http://ompf.org/forum/

This forum treats of realtime raytracing, mostly in C++. It will give you pointers, and sample source.

Most of the time, as every cycle count, people do not rely on external vector math libs: optimizations depend on the compiler you're using, inlining, use of SSE (or kindof) or not, etc.

rotoglup
  • 5,223
  • 25
  • 37
1

I recommend "IlmBase" that is part of the OpenEXR package. It's well-written C++, developed by ILM, and widely used by people who professionally write and use graphics software.

Larry Gritz
  • 13,331
  • 5
  • 42
  • 42
0

For my projects I used glm, maybe it would also suit you.

Note that libraries such as boost::ublas or seldon probably won't suit you, because they're BLAS-oriented (and I assume you're looking for a good 3D-driven linear algebra library).

Also, the dxmath DirectX library is pretty good, although sometimes hard to use, because of it's C-compatible style.

Yippie-Ki-Yay
  • 22,026
  • 26
  • 90
  • 148
0

You might look at the source code for POVRAY

Jay
  • 13,803
  • 4
  • 42
  • 69