150 likes | 273 Views
Luke Curley. Ray tracing using Volumetric Planes. What is a “VP”?. “VP” is short for “Volumetric Plane”. It is an infinite volume defined by a plane in coordinate space. Equation of a VP. The equation for a VP is the exact same as the equation for a plane. Ax + By + Cz + D = 0
E N D
Luke Curley Ray tracing using Volumetric Planes
What is a “VP”? • “VP” is short for “Volumetric Plane”. It is an infinite volume defined by a plane in coordinate space.
Equation of a VP • The equation for a VP is the exact same as the equation for a plane. • Ax + By + Cz + D = 0 • For some constants A, B, C, and D. • The volume of a VP is the volume on the side of the plane that is opposite to the surface normal.
Constructing Objects with VPs • Objects are constructed by taking the intersection of multiple VPs. • Other set operators can be used depending on the implementation.
Constructing Scenes • Scenes are constructed by taking the union of multiple objects. • The only primitive is a VP, and it is possible to create any scene using only VPs and set operators. • This makes it possible to treat each VP individually and combine the results through simple set operators (intersection and union, specifically).
Ray Tracing with VPs • The ray tracing algorithm is unchanged with the exception of the ray intersection code. • Instead of using triangles to represent surfaces, VPs can represent volumes and are faster to calculate per face.
IntervalintersectRayVP(Ray& ray, VP& vp) { float temp = dot(vp.normal, ray.direction); if (temp < 0.0f) { return Interval(-(dot(vp.normal, ray.origin) + vp.offset) / temp, float_max); } elseif (temp > 0.0f) { return Interval(0.0f, -(dot(vp.normal, ray.origin) + vp.offset) / temp); } elseif (vp.offset < -dot(vp.normal, ray.origin)) { return Interval(0.0f, float_max); } else { return Interval(float_max, float_max); } } Ray-VP Intersection • The Ray-VP intersection algorithm is very simple and similar to Ray-Plane. • vp.normal = (A, B, C) • vp.offset = D
IntervalintersectRayVP(Ray& ray, VP& vp) { float temp = dot(vp.normal, ray.direction); if (temp < 0.0f) { return Interval(-(dot(vp.normal, ray.origin) + vp.offset) / temp, float_max); } elseif (temp > 0.0f) { return Interval(0.0f, -(dot(vp.normal, ray.origin) + vp.offset) / temp); } elseif (vp.offset < -dot(vp.normal, ray.origin)) { return Interval(0.0f, float_max); } else { return Interval(float_max, float_max); } } Ray-VP Intersection • VPs have volume, so a ray will intersect a given VP over an interval. • All that is left to do is intersect or union the returned intervals. • Much faster than Ray-Triangle intersection.
Combining the Results • While the Ray-VP code is simple, actually combining the results is more of a problem. • The computation is minimal, but it is hard to structure the data in such a way that lends itself to parallel reduction. • Ray-tracing on a CPU will see enormous performance benefits, but I decided to try implementing a VP ray tracer in CUDA.
CUDA Ray Tracing • CUDA harnesses the full power of parallel computing provided the application is suited. • Calculating Ray-VP intersection with CUDA is very fast, but the reduction from many intervals to one requires synchronization. • The CUDA SDK outlines optimizations for parallel reduction, all of which I implemented for my program.
CUDA Ray Tracing Performance • The fast algorithm treats all VPs as one object. • This is not practical, but gives an idea of the fastest case.
CUDA Ray Tracing Performance • The jumps are related to the CUDA architecture and occur because of the number of threads per block.
CUDA Ray Tracing Performance • Aside from calculating Ray-VP intersection, the program also had to spawn the rays (given a camera model) and perform simple Phong shading with one light. • This took roughly 3000 GPU time, and consisted of 1.5% of the computation time for the highest end case (256 VPs). • Real performance strides can be made by speeding up the intersection code.
CUDA Ray Tracing • Resolution: 800x800 • FPS: 15 • VP Count: 81 • GPU: nVidia 275 GTX • This is using the “fast” algorithm.