mark nelson [email protected] 3d projections fall 2013

26
Mark Nelson [email protected] 3d projections Fall 2013 www.itu.dk

Upload: august-richard

Post on 14-Jan-2016

220 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Mark Nelson [email protected]

3d projections

Fall 2013 www.itu.dk

Page 2: Mark Nelson mjas@itu.dk 3d projections Fall 2013

The 3d pipeline (expansive view)

Tools stage Asset conditioning stage Application stage | Geometry processing stage | Rasterization stage

Page 3: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Tools stage

3d modeling

Export meshes (possibly w/ metadata)

Create textures

Page 4: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Asset conditioning stage

Platform- or engine-specific format conversations

Dependency resolution

”Baked-in” effects E.g., static lighting

Page 5: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Application stage

Run-time management in the engine

Prepare a scene Combine e.g. Movable objects into one scene description Omit anything that can’t possibly be visible Set GPU rendering parameters

Page 6: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Basic GPU pipeline

Receive triangles Triples of (x,y,z) vertices

Compute transformations

Rasterize Turn into (x,y) screen pixels

Page 7: Mark Nelson mjas@itu.dk 3d projections Fall 2013

World space

One 3d coordinate axis with all objects in a scene Pre-culled by the engine to omit things that can’t possibly

be visible

Constitutes the world geometry E.g., can compute distances, collisions, etc.

Page 8: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Model space

We could have only world space But, we often model objects externally (e.g. in 3dsmax)

Model space is the local coordinate space of one model, independent of a scene

Typically: centered at (0,0,0) aligned to an axis

Page 9: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Model to world space

To build a scene, all models have to be converted from local to world coordinates

Place in scene, then translate, rotate, and/or scale

Can be done ahead of time or on the GPU

Page 10: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Scene graph

Hierarchical data structure Represents how to build a scene out of models

Root is world space A transformation applies to anything below it in the tree

Can enable other optimizations

Page 11: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Scene graph

Page 12: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Camera

Engine and scene graph build up a scene description In world space, from models in model space

We the viewer are somewhere in this world At a coordinate (x,y,z) Facing along a particular direction vector (x’,y’,z’)

What it looks like to us is view space

Page 13: Mark Nelson mjas@itu.dk 3d projections Fall 2013

View space

In view space, we are: at (0,0,0) perpendicular to the (x,y) plane facing along the z axis

Need to translate and rotate the world-space coordinates 3d version of rotating a map so up is where we’re facing

Page 14: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Projection

Project the (still 3d) view space onto our 2d screen

Orthographic projection Just ignore z coordinate: (x,y,z) (x,y) for all points

Perspective projection Further away objects look smaller

Page 15: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Frustum

Page 16: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Perspective options

#1: First turn 3d view space into 3d perspective space Make further away stuff smaller Then later do an orthographic projection

Or, #2: Project directly

Impacts how things like frustum culling work

Page 17: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Simple perspective projection

If viewable depths are from z=1 to z=infinity:

x’ = x/z y’ = y/z

2d screen centered at (0,0)

Page 18: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Wireframe projection

For each triangle Project each vertex to 2d Draw lines connecting them in 2d

Page 19: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Wireframe projection

Page 20: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Summary

Model space to world spaceWorld space to view spaceProjection

Missing: occlusion, lighting, shading

Page 21: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Transformation matrices

2d rotation

As matrix:

Page 22: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Transformation matrices

3d rotation is analogous Can also do: scaling, shearing

However, translation can’t be directly done as a matrix x’ = x + x_offset y’ = y + y_offset

No matrix-multiply equivalent

Page 23: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Homogeneous coordinates

Extend 3d points and vectors to a 4d space Stand-in dimension w=1

Now can define a translation transform as well So all basic transforms can be chained

Get back to 3d by dividing x/y/z by w

Page 24: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Translation in matrix form

Page 25: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Affine transformations

Can represent all the relevant transformations with homogeneous coordinate 4x4 transform matrices Translation, rotation, scaling, perspective transform

Common way of representing any transformation in APIs

Advanced alternative: quaternions

Page 26: Mark Nelson mjas@itu.dk 3d projections Fall 2013

Project 2: a DIY renderer

Wireframe renderer Due 22 October

Input: 3d coordinates, view position, view direction Project to 2d coordinates, and draw (to screen or image)

Tuesday: more on perspective, and surfaces