Presentation is loading. Please wait.

Presentation is loading. Please wait.

I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Lecture 28 of 42 Raytracing 2 of.

Similar presentations


Presentation on theme: "I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Lecture 28 of 42 Raytracing 2 of."— Presentation transcript:

1 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Lecture 28 of 42 Raytracing 2 of 3: Basics Wednesday, 29 March 2006

2 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 3/42 Illumination Review (2/3) Important illumination models Local (single-surface element) model -ambient approximates indirect global illumination as constant -Lambertian diffuse reflection (outgoing energy is proportional to the cosine of the angle between the vector to the light and the surface normal, due to geometry) -Phong approximation to specular reflection -these model part of the BRDF (itself an approx!): Global (multi-surface element) models shadows indirect illumination – from other objects specular and diffuse reflection, refraction ii rr ii rr LiLi LrLr Surface

3 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 23/42 Object-Space Intersection Express world-space point of intersection as MQ, where Q is some point in object- space: If is the equation of the untransformed object, we just have to solve -note d is probably not a unit vector -the parameter t along this vector and its world space counterpart always have the same value. Normalizing d would alter this relationship. Do NOT normalize d. Transform ray into object-space (0,0,0) MQ Q

4 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 25/42 Normal Vectors at Intersection For illumination we need to find a way, given a point on the object in object-space, to determine the normal vector to the object at that point so that we can calculate angles between the normal and other vectors If a surface bounds a solid whose interior is given by then we can find the normal vector at a point(x, y, z) via the gradient at that point: Recall that the gradient is a vector with three components: Normal vector to implicit surfaces Points (1/4)

5 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 26/42 Normal Vectors at Intersection Sphere normal vector example Points (2/4) For the sphere, the equation is The partial derivatives are So the gradient is Normalize n before using in dot products! In some degenerate cases, the gradient may be zero, and this method fails…use nearby gradient as a cheap hack

6 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 27/42 Normal Vectors at Intersection Transforming back to world-space Points (3/4) We have an object-space normal vector We want a world-space normal vector To transform the object to world coordinates, we just multiplied its vertices by M, the object’s CTM Can we treat the normal vector the same way? Answer: NO Example: say M scales in x by.5 and y by 2 See the normal scaling applets in Applets  Lighting and Shading n object Mn object Wrong! Normal must be perpendicular

7 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 28/42 Normal Vectors at Intersection Points (4/4) Why doesn’t multiplying the normal work? For translation and rotation, which are rigid body transformations, it actually does work Scale, however, distorts the normal in exactly the opposite sense of the scale applied to the surface, not surprising given that the normal is perpendicular -scaling y by 2 causes normal to scale by.5: -We’ll see this algebraically in the next slides

8 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 29/42 Transforming Normals (1/4) Take the polygonal case, for example Let’s compute the relationship between the object-space normal n obj to a polygon H and the world-space normal n world to a transformed version of H, say MH If v is a vector in world space that lies in the polygon (e.g., one of the edge vectors), then the normal is perpendicular to the vector v: But v world is just a transformed version of some vector in object space, v obj. So we could write But we’d be wrong, because v is a tangent vector it’s transformed by the derivative… …which includes a 3D->4D->3D mapping… Object-space to world-space

9 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 30/42 Transforming Normals (2/4) So we want a vector n world such that We will show in a moment that this equation can be rewritten as We also already have Therefore Left-multiplying by (M t ) -1, Object-space to world-space(cont.)

10 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S So how did we rewrite this: As this: Recall that if we think of vector as nx1 matrices, then switching notation, Rewriting the formula above, we have Writing M = M tt, we get Recalling that (AB) t = B t A t, we can write this: Switching back to dot product notation: Andries van Dam, John Alex October 28, 2003 Raytracing 31/42 Transforming Normals (2/4) Object-space to world-space(cont.)

11 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 32/42 Transforming Normals (4/4) So we ended up with Fortunately, “invert” and “transpose” can be swapped, to get our final form: Why do we do this? It’s easier! A hand-waving interpretation of (M 3 -1 ) t -M 3 is a composition of rotations and scales, R and S (why no translates?). Therefore -so we’re applying the transformed (inverted, transposed) versions of each individual matrix in their original order -for a rotation matrix, this transformed version is equal to the original rotation, i.e., normal rotates with object -(R -1 ) t =R; the inverse reverses the rotation, and the transpose reverses it back -for a scale matrix, the inverse reverses the scale, while the transpose does nothing: -(S(x,y,z) -1 ) t = S(x,y,z) -1 =S(1/x,1/y,1/z) Applying inverse-transpose of M to normals

12 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 33/42 Summary P = eyePt For each sample of image Compute d for each object Intersect ray P+td with object Select object with smallest non-negative t-value(this is the visible object) For this object, find the object-space intersection point Compute the normal at that point Transform the normal to world space Use the world-space normal for lighting computations Simple, non-recursive raytracer

13 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 34/42 What about pixels? We’ve used “samples” rather than “pixels” In the simplest case, can choose our sample points at the centers of each pixel For better results, can supersample: take multiple samples per pixel -e.g., at the corners and at the center Even better techniques do adaptive sampling: increase sample density in areas of rapid change (in geometry or lighting) Can also do stochastic sampling: samples are taken probabilistically For fast results, can subsample: fewer samples than pixels take as many samples as time permits How to convert samples to pixels? This is a resampling problem, hence we filter to get weighted average of samples Pixels aren’t samples

14 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 35/42 Recursive Raytracing By recursively casting new rays into the scene, we can look for more information Start from the point of intersection We’d like to send rays in all directions Send rays in directions we predict will contribute the most: -toward lights (shadow) -bounce off objects (specular reflection) -through the object (transparency) For more info on recursive ray tracing, see section 16.12 of the textbook. Simulating global lighting effects (Whitted, 1979)

15 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 36/42 Shadows Each light in scene makes contribution to the color and intensity of a surface element… Iff it reaches the object! -could be occluded by other objects in the scene -could be occluded by another part of the same object Construct a ray from the surface to each light Check to see if ray intersects other objects before it gets to the light -if ray does NOT intersect that same object or another object on its way to the light, then the full contribution of the light can be counted -if ray does intersect an object on its way to the light, then no contribution of that light should be counted -what about transparent objects?

16 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 37/42 Transparent Surfaces (1/2) For a partially transparent polygon Nonrefractive transparency I λ2 I λ1 polygon 1 polygon 2

17 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S We model the way light bends at interfaces with Snell’s Law Andries van Dam, John Alex October 28, 2003 Raytracing 38/42 Transparent Surfaces (2/2) Refractive transparency medium 1 medium 2

18 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 39/42 Recursive Raytracing (1/2) Trace ‘secondary’ rays at intersections: -light: trace ray to each light source. If light source blocked by opaque object, it does not contribute to lighting, and object in shadow of blocked light at that point -specular reflection: trace ray in mirror direction by reflecting about N -refraction/transparency: trace ray in refraction direction by Snell’s law -recursively spawn new light, reflection, refraction rays at each intersection until contribution negligible -Your new lighting equation… -note: intensity from recursed rays calc’d with same eqn -light sources contribute specular and diffuse lighting -Limitations -recursive interobject reflection is strictly specular: along ray reflected about N -diffuse interobject reflection handled by radiosity Informative videos: silent movie on raytracing, A Long Ray’s Journey into Light Recap

19 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 40/42 Recursive Raytracing (2/2) Light-ray Trees indirect illumination

20 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 41/42 Raytracing Pipeline Raytracer produces visible samples from model -samples convolved with filter to form pixel image Additional pre-processing -pre-process database to speed up per-sample calculations (done once, sometimes must be redone if objects transformed (resize, translate)) Pipeline smallest t generate secondary rays

21 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 42/42 POV-Ray: Pretty Pictures Full-featured raytracer available online: http://www.povray.orghttp://www.povray.org Obligatory pretty pictures (see http://www.irtc.org for more!):http://www.irtc.org Free Advanced Raytracer

22 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Programmable Hardware Halo 2 Doom III Jet Set Radio Future Research

23 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S 1992 - id’s Wolfenstein 3D video game rocks gaming world, all objects are billboards (flat planes) and rendered in software 1996 - id’s Quake introduces a full 3D polygonal game, lighting vertices and shading pixels is still done in software 1996 - Voodoo 3Dfx graphics card released, does shading operations (such as texturing) in hardware. QuakeWorld brings hardware acceleration to Quake 1999 - Geforce 256 graphics card released, now transform and lighting (T&L) of vertices is done in hardware as well (uses the fixed function pipeline) 2001 – Geforce 3 graphics card lets programmers download assembly programs to control vertex lighting and pixel shading keeping the speed of the fixed function pipeline with none of the restrictions Future – Expanded features and high level API’s for vertex and pixel shaders, increased use of lighting effects such as bump mapping and shadowing, higher resolution color values. Doom III and Half-Life 2 usher in a new era of realism History

24 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Starting in 1999 some graphics cards began to do the standard lighting model and transformations in hardware (T&L). CPUs everywhere sighed in relief. –Hardware T&L existed in the 60s and 70s, it was just really slow and really expensive. Implementing the pipeline in hardware made processing polygons much faster, but the developer could not modify the pipeline (hence “fixed function pipeline”). The fixed function pipeline dates back to the first SGI workstations. New programmable hardware allows programmers to write vertex and pixel programs to change the pipeline –Vertex and pixel programs aren’t necessarily slower than the fixed function alternative Note that the common term “vertex shader” to describe a vertex program is misleading: vertices are lit and pixels are shaded Fixed Function Pipeline

25 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S By default, GL will do the following: 1)Take as input various per-vertex quantities (color, light source, eye point, texture coordinates, etc.) 2)Calculate a final color for each vertex using a basic lighting model (OpenGL uses Phong lighting) 3)For each pixel, linearly interpolate the three surrounding vertex colors to shade the pixel (OpenGL uses Gouraud shading) 4)Write the pixel color value to the frame buffer A Quick Review

26 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Programmable Hardware Pipeline Standard T&L Vertices Vertex Program Backface Culling Frustum Clipping Standard Shading Pixel Shader Depth Test 1 unlit model space vertex 1 lit clip space vertex 1 un-colored pixel 1 colored pixel Store Pixel clip space refers to the space of the canonical view volume New graphics cards can use either the fixed function pipeline or vertex/pixel programs

27 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Example: Cartoon Shading Cartoon shading is a cheap and neat looking effect used in video games such as Jet Set Radio Future Instead of using traditional methods to light a vertex, use the dot product of the light vector and the normal of the vertex to index into a 1 dimensional “texture” (A texture is simply a lookup function for colors – nothing more and nothing less) Instead of a smooth transition from low intensity light (small dot product) to high intensity light (large dot product) make the 1 dimensional texture have sharp transitions Textures aren’t just for “wrapping” 2D images on 3D geometry! Viola! Cartoon Teapot 1 dimensional texture light vector normal vector 1.0dot product light 0.0

28 I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S What is Cg? Cg is a C-like language that the graphics card compiles in to a program –The program is run once per-vertex and/or per-pixel on the graphics card Cg does not have all the functionality of C –Different types systems –Can’t include standard system headers –No malloc –http://www.cgshaders.org/articles/ has the technical documentation for Cg Cg is actually an abstraction of the more primitive assembly language that the programmable hardware originally supported


Download ppt "I N T R O D U C T I O N T O C O M P U T E R G R A P H I C S Andries van Dam, John Alex October 28, 2003 Raytracing 1/42 Lecture 28 of 42 Raytracing 2 of."

Similar presentations


Ads by Google