Viewing and Modeling

Similar documents
CS354 Computer Graphics Viewing and Modeling

Computer Viewing Computer Graphics I, Fall 2008

3D Viewing. With acknowledge to: Ed Angel. Professor of Computer Science, Electrical and Computer Engineering, and Media Arts University of New Mexico

Overview. Viewing and perspectives. Planar Geometric Projections. Classical Viewing. Classical views Computer viewing Perspective normalization

Three-Dimensional Graphics III. Guoying Zhao 1 / 67

Computer Viewing. CS 537 Interactive Computer Graphics Prof. David E. Breen Department of Computer Science

Announcement. Project 1 has been posted online and in dropbox. Due: 11:59:59 pm, Friday, October 14

Introduction to Computer Graphics with WebGL

OpenGL Transformations

COMP Computer Graphics and Image Processing. 5: Viewing 1: The camera. In part 1 of our study of Viewing, we ll look at ˆʹ U ˆ ʹ F ˆʹ S

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Computer Viewing. CITS3003 Graphics & Animation. E. Angel and D. Shreiner: Interactive Computer Graphics 6E Addison-Wesley

1 Transformations. Chapter 1. Transformations. Department of Computer Science and Engineering 1-1

Projection: Mapping 3-D to 2-D. Orthographic Projection. The Canonical Camera Configuration. Perspective Projection

Lecture 5: Viewing. CSE Computer Graphics (Fall 2010)

3D Viewing. CMPT 361 Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

Overview. By end of the week:

GEOMETRIC TRANSFORMATIONS AND VIEWING

Fundamental Types of Viewing

Lecture 4: Viewing. Topics:

Spring 2013, CS 112 Programming Assignment 2 Submission Due: April 26, 2013

Computer Viewing and Projection. Overview. Computer Viewing. David Carr Fundamentals of Computer Graphics Spring 2004 Based on Slides by E.

3D Graphics for Game Programming (J. Han) Chapter II Vertex Processing

CITSTUDENTS.IN VIEWING. Computer Graphics and Visualization. Classical and computer viewing. Viewing with a computer. Positioning of the camera

3D Viewing. Introduction to Computer Graphics Torsten Möller. Machiraju/Zhang/Möller

6. Modelview Transformations

Rasterization Overview

Transformation Pipeline

Describe the Orthographic and Perspective projections. How do we combine together transform matrices?

CHAPTER 1 Graphics Systems and Models 3

Surface Graphics. 200 polys 1,000 polys 15,000 polys. an empty foot. - a mesh of spline patches:

CS Computer Graphics: Transformations & The Synthetic Camera

COMS 4160: Problems on Transformations and OpenGL

CS 432 Interactive Computer Graphics

CSC Graphics Programming. Budditha Hettige Department of Statistics and Computer Science

Classical and Computer Viewing. Adapted From: Ed Angel Professor of Emeritus of Computer Science University of New Mexico

Graphics Pipeline 2D Geometric Transformations

CS 428: Fall Introduction to. Viewing and projective transformations. Andrew Nealen, Rutgers, /23/2009 1

COMP3421. Introduction to 3D Graphics

Viewing with Computers (OpenGL)

One or more objects A viewer with a projection surface Projectors that go from the object(s) to the projection surface

Scan Conversion- Polygons

Affine Transformations in 3D

COMP Computer Graphics and Image Processing. a6: Projections. In part 2 of our study of Viewing, we ll look at. COMP27112 Toby Howard

Rendering Objects. Need to transform all geometry then

SUMMARY. CS380: Introduction to Computer Graphics Varying Variables Chapter 13. Min H. Kim KAIST School of Computing 18/04/26.

OpenGL: Open Graphics Library. Introduction to OpenGL Part II. How do I render a geometric primitive? What is OpenGL

GL_MODELVIEW transformation

3D Viewing Episode 2

CS 428: Fall Introduction to. Transformations in OpenGL + hierarchical modeling. Andrew Nealen, Rutgers, /21/2009 1

The Viewing Pipeline adaptation of Paul Bunn & Kerryn Hugo s notes

COMP3421. Introduction to 3D Graphics

CSE 690: GPGPU. Lecture 2: Understanding the Fabric - Intro to Graphics. Klaus Mueller Stony Brook University Computer Science Department

CS4620/5620: Lecture 14 Pipeline

CS 4204 Computer Graphics

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Computer Graphics. Chapter 7 2D Geometric Transformations

Geometry: Outline. Projections. Orthographic Perspective

Graphics and Visualization

Game Architecture. 2/19/16: Rasterization

Interactive Computer Graphics A TOP-DOWN APPROACH WITH SHADER-BASED OPENGL

OpenGL. Toolkits.

Computer Graphics. Basic 3D Programming. Contents

Computer Viewing. Prof. George Wolberg Dept. of Computer Science City College of New York

Evening s Goals. Mathematical Transformations. Discuss the mathematical transformations that are utilized for computer graphics

Chapter 5. Projections and Rendering

CS4202: Test. 1. Write the letter corresponding to the library name next to the statement or statements that describe library.

Fachhochschule Regensburg, Germany, February 15, 2017

Getting Started. Overview (1): Getting Started (1): Getting Started (2): Getting Started (3): COSC 4431/5331 Computer Graphics.

COMP3421. Introduction to 3D Graphics

7. 3D Viewing. Projection: why is projection necessary? CS Dept, Univ of Kentucky

Using GLU/GLUT Objects

Using GLU/GLUT Objects. GLU/GLUT Objects. glucylinder() glutwirecone() GLU/GLUT provides very simple object primitives

Transformations. Rotation and Scaling

Computer Graphics. Bing-Yu Chen National Taiwan University

Graphics Pipeline & APIs

CS451Real-time Rendering Pipeline

CSE 167: Introduction to Computer Graphics Lecture #4: Vertex Transformation

CSE 167: Lecture #4: Vertex Transformation. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2012

Pipeline Operations. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 11

Basic Elements. Geometry is the study of the relationships among objects in an n-dimensional space

CS 130 Final. Fall 2015

1. We ll look at: Types of geometrical transformation. Vector and matrix representations

// double buffering and RGB glutinitdisplaymode(glut_double GLUT_RGBA); // your own initializations

Viewing Transformation

The Importance of Matrices in the DirectX API. by adding support in the programming language for frequently used calculations.

3D Graphics Pipeline II Clipping. Instructor Stephen J. Guy

Introduction to OpenGL Transformations, Viewing and Lighting. Ali Bigdelou

Pipeline Operations. CS 4620 Lecture 14

CS 591B Lecture 9: The OpenGL Rendering Pipeline

Graphics Pipeline & APIs

CS 4620 Program 3: Pipeline

MORE OPENGL. Pramook Khungurn CS 4621, Fall 2011

CS 543: Computer Graphics. Projection

CSE528 Computer Graphics: Theory, Algorithms, and Applications

CS 112 The Rendering Pipeline. Slide 1

For each question, indicate whether the statement is true or false by circling T or F, respectively.

CSCI E-74. Simulation and Gaming

The Graphics Pipeline. Interactive Computer Graphics. The Graphics Pipeline. The Graphics Pipeline. The Graphics Pipeline: Clipping

Name: [20 points] Consider the following OpenGL commands:

Transcription:

Viewing and Modeling Computer Science Department The Universit of Texas at Austin

A Simplified Graphics ipeline Application Vertex batching & assembl Triangle assembl Triangle clipping NDC to window space Triangle rasterization Fragment shading Depth testing Depth buffer Color update Framebuffer

A few more steps expanded Application Vertex batching & assembl Vertex transformation Lighting Texture coordinate generation Triangle assembl User defined clipping Back face culling View frustum clipping NDC to window space Triangle rasterization Fragment shading erspective divide Depth testing Depth buffer Color update Framebuffer

Conceptual Vertex Transformation glvertex* AI commands object-space coordinates (x o, o,z o,w o ) Modelview matrix ee-space coordinates (x e, e,z e,w e ) (x e, e,z e,w e ) User-defined clip planes clipped ee-space coordinates (x e, e,z e,w e ) rojection matrix clip-space coordinates (x c, c,z c,w c ) View-frustum clip planes clipped clip-space coordinates (x c, c,z c,w c ) erspective division normalized device coordinates (NDC) (x n, n,z n,/w c ) Viewport + Depth Range transformation window-space coordinates (x w, w,z w,/w c ) to primitive rasterization

ipeline View modelview transformation nonsingular projection transformation clipping homogeneous for perspective perspective division 4D 3D projection 3D 2D

Computer Viewing There are three aspects of the viewing process, all of which are implemented in the pipeline, ositioning the camera Setting the model-view matrix Selecting a lens Setting the projection matrix Clipping Setting the view volume

The World and Camera Frames When we work with representations, we work with n- tuples or arras of scalars Changes in frame are then defined b 4 x 4 matrices In OpenGL, the base frame that we start with is the world frame Eventuall we represent entities in the camera frame b changing the world representation using the model-view matrix Initiall these frames are the same (M=I)

Vertex Transformation Object-space vertex position transformed b a general linear projective transformation Expressed as a 4x4 matrix = o o o o c c c c w z x m m m m m m m m m m m m m m m m w z x 5 7 3 4 6 2 3 9 5 2 8 4

The OpenGL Camera In OpenGL, initiall the object and camera frames are the same Default model-view matrix is an identit The camera is located at origin and points in the negative z direction OpenGL also specifies a default view volume that is a cube with sides of length 2 centered at the origin Default projection matrix is an identit

Moving the Camera If objects are on both sides of z=, we must move camera frame!!!! " # $ $ $ $ % & d M =

Moving the Camera Frame If we want to visualize object with both positive and negative z values we can either Move the camera in the positive z direction Translate the camera frame Move the objects in the negative z direction Translate the world frame Both of these views are equivalent and are determined b the model-view matrix Want a translation (gltranslatef(.,.,-d);) d >

Translate Transform rototpe gltranslatef(glfloat x, GLfloat, GLfloat z) ost-concatenates this matrix z x

gltranslatef Matrix Modelview specification glloadidentit(); gltranslatef(,,-4) x translate=, translate=, z translate=-4 oint at (,,) would move to (,,-4) Down the negative Z axis Matrix 4 = z x the translation vector

General Camera Motion We can position the camera anwhere b a sequence of rotations and translations Example: side view Move camera to the origin Rotate the camera Model-view matrix C = RT

OpenGL code Remember that last transformation specified is first to be applied glmatrixmode(gl_modelview) glloadidentit(); glrotatef(9.,.,.,.); gltranslatef(.,., -d);

A Better Viewing Matrix rimar OpenGL libraries Look at Transform Link with lglut for GLUT Concept Link with lglu for GLU Given the following Link with lgl for OpenGL a 3D world-space ee position a 3D world-space center of view position (looking at ), and an 3D world-space up vector Then an affine (non-projective) 4x4 matrix can be constructed For a view transform mapping world-space to ee-space A read implementation The OpenGL Utilit librar (GLU) provides it glulookat(gldouble eex, GLdouble ee, GLdouble eez, GLdouble atx, GLdouble atz, GLdouble atz, GLdouble upx, GLdouble up, GLdouble upz);

glulookat glulookat(eex, ee, eez, atx, at, atz, upx, up, upz)

Look At in ractice Consider our prior view situation Instead of an arbitrar view we just translated b 4 in negative Z direction gltranslatef(,,4) What this means in Look At parameters (eex,ee,eez) = (,,4) (atx,at,atz) = (,,) (upx,up,upz) = (,,) Not surprising both are just translates in Z since the Look At parameters alread have use looking down the negative Z axis gltranslatef(,,-4) 4 Same matrix; same transform glulookat(,,4,,,,,,) 4

The Look At Algorithm Vector math Z = ee at Z = normalize(z) /* normalize means Z / length(z) */ Y = up X = Y Z /* means vector cross product! */ Y = Z X /* orthgonalize */ X = normalize(x) Y = normalize(y) Then build the following affine 4x4 matrix X x Yx Z x X Y Z X Y Z z z z X ee Y ee Z ee Warning: Algorithm is prone to failure if normalize divides b zero (or ver nearl does) So. Don t let Z or up be zero length vectors 2. Don t let Z and up be coincident vectors

Look At Examples glulookat(,,4,,,,,,); // ee (x,,z) // at (x,,z) // up (x,,z) Same as the gltranslatef(,,-4) as expected glulookat(,2.5,,,,,,,); // ee (x,,z) // at (x,,z) // up (x,,z) Similar to original, but just a little off angle due to slightl perturbed ee vector

Look At Major Ee Changes glulookat(-2.5,,,,,,,,); Ee is above the scene // ee (x,,z) // at (x,,z) // up (x,,z) glulookat(-2.5,-,,,,,,,); Ee is below the scene // ee (x,,z) // at (x,,z) // up (x,,z)

Look At Changes to AT and U glulookat(,,4, 2,-3,,,,); // ee (x,,z) // at (x,,z) // up (x,,z) Original ee position, but at position shifted glulookat(,,4,,,,,,); Ee is below the scene // ee (x,,z) // at (x,,z) // up (x,,z)

The LookAt Function The GLU librar contains the function glulookat to form the required modelview matrix through a simple interface Note the need for setting an up direction Still need to initialize Can concatenate with modeling transformations Example: isometric view of cube aligned with axes glmatrixmode(gl_modelview): glloadidentit(); glulookat(.,.,.,.,.,.,.,...);

Other Viewing AIs The LookAt function is onl one possible AI for positioning the camera Others include View reference point, view plane normal, view up (HIGS, GKS-3D) Yaw, pitch, roll Elevation, azimuth, twist Direction angles

Two Transforms in Sequence OpenGL thinks of the projective transform as reall two 4x4 matrix transforms FIRST object-space to ee-space x z w e e e e = 2 3 4 5 6 7 8 9 2 3 4 5 x z w o o o o 6 Multipl-Add operations SECOND ee-space to clip-space x z w c c c c = 2 3 4 5 6 7 8 9 2 3 4 5 x z w e e e e Another 6 Multipl-Add operations

Modelview-rojection Transform Matrixes can associate (combine) Combination of the modelview and projection matrix = modelview-projection matrix or often simpl the matrix 2 3 4 5 6 7 8 9 4 5 = 2 3 Matrix multiplication is associative (but not commutative) A(BC) = (AB)C, but ABC CBA 2 3 4 5 6 7 8 9 2 3 4 5 2 3 4 5 6 7 8 9 concatenation is 64 Multipl-Add operations, done b OpenGL driver 2 3 4 5

Specifing the Transforms Specified in two parts First the projection glmatrixmode(gl_rojection); glloadidentit(); glfrustum(-4, +4, // left & right -3, +3, // top & bottom 5, 8); // near & far Second the model-view glmatrixmode(gl_modelview); glloadidentit(); gltranslatef(,, -4); So objects centered at (,,) would be at (,,-4) in ee-space Resulting projection matrix.25.667.333 4.667 Resulting modelview matrix

Modelview-rojection Matrix Transform composition via matrix multiplication 4.667.333.667.25 = 4 5.2.333.667.25 Resulting modelview-projection matrix

Now Draw Some Objects Draw a wireframe cube glcolor3f(,,); // red glutwirecube(6); 6x6x6 unit cube centered at origin (,,) Draw a teapot in the cube glcolor3f(,,); // blue glutsolidteapot(2.); centered at the origin (,,) handle and spout point down the X axis top and bottom in the Y axis As we d expect given a frustum transform, the cube is in perspective The teapot is too but more obvious to observe with a wireframe cube

What We ve Accomplished Simple perspective With glfrustum Establishes how ee-space maps to clip-space Simple viewing With gltranslatef Establishes how world-space maps to ee-space (,,4) (,,) All we reall did was wheel the camera 4 units up the Z axis No actual modeling transforms, just viewing Modeling would be rotating, scaling, or otherwise transform the objects with the view Arguabl the modelview matrix is reall just a view matrix in this example

Some Simple Modeling Tr some modeling transforms to move teapot But leave the cube alone for reference glushmatrix(); { gltranslatef(.5, -.5, ); glutsolidteapot(2.); } glopmatrix(); glushmatrix(); { glscalef(.5,.,.5); glutsolidteapot(2.); } glopmatrix(); glushmatrix(); { glrotatef(3,,,); glutsolidteapot(2.); } glopmatrix(); We bracket the modeling transform with glushmatrix/glopmatrix commands so the modeling transforms are localized to the particular object

Add Some Lighting Some lighting makes the modeling more intuitive glushmatrix(); { gltranslatef(.5, -.5, ); glutsolidteapot(2.); } glopmatrix(); glushmatrix(); { glscalef(.5,.,.5); glutsolidteapot(2.); } glopmatrix(); glushmatrix(); { glrotatef(3,,,); glutsolidteapot(2.); } glopmatrix(); We ve not discussed lighting et but per-vertex lighting allows a virtual light source to interact with the object s surface orientation and material properties

Modelview-rojection Matrix Let s consider the combined modelview matrix with the rotation glrotate(3,,,) defines a rotation matrix Rotating 3 degrees around an axis in the (,,) direction.97.3333.244.244.97.3333.3333.244.97.25.667.333.667 4.97.3333.244.244.97.3333.3333.244.97 projection view model

Combining All Three Matrix-b-matrix multiplication is associative so VM = (V M) = ( V) M OpenGL keeps V and M together because ee-space is a convenient space for lighting " $ $ $ $ # " $ $ $ $ # 4 view.25.667.333.667 % " ' $ ' $ ' $ ' $ & # % " ' $ ' $ ' $ ' $ & #.97.244.3333.3333.97.244.244.3333.97 model.97.244.3333.3333.97.244.244.3333.97 4 % ' ' ' ' & % ' ' ' ' & projection " $ $ $ $ #.384.35.467.5556.578.467.2766.3778.32 5.2.244.3333.97 4 modelview-projection modelview % ' ' ' ' &

Object- to Clip-space = object object object object world world world world w z x w z x.97.3333.244.244.97.3333.3333.244.97 = world world world world ee ee ee ee w z x w z x 4 = ee ee ee ee clip clip clip clip w z x w z x.667.333.667.25 = object object object object clip clip clip clip w z x w z x 4.97.3333.244 5.2.32.3778.2766.467.578.5556.467.35.384 = object object object object ee ee ee ee w z x w z x 4.97.3333.244.244.97.3333.3333.244.97 = ee ee ee ee clip clip clip clip w z x w z x.667.333.667.25 object-to-world-to-ee-to-clip object-to-ee-to-clip object-to-clip modelview projection projection modelview-projection model view

Complex Scene Example Each character, wall, ceiling, floor, and light have their own modeling transformation Universit of Texas at Austin CS354 - Computer Graphics

Representing Objects Interested in object s boundar Various approaches rocedural representations Often fractal Sierpinski gasket Fractal tree [hilip Winston] Explicit polgon (triangle) meshes B far, the most popular method Curved surface patches Often displacement mapped Implicit representation Blobb, volumetric Quake 2 ke frame triangle meshes Utah Teapot Blobb modeling in RenderMan

Focus on Triangle Meshes Easiest approach to representing object boundaries So what is a mesh and how should it be stored? Simplest view A set of triangles, each with its own 3 vertices Essentiall triangle soup Yet triangles in meshes share edges b design Sharing edges implies sharing vertices More sophisticated view Store single set of unique vertexes in arra Then each primitive (triangle) specifies 3 indices into arra of vertexes More compact Vertex data size >> index size Avoids redundant vertex data Separates topolog (how the mesh is connected) from its geometr (vertex positions and attributes) Connectivit can be deduced more easil Makes mesh processing algorithms easier Geometr data can change without altering the topolog

Consider a Tetrahedron Simplest closed volume Consists of 4 triangles and 4 vertices (and 4 edges) (x2,2,z2) v2 v3 (x3,3,z3) v (x,,z) v (x,,z) triangle list : v,v,v2 : v,v3,v2 2: v3,v,v2 3: v,v,v3 topolog vertex list : (x,,z) : (x,,z) 2: (x2,2,z2) 3: (x3,3,z3) geometr potentiall on-gu!

Benefits of Vertex Arra Approach Unique vertices are stored once Saves memor On CU, on disk, and on GU Matches OpenGL vertex arra model of operation And this matches the efficient GU mode of operation The GU can cache post-transformed vertex results b vertex index Saves retransformation and redundant vertex fetching Direct3D has the same model Allows vertex data to be stored on-gu for even faster vertex processing OpenGL supported vertex buffer objects for this

Next Lecture More about triangle mesh representation Scene graphs