Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 508
rapidash Avatar asked May 06 '26 22:05

rapidash


2 Answers

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.
like image 137
Alejandro Piad Avatar answered May 11 '26 05:05

Alejandro Piad


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

like image 25
Jay Avatar answered May 11 '26 06:05

Jay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!