35
David Luebke 06/27/22 CS 551 / 645: Introductory Computer Graphics David Luebke [email protected] http://www.cs.virginia.edu/~cs551

David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke [email protected] cs551

Embed Size (px)

Citation preview

Page 1: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

CS 551 / 645: Introductory Computer Graphics

David Luebke

[email protected]

http://www.cs.virginia.edu/~cs551

Page 2: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Administrivia

Final exam:– Tuesday December 14,

9 AM to noon in MEC 339– Closed-book, closed-note exam

Study notes:– PDF versions of six slides-per-page handouts will

be put on the course web page

Page 3: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Review For Test

3-D graphics:

Transform

Illuminate

Transform

Clip

Project

Rasterize

Model & CameraModel & CameraParametersParameters Rendering PipelineRendering Pipeline FramebufferFramebuffer DisplayDisplay

Page 4: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Review For Test Rendering pipeline:

ModelingTransforms

Scene graphObject geometry

LightingCalculations

ViewingTransform

Clipping

ProjectionTransform

Result:Result:

• All vertices of scene in shared 3-D “world” coordinate All vertices of scene in shared 3-D “world” coordinate systemsystem

• Vertices shaded according to lighting modelVertices shaded according to lighting model

• Scene vertices in 3-D “view” or “camera” coordinate Scene vertices in 3-D “view” or “camera” coordinate systemsystem

• Exactly those vertices & portions of polygons in view Exactly those vertices & portions of polygons in view frustumfrustum

• 2-D screen coordinates of clipped vertices2-D screen coordinates of clipped vertices

Page 5: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Review For Test

Transformations– Shift in coordinate systems (basis sets)– Accomplished via matrix multiplication– Modeling transforms: object->world– Viewing transform: world->view– Projection transform: view->screen

Page 6: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Review For Test

Rigid-body transforms– Rotation: 2-D. 3-D (canonical & arbitrary axis)– Scaling– Translation: homogeneous coords, 4x4 matrices– Composiing transforms

Matrix multiplication Order from right to left

Projection transforms– Geometry of perspective projection– Derive perspective projection matrix

Page 7: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Recap: 3-D Clipping

Clipping in 3-D– Sutherland-Hodgman extends easily to clipping

against six view-frustum planes– Issue: when in the pipeline to clip?

World coordinates: arbitrary planes expensive Camera coordinates: two planes easy, four hard Canonical perspective coordinates: two easy, four okay Canonical orthographic coordinates/screen coordinates:

reduces matrix multiplies, requires clipping in homogeneous coordinates

Common shortcut: clip near-far in camera coordinates, multiply by perspective matrix, clip left-right-top-bottom

Page 8: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

3-D Clipping Recall this sequence of diagrams:

Clip againstview volume

Apply projectionmatrix and

homogeneousdivide

Transform intoviewport for2-D display

Applynormalizing

transformation

projectionmatrix;

homogeneousdivide

Transform intoviewport for2-D display

Clip against

canonical view

volume

Clipagainstview

volume

Apply projection

matrix

Transform intoviewport for2-D display

Homogeneousdivide

Page 9: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Canonical Perspective Coordinates

1

-1

x or y

z-1

Front or hither plane

Back or yon plane

Why is this going to besimpler?

Page 10: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Visible Surface Determination

Why might a polygon be invisible?– Polygon outside the field of view:

view-frustum culling– Polygon is backfacing:

backface culling– Polygon is occluded by object(s)

nearer the viewpoint: occlusion culling

Efficiency

Efficiency &Correctness

Page 11: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

View-Frustum Culling

Clump primitives and classify clump bounding volumes as inside, outside, or intersecting view frustum

If bounding volume isn’t in frustum, don’t draw primitives in clump

For better performance, use a hierarchy of bounding volumes– Spheres– Bounding boxes– Others

Page 12: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

On the surface of a closed manifold, polygons whose normals point away from the camera are always occluded:

Back-Face Culling

Page 13: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Occlusion

Need to find visible polygon fragments:– Upper bound on fragments?

Page 14: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Occlusion

Painter’s Algorithm (and problem cases) Binary Space Partition (BSP) Tree

– Splitting planes, recursively divide space into half-spaces

– Allows front-to-back traversal, thus painter’s alg.– Know the pros and cons

Warnock’s Algorithm– Clip objects to viewport– If number of objects is 0 or 1, visibility is trivial– Else subdivide into smaller viewports and recurse

Page 15: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

The Z-Buffer Algorithm

Resolve visibility independently at each pixel:

Interpolating Z: just another (planar) parameter

Page 16: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Z-Buffer Pros and Cons

Pros: – Simple– Good for hardware– Handles polygon interpenetration and overlap– Handles polygons in arbitrary order

Cons– Lots of memory (16 bits barely okay, 32 bits best)– Needs fast memory– Hard to do antialiasing/translucent– Precision issues

Page 17: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Visibility: Ray Casting

An example:

ScreenEyepoint Scene

Page 18: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Cells & Portals

Works well for architectural models Cells are regions of model mostly occluded

from each other– Rooms, alcoves, corridors…

Transparent portals connect cells on their boundaries– Doorways, entrances, windows…

Adjacency graph captures cell connectivity Cells visible if a line of sight through portals

Page 19: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Cells & Portals

View-dependent vs. view-independent solutions pfPortals algorithm:

– Recursive traversal of adjacency graph:– Treat portals as special polygons

If portal is visible, render adjacent cell But clip to boundaries of portal! Recursively check portals in that cell against new clip

boundaries (and render)

– Each visible portal sequence amounts to a series of nested portal boundaries

Kept implicitly on recursion stack

Page 20: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Lighting

Simulate physics/optics of surface illumination Definitions: illumination vs. lighting vs. shading Components of illumination:

– Light sources Position, direction, shape Spectrum of emittance (color) & attenuation

– Surface properties Position, orientation Reflectance spectrum (color) & micro-structure

Simplifications of various components

Page 21: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Phong-Style Lighting

Light-source approximations:– Ambient light sources– Directional light sources– Point light sources

Lambert’s Cosine Law and Lambertian surfaces

Specular reflection – Microgeometry (underlying reasoning)– Cosine-to-a-power (empirical hack)

Page 22: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Phong-Style Lighting

Understand this equation and where its terms all came from:

lights

i

n

sdiambientatotal

shiny

RVkLNkIIkI#

1

ˆˆˆˆ

Page 23: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Lighting & Shading

Lighting: applying illumination calculations Shading: coloring pixels (interpolation)

– Flat shading– Gouraud shading– Phong shading

Page 24: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Texture Mapping

Page 25: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Texture Mapping

Texture coordinates Perspective-correct interpolation of texture

coordinates – Basically, interpolate u/z and v/z rather than u and v

Texture-map antialiasing– The problem: uneven pixel-texel coverage– Bilinear interpolation– MIP-maps and trilinear interpolation

Page 26: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Texture Maps

Value stored in texels can modulate other parameters besides color:– Bump-mapping: use texture to perturb surface

normal used for lighting calculations– Displacement mapping: actually displace

geometry, applying texture as a height-field– Illumination mapping: combine a low-res

brightness map with a high-res texture map– Shadow maps: store depth from light source

3-D textures work well for marble, wood

Page 27: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

OpenGL

Conventions: – glVertex3fv, etc– gluPerspective

Specifying geometry (list of vertices) Triangle strips & fans Be able to reason about simple OpenGL

lighting code Modeling transforms Double-buffering for flicker-free animation

Page 28: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Animation & The Scene Graph

Instancing– OpenGL display lists

The scene graph captures transformations and object-object relationships in a DAG

Traversing the scene graph with the OpenGL matrix stack

Page 29: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Ray Tracing

Recursive ray tracing: primary and secondary (reflected & refracted) rays

Shadow rays Representing rays parametrically: R = O + tD Intersecting rays with spheres

– Don’t know the details

Intersecting rays with polygons– Know (or be able to derive) the details

Page 30: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Shadow Rays

The concept The problems:

– Lots of computation Light buffer Shadow ray cahcing

– Infinitely sharp shadows Shoot more shadow rays or larger shadow rays

– No translucent object shadows (caustics) Can fake it though

Page 31: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Accelerating Ray Tracing

Hierarchical bounding volumes – Spheres vs. AABBs vs. OBBs

Spatial partitions– Grid vs. octree vs BSP tree

Page 32: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Level of Detail

Traditional static LOD: start with original highly-detailed object and create multiple levels of detail (LODs) in a preprocess

Creating levels of detail: mechanisms– Sample-and-reconstruct– Decimation– Vertex-merging– Adaptive subdivision

Creating levels of detail: criteria– Geometric criteria (e.g., curvature)– Visual criteria (e.g., coloration or texture maps)

Page 33: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Dynamic LOD

Create a data structure (the vertex tree) in preprocess and extract desired LOD at runtime

Enables view-dependent LOD, for example:– Distant regions in lower detail than nearby regions– Silhouette regions in higher detail

Vertex tree: hierarchical clustering of vertices– Folding/unfolding nodes– Tris and subtris

Page 34: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Radiosity

Models light transfer among surfaces in a scene

Simplifying assumptions:– Surface consists of uniformly lit patches – Surfaces are Lambertian (perfectly diffuse)– Environment is closed

Definitions: radiosity, reflectivity, form factors

Page 35: David Luebke9/7/2015 CS 551 / 645: Introductory Computer Graphics David Luebke cs551@cs.virginia.edu cs551

David Luebke 04/21/23

Radiosity

The radiosity equation: Bi = Ei + i Bj Fij

Know the matrix form and what it means Computing form factors

– Relevant factors (distance, shape, etc).– Hemicube algorithm (pros & cons)– Ray casting (pros & cons)

End result: a colored polygonal model– View-independent solution!