The Graphics Pipeline and OpenGL I: Transformations!

Similar documents
The Graphics Pipeline and OpenGL I: Transformations!

Rasterization Overview

COMS 4160: Problems on Transformations and OpenGL

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

CMSC427 Transformations II: Viewing. Credit: some slides from Dr. Zwicker

Notes on Assignment. Notes on Assignment. Notes on Assignment. Notes on Assignment

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

The Graphics Pipeline and OpenGL IV: Stereo Rendering, Depth of Field Rendering, Multi-pass Rendering!

Lecture 2. Shaders, GLSL and GPGPU

Projection and viewing. Computer Graphics CSE 167 Lecture 4

Rendering Objects. Need to transform all geometry then

C P S C 314 S H A D E R S, O P E N G L, & J S RENDERING PIPELINE. Mikhail Bessmeltsev

Virtual Cameras and The Transformation Pipeline

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

CSE 167: Introduction to Computer Graphics Lecture #5: Projection. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2017

Lecture 4. Viewing, Projection and Viewport Transformations

CSE 167: Introduction to Computer Graphics Lecture #5: Rasterization. Jürgen P. Schulze, Ph.D. University of California, San Diego Fall Quarter 2015

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

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

Transforms 3: Projection Christian Miller CS Fall 2011

CS230 : Computer Graphics Lecture 6: Viewing Transformations. Tamar Shinar Computer Science & Engineering UC Riverside

Overview. By end of the week:

Computer graphics 2: Graduate seminar in computational aesthetics

Game Architecture. 2/19/16: Rasterization

Announcements. Submitting Programs Upload source and executable(s) (Windows or Mac) to digital dropbox on Blackboard

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

The Graphics Pipeline and OpenGL III: OpenGL Shading Language (GLSL 1.10)!

Viewing with Computers (OpenGL)

Lecture 3 Sections 2.2, 4.4. Mon, Aug 31, 2009

Shaders. Slide credit to Prof. Zwicker

Computer Graphics 7: Viewing in 3-D

Drawing in 3D (viewing, projection, and the rest of the pipeline)

GEOMETRIC TRANSFORMATIONS AND VIEWING

Pipeline Operations. CS 4620 Lecture 14

CS451Real-time Rendering Pipeline

Computer Graphics with OpenGL ES (J. Han) Chapter VII Rasterizer

OPENGL RENDERING PIPELINE

CS 112 The Rendering Pipeline. Slide 1

CSC 305 The Graphics Pipeline-1

CS 130 Final. Fall 2015

Geometry: Outline. Projections. Orthographic Perspective

Models and The Viewing Pipeline. Jian Huang CS456

Drawing in 3D (viewing, projection, and the rest of the pipeline)

CSE328 Fundamentals of Computer Graphics

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

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

CSE528 Computer Graphics: Theory, Algorithms, and Applications

OpenGL Transformations

Spring 2011 Prof. Hyesoon Kim

Perspective transformations

Drawing in 3D (viewing, projection, and the rest of the pipeline)

CS4620/5620: Lecture 14 Pipeline

TSBK03 Screen-Space Ambient Occlusion

3D Viewing. CS 4620 Lecture 8

Orthogonal Projection Matrices. Angel and Shreiner: Interactive Computer Graphics 7E Addison-Wesley 2015

Graphics pipeline and transformations. Composition of transformations

Rendering. Converting a 3D scene to a 2D image. Camera. Light. Rendering. View Plane

Today. Rendering algorithms. Rendering algorithms. Images. Images. Rendering Algorithms. Course overview Organization Introduction to ray tracing

Head Mounted Display Optics I!

Drawing Fast The Graphics Pipeline

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

Spring 2009 Prof. Hyesoon Kim

Graphics Pipeline 2D Geometric Transformations

Wire-Frame 3D Graphics Accelerator IP Core. C Library Specification

CS 354R: Computer Game Technology

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

1 OpenGL - column vectors (column-major ordering)

SUMMARY. CS380: Introduction to Computer Graphics Projection Chapter 10. Min H. Kim KAIST School of Computing 18/04/12. Smooth Interpolation

Real-Time Rendering (Echtzeitgraphik) Michael Wimmer

Models and Architectures

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

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

3D Viewing. CS 4620 Lecture Steve Marschner. Cornell CS4620 Spring 2018 Lecture 9

Virtual Cameras & Their Matrices

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

graphics pipeline computer graphics graphics pipeline 2009 fabio pellacini 1

Real - Time Rendering. Graphics pipeline. Michal Červeňanský Juraj Starinský

The Rasterization Pipeline

CS452/552; EE465/505. Intro to Lighting

CS230 : Computer Graphics Lecture 4. Tamar Shinar Computer Science & Engineering UC Riverside

COMP Preliminaries Jan. 6, 2015

Computer Graphics. Chapter 10 Three-Dimensional Viewing

Computer Graphics Seminar

CS GPU and GPGPU Programming Lecture 2: Introduction; GPU Architecture 1. Markus Hadwiger, KAUST

INTRODUCTION TO COMPUTER GRAPHICS. It looks like a matrix Sort of. Viewing III. Projection in Practice. Bin Sheng 10/11/ / 52

Advanced Rendering Techniques

Lecturer Athanasios Nikolaidis

CSE452 Computer Graphics

Scanline Rendering 2 1/42

CS 4620 Program 3: Pipeline

Tutorial on GPU Programming #2. Joong-Youn Lee Supercomputing Center, KISTI

INTRODUCTION TO COMPUTER GRAPHICS. cs123. It looks like a matrix Sort of. Viewing III. Projection in Practice 1 / 52

S U N G - E U I YO O N, K A I S T R E N D E R I N G F R E E LY A VA I L A B L E O N T H E I N T E R N E T

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

Ciril Bohak. - INTRODUCTION TO WEBGL

Lecture 5: Transforms II. Computer Graphics and Imaging UC Berkeley CS184/284A

We will use WebGL 1.0. WebGL 2.0 is now being supported by most browsers but requires a better GPU so may not run on older computers or on most cell

Lecture 4: 3D viewing and projections

Rendering If we have a precise computer representation of the 3D world, how realistic are the 2D images we can generate? What are the best way to mode

E.Order of Operations

Transcription:

! The Graphics Pipeline and OpenGL I: Transformations! Gordon Wetzstein! Stanford University! EE 267 Virtual Reality! Lecture 2! stanford.edu/class/ee267/!!

Albrecht Dürer, Underweysung der Messung mit dem Zirckel und Richtscheyt, 1525!

Lecture Overview! what is computer graphics?! the graphics pipeline! primitives: vertices, edges, triangles!! model transforms: translations, rotations, scaling! view transform! perspective transform! window transform!

blender.org!

Modeling 3D Geometry! Courtesy of H.G. Animations! https://www.youtube.com/watch?v=fewbfva5ogk!

blender.org!

What is Computer Graphics?! at the most basic level: conversion from 3D scene description to 2D image! what do you need to describe a static scene?! 3D geometry and transformations! lights! material properties! most common geometry primitives in graphics:! vertices (3D points) and normals (unit-length vector associated with vertex)! triangles (set of 3 vertices, high-resolution 3D models have M or B of triangles)!

! The Graphics Pipeline! blender.org! geometry + transformations! cameras and viewing! lighting and shading! rasterization! texturing!

Some History! Stanford startup in 1981! computer graphics goes hardware! based on Jim Clark s geometry engine!

Some History!

The Graphics Pipeline! monolithic graphics workstations of the 80s have been replaced by modular GPUs (graphics processing units); major companies: NVIDIA, AMD, Intel! early versions of these GPUs implemented fixed-function rendering pipeline in hardware! GPUs have become programmable starting in the late 90s! e.g. in 2001 Nvidia GeForce 3 = first programmable shaders! now: GPUs = programmable (e.g. OpenGL, CUDA, OpenCL) processors!

The Graphics Pipeline! GPU = massively! parallel processor!

OpenGL is our interface to the GPU! The Graphics Pipeline! right: old-school OpenGL state machine! today s lecture: vertex transforms! I had this poster hanging on my dorm wall during undergrad!

WebGL! JavaScript application programmer interface (API) for 2D and 3D graphics! OpenGL ES 2.0 running in the browser, implemented by all modern browsers! overview, tutorials, documentation: see lab 1!!

three.js! cross-browser JavaScript library/api! higher-level library that provides a lot of useful helper functions, tools, and abstractions around WebGL easy and convenient to use! https://threejs.org/! simple examples: https://threejs.org/examples/! great introduction (in WebGL):! http://davidscottlyons.com/threejs/presentations/frontporch14/!

The Graphics Pipeline! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

The Graphics Pipeline! 1. Vertex Processing: Process and transform individual vertices & normals. 2. Rasterization: Convert each primitive (connected vertices) into a set of fragments. A fragment can be treated as a pixel in 3D spaces, which is aligned with the pixel grid, with attributes such as position, color, normal and texture.! 3.! Fragment Processing: Process individual fragments.! 4.! Output Merging: Combine the fragments of all primitives (in 3D space) into 2D color-pixel for the display.! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

The Graphics Pipeline! 1. Vertex Processing: Process and transform individual vertices & normals. 2. Rasterization: Convert each primitive (connected vertices) into a set of fragments. A fragment can be treated as a pixel in 3D spaces, which is aligned with the pixel grid, with attributes such as position, color, normal and texture.! 3.! Fragment Processing: Process individual fragments.! 4.! Output Merging: Combine the fragments of all primitives (in 3D space) into 2D color-pixel for the display.! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

The Graphics Pipeline! vertex shader! fragment shader! transforms & (pervertex) lighting! texturing! (per-fragment) lighting! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Coordinate Systems! right hand coordinate system! a few different coordinate systems:! object coordinates! world coordinates! viewing coordinates! also clip, normalized device, and window coordinates! wikipedia!

Primitives! vertex = 3D point v(x,y,z)! triangle = 3 vertices! normal = 3D vector per vertex describing surface orientation n=(n x,n y,n z )! n 2 n 3 v 3 v 2 n 1 v 1

Pixels v Fragments! fragments have rasterized 2D coordinates on screen but a lot of other attributes too (texture coordinates, depth value, alpha value, )! pixels appear on screen! won t discuss in more detail today! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! vertex/normal! transforms! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). 3. Select a camera lens (wide angle, normal or telescopic), adjust the focus length and zoom factor to set the camera's field of view (Projection transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). 3. Select a camera lens (wide angle, normal or telescopic), adjust the focus length and zoom factor to set the camera's field of view (Projection transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). 3. Select a camera lens (wide angle, normal or telescopic), adjust the focus length and zoom factor to set the camera's field of view (Projection transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Vertex Transforms! 1. Arrange the objects (or models, or avatar) in the world (Model Transform). 2. Position and orientation the camera (View transform). 3. Select a camera lens (wide angle, normal or telescopic), adjust the focus length and zoom factor to set the camera's field of view (Projection transform). https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Model Transform!! x $ transform each vertex v = # y & from object coordinates to world coordinates! " # z % & https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Model Transform - Scaling! x transform each vertex v = y from object coordinates to world coordinates! z 1. scaling as 3x3 matrix! S(s x,s y,s z ) = s x 0 0 0 s y 0 0 0 s z scaled vertex = matrix-vector product:! Sv = s x 0 0 0 s y 0 0 0 s z x y z = s x x s y y s z z

Model Transform - Rotation! x transform each vertex v = y from object coordinates to world coordinates! z 2. rotation as 3x3 matrix! R z (θ) = cosθ sinθ 0 sinθ cosθ 0 0 0 1 R x (θ) = 1 0 0 0 cosθ sinθ 0 sinθ cosθ R y (θ) = cosθ 0 sinθ 0 1 0 sinθ 0 cosθ rotated vertex = matrix-vector product, e.g.! R z v = cosθ sinθ 0 sinθ cosθ 0 0 0 1 x y z = x cosθ ysinθ xsinθ + ycosθ z

Model Transform - Translation! transform each vertex from object coordinates to world coordinates! v = x y z 3. translation cannot be represented as 3x3 matrix!! x y z + d x d y d z = x + d x y + d y z + d z that s unfortunate L!

Model Transform - Translation! solution: use homogeneous coordinates, vertex is! v = x y z 1 3. translation is 4x4 matrix! T (d) = 1 0 0 d x 0 1 0 d y 0 0 1 d z 0 0 0 1 better J! Tv = 1 0 0 d x 0 1 0 d y 0 0 1 d z 0 0 0 1 x y z 1 = x + d x y + d y z + d z 1

Summary of Homogeneous Matrix Transforms!!!! translation! scale! T (d) = S(s) = 1 0 0 d x 0 1 0 d y 0 0 1 d z 0 0 0 1 s x 0 0 0 0 s y 0 0 0 0 s z 0 0 0 0 1 rotation! R z (θ) = cosθ sinθ 0 0 sinθ cosθ 0 0 0 0 1 0 0 0 0 1 R x = 1 0 0 0 0 cosθ sinθ 0 0 sinθ cosθ 0 0 0 0 1 R y = cosθ 0 sinθ 0 0 1 0 0 sinθ 0 cosθ 0 0 0 0 1 Read more: https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Summary of Homogeneous Matrix Transforms!!!! 1 0 0 d x 0 1 0 d y translation T (d) = inverse translation! 0 0 1 d z 0 0 0 1 s x 0 0 0 0 s y 0 0 scale S(s) = inverse scale! 0 0 s z 0 0 0 0 1 T 1 (d) = T ( d) = 1 0 0 d x 0 1 0 d y 0 0 1 d z 0 0 0 1 1/ s x 0 0 0 S 1 (s) = S 1 s 0 1/ s = y 0 0 0 0 1/ s z 0 0 0 0 1 cosθ sinθ 0 0 sinθ cosθ 0 0 0 0 1 0 0 0 0 1 rotation R z (θ) = inverse rotation! R 1 z (θ) = R z ( θ ) = cos θ sin θ 0 0 sin θ cos θ 0 0 0 0 1 0 0 0 0 1 Read more: https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Summary of Homogeneous Matrix Transforms!!! successive transforms:! inverse successive transforms:! v' = T S R z R x T v v = ( T S R z R x T ) 1 v' = T 1 R x 1 R z 1 S 1 T 1 v' Read more: https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

! Vector and Normal Transforms! homogeneous representation of a vector t, i.e. pointing from v 1 to v 2 :! " $ t = $ $ # $ (v 2! v 1 ) x (v 2! v 1 ) y (v 2! v 1 ) z (1!1) % " ' $ ' $ ' $ & ' # $ t x t y t z 0 % ' ' ' & ' successive transforms:! this works! t ' = M!t = M!( v 2 " v 1 ) = M!v 2 " M!v 1 v' 2 v 2 t M t ' v 1 v' 1

! Vector and Normal Transforms! homogeneous representation of a normal (unit length, perpendicular to surface)!! # n = # # " # n x n y n z 0 $ & & & % & successive transforms???! this does NOT work! (non-uniform scaling is a problem)! v 2 n' = M!n n t M v' 2 n' t ' v 1 v' 1

! Vector and Normal Transforms! homogeneous representation of a normal (unit length, perpendicular to surface)!! # n = # # " # n x n y n z 0 $ & & & % & need to use transpose of inverse for transformation! v 2 n t M n' = ( M!1 ) T "n v' 2 n' t ' v 1 v' 1

Attention!! rotations and translations (or transforms in general) are not commutative!! make sure you get the correct order!!

View Transform! so far we discussed model transforms, e.g. going from object or model space to world space! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

View Transform! so far we discussed model transforms, e.g. going from object or model space to world space! one simple 4x4 transform matrix is sufficient to go from world space to camera or view space! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

!!!! View Transform! specify camera by!! eye x $ # & eye position! eye = # eye y & # eye & " z %! # reference position! center = # # "! up x $ # & up vector! up = # up y & # " up & z % center x center y center z $ & & & %

!!!! View Transform! specify camera by! eye x eye position! eye = eye y eye z reference position! center = up x up vector! up = up y up z center x center y center z compute 3 vectors:! z c = x c = eye center eye center up zc up z c y c = z c x c

!! View Transform! view transform M is translation into eye position,! followed by rotation! compute 3 vectors:! z c = x c = eye center eye center up zc up z c y c = z c x c

!! View Transform! view transform M is translation into eye position,! followed by rotation! M = R T ( e) = x x c y x c z x c x y c y y c z y c x z c y z c z z c 0 0 0 0 0 0 1 1 0 0 eye x 0 1 0 eye y 0 0 1 eye z 0 0 0 1 compute 3 vectors:! z c = x c = eye center eye center up zc up z c y c = z c x c

!! View Transform! view transform M is translation into eye position,! followed by rotation! M = R T ( e) = c x x c x y c x z c y x c y y c y z c z x c z y c z z ( ) ( ) ( ) x x c eye x + x y c eye y + x z c eye z y x c eye x + y y c eye y + y z c eye z z x c eye x + z y c eye y + z z c eye z 0 0 0 1

View Transform! in camera/view space, the camera is at the origin, looking into negative z! modelview matrix is combined model (rotations, translations, scaling) and view matrix! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

View Transform! in camera/view space, the camera is at the origin, looking into negative z! up e z x z x vodacek.zvb.cz!

Projection Transform! similar to choosing lens and sensor of camera specify field of view and aspect! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Projection Transform - Perspective Projection! have symmetric view frustum! fovy: vertical angle in degrees! aspect: ratio of width/height! znear: near clipping plane (relative from cam)! zfar: far clipping plane (relative from cam)! f = cot( fovy / 2) # % % % M proj = % % % $ % f aspect 0 0 0 0 f 0 0 zfar + znear 2 " zfar " znear 0 0!! zfar! znear zfar! znear 0 0!1 0 & ( ( ( ( ( ( ' ( projection matrix! (symmetric frustum)!

Projection Transform - Perspective Projection! more general: a perspective frustum (truncated, possibly sheared pyramid)! left (l), right (r), bottom (b), top (t): corner coordinates on near clipping plane (at znear)! perspective frustum! # % % % M proj = % % % % $ % 2! znear r + l 0 0 r " l r " l 2! znear t + b 0 0 t " b t " b zfar + znear 2! zfar! znear 0 0 " " zfar " znear zfar " znear 0 0 "1 0 & ( ( ( ( ( ( ( ' ( projection matrix! (asymmetric frustum)!

Projection Transform - Orthographic Projection! more general: a box frustum (no perspective, objects don t get smaller when farther away)! left (l), right (r), bottom (b), top (t): corner coordinates on near clipping plane! " $ $ $ M proj = $ $ $ $ $ # 2 r! l 0 0 0 0 0! r + l r! l 2 0! t + b t! b t! b!2! f + n f! n f! n 0 0 0 1 % ' ' ' ' ' ' ' ' & projection matrix! (orthographic)!

Perspective! Orthographic! [Song Ho Ahn]!

! Projection Transform! possible source of confusion for znear and zfar:! Marschner & Shirley define it as absolute z coordinates, thus znear>zfar and both values are always negative! OpenGL and we define it as positive values, i.e. the distances of the near and far clipping plane from the camera (zfar > znear)!

Modelview Projection Matrix! put it all together with 4x4 matrix multiplications!! v clip = M proj! M view! M model!v = M proj! M mv!v vertex in clip space! projection matrix! modelview matrix!

Clip Space! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

Normalized Device Coordinates (NDC)! not shown in previous illustration! get to NDC by perspective division! from: OpenGL Programming Guide!! # # v clip = # # # " x clip y clip z clip w clip $ & & & & & %! # v NDC = # # " # x clip / w clip y clip / w clip z clip / w clip 1 $ & & & % & ( ) ( ) ( )! "1,1! "1,1! "1,1 vertex in clip space! vertex in NDC!

! Viewport Transform! define (sub)window as viewport(x,y,width,height),! x,y lower left corner of viewport rectangle (default is (0,0))! width, height size of viewport rectangle in pixels! from: OpenGL Programming Guide! x window = width ( x NDC +1) + x 2 y window = height y NDC +1 2 z window = 1 2 z NDC + 1 2 ( ) + y! # v NDC = # # " # x clip / w clip y clip / w clip z clip / w clip 1 $ & & & % &! # v window = # # # " x window y window z window 1 $ & & & & % ( ) ( ) '( 0,1) ' 0,width (1 ' 0,height (1 vertex in NDC! vertex in window coords!

The Graphics Pipeline Another Illustration!

The Graphics Pipeline! all vertex transforms from today! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

! The Graphics Pipeline! assign fixed color (e.g. red) to each vertex in window coordinates (fragment)! interpolate (i.e. rasterize) lines between vertices (as defined by user)! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

and we can almost do this! Nintendo Virtual Boy Game Red Alarm!

Summary! graphics pipeline is a series of operations that takes 3D vertices/normals/ triangles as input and generates fragments and pixels! today, we only discussed a part of it: vertex and normal transforms! transforms include: rotation, scale, translation, perspective projection, perspective division, and viewport transform! most transforms are represented as 4x4 matrices in homogeneous coordinates à know your matrices & be able to create, manipulate, invert them!!

Next Lecture: Lighting and Shading, Fragment Processing! vertex shader! fragment shader! transforms & (pervertex) lighting! texturing! (per-fragment) lighting! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html!

!! Further Reading! good overview of OpenGL (deprecated version) and graphics pipeline (missing a few things) :! https://www.ntu.edu.sg/home/ehchua/programming/opengl/cg_basicstheory.html! textbook: Shirley and Marschner Fundamentals of Computer Graphics, AK Peters, 2009! definite reference: OpenGL Programming Guide aka OpenGL Red Book! WebGL / three.js tutorials: https://threejs.org/!