cs559: computer graphics lecture 28: ray tracing li zhang spring 2010 slides are from ravi...

76
CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Colu

Upload: harvey-hopkins

Post on 21-Jan-2016

214 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

CS559: Computer Graphics

Lecture 28: Ray Tracing

Li ZhangSpring 2010

Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Page 2: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Effects needed for RealismEffects needed for Realism

Reflections (Mirrors and Glossy)

Transparency (Water, Glass)

Interreflections (Color Bleeding)

(Soft) Shadows

Complex Illumination (Natural, Area Light)

Realistic Materials (Velvet, Paints, Glass)

And many more

Image courtesy Paul Heckbert 1983

Page 3: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray TracingRay Tracing

Different Approach to Image Synthesis as compared to Hardware pipeline (OpenGL)

OpenGL : Object by Object Ray Tracing : Pixel by Pixel

Advantage: Easy to compute shadows/transparency/etc

Disadvantage: Slow (in early days)

Page 4: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Basic Version: Ray Casting

Virtual Viewpoint

Virtual Screen Objects

Ray misses all objects: Pixel colored blackRay intersects object: shade using color, lights, materialsMultiple intersections: Use closest one (as does OpenGL)

Page 5: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Shadows

Virtual Viewpoint

Virtual Screen Objects

10.5 in textbook

Light Source

Shadow ray to light is unblocked: object visibleShadow ray to light is blocked: object in shadow

Page 6: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Mirror Reflections/Refractions

Virtual Viewpoint

Virtual Screen ObjectsGenerate reflected ray in mirror direction, Get reflections and refractions of objects

Page 7: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Recursive Ray Tracing Recursive Ray Tracing (Core Idea)(Core Idea)

For each pixel Trace Primary Eye Ray, find intersection

Trace Secondary Shadow Ray(s) to all light(s) Color = Visible1 ? Illumination Model(light1) : 0 ; Color += Visible2 ? Illumination Model(light2) : 0 ; …

Trace Reflected Ray Color += reflectivity * Color of reflected ray

Trace Refracted Ray Color += transparency * Color of refracted ray

Recursive function Calls

Page 8: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U
Page 9: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

ExampleExample

Sphere How to decide there is an intersection?

Triangle How to decide the intersection is inside?

Polygon How to decide the intersection is inside?

How about an ellipsoid?

Page 10: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray-Tracing Transformed ObjectsRay-Tracing Transformed Objects

We have an optimized ray-sphere test But we want to ray trace an ellipsoid…

Solution: Ellipsoid transforms sphere Apply inverse transform to ray, use ray-sphere

Page 11: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

AccelerationAcceleration

Testing each object for each ray is slow Faster Intersections

Optimized Ray-Object Intersections Fewer Intersections

Page 12: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Acceleration StructuresAcceleration Structures

Bounding boxes (possibly hierarchical) If no intersection bounding box, needn’t check objects

Bounding Box

Ray

Different Spatial Hierarchies (Oct-trees, kd trees, BSP trees)

Page 13: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

OctreeOctree

Page 14: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

K-d treeK-d tree

Page 15: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Acceleration Structures: GridsAcceleration Structures: Grids

Page 16: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Anti-aliasingAnti-aliasing

Aliasing when drawing a diagonal on a square grid: stairstepping AKA jaggies

Especially noticeable: high-contrast edges near horizontal or near vertical As line rotates (in 2D)

steps change length corners of steps slide along the edge known as crawlies

Page 17: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

SupersamplingSupersampling A more popular method (although less elegant) is supersampling:

Point sample the pixel at several locations Combine the results into the final pixel color

By sampling more times per pixel: Raises the sampling rate Raises the frequencies we can capture

Commonly use 16 or more samples per pixel Requires potentially 16 times as much work to generate image 16 times Memory?

A brute-force approach But straightforward to implement Very powerful

Page 18: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Moiré ArtifactMoiré Artifact

Page 19: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Random SamplingRandom Sampling Supersample at several randomly located points

Breaks up repeating signals Eliminates Moiré patterns Instead of aliasing, frequencies greater than 1 pixel appear as noise in the image

Noise tends to be less objectionable to the viewer than jaggies or Moiré patterns The human eye is pretty good at filtering out noise

But suffers from potential clustering and gaps Result is not necessarily accurate Too much noise.

Page 20: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Jittered SamplingJittered Sampling AKA stratified sampling,

Divide pixel into a grid of subpixels Sample each subpixel at a random location

Combines the advantages of both uniform and random sampling filters high frequencies frequencies greater than subpixel sampling rate turned into noise

Commonly used

Page 21: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Soft shadowSoft shadow

penumbra

Page 22: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Soft ShadowSoft Shadow

Page 23: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

ComparisonComparison

Page 24: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Glossy SurfaceGlossy Surface

http://www.neilblevins.com/cg_education/brushed_metal/brushed_metal.htm

Page 25: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Vertical vs Horizonal roughnessVertical vs Horizonal roughness

http://www.neilblevins.com/cg_education/brushed_metal/brushed_metal.htm

Page 26: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray tracing a glossy surfaceRay tracing a glossy surface

http://www.neilblevins.com/cg_education/brushed_metal/brushed_metal.htm

Page 27: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray tracing a glossy surfaceRay tracing a glossy surface

Page 28: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Depth of FieldDepth of Field

Page 29: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Depth of FieldDepth of Field

aperturesensor

Focal plane

Page 30: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Depth of FieldDepth of Field

aperturesensor

Focal plane

Page 31: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Depth of Field in OpenGLDepth of Field in OpenGL

Page 32: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Depth of Field in OpenGLDepth of Field in OpenGL

Render an image at each jittered location

Then average the images

Page 33: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Motion BlurMotion Blur

Ray trace a moving scene at different time instance and average the images

Page 34: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Motion Blur in OpenGLMotion Blur in OpenGL

Render a moving scene at different time instance

Average the images (using Accumulation buffer)

Page 35: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray tracing examplesRay tracing examples

Page 36: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray tracing examplesRay tracing examples

Page 37: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray tracing examplesRay tracing examples

Page 38: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Image Based RenderingImage Based Rendering

Motivation Realistic Rendering requires

realistic 3D models realistic material models takes time

Page 39: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Rendering a desktopRendering a desktop

Page 40: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U
Page 41: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Rendering a desktopRendering a desktop

Rendering in real-time, with global illumination effect (e.g. inter-reflection)

Page 42: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Image Based RenderingImage Based Rendering

Fast Realistic Rendering without 3D models

Page 43: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Start from Ray TracingStart from Ray Tracing

Rendering is about computing color along each ray

Page 44: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Sampling RaysSampling Rays

Page 45: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Sampling Rays by Taking PicturesSampling Rays by Taking Pictures

Page 46: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Rendering as Ray ResamplingRendering as Ray Resampling

Page 47: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Ray spaceRay space

How to parameterize the ray space

How to sample and resample rays

Page 48: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Two Plane ParameterizationTwo Plane Parameterization

Page 49: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Stanford Camera ArrayStanford Camera Array

Page 50: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Light Field RenderingLight Field Rendering

Very Fast

Page 51: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Light Field RenderingLight Field Rendering

4D interpolation

Page 52: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Light Field RenderingLight Field Rendering

Don’t need to model anything: surface model, volumetric model, lighting model, surface property model…

NOTHING but sampling and resampling rays.

Page 53: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Application in MoviesApplication in Movies

Page 54: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Capture scene with a camera arrayCapture scene with a camera array

Page 55: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Bullet time in GamesBullet time in Games

Max Payne (2001)

Page 56: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

DiscussionDiscussion

Limitation Sampling density must be high Fixed Illumination, static scene

Page 57: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Methods using Fewer CamerasMethods using Fewer Cameras

High-quality video view interpolation using a layered representation. C. L. Zitnick, S.B. Kang, M. Uyttendaele, S. Winder, and R. Szeliski, SIGGRAPH 2004

http://research.microsoft.com/~larryz/videoviewinterpolation.htm

Page 58: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

CS559: Computer Graphics

Final ReviewLi Zhang

Spring 2010

Page 59: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

What’s not in the final• OpenGL and FLTK syntax• Image based Rendering

Page 60: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Eyes and Cameras• Camera obscura

– Pinhole, lens– Different ways of capturing color

• Optical effect– Motion blur– Depth of Field

Page 61: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Images• Minimum Sample requirement

– Sampling theorem

• Re-sampling– Up-sampling, down-sampling– Anti-aliasing

• Compositing– Alpha channel

Page 62: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Image Filtering• Convolution

– Continuous and discrete

• Linear filter– Blur, shift, sharpen, edge detection…

• Painter algorithm, Project 1– Iteratively apply strokes

Page 63: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Image warping• 2D transformation

– Scale, Rotate, affine, translate, …– Inverse transformation

• Properties of 2D transformations– Line to line, parallel to parallel, …

• Homogeneous transformation• Forward warping

– Splatting

• Inverse warping– Reconstruction

Page 64: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Image morphing• What do we need?

– Avoid ghosting

• How to do it?– Warping + blending

Page 65: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

3D transform• Homogenous Coordinate

– Point vs direction– Transforming normals

• 3D rotation– property– Different representation– Geometric interpretation

• Concatenation of transforms– Hierarchical modeling

Page 66: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Projection• Graphics pipeline• Orthographic vs perspective projection

– Matrix representation– Vanishing point

• View frustum– Clipping plane, Field of view– Convert to projection matrix

• Canonical view volume– From perspective view volume

Page 67: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Scan conversion and visibility• Draw lines and triangles

– Tricks to make it fast– Anti-aliasing

• BSP– How to construct and how to use

• Z buffer vs A buffer– Pros and cons

Page 68: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Shading• Phong shading model

– Emission, diffuse, specular

• Types of light sources– Point, spot, directional

• Shading interpolation– Flat, Gouraud, and Phong

Page 69: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Curves• Implicit vs Parametric Curves• Polynomial Curves

– How to evaluate polynomial– How to compute the curve– Problem with high order polynomials

• Piecewise cubic polynomial– Continuity: C0,C1,C2– Local control– interpolation

Page 70: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Curves• Natural, Hermite, Catmull-Rom, Cardinal, Bezier,

– Commonality and differences

• Bezier curves– Subdivision– De Casteljau – Generalization– …

Page 71: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Texture• Calculate texture coord

– Perspective correct interpolation

• Texture resampling– Antialiasing: Mipmap, Ripmap, SAT

• How do they work, • What can they do, limitation

• Other usages:– Bump Map, Displacement Map, 3D Texture,

Environment Map, Shadow map– Projector texture (no requirement)

Page 72: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Shape• Boundary vs Solid modeling• Parametric, Implicit, Procedural

– Pros and cons

• Polygon meshes– Why popular– Pros and cons– Data structure

Page 73: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Shape• Sweep objects• Spatial enumeration

– Oct tree

• Bezier Patch– Bilinear, biquadric, bicubic– De Casteljau

Page 74: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Subdivision Curves and Surfaces• Approximating vs Interpolating• Regular vs Irregular vertices• Continuity• Loop, sqrt(3), Catmull-Clark

– Commanality and difference– Piecewise smoothness (no requirement)

• Fractal Modeling– Terrains, trees, …

Page 75: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Animation• Particle Systems

– Euler method– Collision Detection and Response

• Principles of Cartoon

Page 76: CS559: Computer Graphics Lecture 28: Ray Tracing Li Zhang Spring 2010 Slides are from Ravi Ramamoorthi’s graphics class at Columbia U

Raytracing• Recursive procedure

– Shadow, Transparency, Reflection, Refraction– Why inter-reflection is hard? – Anti-aliasing: jittered sampling, why– Soft shadow, glossy surface, – Depth of field, Motion blur

• Ray object intersection– Simple objects: triangle, polygons, …

• Spatial data structure for Acceleration – BSP, octtree, grid