The Fundamentals of Ray-Tracing Szirmay-Kalos László Dept. of Control Engineering and Information Technology Budapest University of Technology

Slides:



Advertisements
Similar presentations
GR2 Advanced Computer Graphics AGR
Advertisements

13.1 si31_2001 SI31 Advanced Computer Graphics AGR Lecture 13 An Introduction to Ray Tracing.
Ray tracing. New Concepts The recursive ray tracing algorithm Generating eye rays Non Real-time rendering.
Ray Tracing & Radiosity Dr. Amy H. Zhang. Outline  Ray tracing  Radiosity.
Light Issues in Computer Graphics Presented by Saleema Amershi.
1. What is Lighting? 2 Example 1. Find the cubic polynomial or that passes through the four points and satisfies 1.As a photon Metal Insulator.
Illumination Model & Surface-rendering Method 박 경 와.
CS6500 Adv. Computer Graphics © Chun-Fa Chang, Spring 2003 Object-Order vs. Screen-Order Rendering April 24, 2003.
CSCE 641: Computer Graphics Ray Tracing Jinxiang Chai.
Ray Casting Ray-Surface Intersections Barycentric Coordinates Reflection and Transmission [Shirley, Ch.9] Ray Tracing Handouts Ray Casting Ray-Surface.
Parallelizing Raytracing Gillian Smith CMPE 220 February 19 th, 2008.
1 CSCE 641: Computer Graphics Lighting Jinxiang Chai.
Global Illumination May 7, Global Effects translucent surface shadow multiple reflection.
7M836 Animation & Rendering
Photorealism Reflection, Refraction Bump maps
Ray Tracing Outline For each pixel { Shoot ray r from eye to center of pixel with trace( r ) } function trace( r ) For each object { Find object with closest.
1 7M836 Animation & Rendering Global illumination, ray tracing Arjan Kok
Ray Tracing 1 Angel: Interactive Computer Graphics 5E © Addison-Wesley 2009.
Lecture 8 Advanced Rendering – Ray Tracing, Radiosity & NPR.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
CSC418 Computer Graphics n Raytracing n Shadows n Global Illumination.
Fundamentals of Computer Graphics Part 6 Shading prof.ing.Václav Skala, CSc. University of West Bohemia Plzeň, Czech Republic ©2002 Prepared with Angel,E.:
Ray Tracing Primer Ref: SIGGRAPH HyperGraphHyperGraph.
Ray Tracing II A More Practical Version. A QUICK REVIEW.
What is Computer Graphics and Image Processing? lAll visual computer output depends on computer graphics and image processing. l3D computer graphics is.
Computer graphics & visualization Ray-Tracing – A Quick review.
Technology and Historical Overview. Introduction to 3d Computer Graphics  3D computer graphics is the science, study, and method of projecting a mathematical.
12/05/02(c) 2002 University of Wisconsin Last Time Subdivision techniques for modeling Very brief intro to global illumination.
-Global Illumination Techniques
Project Raytracing. Content Goals Idea of Raytracing Ray Casting – Therory – Practice Raytracing – Theory – Light model – Practice Output images Conclusion.
CS 376 Introduction to Computer Graphics 04 / 16 / 2007 Instructor: Michael Eckmann.
Ray Tracing Chapter CAP4730: Computational Structures in Computer Graphics.
University of Texas at Austin CS384G - Computer Graphics Fall 2008 Don Fussell Ray Tracing.
Rendering Overview CSE 3541 Matt Boggus. Rendering Algorithmically generating a 2D image from 3D models Raster graphics.
Basic Ray Tracing CMSC 435/634. Visibility Problem Rendering: converting a model to an image Visibility: deciding which objects (or parts) will appear.
Computer graphics & visualization Photon Mapping.
Rendering Problem László Szirmay-Kalos. Image synthesis: illusion of watching real world objects Le(x,)Le(x,) pixel f r (  ’, x,  ) S We(x,)We(x,)
Recursion and Data Structures in Computer Graphics Ray Tracing 1.
04/30/02(c) 2002 University of Wisconsin Last Time Subdivision techniques for modeling We are now all done with modeling, the standard hardware pipeline.
Basic Ray Tracing CMSC 435/634.
Graphics Graphics Korea University cgvr.korea.ac.kr 1 Surface Rendering Methods 고려대학교 컴퓨터 그래픽스 연구실.
BRDF models and their use in Global Illumination Algorithms László Szirmay-Kalos.
CS380: Computer Graphics Distributed Ray Tracing TA Course URL:
Monte-Carlo Ray Tracing and
Ray Tracing Fall, Introduction Simple idea  Forward Mapping  Natural phenomenon infinite number of rays from light source to object to viewer.
Ray Tracing II. HW1 Part A due October 10 Camera module Object module –Read from a file –Sphere and Light only Ray tracer module: –No shading. No reflection.
In the name of God Computer Graphics. Last Time Some techniques for modeling Today Global illumination and raytracing.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Illumination Model How to compute color to represent a scene As in taking a photo in real life: – Camera – Lighting – Object Geometry Material Illumination.
1. Ray Casting Surface intersection Visible surface detection Ray Tracing Bounce the ray Collecting intensity Technique for global reflection and transmission.
RENDERING : Global Illumination
CSE 681 Introduction to Ray Tracing. CSE 681 Ray Tracing Shoot a ray through each pixel; Find first object intersected by ray. Image plane Eye Compute.
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
CSL 859: Advanced Computer Graphics Dept of Computer Sc. & Engg. IIT Delhi.
Ray Tracing I. Reading Hill, Chapter 14, Sections 14.1 to 14.5 Hill, Chapter 14, Sections and
1 CSCE 441: Computer Graphics Lighting Jinxiang Chai.
Review Ray Tracing III Review. Pseudo codes RayCast-1  Plain ray caster (direct illumination) RayCast-2  RayCast-1 + shadow rays RayTrace-1  Recursive.
Physics fundamentals of 3D rendering Szirmay-Kalos László Science is either physics or stamp collecting. Rutherford.
Introduction to Ray Tracing Dr. B. Raghu Professor /CSE Sri Ramanujar Engineering College.
Basic Ray Tracing CMSC 435/634.
Photorealistic Rendering vs. Interactive 3D Graphics
3D Graphics Rendering PPT By Ricardo Veguilla.
Unit-7 Lighting and Shading
© University of Wisconsin, CS559 Fall 2004
Lighting.
Fundamentals of Computer Graphics Part 6 Shading
Image synthesis using classical optics
CS5500 Computer Graphics May 29, 2006
GR2 Advanced Computer Graphics AGR
CSC418 Computer Graphics Raytracing Shadows Global Illumination.
Presentation transcript:

The Fundamentals of Ray-Tracing Szirmay-Kalos László Dept. of Control Engineering and Information Technology Budapest University of Technology Web:

Rendering Tone mapping Real worldcolor pixelVirtual world

Light-object interaction L in k r L in k t L in L in L in f r (  ’,  ) cos  ’ Coherent terms geometric optics Incoherent terms probability theory ’’  ’’ BRDF: f r (  ’,  ) = L out /L in cos  ’ Bi-directional reflection distribution function prob. density

BRDF modelling l Depends on –the wavelength –light direction –viewing direction –surface normal l Physical measurements l Tuning simple formulae

Diffuse reflection l Light intensity is independent of the viewing direction ’’ ’’ L ref = L ir k d ( ) cos  ’ Lambert’s law

Diffuse surfaces

Phong’s specular reflection ’’  ’r’r ’’  ’r’r = diffuse +  Function: large at  =0 and goes to zero k s cos n 

Diffuse+Phong materials n= diffuse Phong diffuse + Phong own color Plastics: k s is white

Diffuse + Phong materials

General rendering problem L  LeLe rr tt

Local Illumination pixel L (  )  L e (  )+  l  r l  L l (  ’ l ) f r (  ’ l,  ) cos  ’ l Point, directional light sources Light sources 0/1: Light source visibility Shadows ’l’l

Role of the ambient term L (  )  L e (  )+  l  r l  L l (  ’ l ) f r (  ’ l,  ) cos  ’ l + k a L a Local illumination + ambient term

Ray-tracing LlLl shadow ray Reflection ray Refracted ray L (  ) = L e (  )+  l  r l  L l (  ’ l ) f r (  ’ l,  ) cos  ’ l + k a L a + + k r L in (  r ) + k t L in (  t ) from the reflection direction from the refraction direction

Local illumination Local illumination + shadows Ray-tracing Global illumination Photorealistic image synthesis

Steps of ray-tracing l Light intensity coming through a pixel –Visible point and the normal vector here –Visible light sources from here –mirror and refraction directions –Light intensity coming from the reflection direction –Light intensity coming form the refraction direction –Adding up the light components and color the pixel Recursion shadow ray Reflection ray Refracted ray

Tasks of ray-tracing l Visibility computation –Determination of that point which is visible from a point in a given direction + normal vector here –point+direction = ray l Computation of the mirroring and refraction directions l Evaluation of the illumination formula L (  ) = L e (  )+  l  r l  L l (  ’ l ) f r (  ’ l,  ) cos  ’ l + k a L a + + k r L in (  r ) + k t L in (  t )

Visibility calculation ray(t) = eye + v ·t, t > 0 float FirstIntersect(ray  iobject, x) // <=0 if no intersection t = -1 FOR each object tnew = Intersect( ray, object );// <= 0 if no intersection IF (tnew > 0 && tnew < t) t = tnew, iobject = object ENDFOR IF (t > 0) x = eye + v ·t; RETURN t; END x

Intersection with a Sphere |ray(t) - center | 2 = R 2 Surface normal: (ray(t) - center)/R center R |r - center | 2 = R 2 r (v ·v) t ((eye-center) ·v) t +((eye-center) ·(eye-center))- R 2 = 0 Wanted: minimum from the positive solutions no root 1 root 2 roots

 +  +  -1=0 Quadric surfaces xyz1xyz1 [x,y,z,1] A = 0Quadric surface: Second order equation Ellipsoid x 2 y 2 z 2 a 2 b 2 c 2  +  - z 2 =0 Infinite cone x 2 y 2 a 2 b 2 Infinite cylinder x 2 y 2 a 2 b 2  +  - 1 =0

Triangle 1. Intersection with the plane: (ray(t) - r1) ·n = 0, t > 0 Normal vector: n = (r2 - r1) x (r3 - r1) 2. Is the intersection point p inside the triangle? ((r2 - r1) x (p - r1)) · ((r2 - r1) x (r3 - r1)) > 0 ((r3 - r2) x (p - r2)) · ((r3 - r2) x (r1 - r2)) > 0 ((r1 - r3) x (p - r3)) · ((r1 - r3) x (r2 - r3)) > 0 r1 r2 p r3 n Phase 1 Phase 2

Shading normals N1N1 N2N2 N3N3 N N = A X + B Y + C (X 1, Y 1, Z 1 ) N 1 = A X 1 + B Y 1 + C N 2 = A X 2 + B Y 2 + C N 3 = A X 3 + B Y 3 + C 3 systems of equations of 3 unknowns A, B, C

Parametric surfaces r(u,v) =   B i,j (u,v) r i, j blending functions control points

Intersecting parametric sufaces r(u,v), u,v in [0,1] ray(t) = eye + v ·t, t > 0 r(u,v) = ray(t) Solution of the equation: u,v,t Test: 0< u,v < 1, t > 0 Recursive tessellation r(0.5,0.5) r(0,0) r(0,1) r(1,1) r(1,0) r(0,0.5) r(0.5,0)

Animated objects T1T1 T2T2 T 1 -1 T 2 -1

Tasks of ray-tracing l Visibility computation –Determination of that point which is visible from a point in a given direction + normal vector here –point+direction = ray l Computation of the mirroring and refraction directions l Evaluation of the illumination formula

Reflection Direction v r = v + 2 cos  N vrvr v v + N cos   N N cos  L = v r, V= v ReflectDir( L, N, V ) { L = V - N * (N * V) * 2; } cos  = - ( v ·N) horizontal vector new ray = x + v r ·t x

Refraction Direction vtvt v  v + N cos  N NN N  sin   -Ncos  v t = v  n + N (cos  n -  (1- (1 - cos 2  )/ n 2 ) ) n =n = sin  sin  Snellius law v  Ncos  sin  N =N = v t = N  sin  Ncos  horizontal vector v t = v  n + N(cos  n  cos  ) cos   1- sin 2   1- sin 2  / n 2

Camera definition eye lookat fov, aspect XRES, YRES

Ray-tracing algorithm Render( ) for each pixel p Ray r = ray( eye  pixel p ) color = Trace(ray) WritePixel(p, color) endfor end ray color p p

Trace function Color Trace( ray ) IF (FirstIntersect(ray  object, x) <= 0) RETURN L a ENDIF color = L e (x, -ray.dir) color += Direct Lightsource(x, -ray.dir) IF ( k r > 0 ) THEN ReflectDir( ray, reflected ray) color += k r · Trace( reflected ray ) ENDIF IF ( k t > 0 && RefractDir( ray, refracted ray ) ) color += k t · Trace( refracted ray ) ENDIF RETURN color Color Trace( ray, d) IF d > dmax THEN RETURN L a IF ( FirstIntersect(ray  object, x) <= 0) RETURN L a ENDIF color = L e (x, -ray.dir) color += Direct Lightsource(x, -ray.dir) IF ( k r > 0 ) THEN ReflectDir( ray, reflected ray) color += k r · Trace( reflected ray, d+1 ) ENDIF IF ( k t > 0 && RefractDir( ray, refracted ray ) ) color += k t · Trace( refracted ray, d+1 ) ENDIF RETURN color ray x

DirectLightsource function DirectLightsource( x, vdir ) color = k a L a FOR each lightsource l DO shadowray = x to lightsource[l] t = FirstIntersect( shadowray ); IF (t |x - lightsource[l].pos|) color += Brdf(ldir, x, vdir) cos  l ' lightsource[l].Intensity ENDIF ENDFOR RETURN color shadow pixel x vdir

Ray-tracer class diagram SceneObject SphereMesh Primitive( ) Intersect(Ray) Normal( ) Intersect(Ray) Normal( ) Define Render FirstIntersect DirectLightsource Trace(Ray) Light Dir(Point) Intens(Point) LatransformLe, pos Camera XRES, YRES eye, lookat, vup fov, aspect GetXRes( ) GetYRes( ) GetRay(int,int) Ray Dir( ) Start( ) dir, start Material Le, kd, ks, shine kr, kt, n BRDF ReflectDir RefractDir Center, radiusvertices[ ] Primitive Intersect(Ray) Normal( )

Ray-tracing: results Computation time  Pixel# · Object# ·(Light source# + 1) PovRay

Speeding up the intersection calculation l Speeding up for each objects: –bounding volumes l Computing for less number of objects: –space partitioning

Bounding Volume float IntersectBV( ray, object ) // < 0 ha nincs IF ( Intersect( ray, bounding volume of object) <=0) RETURN -1; RETURN Intersect( ray, object ); END

Space partitioning methods Data structure: Knowing the ray, it reduces the number of objects the ray may intersect. If we find an intersected object, the search can be terminated. pre- processing objects Space-partitioning data structure ray- tracing First intersection

Ray-tracing: FOR each cell of the line // line drawing Intersect objects registered in this cell IF intersection exists RETURN ENDFOR average case complexity: O(1 ) Uniform space partitioning Preprocessing: FOR each cell identify the objects that are partly here complexity: O(n · c ) = O(n 2 )

Ray-shooting: FOR each cell intersecting the line Intersect objects registered in this cell IF intersection exists RETURN ENDFOR Octree Octree Tree build IF a cell contains just a few objects register objects in this cell ELSE subdivide cells: c1, c2, …, c8 Tree build(c1); … Tree build(c8); ENDIF

Ray-shooting: FOR each cell intersecting the line Intersect with the included objects IF intersection exists RETURN ENDFOR Kd (BSP) tree kd-tree Tree build: IF a cell contains just a few objects register objects in this cell ELSE find a subdivision plane cell halving with the plane: c1, c2 Tree build (c1); Tree build (c2); ENDIF 1 23

Example 1

Example 2