rapidash
rapidash

Reputation: 278

Ray Tracing Calculations

I'm trying to do some calculations involving ray tracing, but am a little confused. Lets say I had an n-by-n image with N geometric primitives, l light sources, and k x k supersampling. How many ray intersections would I be calculating in the worst case? What if I added in reflection/refraction with depth d?

Upvotes: 2

Views: 873

Answers (2)

Jay
Jay

Reputation: 3355

Not that this is a complete answer however.... See this article: http://blogs.msdn.com/b/lukeh/archive/2007/10/01/taking-linq-to-objects-to-extremes-a-fully-linqified-raytracer.aspx You could probably utilize that modified with some counting code to have these statistics automatically given to you when you do the trace :P

Upvotes: 2

Alejandro Piad
Alejandro Piad

Reputation: 1877

You would have to launch k x k rays for each of the n x n pixels of the image. For each of these rays you have to do collision testing, which, in a very simplified and inefficient way would translate to N comparisons (each depending on the complexity of the primitive). Now, if any of these rays hits an specular or translucid surface, you have to split the ray and call recursively. However, this time you don't do supersampling, so you just send one ray out in the reflect/refract direction. For depth d you would send that number of extra rays, one for each recursive call.

So, in total: k^2 x n^2 x d.

This is without counting the intersection calculations, which do not add any more rays but do add a lot of complexity.

There are, however, many simplifications.

  • Adaptive multisampling, reducing the k^2 factor.
  • Pixel interpolations, reducing the n^2 factor.
  • Use some space partition structure, like BSP and/or OctTree for collision testing.
  • Use some heuristic to cut out the recursion.

Upvotes: 7

Related Questions