320 likes | 341 Vues
2IV60 Computer graphics set 11: Ray-tracing. Jack van Wijk TU/e. John Tsiombikas. Caustic Graphics. Overview. Ray-tracing: Based on geometric optics; Mirroring, transparency, cast shadows; Many other effects… And very time consuming…. H&B 21-1:639-647. Normalized view volume. z.
E N D
2IV60 Computer graphicsset 11: Ray-tracing Jack van Wijk TU/e
Overview Ray-tracing: • Based on geometric optics; • Mirroring, transparency, cast shadows; • Many other effects… • And very time consuming… H&B 21-1:639-647
Normalized view volume z front = visible pixel Ray casting (reprise) Algorithm: Per pixel: - Calculate intersections - Determine first yv xv zv View plane H&B 21-1:639-647
opaque mirroring Mirroring and transparent Ray-tracing principle 1 light source Ray-tracing: projection point view plane H&B 21-1:639-647
Ray-tracing principle 2 light source Ray-tracing: projection point pixel view plane H&B 21-1:639-647
Ray-tracing algorithm 1 varfbuf: array[N,N] ofcolor; { frame-buffer } For all 1<= i, j <=N do { for all pixels } fbuf [i,j]:= RayTrace((0,0,0),(i,j,d), 1) projection point pixel d H&B 21-1:639-647
N H R P L u Q T Ray-tracing algorithm 2 functionRayTrace(P: point;u:vector; level: integer): color; iflevel > MaxLevel orGetIntersections (P,u, t, N) = 0 thenreturnBkColor; level := level+1; col := famb*Iamb; Q := P+ ut; if (L Q).N > 0 and GetIntersections (Q,L Q) = 0 then col := col + fdif*I + fspec*I*power(N.H(u,N), nspec); col := col + fspec*Raytrace(Q, R(u,N), level); col:= (1–ftra)*col + ftra*Raytrace(Q, T(u,N), level); returncol; H&B 21-1:639-647
Calculation intersections functionGetIntersections (P: point; u: vector; t: array of real; N: array ofvector): integer; { Get the intersections of a line with the scene } For all objects do: Calculate intersection points with surface; Store the results in the arrays t and N, sorted for t. Return the number of intersection points. Equation line: P u t H&B 21-1:639-647
Line/Sphere intersections Equation line: Equation sphere: P u t Q Substitute (1) in (2): C r H&B 21-1:639-647
Equation plane polygon: Substitute (1) in (2): Line/polygon intersection Equation line: N P u t Q Check if Q is inside polygon H&B 21-1:639-647
Bounding Boxes Bounding Spheres Ray-tracing acceleration 1 Limit intersection calculations: Hierarchy of Bounding Volumes H&B 21-1:639-647
Regular Adaptive (Octtree, quadtree) Ray-tracing acceleration 2 Limit intersection calculations: Space-subdivision H&B 21-1:639-647
Aliasing 1 • Generic problem of raster graphics • Shapes are continuous, pixels are discrete • Jagged edges, Moiré patterns, flickering textures, … • Especially annoying during animation • More pixels? • More samples! H&B 21-1:639-647 Aliased Anti-aliased
1 ray/pixel: blocky patterns Aliasing 2 pixel ray H&B 21-1:639-647
average 5 rays/pixel: smoother transitions Anti-aliasing 1 pixel ray H&B 21-1:639-647
adaptive sampling: more efficient, not fail save Anti-aliasing 2 pixel ray H&B 21-1:639-647
Anti-aliasing 3 pixel dense patterns give problems ray H&B 21-1:639-647
Anti-aliasing 3 pixel dense patterns give problems ray H&B 21-1:639-647
Anti-aliasing 3 pixel dense patterns give problems ray H&B 21-1:639-647
Anti-aliasing 4 pixel random sampling gives a better result ray H&B 21-1:639-647
Anti-aliasing 4 pixel random sampling gives a better result ray H&B 21-1:639-647
Anti-aliasing 4 pixel random sampling gives a better result ray H&B 21-1:639-647
Imperfect reflection Non-point light source Cook, Porter, Carpenter, 1984
Distributed ray tracing 1 Motion blur Cook, Porter, Carpenter, 1984
Distributed ray tracing 1 • Monte Carlo sampling • Typically 16 rays/pixel; • Each ray is shifted along a small random vector (jitter) • rough reflecting surfaces, non-point light sources, depth of field, motion blur pixel ray H&B 21-1:651-653
R L T Distributed ray tracing 2 • rough reflecting surfaces, non-point light sources, depth of field, motion blur P u H&B 21-1:651-653
Radiosity • Surface-surface interreflection • Physically based simulation • Calculate for each polygon the balance between incoming and outgoing light • Important for architecture and indoor scenes • Cornell box
Finally • That concludes our tour through the world of 2D and 3D graphics