Ray tracing in computer graphics ppt

ray tracing in computer graphics notes and ray tracing method in computer graphics
Dr.ShaneMatts Profile Pic
Dr.ShaneMatts,United States,Teacher
Published Date:23-07-2017
Your Website URL(Optional)
Comment
MIT EECS 6.837 Computer Graphics Ray Casting II Courtesy of Henrik Wann Jensen. Used with permission. 1 MIT EECS 6.837 – Matusik Henrik Wann Jensen C++ • 3 ways to pass arguments to a function – by value, e.g. float f(float x) – by reference, e.g. float f(float &x) • f can modify the value of x – by pointer, e.g. float f(float x) • x here is a just a memory address • motivations: less memory than a full data structure if x has a complex type dirty hacks (pointer arithmetic),but just do not do it • clean languages do not use pointers • kind of redundant with reference • arrays are pointers 2 Pointers • Can get it from a variable using & – often a BAD idea. see next slide • Can be dereferenced with – float px=new float; // px is a memory address to a float – px=5.0; //modify the value at the address px • Should be instantiated with new. See next slide 3 Pointers, Heap, Stack • Two ways to create objects – The BAD way, on the stack • myObject f() – myObject x; – ... – return &x • will crash because x is defined only locally and the memory gets de-allocated when you leave function f – The GOOD way, on the heap • myObject f() – myObject x=new myObject; – ... – return x • but then you will probably eventually need to delete it 4 Segmentation Fault • When you read or, worse, write at an invalid address • Easiest segmentation fault: – float px; // px is a memory address to a float – px=5.0; //modify the value at the address px – Not 100% guaranteed, but you haven’t instantiated px, it could have any random memory address. • 2nd easiest seg fault – Vectorfloat vx(3); – vx9=0; 5 Segmentation Fault • TERRIBLE thing about segfault: the program does not necessarily crash where you caused the problem • You might write at an address that is inappropriate but that exists • You corrupt data or code at that location • Next time you get there, crash • When a segmentation fault occurs, always look for pointer or array operations before the crash, but not necessarily at the crash 6 Debugging • Display as much information as you can – image maps (e.g. per-pixel depth, normal) – OpenGL 3D display (e.g. vectors, etc.) – cerr or cout (with intermediate values, a message when you hit a given if statement, etc.) • Doubt everything – Yes, you are sure this part of the code works, but test it nonetheless • Use simple cases – e.g. plane z=0, ray with direction (1, 0, 0) – and display all intermediate computation 7 Questions? 8 Thursday Recap • Intro to rendering – Producing a picture based on scene description – Main variants: Ray casting/tracing vs. rasterization – Ray casting vs. ray tracing (secondary rays) • Ray Casting basics – Camera definitions • Orthographic, perspective – Ray representation • P(t) = origin + t direction This image is in the – Ray generation public domain. Source: openclipart – Ray/plane intersection – Ray-sphere intersection 9 Questions? © ACM. All rights reserved. This content is excluded from our Creative Commons license. For more information, see http://ocw.mit.edu/help/faq-fair-use/. 10 Ray-Triangle Intersection • Use ray-plane intersection followed by in-triangle test • Or try to be smarter – Use barycentric coordinates c P R R d o a b 11 Barycentric Definition of a Plane • A (non-degenerate) triangle (a,b,c) defines a plane • Any point P on this plane can be written as P(,,) = a + b + c, with ++ = 1 c Why? How? P R R d o a Möbius, 1827 b 12 Barycentric Coordinates • Since ++ =1, we can write  = 1–– rewrite P(,,) = a + b + c P(,) = (1––)a + b + c = a + (b-a) + (c-a) c Vectors that lie on the triangle plane P Non-orthogonal coordinate system a b on the plane 13 Barycentric Definition of a Plane Möbius, 1827 • P(,,) = a + b + c with ++ =1 • Is it explicit or implicit? c Fun to know: P is the barycenter, the single point upon which P the triangle would balance if weights of size , , &  are placed on points a, b & c. a b 14 Barycentric Definition of a Triangle • P(,,) = a + b + c with ++ =1 parameterizes the entire plane c P a b 15 Barycentric Definition of a Triangle • P(,,) = a + b + c with ++ =1 parameterizes the entire plane • If we require in addition that , ,  = 0, we get just the triangle – Note that with ++ =1 this implies c 0    1 & 0    1 & 0    1 – Verify: •  =0 = P lies on line b-c P • ,  =0 = P = c • etc. a b 16 Barycentric Definition of a Triangle • P(,,) = a + b + c • Condition to be barycentric coordinates: ++ =1 • Condition to be inside the triangle: , ,   0 c P a b 17 How Do We Compute , ,  ? • Ratio of opposite sub-triangle area to total area –  = A /A  = A /A  = A /A a b c • Use signed areas for points outside the triangle c A a A P a b 18 How Do We Compute , ,  ? • Or write it as a 22 linear system • P(,  ) = a + e + e 1 2 e = (b-a), e = (c-a) 1 2 This should be zero c P a b 19 How Do We Compute , ,  ? • Or write it as a 22 linear system • P(,  ) = a + e + e 1 2 e = (b-a), e = (c-a) 1 2 This should be zero c Something’s wrong... This P is a linear system of 3 equations and 2 unknowns a b 20

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.