COMP30019 Graphics and Interaction Ray Tracing Department of Computer Science and Software Engineering The
Lecture outline Ray tracing Recursive Ray Tracing Binary Space Partition (BSP) Trees Refraction Transparency Shadow volumes & the Stencil Buffer
What alternatives are there to the rendering pipeline approach? Aim: understand the computational implications of ray tracing and the radiance illumination model. Reading: 13.4 Visible-surface ray tracing and 14.7 Recursive Ray tracing and Foley Sections 12.4.8 Shadows.
Alternative to rendering pipeline: Ray tracing Idea is simple: tracing backwards the path of each ray of light entering the camera to find out what objects it encountered, and what light sources it came from! 1. Each pixel in the created image corresponds to a line of sight. 2. Start from image not polygon or object as in rendering pipeline approach. 3. We can trace back this line of sight (ray) to find the nearest object surface it intersects. At this inter point, we can check for visibility of light sources, and compute Lambertian, ambient, and specular contributions to our ray.
Recursive rays T 2 R 2 N 2 N i Surface normal R 1 T 1 N 3 R 3 R i Reflected ray L i Shadow ray L 2 L 3 L 1 T i Transmitted ray N 1 Viewpoint Point light source (Foley Figure 14.35)
fxguide: A SSS render using Lightstage data
Real-time ray tracing? The cardinality (or size) of the ray tracing problem is determined by the number of pixels in the image or viewport, as opposed to the number of polygons in the scene as in the rendering pipeline approach. In addition, ray tracing is made more computationally intensive by the recursive nature of ray tracing (depending upon what order you assume in terms of how many re-reflections of rays you cater for).
Octane Render: raltime ray tracing
Octane Render: realtime ray tracing
Some real-time ray tracing techiques Quite a large number of approaches to speed up. Pre-baking, OpenRL (low level interactive ray tracing API), Bounding volumes, e.g. Binary space parition trees (BSPs)...
World space scene intersection in Unity 5 http://www.gdcvault.com/play/1020688/ Practical-Techniques-for-Ray-Tracing
Binary Space Partition (BSP) Trees Binary partition sort (akin to quicksort): Choose a face Partition other faces into those closer or farther than the plane of this face (cutting faces where they straddle the partitioning plane) Recursively work on the partitions, until single faces Note: This partitioning structure (tree) is invariant to change of viewpoint
A BSP tree representation in two-dimensions (2D) f a c e d b i h j (a) g k in a b j c e k out d out f g in out out in out h out in i in out (b) (a) A concave polygon bounded by black lines.(b) The BSP tree. Foley Figure 10.19 Lines defining the half-spaces are dark grey, and in cells are light grey.
The BSP tree algorithm is an extremely efficient method for calculating the visibility relationships among a static group of 3D polygons as seen from an arbitrary viewpoint. Remarkably, the BSP tree can be traversed in a modified in-order tree walk to yield a correct priority ordered polygon list. Based on relationship to polygons surface normal. unlike other approaches where data structures need re-calculating (note, if using z-buffering, or scan-line variant rely on sortedness of polygons, and as viewpoint changes will need to re-sort these lists. Downside: need to pre-process all polygons.
Refraction When going from one medium to another, a ray of light will be bent at the intermediate surface. This bending, refraction, is governed by Snell s Law: sin θ i sin θ t = η tλ η iλ where θ i is the angle of incidence, θ t is the angle of refraction and η tλ and η iλ are the indices of refraction of each material as a function of wavelength λ. Notice that, for a solid piece of transparent material, light will be refracted both on entering and leaving the material.
Calculating the Refraction vector N cosθ i I N I N cosθ i θ i sinθ t M θ t M = (N cosθ i I) /sinθ i cos θ t N N T = sinθ t M cosθ t N (Foley Figure 14.32)
Transparency Some of this loss is from reflection at the surfaces as the light enters and leaves the object. This is the factor t. The rest of the loss is from absorption within the transparent material. A constant increase in path length within the material reduces the light by a constant factor, leading to an exponential behaviour. T = te ad where a is parameter, and d is the distance travelled within the material. Note, because light may take an oblique path, the distance d is not usually the same as the thickness of the material.
Ray tracing Recursive Ray Tracing Binary Space Partition (BSP) Trees Refraction Transparency Shadow volumes & the Stencil
Shadow volumes & the Stencil Buffer Light Object C B A A front facing shadow polygon, A or B in above Figure, causes polygons behind it to be shadowed. (Foley Figure 14.28)
Scan-line generation of shadows Light A A Current scan line a b c d B Viewer (Foley Figure 14.27)
Stencil buffer & Shadow Volumes toolkit - Unity