+ All Categories
Home > Documents > CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on...

CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on...

Date post: 21-Dec-2015
Category:
View: 217 times
Download: 2 times
Share this document with a friend
Popular Tags:
70
CSCE 590E Spring 2007 Graphics I By Jijun Tang
Transcript
Page 1: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

CSCE 590E Spring 2007

Graphics I

By Jijun Tang

Page 2: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Announcements

Second presentation will be held on April 16th and 18th

April 16th: Space Banditos, Slackers, Psychosoft

April 18th: Project Gnosis, Cheeze Puffs!, Team Swampus

Final demo will be open to public, including people from media arts

Page 3: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

What is Collision Detection

A fundamental problem in computer games, computer animation, physically-based modeling, geometric modeling, and robotics.

Including algorithms: To check for collision, i.e. intersection, of

two given objects To calculate trajectories, impact times and

impact points in a physical simulation.

Page 4: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Overlap Testing (a posteriori)

Overlap testing: Detects whether a collision has already occurred, sometime is referred as a posteriori

Facts Most common technique used in games Exhibits more error than intersection testing

Concept For every (small) simulation step, test every pair

of objects to see if they overlap Easy for simple volumes like spheres, harder for

polygonal models

Page 5: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Overlap Testing: Limitations

Fails with objects that move too fast (compared to the object) Thin glass vs. bulltes Unlikely to catch time slice during overlap

t0t -1 t1 t2

b u lle t

w in d o w

Page 6: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Intersection Testing (a priori)

Predict future collisions When predicted:

Move simulation to time of collision Resolve collision Simulate remaining time step

Page 7: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Intersection Testing:Swept Geometry

Extrude geometry in direction of movement Swept sphere turns into a “capsule” shape

t0

t1

Page 8: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Simplified Geometry

Approximate complex objects with simpler geometry, like this ellipsoid or bounding boxes

Page 9: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Minkowski Sum

Y}B and :{ XABAYX

X Y =YX X Y =

Page 10: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Bounding Volumes

Bounding volume is a simple geometric shape Completely encapsulates object If no collision with bounding volume, no

more testing is required Common bounding volumes

Sphere Box

Page 11: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Box Bounding Volumes

Ax is - Alig n ed Bo u n d in g Bo x O r ien ted Bo u n d in g Bo x

Page 12: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Terrain Collision Detection:Height Field Landscape

T o p - D o wn Vie w

P e r sp e c t iv e Vie w

T o p - D o wn Vie w ( h e igh t s a dde d)

P e r sp e c t iv e Vie w ( h e igh t s a dde d)

Page 13: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Collision Resolution:Examples

Two billiard balls strike Calculate ball positions at time of impact Impart new velocities on balls Play “clinking” sound effect

Rocket slams into wall Rocket disappears Explosion spawned and explosion sound effect Wall charred and area damage inflicted on nearby

characters

Character walks through wall Magical sound effect triggered No trajectories or velocities affected

Page 14: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Collision Resolution:Parts

Resolution has three parts1. Prologue

2. Collision

3. Epilogue

Page 15: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Graphics

Page 16: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Fundamentals

Frame and Back Buffer Visibility and Depth Buffer Stencil Buffer Triangles Vertices Coordinate Spaces Textures Shaders Materials

Page 17: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Frame and Back Buffer

Both hold pixel colors Frame buffer is displayed on screen Back buffer is just a region of memory Image is rendered to the back buffer

Half-drawn images are very distracting You do not want to see the screen is

drawn pixel by pixel

Page 18: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Two Buffers

Page 19: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Switching

Back buffer can be standard, frame buffer should aim at each hardware

Swapped to the frame buffer May be a swap, or may be a copy Copy is actually preferred, because you can still

modify the format Back buffer is larger if anti-aliasing

Some hardware may not support anti-aliasing Shrink and filter to frame buffer

Page 20: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Anti-aliasing

Page 21: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Visibility and Depth Buffer

Depth buffer is a buffer that holds the depth of each pixel in the scene, and is the same size as back buffer

Holds a depth or “Z” value (often called the “Z buffer”) Pixels test their depth against existing value

If greater, new pixel is further than existing pixel Therefore hidden by existing pixel – rejected Otherwise, is in front, and therefore visible Overwrites value in depth buffer and color in back buffer

No useful units for the depth value By convention, nearer means lower value Non-linear mapping from world space

Page 22: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Object Depth Is Difficult

Page 23: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Basic Depth Buffer Algorithm

for each object in scene in any orderfor each pixel in the object being rendered

if the pixel has already been rendered, then

if the new object pixel is closer than the old one, then

Replace the displayed pixel with the new one

Page 24: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Stencil Buffer

The stencil buffer is buffer that guides the translation between the back buffer and the front buffer

Usually eight bits in size and usually interleaved with 24-bit depth buffer

Can write to stencil buffer Can reject pixels based on comparison

between existing value and reference Many uses for masking and culling

Page 25: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Triangles

Fundamental primitive of pipelines Everything else constructed from them (except lines and point sprites)

Three points define a plane Triangle plane is mapped with data

Textures Colors

“Rasterized” to find pixels to draw

Page 26: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Mesh

Page 27: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Vertices

A vertex is a point in space Plus other attribute data

Colors Surface normal Texture coordinates Whatever data shader programs need

Triangles use three vertices Vertices shared between adjacent triangles

Page 28: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Frustum

The viewing frustum is the region of space in the modeled world that may appear on the screen

Frustum culling is the process of removing objects that lie completely outside the viewing frustum from the rendering process

Page 29: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Frustum and Frustum Culling

Page 30: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Coordinate Spaces

World space Arbitrary global game space

Object space Child of world space Origin at entity’s position and orientation Vertex positions and normals stored in this

Camera space Camera’s version of “object” space

Screen space Clip space vertices projected to screen space Actual pixels, ready for rendering

Page 31: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Coordinate Spaces (2)

Clip space Distorted version of camera space Edges of screen make four side planes Near and far planes

Needed to control precision of depth buffer Total of six clipping planes Distorted to make a cube in 4D clip space Makes clipping hardware simpler

Page 32: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Clip Space

Eye

Triangles will be clipped

Cameraspacevisible

frustum

Clipspace

frustum

Page 33: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Coordinate Spaces (3)

Tangent space Defined at each point on surface of mesh Usually smoothly interpolated over surface Normal of surface is one axis “tangent” and “binormal” axes lie along surface Tangent direction is controlled by artist Useful for lighting calculations

Page 34: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Tangent Space

Page 35: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Textures

Array of texels Same as pixel, but for a texture Nominally R,G,B,A but can mean anything

1D, 2D, 3D and “cube map” arrays 2D is by far the most common Basically just a 2D image bitmap Often square and power-of-2 in size

Cube map - six 2D arrays makes hollow cube Approximates a hollow sphere of texels

Page 36: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Texture Example

Page 37: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Shaders

A program run at each vertex or pixel Generates pixel colors or vertex positions

Relatively small programs Usually tens or hundreds of instructions

Explicit parallelism No direct communication between shaders “Extreme SIMD” programming model

Hardware capabilities evolving rapidly

Page 38: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Example

Page 39: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Materials

Description of how to render a triangle Big blob of data and state

Vertex and pixel shaders Textures Global variables Description of data held in vertices Other pipeline state Does not include actual vertex data

Page 40: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

High-Level Organization

Gameplay and Rendering Render Objects Render Instances Meshes Skeletons Volume Partitioning

Page 41: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Gameplay and Rendering

Rendering speed varies according to scene Some scenes more complex than others Typically 15-60 frames per second

Gameplay is constant speed Camera view should not change game In multiplayer, each person has a different view,

but there is only one shared game 1 update per second (RTS) to thousands (FPS)

Keep the two as separate as possible!

Page 42: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Render Objects

Description of renderable object type Mesh data (triangles, vertices) Material data (shaders, textures, etc) Skeleton (+rig) for animation Shared by multiple instances

Page 43: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Render Instances

A single entity in a world References a render object

Decides what the object looks like Position and orientation Lighting state Animation state

Page 44: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Meshes

Triangles Vertices Single material “Atomic unit of rendering”

Not quite atomic, depending on hardware Single object may have multiple meshes

Each with different shaders, textures, etc Level-Of-Distance (LOD)

Page 45: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

LOD

Objects have different mesh for different distance from the player

The mesh should be simpler if object is faraway

Many games have LOD, for example, Microsoft Train Simulator

Page 46: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

LOD Example in MSTS

Page 47: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Skeletons

Skeleton is a hierarchy of bones Deforms meshes for animation Typically one skeleton per object

Used to deform multiple meshes We have done a demo about skeleton

animation See “Character Animation” chapter

(although deformation is part of rendering)

Page 48: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning

Cannot draw entire world every frame Lots of objects – far too slow

Need to decide quickly what is visible Partition world into areas Decide which areas are visible Draw things in each visible area Many ways of partitioning the world

Page 49: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning - Portals

Nodes joined by portals Usually a polygon, but can be any shape

See if any portal of node is visible If so, draw geometry in node See if portals to other nodes are visible

Check only against visible portal shape Common to use screen bounding boxes

Recurse to other nodes

Page 50: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Viewfrustum

Node

Portal

Test first two portals

? ?

Page 51: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

Both visible

Page 52: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

Mark node visible, test all portals going from node

??

Page 53: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

One portal visible, one invisible

Page 54: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

Mark node as visible, other node not visited at all.Check all portals in visible node

? ?

?

Page 55: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

One visible, two invisible

Page 56: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

Mark node as visible, check new node’s portals

?

Page 57: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Visible

Invisible

Not tested

Eye

Node

Portal

One portal invisible.No more visible nodes or portals to check.Render scene.

Page 58: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Real Example

Page 59: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – Portals

Portals are simple and fast Low memory footprint Automatic generation is difficult

Generally need to be placed by hand Hard to find which node a point is in

Must constantly track movement of objects through portals

Best at indoor scenes Outside generates too many portals to be

efficient

Page 60: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – BSP

Binary space partition tree Tree of nodes Each node has plane that splits it in two

Two child nodes, one on each side of plane

Some leaves marked as “solid” Others filled with renderable geometry

Page 61: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

BSP

Page 62: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning – BSP

Finding which node a point is in is fast Start at top node Test which side of the plane the point is on Move to that child node Stop when leaf node hit

Visibility determination is similar to portals Portals implied from BSP planes

Automated BSP generation is common Generates far more nodes than portals

Higher memory requirements

Page 63: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning: Quadtree

Quadtree (2D) and octree (3D) Quadtrees described here Extension to 3D octree is obvious

Each node is square Usually power-of-two in size

Has four child nodes or leaves Each is a quarter of size of parent

Page 64: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Quadtree

Page 65: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Octree

Page 66: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning: Quadtree

Fast to find which node point is in Mostly used for simple frustum culling Not very good at indoor visibility

Quadtree edges usually not aligned with real geometry

Very low memory requirements Good at dynamic moving objects

Insertion and removal is very fast

Page 67: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning - PVS

Potentially visible set Based on any existing node system For each node, stores list of which nodes

are potentially visible Use list for node that camera is currently in

Ignore any nodes not on that list – not visible Static lists

Precalculated at level authoring time Ignores current frustum Cannot deal with moving occluders

Page 68: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

PVS

RoomA

RoomB

Room C

RoomD

RoomE

Viewpoint

PVS = B, A, D

Page 69: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning - PVS

Very fast No recursion, no calculations

Still need frustum culling Difficult to calculate

Intersection of volumes and portals Lots of tests – very slow

Most useful when combined with other partitioning schemes

Page 70: CSCE 590E Spring 2007 Graphics I By Jijun Tang. Announcements Second presentation will be held on April 16 th and 18 th  April 16 th : Space Banditos,

Volume Partitioning

Different methods for different things Quadtree/octree for outdoor views

Does frustum culling well Hard to cull much more for outdoor views

Portals or BSP for indoor scenes BSP or quadtree for collision detection

Portals not suitable


Recommended