SlideShare a Scribd company logo
1 of 39
Download to read offline
Virtual Cameras
and
The Transformation Pipeline
Anton Gerdelan
gerdela@scss.tcd.ie
with content from
Rachel McDonnell
13 Oct 2014
Virtual Camera
●
We want to navigate through our scene in 3d
●
Solution = create a transformation pipeline
●
Move all points relative to some arbitrary view point,
such that the view point is the new (0,0,0) origin
●
Also project our scene with a perspective rather than
orthogonal view
Transformation Pipeline – Coordinate Spaces
* model
matrix
* view
matrix
vertex shader output
* projection
matrix
perspective
division
(x,y,z) / w
Transformation Pipeline – Coordinate Spaces
* model
matrix
* view
matrix
vertex shader output
perspective
division
(x,y,z) / w
* projection
matrix
? ?
?
Local Space
●
When you create a triangle or
●
Load a mesh from a file
●
Has some (0,0,0) origin, local to that particular mesh
●
Translate, rotate, scale to position in a virtual world
– Multiply points with a model matrix aka “world matrix”
– mat4 M = T * R * S;
vec4 pos_wor = M * vec4 (pos_loc, 1.0);
World Space
●
Objects positioned in scene or “virtual world”
●
Has a world (0,0,0) origin
●
Can get distances between objects
●
Now we want to show the view from a camera, moving through the virtual
world
●
Multiply world space points by a view matrix to get to eye space
mat4 V = R * T; // inverse of cam pos & angle
mat4 V = lookAt (vec3 pos, vec3 target, vec3 up);
vec4 pos_eye = M * pos_wor;
What the View Matrix Does
View Matrix
Right xyz
Up xyz
-Forward xyz
-Position xyz
Careful now!
lookAt(vec3 eye, vec3 look, vec3 up)
●
Typical maths library
function
●
Returns mat4
●
Sets camera position
●
Point at target
●
Careful with “up” unit vector
●
Not ideal for full 3d rotation
lookAt(vec3 eye, vec3 look, vec3 up)
●
Rem: view matrix needs
– Right
– Forward
– Up
– Position
●
(set of 3d vectors)
●
Q1: How can we work
out “forward”?
lookAt(vec3 eye, vec3 look, vec3 up)
vec3 f = normalise(look
– eye);
●
Q2. How can we work out
“right” from “up” and
“forward” ?
lookAt()
vec3 r = cross(f, up);
// recalc up to be sure
vec3 u = normalise (cross (r, f));
mat4 T = translate (-eye);
mat4 R = plug-in r,u,-f
return R * T;
●
Q3. Why did I re-calculate “up”?
●
Q4. What would happen if I did cross(up, f)
instead?
●
Q5. What must you do if camera pitches up/down?
Q1. What is the cross product of these vectors?
[0.0, 0.0, 1.0] X [1.0, 0.0, 0.0]
Q2. How do you normalise a 4d vector?
[10.0, 0.0, 0.0, 0.0]
Rotation Method Limitations
●
Calculating from fixed-axis X*Y*Z
rotation matrices
●
LookAt() is good for panning,
not great for flight sims
●
quaternions better suited to
creating rotation matrix with full
3d rotation
– Euler axis & angle in 4 numbers
– then some multiplications to get a
4X4 rotation matrix
– Good for local pitch/yaw/roll
Arbitrary “Euler axis”
Transformation Pipeline – Coordinate Spaces
* model
matrix
* view
matrix
vertex shader output
* projection
matrix
perspective
division
(x,y,z) / w
Eye Space
●
Objects positioned relative to view point and direction
●
Has an eye origin (0, 0, 0)
●
Our view area is still -1 to 1 on XYZ.
●
Our view is still a parallel (orthogonal/orthographic)
projection.
●
Q. How can we manipulate the projection?
What We Have Now
Q. How can we make our view cover more of the scene?
Orthographic Projection Matrix
Q. What affine matrices does this look similar to?
Zi -
Zi + Zf
Zf - Zi
How can we approximate a cone of view?
●
Has to map to a 2d rectangular view, not a circle
(well...we could do a circle)
●
Has to have minimum and maximum cut-of distances
●
Some sort of angle of view
●
We had a cuboid before for orthographic
●
Q. What 3d geometric shape is this?
Perspective Projection
Typical Perspective Function
mat4 perspective (
float fovy,
float aspect,
float zNear,
float zFar
);
●
Fovy is “field of view y-axis”
– angle from horizon to top
– convert to radians
●
Aspect ratio is
(float)width / (float)height
of viewport
●
Near and far are “clip
planes”
– 0.1 and 1000.0 are typical
A Symmetric Perspective Matrix
●
Q. An aspect of 2.0 means?
●
Wrong aspect = distortion
●
Depth bufer precision
(ranges of z) has only so many
bits per pixel.
●
Smaller zFar / zNear ratio =
more precision
●
As zNear -> 0, zFar -> infinity
– Do not make zNear = 0.0
1.0 / tan (fovy * 0.5);
???
FOV
●
Beware comparisons of angle of view
●
Older games etc. used horizontal angles of view ~90
degrees
●
These also had fixed-aspect displays:
– 320x200 (2.5:4)
– 320x240, 640x480, etc. -> (3:4) = 1.3333...
●
LookAt() etc. Use vertical angles
– 90 degrees horiz. / 1.333333 = 67.5 degrees vert.
Transformation Pipeline – Coordinate Spaces
* model
matrix
* view
matrix
vertex shader output
* projection
matrix
perspective
division
(x,y,z) / w
Homogenous Clip Space
●
Geometry outside near/far xyz clip planes is “clipped” after the VS
●
Q. How will we map our frustum area onto a 2d drawing surface?
Hint: The orthographic cuboid was easy.
?
Perspective Division
A. We will squish in the large back end until it is a -1 to 1 XYZ
box.
Q. How? Hint: Some of you did this in Assignment 0
Perspective Division
●
Vertex shader output is a 4d variable
gl_Position = P * V * M * vec4 (vp, 1.0);
gl_Position = vec4 (x, y, z, w);
●
After the VS, a built-in mechanism does
position = vec3 (gl_Position.xyz / gl_Position.w);
●
Q. What does the perspective matrix do to w?
Perspective Division
Transformation Pipeline – Coordinate Spaces
* model
matrix
* view
matrix
vertex shader output
* projection
matrix
perspective
division
(x,y,z) / w
Normalised Device Space
●
All coordinates are between -1 and 1 – the unit cube
●
This is very easy to scale by # pixels wide and high
●
Project to 2d
●
Front/back face select and cull if enabled
●
Rasterise to pixels/fragments
Typical Vertex Shader w/ Camera
#version 400
in vec3 vertex_point, vertex_normal;
uniform mat4 P, V, M;
out vec3 p_eye, n_eye;
void main () {
gl_Position = P * V * M * vec4 (vertex_point, 1.0);
p_eye = V * M * vec4 (vertex_point, 1.0);
n_eye = V * M * vec4 (vertex_normal, 0.0);
}
●
Order of multiplication is fundamentally important
●
Never compare variables from diferent coordinate spaces
●
Use a postfix or prefix naming convention for variables
useful for
lighting
Normalised Device Space
●
All coordinates are between -1 and 1 – the unit cube
●
This is very easy to scale by # pixels wide and high
●
Project to 2d
●
Front/back face select and cull if enabled
●
Rasterise to pixels/fragments
Depth Testing (automatic step)
and The Depth Bufer
●
Edwin Catmull again – PhD thesis 1974, U. Utah.
●
Whenever we write a fragment it writes the colour to the
framebufer's colour bufer (a big 2d image)
●
But first...if depth testing is enabled
●
It checks another 2d image called the depth bufer
●
If its own depth is smaller/closer it overwrites both the depth and
colour bufer pixels
●
Q. What does this do?
●
Can we disable the depth testing and try?
Depth Bufer
Smaller value = farther
away
Bigger = closer
In F.Shader use built-in gl_FragCoord.w to get
this value and use as a colour
Reading List and Practical Tasks
●
Shirley & Marschner – “Fundamentals” Ch. 7 “Viewing”
●
Akenine Moeller et. al “Real-Time Rendering” Ch. 2 and
4.6 “Projections” (very good)
●
Know how to work out the pipeline by hand on paper for
1 vertex & M, V, and P
●
Hint: add a “print_matrix(m)” function to check contents
3rd
Assignment - Viewing
●
Due next week!
●
Start way ahead of time
(easy to get into a transformations mess)
●
If you finish early, get a head start on game project skills:
– Play
– Upgrade – Load a mesh? Full 3d camera controls?
– make all the mistakes
– ask for advice now (discussion boards)

More Related Content

What's hot

Precomputed atmospheric scattering(사전 계산 대기 산란)
Precomputed atmospheric scattering(사전 계산 대기 산란)Precomputed atmospheric scattering(사전 계산 대기 산란)
Precomputed atmospheric scattering(사전 계산 대기 산란)Bongseok Cho
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9fungfung Chen
 
Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015)
Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015) Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015)
Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015) Konrad Wenzel
 
셰이더가 뭐에요?
셰이더가 뭐에요?셰이더가 뭐에요?
셰이더가 뭐에요?Jungsoo Park
 
Défis de programmation créative: Du conte au code avec Scratch et #VibotLeRobot
Défis de programmation créative:  Du conte au code avec Scratch et #VibotLeRobotDéfis de programmation créative:  Du conte au code avec Scratch et #VibotLeRobot
Défis de programmation créative: Du conte au code avec Scratch et #VibotLeRobotMargarida Romero
 
Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들
Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들
Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들Dae Hyek KIM
 
Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법장규 서
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016Mark Kilgard
 
게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동세민 이
 
포인트 셰도우
포인트 셰도우포인트 셰도우
포인트 셰도우Sukwoo Lee
 
3 d transformation
3 d transformation3 d transformation
3 d transformationMani Kanth
 
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술Ki Hyunwoo
 
노말 맵핑(Normal mapping)
노말 맵핑(Normal mapping)노말 맵핑(Normal mapping)
노말 맵핑(Normal mapping)QooJuice
 
Digital_image_processing_-Vijaya_Raghavan.pdf
Digital_image_processing_-Vijaya_Raghavan.pdfDigital_image_processing_-Vijaya_Raghavan.pdf
Digital_image_processing_-Vijaya_Raghavan.pdfVaideshSiva1
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fillwahab13
 
[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기
[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기
[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기강 민우
 
2009-2016 기본기(손맵)의 중요성
2009-2016 기본기(손맵)의 중요성2009-2016 기본기(손맵)의 중요성
2009-2016 기본기(손맵)의 중요성Gunho Shin
 
Convolutional Neural Network (CNN)
Convolutional Neural Network (CNN)Convolutional Neural Network (CNN)
Convolutional Neural Network (CNN)Muhammad Haroon
 
Unreal Engine 4 Study - 閉じた空間でのライティング
Unreal Engine 4 Study - 閉じた空間でのライティングUnreal Engine 4 Study - 閉じた空間でのライティング
Unreal Engine 4 Study - 閉じた空間でのライティングJugando Develop
 

What's hot (20)

Precomputed atmospheric scattering(사전 계산 대기 산란)
Precomputed atmospheric scattering(사전 계산 대기 산란)Precomputed atmospheric scattering(사전 계산 대기 산란)
Precomputed atmospheric scattering(사전 계산 대기 산란)
 
CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9CG OpenGL surface detection+illumination+rendering models-course 9
CG OpenGL surface detection+illumination+rendering models-course 9
 
Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015)
Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015) Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015)
Dense Image Matching - Challenges and Potentials (Keynote 3D-ARCH 2015)
 
셰이더가 뭐에요?
셰이더가 뭐에요?셰이더가 뭐에요?
셰이더가 뭐에요?
 
Défis de programmation créative: Du conte au code avec Scratch et #VibotLeRobot
Défis de programmation créative:  Du conte au code avec Scratch et #VibotLeRobotDéfis de programmation créative:  Du conte au code avec Scratch et #VibotLeRobot
Défis de programmation créative: Du conte au code avec Scratch et #VibotLeRobot
 
Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들
Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들
Ndc17 - 차세대 게임이펙트를 위해 알야아할 기법들
 
Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법Unite2019 HLOD를 활용한 대규모 씬 제작 방법
Unite2019 HLOD를 활용한 대규모 씬 제작 방법
 
NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016NVIDIA OpenGL in 2016
NVIDIA OpenGL in 2016
 
게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동게임에서 사용할 수 있는 포물선 운동
게임에서 사용할 수 있는 포물선 운동
 
Niagara In UE4
Niagara In UE4Niagara In UE4
Niagara In UE4
 
포인트 셰도우
포인트 셰도우포인트 셰도우
포인트 셰도우
 
3 d transformation
3 d transformation3 d transformation
3 d transformation
 
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
NDC2016 프로젝트 A1의 AAA급 캐릭터 렌더링 기술
 
노말 맵핑(Normal mapping)
노말 맵핑(Normal mapping)노말 맵핑(Normal mapping)
노말 맵핑(Normal mapping)
 
Digital_image_processing_-Vijaya_Raghavan.pdf
Digital_image_processing_-Vijaya_Raghavan.pdfDigital_image_processing_-Vijaya_Raghavan.pdf
Digital_image_processing_-Vijaya_Raghavan.pdf
 
Polygon Fill
Polygon FillPolygon Fill
Polygon Fill
 
[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기
[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기
[IGC 2016] 넷게임즈 김영희 - Unreal4를 사용해 모바일 프로젝트 제작하기
 
2009-2016 기본기(손맵)의 중요성
2009-2016 기본기(손맵)의 중요성2009-2016 기본기(손맵)의 중요성
2009-2016 기본기(손맵)의 중요성
 
Convolutional Neural Network (CNN)
Convolutional Neural Network (CNN)Convolutional Neural Network (CNN)
Convolutional Neural Network (CNN)
 
Unreal Engine 4 Study - 閉じた空間でのライティング
Unreal Engine 4 Study - 閉じた空間でのライティングUnreal Engine 4 Study - 閉じた空間でのライティング
Unreal Engine 4 Study - 閉じた空間でのライティング
 

Similar to Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline

6. Perspective Projection .pdf
6. Perspective  Projection                    .pdf6. Perspective  Projection                    .pdf
6. Perspective Projection .pdfYatruHarshaHiski
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationMark Kilgard
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf ChicagoJanie Clayton
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerJanie Clayton
 
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESGFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESPrabindh Sundareson
 
Paris Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsParis Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsWolfgang Engel
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingMark Kilgard
 
Programming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin EvolveProgramming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin EvolveFrank Krueger
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupdreambreeze
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Groupbernice-chan
 
Stixel based real time object detection for ADAS using surface normal
Stixel based real time object detection for ADAS using surface normalStixel based real time object detection for ADAS using surface normal
Stixel based real time object detection for ADAS using surface normalTaeKang Woo
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2Sardar Alam
 
Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5Takao Wada
 
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2StanfordComputationalImaging
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardwarestefan_b
 
Computer Vision panoramas
Computer Vision  panoramasComputer Vision  panoramas
Computer Vision panoramasWael Badawy
 
visible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewingvisible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewingsrinivasan779644
 

Similar to Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline (20)

6. Perspective Projection .pdf
6. Perspective  Projection                    .pdf6. Perspective  Projection                    .pdf
6. Perspective Projection .pdf
 
CS 354 Object Viewing and Representation
CS 354 Object Viewing and RepresentationCS 354 Object Viewing and Representation
CS 354 Object Viewing and Representation
 
3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago3D Math Primer: CocoaConf Chicago
3D Math Primer: CocoaConf Chicago
 
The Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math PrimerThe Day You Finally Use Algebra: A 3D Math Primer
The Day You Finally Use Algebra: A 3D Math Primer
 
Surface design and visible surfaces
Surface design and visible surfacesSurface design and visible surfaces
Surface design and visible surfaces
 
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ESGFX Part 5 - Introduction to Object Transformations in OpenGL ES
GFX Part 5 - Introduction to Object Transformations in OpenGL ES
 
Paris Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow MapsParis Master Class 2011 - 04 Shadow Maps
Paris Master Class 2011 - 04 Shadow Maps
 
Notes04.pdf
Notes04.pdfNotes04.pdf
Notes04.pdf
 
CS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and CullingCS 354 Transformation, Clipping, and Culling
CS 354 Transformation, Clipping, and Culling
 
Programming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin EvolveProgramming Augmented Reality - Xamarin Evolve
Programming Augmented Reality - Xamarin Evolve
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Introduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User GroupIntroduction to Canvas - Toronto HTML5 User Group
Introduction to Canvas - Toronto HTML5 User Group
 
Stixel based real time object detection for ADAS using surface normal
Stixel based real time object detection for ADAS using surface normalStixel based real time object detection for ADAS using surface normal
Stixel based real time object detection for ADAS using surface normal
 
3 d graphics with opengl part 2
3 d graphics with opengl  part 23 d graphics with opengl  part 2
3 d graphics with opengl part 2
 
Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5Trident International Graphics Workshop 2014 2/5
Trident International Graphics Workshop 2014 2/5
 
Intro to Canva
Intro to CanvaIntro to Canva
Intro to Canva
 
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
Build Your Own VR Display Course - SIGGRAPH 2017: Part 2
 
Shadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics HardwareShadow Volumes on Programmable Graphics Hardware
Shadow Volumes on Programmable Graphics Hardware
 
Computer Vision panoramas
Computer Vision  panoramasComputer Vision  panoramas
Computer Vision panoramas
 
visible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewingvisible surface detection in 3D objects for viewing
visible surface detection in 3D objects for viewing
 

Recently uploaded

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Celine George
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docxPoojaSen20
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13Steve Thomason
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesFatimaKhan178732
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentInMediaRes1
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptxVS Mahajan Coaching Centre
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfakmcokerachita
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application ) Sakshi Ghasle
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docxPoojaSen20
 

Recently uploaded (20)

Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
Incoming and Outgoing Shipments in 1 STEP Using Odoo 17
 
mini mental status format.docx
mini    mental       status     format.docxmini    mental       status     format.docx
mini mental status format.docx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13The Most Excellent Way | 1 Corinthians 13
The Most Excellent Way | 1 Corinthians 13
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Separation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and ActinidesSeparation of Lanthanides/ Lanthanides and Actinides
Separation of Lanthanides/ Lanthanides and Actinides
 
Alper Gobel In Media Res Media Component
Alper Gobel In Media Res Media ComponentAlper Gobel In Media Res Media Component
Alper Gobel In Media Res Media Component
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
9953330565 Low Rate Call Girls In Rohini Delhi NCR
9953330565 Low Rate Call Girls In Rohini  Delhi NCR9953330565 Low Rate Call Girls In Rohini  Delhi NCR
9953330565 Low Rate Call Girls In Rohini Delhi NCR
 
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions  for the students and aspirants of Chemistry12th.pptxOrganic Name Reactions  for the students and aspirants of Chemistry12th.pptx
Organic Name Reactions for the students and aspirants of Chemistry12th.pptx
 
Class 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdfClass 11 Legal Studies Ch-1 Concept of State .pdf
Class 11 Legal Studies Ch-1 Concept of State .pdf
 
Hybridoma Technology ( Production , Purification , and Application )
Hybridoma Technology  ( Production , Purification , and Application  ) Hybridoma Technology  ( Production , Purification , and Application  )
Hybridoma Technology ( Production , Purification , and Application )
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
MENTAL STATUS EXAMINATION format.docx
MENTAL     STATUS EXAMINATION format.docxMENTAL     STATUS EXAMINATION format.docx
MENTAL STATUS EXAMINATION format.docx
 
Staff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSDStaff of Color (SOC) Retention Efforts DDSD
Staff of Color (SOC) Retention Efforts DDSD
 

Computer Graphics - Lecture 03 - Virtual Cameras and the Transformation Pipeline

  • 1. Virtual Cameras and The Transformation Pipeline Anton Gerdelan gerdela@scss.tcd.ie with content from Rachel McDonnell 13 Oct 2014
  • 2. Virtual Camera ● We want to navigate through our scene in 3d ● Solution = create a transformation pipeline ● Move all points relative to some arbitrary view point, such that the view point is the new (0,0,0) origin ● Also project our scene with a perspective rather than orthogonal view
  • 3. Transformation Pipeline – Coordinate Spaces * model matrix * view matrix vertex shader output * projection matrix perspective division (x,y,z) / w
  • 4. Transformation Pipeline – Coordinate Spaces * model matrix * view matrix vertex shader output perspective division (x,y,z) / w * projection matrix ? ? ?
  • 5. Local Space ● When you create a triangle or ● Load a mesh from a file ● Has some (0,0,0) origin, local to that particular mesh ● Translate, rotate, scale to position in a virtual world – Multiply points with a model matrix aka “world matrix” – mat4 M = T * R * S; vec4 pos_wor = M * vec4 (pos_loc, 1.0);
  • 6. World Space ● Objects positioned in scene or “virtual world” ● Has a world (0,0,0) origin ● Can get distances between objects ● Now we want to show the view from a camera, moving through the virtual world ● Multiply world space points by a view matrix to get to eye space mat4 V = R * T; // inverse of cam pos & angle mat4 V = lookAt (vec3 pos, vec3 target, vec3 up); vec4 pos_eye = M * pos_wor;
  • 7. What the View Matrix Does
  • 8. View Matrix Right xyz Up xyz -Forward xyz -Position xyz Careful now!
  • 9. lookAt(vec3 eye, vec3 look, vec3 up) ● Typical maths library function ● Returns mat4 ● Sets camera position ● Point at target ● Careful with “up” unit vector ● Not ideal for full 3d rotation
  • 10. lookAt(vec3 eye, vec3 look, vec3 up) ● Rem: view matrix needs – Right – Forward – Up – Position ● (set of 3d vectors) ● Q1: How can we work out “forward”?
  • 11. lookAt(vec3 eye, vec3 look, vec3 up) vec3 f = normalise(look – eye); ● Q2. How can we work out “right” from “up” and “forward” ?
  • 12. lookAt() vec3 r = cross(f, up); // recalc up to be sure vec3 u = normalise (cross (r, f)); mat4 T = translate (-eye); mat4 R = plug-in r,u,-f return R * T; ● Q3. Why did I re-calculate “up”? ● Q4. What would happen if I did cross(up, f) instead? ● Q5. What must you do if camera pitches up/down?
  • 13. Q1. What is the cross product of these vectors? [0.0, 0.0, 1.0] X [1.0, 0.0, 0.0] Q2. How do you normalise a 4d vector? [10.0, 0.0, 0.0, 0.0]
  • 14. Rotation Method Limitations ● Calculating from fixed-axis X*Y*Z rotation matrices ● LookAt() is good for panning, not great for flight sims ● quaternions better suited to creating rotation matrix with full 3d rotation – Euler axis & angle in 4 numbers – then some multiplications to get a 4X4 rotation matrix – Good for local pitch/yaw/roll Arbitrary “Euler axis”
  • 15. Transformation Pipeline – Coordinate Spaces * model matrix * view matrix vertex shader output * projection matrix perspective division (x,y,z) / w
  • 16. Eye Space ● Objects positioned relative to view point and direction ● Has an eye origin (0, 0, 0) ● Our view area is still -1 to 1 on XYZ. ● Our view is still a parallel (orthogonal/orthographic) projection. ● Q. How can we manipulate the projection?
  • 17. What We Have Now Q. How can we make our view cover more of the scene?
  • 18. Orthographic Projection Matrix Q. What affine matrices does this look similar to? Zi - Zi + Zf Zf - Zi
  • 19.
  • 20. How can we approximate a cone of view? ● Has to map to a 2d rectangular view, not a circle (well...we could do a circle) ● Has to have minimum and maximum cut-of distances ● Some sort of angle of view ● We had a cuboid before for orthographic ● Q. What 3d geometric shape is this?
  • 22. Typical Perspective Function mat4 perspective ( float fovy, float aspect, float zNear, float zFar ); ● Fovy is “field of view y-axis” – angle from horizon to top – convert to radians ● Aspect ratio is (float)width / (float)height of viewport ● Near and far are “clip planes” – 0.1 and 1000.0 are typical
  • 23.
  • 24. A Symmetric Perspective Matrix ● Q. An aspect of 2.0 means? ● Wrong aspect = distortion ● Depth bufer precision (ranges of z) has only so many bits per pixel. ● Smaller zFar / zNear ratio = more precision ● As zNear -> 0, zFar -> infinity – Do not make zNear = 0.0 1.0 / tan (fovy * 0.5); ???
  • 25.
  • 26. FOV ● Beware comparisons of angle of view ● Older games etc. used horizontal angles of view ~90 degrees ● These also had fixed-aspect displays: – 320x200 (2.5:4) – 320x240, 640x480, etc. -> (3:4) = 1.3333... ● LookAt() etc. Use vertical angles – 90 degrees horiz. / 1.333333 = 67.5 degrees vert.
  • 27. Transformation Pipeline – Coordinate Spaces * model matrix * view matrix vertex shader output * projection matrix perspective division (x,y,z) / w
  • 28. Homogenous Clip Space ● Geometry outside near/far xyz clip planes is “clipped” after the VS ● Q. How will we map our frustum area onto a 2d drawing surface? Hint: The orthographic cuboid was easy. ?
  • 29. Perspective Division A. We will squish in the large back end until it is a -1 to 1 XYZ box. Q. How? Hint: Some of you did this in Assignment 0
  • 30. Perspective Division ● Vertex shader output is a 4d variable gl_Position = P * V * M * vec4 (vp, 1.0); gl_Position = vec4 (x, y, z, w); ● After the VS, a built-in mechanism does position = vec3 (gl_Position.xyz / gl_Position.w); ● Q. What does the perspective matrix do to w?
  • 32. Transformation Pipeline – Coordinate Spaces * model matrix * view matrix vertex shader output * projection matrix perspective division (x,y,z) / w
  • 33. Normalised Device Space ● All coordinates are between -1 and 1 – the unit cube ● This is very easy to scale by # pixels wide and high ● Project to 2d ● Front/back face select and cull if enabled ● Rasterise to pixels/fragments
  • 34. Typical Vertex Shader w/ Camera #version 400 in vec3 vertex_point, vertex_normal; uniform mat4 P, V, M; out vec3 p_eye, n_eye; void main () { gl_Position = P * V * M * vec4 (vertex_point, 1.0); p_eye = V * M * vec4 (vertex_point, 1.0); n_eye = V * M * vec4 (vertex_normal, 0.0); } ● Order of multiplication is fundamentally important ● Never compare variables from diferent coordinate spaces ● Use a postfix or prefix naming convention for variables useful for lighting
  • 35. Normalised Device Space ● All coordinates are between -1 and 1 – the unit cube ● This is very easy to scale by # pixels wide and high ● Project to 2d ● Front/back face select and cull if enabled ● Rasterise to pixels/fragments
  • 36. Depth Testing (automatic step) and The Depth Bufer ● Edwin Catmull again – PhD thesis 1974, U. Utah. ● Whenever we write a fragment it writes the colour to the framebufer's colour bufer (a big 2d image) ● But first...if depth testing is enabled ● It checks another 2d image called the depth bufer ● If its own depth is smaller/closer it overwrites both the depth and colour bufer pixels ● Q. What does this do? ● Can we disable the depth testing and try?
  • 37. Depth Bufer Smaller value = farther away Bigger = closer In F.Shader use built-in gl_FragCoord.w to get this value and use as a colour
  • 38. Reading List and Practical Tasks ● Shirley & Marschner – “Fundamentals” Ch. 7 “Viewing” ● Akenine Moeller et. al “Real-Time Rendering” Ch. 2 and 4.6 “Projections” (very good) ● Know how to work out the pipeline by hand on paper for 1 vertex & M, V, and P ● Hint: add a “print_matrix(m)” function to check contents
  • 39. 3rd Assignment - Viewing ● Due next week! ● Start way ahead of time (easy to get into a transformations mess) ● If you finish early, get a head start on game project skills: – Play – Upgrade – Load a mesh? Full 3d camera controls? – make all the mistakes – ask for advice now (discussion boards)