560 likes | 937 Views
Computer Graphics 2 Lecture 13: Ray-Tracing Techniques. Dr. Benjamin Mora. University of Wales Swansea. 1. Benjamin Mora. Content. What is Ray-Tracing? Mathematics for ray-tracing intersections. Common Ray-Tracing effects. Other Ray-Tracing Algorithms. Current Ray-Tracing Technology.
E N D
Computer Graphics 2Lecture 13:Ray-Tracing Techniques Dr. Benjamin Mora University of Wales Swansea 1 Benjamin Mora
Content • What is Ray-Tracing? • Mathematics for ray-tracing intersections. • Common Ray-Tracing effects. • Other Ray-Tracing Algorithms. • Current Ray-Tracing Technology. University of Wales Swansea 2 Benjamin Mora
What Is Ray-Tracing ? University of Wales Swansea 3 Benjamin Mora
What is Ray Tracing ? • The alternative to rasterization-based methods (like OpenGL or DirectX). • Image-Order algorithm. • Every pixel is processed separately. • Slower than rasterization methods in the case of few primitives to render. • Rarely used in games, widely used for realistic computer graphics. • www.povray.org. University of Wales Swansea 4 Benjamin Mora
What is Ray Tracing ? Jaime Vives Piqueres (2004), http://www.povray.org/i/hof/office-13.jpg University of Wales Swansea 5 Benjamin Mora
What is Ray Tracing ? Jaime Vives Piqueres (2001), http://www.povray.org/i/hof/office-13.jpg University of Wales Swansea 6 Benjamin Mora
image plane primary ray viewlocation secondary rays What is Ray Tracing ? University of Wales Swansea 7 Benjamin Mora
What is Ray Tracing ? • Basic (or Naïve )Algorithm (Whitted 1980): FOR every pixel DO FOR every primitive in the scene DO IF there is a ray/primitive intersection test if this is the closest intersection computed so far. If this is the case, keep this primitive as the closest primitive for the next tests. • Basic Complexity: • O(number of rays*number of primitives). • Optimized algorithms can do much better (See the next lectures)! University of Wales Swansea 8 Benjamin Mora
Mathematics for Ray-Tracing intersections University of Wales Swansea 9 Benjamin Mora
Vz Vy Vx P0 Parametric Ray/Plane Formulation • A ray can be described with a parametric formulation from a (starting) point and a direction • A parametric plane can be described from one point and two vectors: • A plane can also be defined from a point and a normal vector (here P0 and Vz). University of Wales Swansea 10 Benjamin Mora
p0 n vdir p(t) h o Ray/Plane Intersection • We are looking for the point p(t) such that p(t) belong to the plane h. • h is defined with a point o and a normal n. • If vdirperpendicular to n, then either 0 solution, or an infinite number of solutions if p0 belongs to h (the vector p0o perpendicular to n). University of Wales Swansea 11 Benjamin Mora
p0 n vdir p(t) h o Ray/Plane Intersection • Otherwise, there is only one point that is solution. We have to find out t. • The solution comes from the fact that the vector p(t)o is perpendicular to n: University of Wales Swansea 12 Benjamin Mora
txmin txmax tymax p0 tymin tymin tymax t txmin txmax Ray/Cube Intersection p(t)= p0+v•t v The ray intersects the cell only if max(txmin, tymin)<min(txmax, tymax). Finding out the exit face consists of finding out the minimum of (txmax, tymax). University of Wales Swansea 13 Benjamin Mora
Ray/Cube Intersection • A cube can be defined with 6 planes (faces). • 3 pairs of opposite faces (let’s reference them as x,y,z) . • A parametric ray p(t) intersects 2 opposite faces at 2 locations, with 2 respective parameters tmin and tmax. (let’s suppose tmin<=tmax). • The 6 faces are intersected with 6 different parameters (txmin,txmax, tymin,tymax, tzmin,tzmax). • The ray intersects the cube only if: Max (txmin,tymin,tzmin)< Min(txmax,tymax,tzmax). University of Wales Swansea 14 Benjamin Mora
p(t) vdir p0 r o Ray/Sphere Intersection • A sphere can be defined by a center o and a radius r. • Looking for the points p(t) such as: norm(p(t)o)=r. University of Wales Swansea 15 Benjamin Mora
p0 vdir p(t) Ray/Triangle Intersections • Several ways to achieve this goal. • Badouel’s Algorithm. • Moller’s Algorithm (not shown). • Other Algorithm (close to Segura et al. 98). University of Wales Swansea 16 Benjamin Mora
p2 p(t) p1 p0 Badouel’s Algorithm • First, find the intersection p(t) between the ray and the plane containing the triangle. • Then use the barycentric coordinates of the point to sort the intersection out (2D algorithm). University of Wales Swansea 17 Benjamin Mora
Other Ray/Triangle Algorithms • The edges of the triangles can be considered as oriented. • The Ray should always be “on the same side” of the edges • => Three triple products with the same sign. p vdir p0 p1 p(t) p2 Segura, R.J., Feito, F.R. Segura, R.J., Feito, F.R.: An algorithm for determining intersection segment-polygon in 3D. Computer & Graphics, Vol.22, No.5, pp.587-592, 1998. University of Wales Swansea 18 Benjamin Mora
p vdir p0 p1 p(t) p2 Other Ray/Triangle Algorithms • There is an intersection Ray/Triangle only if: • Fast algorithm. • Can take advantage of SIMD instructions on processor. • But: • Only in order to detect an intersection. • Extra work must be done in order to get the tri-linear interpolating weights (including a div) and the real intersection location if needed (but not always required). University of Wales Swansea 19 Benjamin Mora
Triangle/Box Intersection • Why? • Bounding boxes are used much to speed-up intersections. • Standalone boxes. • Spatial subdivision techniques. • Therefore needed to construct such acceleration structures. University of Wales Swansea 20 Benjamin Mora
Triangle/Box Intersection • Solution 1: Working in the triangle plane. • For every face of the cube: • Find the face/triangle plane intersection. • A line! • Clip the triangle/polygon with this line. (Sutherland ). • Intersection occurs if result not NULL! • Complex and Costly. University of Wales Swansea 21 Benjamin Mora
Triangle/Box Intersection • Solution 2: Use the Separating Axis Theorem. (Akenine-Moller) • No intersection occurs between 2 convex objects if there exists a separating plane. University of Wales Swansea 22 Benjamin Mora
Triangle/Box Intersection (2D) University of Wales Swansea 23 Benjamin Mora
Triangle/Box Intersection (2D) University of Wales Swansea 24 Benjamin Mora
Triangle/Box Intersection (3D) • 13 planes to be tested in 3D. • For each plane: • Compute distances to the triangle vertices • Using the plane equation. • Compute distances to the box vertices. • No intersection if MIN of one distance set greater than MAX of the other distance set. • If condition is false for all 13 cases, an intersection exists. University of Wales Swansea 25 Benjamin Mora
Ei X Tj Triangle/Box Intersection (3D) • Plane directions are determined from: Where Ei are the directions of the edges of the box, and Tj the directions of the edges of the triangle. (9 cases) • The faces of the box. (3 cases) • The triangle plane normal. (1 case) University of Wales Swansea 26 Benjamin Mora
Simple Ray-Tracing Effects University of Wales Swansea 27 Benjamin Mora
SimpleRay-Tracing Effects • The main operation is to find an intersection from a given ray. • This operation can be used (by casting secondary rays) to compute simple effects that are more difficult to implement with OpenGL like (but fog): • Reflection. • Refraction. • Shadows. • Fog. Source: Min Chen University of Wales Swansea 28 Benjamin Mora
object colour result of tracing reflective ray result of tracing refractive ray + + SimpleRay-Tracing Effects • Basic Lighting model: Rin kt Rfr km Rfl University of Wales Swansea 29 Benjamin Mora
SimpleRay-Tracing Effects • Shading can be done in the same way as to OpenGL. • But better methods exist. N V (-Rin) R L Source: Min Chen University of Wales Swansea 30 Benjamin Mora
SimpleRay-Tracing Effects • Reflection: University of Wales Swansea 31 Benjamin Mora
SimpleRay-Tracing Effects • Reflection: N Vincident Vreflected i i L University of Wales Swansea 32 Benjamin Mora
N V (-Rin) Rfl i i R L Snell’s Law r Rfr SimpleRay-Tracing Effects • Refraction: University of Wales Swansea 33 Benjamin Mora
N critical angle critical V (-Rin) Rfr SimpleRay-Tracing Effects • Total Internal Reflection: University of Wales Swansea 34 Benjamin Mora
SimpleRay-Tracing Effects • Taking into account reflection and refraction several times (recursively) requires an exponential number of rays! • The algorithm should stop after reaching a maximum number of consecutive reflections/refractions. • Only reduced to some specific lighting effects. University of Wales Swansea 35 Benjamin Mora
Simple Ray-Tracing Effects University of Wales Swansea 36 Benjamin Mora
Simple Ray-Tracing Effects • Fog effect (also possible with OpenGL). • Depth Cue: • Fog: or University of Wales Swansea 37 Benjamin Mora
non-adaptive supersampling stochastic sampling adaptive supersampling Simple Ray-Tracing Effects • Super Sampling can be used in order to improve Anti-Aliasing. University of Wales Swansea 38 Benjamin Mora
Simple Ray-Tracing Effects University of Wales Swansea 39 Benjamin Mora
Simple Ray-Tracing Effects • The final color is the average of all the sub-sampled rays. • Uniform Super-Sampling: • Nice but not always needed. • Adaptive Super-Sampling: • Useful for the regions with large color transitions (high frequencies), like object boundaries. • Trade-off between quality and speed. • Stochastic Super-Sampling: • Take advantage of the visual system limitations. University of Wales Swansea 40 Benjamin Mora
Simple Ray-Tracing Effects • Stochastic Super-Sampling: • Proposed by Robert L. Cook. • Stochastic Sampling in Computer Graphics, ACM transaction on Graphics No. 5(1), January 1986, pp. 51-72. • The ray location(s) are randomly chosen inside a pixel. • Our visual system is less sensitive to noise than to contours. University of Wales Swansea 41 Benjamin Mora
Other Ray-Tracing Algorithms. University of Wales Swansea 42 Benjamin Mora
Other Ray-Tracing Algorithms. • Pyramidal Ray-Tracing. • Cone Tracing. • Beam Tracing. University of Wales Swansea 43 Benjamin Mora
image plane primary ray viewlocation Pyramidal Ray-Tracing. • Proposed by: • And improved by: • Main Idea: Replacing Rays by Pyramids to improve aliasing. Whitted, Turner. An Improved Illumination Model for Shaded Display. C.A.C.M. vol. 23, no. 6, June 1980, pp. 343-3~19. J. Genetti, D. Gordon and G. Williams. Adaptive supersampling in object space using pyramidal rays. Computer Graphics Forum 17 (1998) 29-54. University of Wales Swansea 44 Benjamin Mora
The triangle will contribute here to 7/64 of the final pixel colour. Pyramidal Ray-Tracing. J. Genetti, D. Gordon and G. Williams. Adaptive supersampling in object space using pyramidal rays. Computer Graphics Forum 17 (1998) 29-54. University of Wales Swansea 45 Benjamin Mora
Pyramidal Ray-Tracing. • If a pyramid only partially intersects a graphics primitive (e.g., triangle), then the pyramid is subdivided until a given depth is reached. • The final pixel value is the (weighted) average of all the samples inside the triangle. • Non-intersecting pyramids keep on computing intersections with the rest of the scene. University of Wales Swansea 46 Benjamin Mora
Cone Tracing. • Proposed by: John Amanatides. Ray Tracing with Cones. Siggraph 1984, pp. 129-135. image plane primary ray viewlocation Partial intersection University of Wales Swansea 47 Benjamin Mora
Cone Tracing. • Similar to pyramidal ray-tracing, but the pyramid is now replaced by a cone. • Allows easier intersection computations. • 1 cone per pixel, no subdivision. • For a ray-triangle intersection: • The cone is projected onto the triangle plane. • Circular projection. • If there is a partial intersection detected, the colour of the triangle is weighted by the corresponding covering percentage, and computing intersections will carry on. University of Wales Swansea 48 Benjamin Mora
Cone Tracing: Result University of Wales Swansea 49 Benjamin Mora
Beam Tracing. • Proposed by: • Takes advantages of spatial coherency between rays to group them and save computations. • Rays are distributed after Reflections and Refractions according to the reflection/refraction coefficients. • Constructs a beam tree. • Outdated. Paul S. Heckbert and Pat Hanrahan. BEAM TRACING POLYGONAL OBJECTS. Siggraph 1984, pp. 119-127. University of Wales Swansea 50 Benjamin Mora