Teoria i praktyka programowania gier komputerowych

Podobne dokumenty
Podstawy graki 3D. Ostrosªup widzenia. Piotr Fulma«ski. 11 czerwca 2014

Teoria i praktyka programowania gier komputerowych

Stereometria (geometria przestrzenna)

Zadania z z matematyki dla studentów gospodarki przestrzennej UŠ. Marek Majewski Aktualizacja: 31 pa¹dziernika 2006

Arkusz 4. Elementy geometrii analitycznej w przestrzeni

Tychy, plan miasta: Skala 1: (Polish Edition)

Helena Boguta, klasa 8W, rok szkolny 2018/2019

Elementy geometrii w przestrzeni R 3

Camspot 4.4 Camspot 4.5

Hard-Margin Support Vector Machines

Lecture 20. Fraunhofer Diffraction - Transforms

r = x x2 2 + x2 3.

Zakopane, plan miasta: Skala ok. 1: = City map (Polish Edition)

Elementy geometrii analitycznej w przestrzeni

Machine Learning for Data Science (CS4786) Lecture11. Random Projections & Canonical Correlation Analysis

Weronika Mysliwiec, klasa 8W, rok szkolny 2018/2019

Machine Learning for Data Science (CS4786) Lecture 11. Spectral Embedding + Clustering

Installation of EuroCert software for qualified electronic signature

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Standardized Test Practice

Wektory w przestrzeni

Revenue Maximization. Sept. 25, 2018

Wprowadzenie do programu RapidMiner, część 2 Michał Bereta 1. Wykorzystanie wykresu ROC do porównania modeli klasyfikatorów

SSW1.1, HFW Fry #20, Zeno #25 Benchmark: Qtr.1. Fry #65, Zeno #67. like

EXAMPLES OF CABRI GEOMETRE II APPLICATION IN GEOMETRIC SCIENTIFIC RESEARCH

SubVersion. Piotr Mikulski. SubVersion. P. Mikulski. Co to jest subversion? Zalety SubVersion. Wady SubVersion. Inne różnice SubVersion i CVS

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Stargard Szczecinski i okolice (Polish Edition)

Katowice, plan miasta: Skala 1: = City map = Stadtplan (Polish Edition)

Karpacz, plan miasta 1:10 000: Panorama Karkonoszy, mapa szlakow turystycznych (Polish Edition)

MaPlan Sp. z O.O. Click here if your download doesn"t start automatically

Some Linear Algebra. Vectors operations = =(,, ) =( 1 + 2, 1 + 2, ) λ =(λ,λ,λ ) Addition. Scalar multiplication.

Rozpoznawanie twarzy metodą PCA Michał Bereta 1. Testowanie statystycznej istotności różnic między jakością klasyfikatorów

OpenPoland.net API Documentation

DODATKOWE ĆWICZENIA EGZAMINACYJNE

Graka komputerowa Wykªad 3 Geometria pªaszczyzny

Financial support for start-uppres. Where to get money? - Equity. - Credit. - Local Labor Office - Six times the national average wage (22000 zł)

WBiA Architektura i Urbanistyka. 1. Wykonaj dziaªania na macierzach: Które z iloczynów: A 2 B, AB 2, BA 2, B 2 3, B = 1 2 0

Analysis of Movie Profitability STAT 469 IN CLASS ANALYSIS #2

Instrukcja konfiguracji usługi Wirtualnej Sieci Prywatnej w systemie Mac OSX

Knovel Math: Jakość produktu

Rachunek caªkowy funkcji wielu zmiennych

Jak zasada Pareto może pomóc Ci w nauce języków obcych?

ERASMUS + : Trail of extinct and active volcanoes, earthquakes through Europe. SURVEY TO STUDENTS.

Previously on CSCI 4622

DUAL SIMILARITY OF VOLTAGE TO CURRENT AND CURRENT TO VOLTAGE TRANSFER FUNCTION OF HYBRID ACTIVE TWO- PORTS WITH CONVERSION

Miedzy legenda a historia: Szlakiem piastowskim z Poznania do Gniezna (Biblioteka Kroniki Wielkopolski) (Polish Edition)

Krzywe i powierzchnie stopnia drugiego

JĘZYK ANGIELSKI POZIOM PODSTAWOWY

Convolution semigroups with linear Jacobi parameters

DO MONTAŻU POTRZEBNE SĄ DWIE OSOBY! INSTALLATION REQUIRES TWO PEOPLE!

Realizacja systemów wbudowanych (embeded systems) w strukturach PSoC (Programmable System on Chip)

KONSPEKT DO LEKCJI MATEMATYKI W KLASIE 3 POLO/ A LAYER FOR CLASS 3 POLO MATHEMATICS

tum.de/fall2018/ in2357

OSTC GLOBAL TRADING CHALLENGE MANUAL

HAPPY ANIMALS L01 HAPPY ANIMALS L03 HAPPY ANIMALS L05 HAPPY ANIMALS L07

HAPPY ANIMALS L02 HAPPY ANIMALS L04 HAPPY ANIMALS L06 HAPPY ANIMALS L08

USB firmware changing guide. Zmiana oprogramowania za przy użyciu połączenia USB. Changelog / Lista Zmian

Machine Learning for Data Science (CS4786) Lecture 24. Differential Privacy and Re-useable Holdout

& portable system. Keep the frame, change the graphics, change position. Create a new stand!

Pielgrzymka do Ojczyzny: Przemowienia i homilie Ojca Swietego Jana Pawla II (Jan Pawel II-- pierwszy Polak na Stolicy Piotrowej) (Polish Edition)

2017 R. Robert Gajewski: Mathcad Prime 4. Solution of examples Rozwiązania przykładów

y = The Chain Rule Show all work. No calculator unless otherwise stated. If asked to Explain your answer, write in complete sentences.

GRK 2. dr Wojciech Palubicki


Patients price acceptance SELECTED FINDINGS

deep learning for NLP (5 lectures)

Dolny Slask 1: , mapa turystycznosamochodowa: Plan Wroclawia (Polish Edition)

Assignment 3.1 (SA and LA)

Instrukcja obsługi User s manual

Leba, Rowy, Ustka, Slowinski Park Narodowy, plany miast, mapa turystyczna =: Tourist map = Touristenkarte (Polish Edition)

Egzamin maturalny z języka angielskiego na poziomie dwujęzycznym Rozmowa wstępna (wyłącznie dla egzaminującego)

Maximum Ride Ostatnie Ostrzezenie Globalne Ocieplenie (Polska Wersja Jezykowa)

PSB dla masazystow. Praca Zbiorowa. Click here if your download doesn"t start automatically

Ankiety Nowe funkcje! Pomoc Twoje konto Wyloguj. BIODIVERSITY OF RIVERS: Survey to students

Geometria. Šukasz Dawidowski. 25 kwietnia 2016r. Powtórki maturalne

II wariant dwie skale ocen II alternative two grading scales

Miedzy legenda a historia: Szlakiem piastowskim z Poznania do Gniezna (Biblioteka Kroniki Wielkopolski) (Polish Edition)

STANLUX SLX DO ŚCIANY STANLUX SLX TO THE WALL

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Grafika komputerowa Wykład 4 Geometria przestrzenna

Immigration Studying. Studying - University. Stating that you want to enroll. Stating that you want to apply for a course.


TTIC 31210: Advanced Natural Language Processing. Kevin Gimpel Spring Lecture 9: Inference in Structured Prediction

Wektor. Uporz dkowany ukªad liczb (najcz ±ciej: dwóch - na pªaszczy¹nie, trzech - w przestrzeni 3D).

Transformacje obiektów 3D

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

Wojewodztwo Koszalinskie: Obiekty i walory krajoznawcze (Inwentaryzacja krajoznawcza Polski) (Polish Edition)

User s manual for icarwash

Zestawienie czasów angielskich

1. Przedstaw w postaci algebraicznej liczby zespolone: 2. Narysuj zbiory punktów na pªaszczy¹nie:


Working Tax Credit Child Tax Credit Jobseeker s Allowance

Poniżej moje uwagi po zapoznaniu się z prezentowanymi zasadami:

17-18 września 2016 Spółka Limited w UK. Jako Wehikuł Inwestycyjny. Marek Niedźwiedź. InvestCamp 2016 PL

Blow-Up: Photographs in the Time of Tumult; Black and White Photography Festival Zakopane Warszawa 2002 / Powiekszenie: Fotografie w czasach zgielku

Zarządzanie sieciami telekomunikacyjnymi

Maximum Ride Ostatnie Ostrzezenie Globalne Ocieplenie (Polska Wersja Jezykowa)

INSTRUKCJA MONTAŻU MARBO E SPORT LISTA CZĘŚCI (PARTS LIST) (ASSEMBLY INSTRUCTION) MH-W102 NR CZĘŚCI (PART NO.) ILOŚĆ (QUANTITY) OPIS (DESCRIPTION)

OBWIESZCZENIE MINISTRA INFRASTRUKTURY. z dnia 18 kwietnia 2005 r.

Transkrypt:

Teoria i praktyka programowania gier komputerowych 3D projection Piotr Fulma«ski Wydziaª Matematyki i Informatyki, Uniwersytet Šódzki, Polska 8 grudnia 2014

Spis tre±ci 1 View (Camera) Space 2 3D projection General information Ortographic projection Rzut równolegªy Rzut perspektywiczny idea View frustum View frustum parameters View frustum corners View frustum homogeneous clip space View frustum screen space coordinates

View (Camera) Space Suppose that all the models are positioned and oriented in the world (using dierent transformation matrix for the 3D case we will discuss transformation matrix in the next lecture). The next thing to consider is the location of the camera. Thus we need another matrix that tells the graphics card how to transform the models from world space into a coordinate space that is relative to the camera. The matrix most commonly used for this is a look-at matrix. In a look-at matrix, the position of the camera is expressed in addition to the three coordinate axes of the camera.

View (Camera) Space For a row-major left-handed coordinate system, the look-at matrix is expressed as L x U x F x 0 L y U y F y 0 L z U z F x 0 T x T y T z 1 where L is the left or x-axis, U is the up or y-axis, F is the forward or z-axis, and T is the translation.

View (Camera) Space To calculate this matrix three inputs are needed: the position of the camera (the eye), the position of the target the camera is looking at, and the up vector of the camera.

View (Camera) Space 1 f u n c t i o n C r e a t e L o o k A t ( V e c t o r 3 eye, V e c t o r 3 t a r g e t, V e c t o r 3 Up ) V e c t o r 3 F = N o r m a l i z e ( t a r g e t e y e ) 3 V e c t o r 3 L = N o r m a l i z e ( C r o s s P r o d u c t ( Up, F ) ) V e c t o r 3 U = C r o s s P r o d u c t ( F, L ) 5 V e c t o r 3 T 7 T. x = DotProduct ( L, eye ) T. y = DotProduct ( U, eye ) 9 T. z = DotProduct ( F, eye ) 11 // C r e a t e and r e t u r n l o o k a t m a t r i x from F, L, U, and T end

3D projection Types Podstawowym przeksztaªceniem w grace trójwymiarowej jest rzutowanie, gdy» komputerowa wizualizacja jakiegokolwiek obiektu przestrzennego wymaga odwzorowania go na pªaski ekran monitora. Metody rzutowania mo»emy podzieli na dwie grupy rzuty równolegªe (rysunek techniczny; zachowuje równolegªo± prostych, stosunek dªugo±ci odcinków równolegªych itd), rzuty perspektywicze nazywane te» rzutami perspektywicznymi (realistyczna wizualizacja obiektów, wra»enie gª bi).

3D projection Comments Przy rzutowaniu na pªaszczyzn Π obrazem punktu p jest punkt p przeci cia si tej pªaszczyzny z prost (nazywan promieniem rzutowania) przechodz c przez p. Oczywi±cie takich prostych jest niesko«czenie wiele, ale w przypadku rzutu równolegªego ustalamy,»e wszystkie proste maj ten sam kierunek rzutowania d (je±li jest on prostopadªy do rzutni, to rzut nazywamy ortogonalnym); rzutu perspektywicznego ustalamy,»e wszystkie proste (promienie rzutowania) maj wspólny punkt e (odlegªo± tego punktu od rzutni Π decyduje o deformacji rysunku).

3D projection In practice simple case In practice znalezienie wspórz dnych rzutu p punktu p sprowadza si do rozwi zania zadania wyznaczenia przeciecia pªaszczyzny Π i prostej (promienia rzutowania) okre±lonej punktem p i kierunkiem d przy rzucie równolegªym lub punktem p i ±rodkiem rzutowania e w przypadku rzutu perspektywicznego. Zauwa»my przy tym,»e milcz co zaªo»yli±my, i» poªo»enie wszelkich obiektów wyra»one jest w jednym i tym samym ukªadzie wspóªrz dnych: w ukªadzie, w którym zostaª opisany rysowany obiekt (ukªad danych, world-space coordinates); wszystkie obiekty umiejscowione s na scenie w taki sposób aby±my nie musieli przejmowa si ich widzialno±ci (tzn. zakªadamy,»e wszystkie obiekty daj si narysowa ).

3D projection In practice real case Unfortunately real life is not so simple. Jak ju» zauwa»yli±my, stosuj c uprzednio opisane podej±cie otrzymujemy wspóªrz dne punktu p w ukªadzie trójwymiarowym, w którym zostaª opisany rysowany obiekt (world-space coordinates). My natomiast potrzebujemy wspóªrz dnych w ukªadzie dwuwymiarowym okre±lonym na pªaszczy¹nie rzutowania Π. Metod wyznaczenia takich wspóªrz dnych jest wiele w dalszej cz ±ci omówimy: intuitive approach (screen space = view space), ostrosªup widzenia (view frustum). Dodatkow trudno±ci jest to,»e zwykle musimy pracowa z wi cej ni» dwoma ukªadami wspóªrz dnych (zwykle przynajmniej dwa, gdy» mamy ukªad danych oraz ukªad zwi zany z punktami pªaszczyzny Π).

3D projection In practice: intuitive approach (screen space = view space): rzut równolegªy: szczególny przypadek: rzut prostopadªy (ortographic projection) Najbardziej intuicyjnym rozwi zaniem jest przyj cie, i» rzutnia Π pokrywa si z pªaszczyzn z = 0 ukªadu obserwatora. Zalety takiego wyboru ukªadu najlepiej wida przy rzucie ortogonalnym, kiedy rzutem punktu p = (x, y, z) jest punkt p = (x, y, 0).

3D projection In practice: intuitive approach (screen space = view space): rzut równolegªy: szczególny przypadek: rzut prostopadªy (ortographic projection): computer graphics In computer graphics, one of the most common matrices used for orthographic projection can be dened by a 6-tuple, (left, right, bottom, top, near, far), which denes the clipping planes. These planes form a box with the minimum corner at (left, bottom, -near) and the maximum corner at (right, top, -far). The box is translated so that its center is at the origin, then it is scaled to the unit cube which is dened by having a minimum corner at (-1,-1,-1) and a maximum corner at (1,1,1). In this case the orthographic transform can be given by the following matrix: 2 0 0 right+left right left right left 2 0 0 top+bottom top bottom top bottom 2 far near 0 0 0 0 0 1 far+near far near

3D projection In practice: intuitive approach (screen space = view space): rzut równolegªy: szczególny przypadek: rzut prostopadªy (ortographic projection): computer graphics In [Mad, 2014] on page 75 you can nd orthographic projection matrix dened as 2 0 0 0 width 2 0 0 0 height 1 0 0 0 far near near 0 0 near far 1 With this matric the box is translated so that its center is..., then it is scaled to the unit cube which is dened by having a minimum corner at (...) and a maximum corner at (...).

3D projection In practice: intuitive approach (screen space = view space): rzut równolegªy Uogólniaj c rzut ortogonalny na dowolny rzut równolegªy w którym kierunek rzutu równolegªego tworzy z rzutni Π kat α otrzymujemy nast pujace wspóªrz dne x i y rzutu punktu p = (x, y, z) x = x + r cos ϕ y = y + r sin ϕ gdzie r = x ctg α a ϕ jest k tem nachylenia prostej przechodz cej przez (x, y, 0) i (x, y, 0) do osi x. Uzyskanie warto±ci dla α i ϕ nie jest trudne, gdy» zwykle kierunek d wyra»a si wªa±nie przez podanie tych k tów a nie odpowiednich skªadowych tworz cych wektor d.

3D projection: A Dürer Woodcut Intuitive approach (screen space = view space): rzut perspektywiczny

3D projection In practice: intuitive approach (screen space = view space): rzut perspektywiczny Uto»samiamy obserwatora ze ±rodkiem rzutowania e, który znajduje si na ujemnej cz ±ci ukªadu w punkcie (0, 0, e z ) (a wi c korzystamy z lewoskr tnego ukªadu wspóªrz dnych, left-handed coordinate system).

3D projection In practice: intuitive approach (screen space = view space): rzut perspektywiczny Korzystaj c jedynie z wªasno±ci podobie«stwa trójk tów bez kªopotu znajdujemy zale»no±ci pomi dzy p i p y z + e z = y e z e z y e z = y z + e z gdzie z+e z nazywane jest skal podobie«stwa. Oznaczaj c j przez s otrzymujemy ostatecznie x = xs, y = ys,

3D projection View frustum In 3D computer graphics, the viewing frustum or view frustum is the region of space in the modeled world that may appear on the screen; it is the eld of view of the notional camera. The exact shape of this region varies depending on what kind of camera lens is being simulated, but typically it is a frustum of a rectangular pyramid (hence the name). The planes that cut the frustum perpendicular to the viewing direction are called the near plane and the far plane. Objects closer to the camera than the near plane or beyond the far plane are not drawn. Often, the far plane is placed innitely far away from the camera so all objects within the frustum are drawn regardless of their distance from the camera.

3D projection View frustum W tym podej±ciu ±rodek rzutowania e pokrywa si z wierzchoªkiem ostrosªupa widzenia a w konsekwencji screen space (czyli rzutnia Π) nie jest tym samym co ukªad obserwatora (view space). Zadania stawiane przed nami w tym podej±ciu to: wyznaczenie wierzchoªków lub pªaszczyzn ograniczaj cych ostrosªu widzenia; rozstrzyaganie czy punkt p le»y wewn trz ostrosªupa widzenia (w szczególno±ci interesuje nas wspóªrz dna z jej znajomo± pozwoli nam wyznacza obiekty zasªaniane o której nie mieli±my»adnej informacji w poprzednim podej±ciu); poszukiwanie wspóªrz dnych rzutu perspektywicznego p punktu p w ukªadzie ekranu (screen space) a wi c na rzutni Π.

View frustum View frustum parameters Before we start calculation notice that the view frustum is dened by two sets of parameters Set of view parameters: the camera position, the look and up vector. The up vector determines the tilt of the scene. These parameters determine the general direction and orientation for the view frustum. Set of projection parameters: The eld of view (fov) parameter determines how much of the scene will be visible. The near plane and far plane parameters are distances that dene clipping planes. The aspect ratio parameter denes the ratio between the width and height of the view volume (width is dened in the direction of the right vector, height is dened in the direction of the up vector). These parameters determine the shape for the view frustum.

View frustum Height of view frustum Assume that view space is dened by unit vectors e 1 = (1, 0, 0), e 2 = (0, 1, 0) and e 3 = (0, 0, 1) coresponding to right, up and look vector respectively. Then it is very easy to calculate the centres of the near and far clip plane. Denote by e top of the frustum typicaly e = (0, 0, 0), n distance to near clipping plane, f distance to far clipping plane.

View frustum Height of view frustum With the above we have n c = e + ne 3 = (0, 0, 0) + n(0, 0, 1) = (0, 0, n) Finally n c = e + ne 3, f c = e + fe 3,

View frustum Height of view frustum We can now use centre points as base points to calculate the corners of the near and far clip plane.

View frustum Height of view frustum The half height of the near and far plane are given by h n = n tg(ϕ), h f = f tg(ϕ), where ϕ is a half the eld of view in radians.

View frustum Width of view frustum For the width of the near and far plane we need to take the aspect ratio into account w n = h n a, w f = h f a, where a is a given aspect ration (which sholud full the following equation a = w n h n = w f ). h f

View frustum Coordinates of the 8 points that dene the view frustum volume p nrb = n c h n e 2 + w n e 1, p nrt = n c + h n e 2 + w n e 1, p nlt = n c + h n e 2 w n e 1, p nlb = n c h n e 2 w n e 1, p frb = f c h f e 2 + w f e 1, p frt = f c + h f e 2 + w f e 1, p t = f c + h f e 2 w f e 1, p b = f c h f e 2 w f e 1.

View frustum Homogeneous clip space. Transformation of x and y Now we are going to transform a vertex in the view frustum to a homogeneous coordinate in the unit cube. Assume that the view frustum is dened as a pyramid starting at point e = (0, 0, 0) and left-handed coordinate system is used. We start with the formula for the x and y value. The projected x and y coordinates can be found by projecting the x and y values of the vertices on the near plane and dividing by half the near plane width and height (see gure and compare with previous part of this lecture).

View frustum Homogeneous clip space. Transformation of x and y As we have seen before, the formula for the y coordinate is easy to derive by application of congruent triangles y n = y z, where n is the length of n c vector. In consequence y = yn z.

View frustum Homogeneous clip space. Transformation of x and y Now have a y value in the range [ h n, +h n ] for vertices inside the view frustum. For a correct DirectX or OpenGL projection transform we need to calculate a y value in the range of [ 1, +1]. To do this, we just need to divide the y value with half of the near height. Because the half height of the near plane, previously calculated, is given by then and nally h n = n tg(ϕ), y = y = yn zn tg(ϕ), y z tg(ϕ) The nal y coordinate is inside the [ 1, +1] range for vertices inside the view frustum.

View frustum Homogeneous clip space. Transformation of x and y The x coordinate is calculated in exactly the same way as y, but we need to take the aspect ratio of the view frustum into account x n = x z, where n is the length of n c vector. In consequence x = xn z. Again, for vertices inside the view frustum, x is in the range [ w n, +w n ] and this range needs to be converted to the range [ 1, +1]. The aspect ratio for a perspective transform which denes the width of the near plane relative to the height of the near plane is equal to so we have a = w n h n. w n = ah n, w n = an tg(ϕ).

View frustum Homogeneous clip space. Transformation of x and y In consequence we have x = and nally In consequence we have x = xn zan tg(ϕ), x za tg(ϕ). Again for vertices inside the view frustum, x is inside the range [ 1, +1].

View frustum Matrix form for the transformation As always we want to apply the formulas via a 4x4 matrix. The following matrix is only valid for the transformation of the x and y coordinates (matrix is in row major order) 1 a tg(ϕ) 0 0 0 1 [x, y, z, 1] 0 tg(ϕ) 0 0 0 0 1 1 0 0 0 0 [ [x, y, z, w ] = x a tg(ϕ), ] y tg(ϕ), z, z.

View frustum Matrix form for the transformation If we divide this homogeneous coordinate by the w coordinate to convert to a normal 3D coordinate, we get the following result ] [ [ x w, y w, z w [ x w, y w, z w = ] [ = x aw tg(ϕ), x az tg(ϕ), y w tg(ϕ), w w ] y z tg(ϕ), 1. The x and y coordinate are correct, however the z coordinate is messed up, it is always one. So we have to change something in the perspective matrix to create a valid z value. ].

View frustum Transformation z coordinate: shift and scale The DirectX and OpenGL pipeline requires that the z value after the perspective transform is in the range [0,1] (or [-1,1] for OpenGL). The z value before previously discussed transform is in the range [near, far]. We start with a simple range conversion that will transform the [n, f ] range to the range [0, 1]. Because the shift z n transform the [n, f ] range to the range [0, f n], so z n f n transform the [n, f ] range to the range [0, 1]. To t this conversion into the transformation matrix we have to split it into 2 terms, a factor to scale z with and a factor to shift z f + n n f. n

View frustum Transformation z coordinate: shift and scale Taking both factors, our matrix takes the form 1 a tg(ϕ) 0 0 0 1 0 [x, y, z, 1] tg(ϕ) 0 0 1 0 0 1 f n n 0 0 [ [x, y, z, w ] = x a tg(ϕ), f n 0 y tg(ϕ), z n f, n z Unfortunately, this is still not correct. When we convert the homogeneous coordinate back to a normal 3D coordinate we get ] [ [ x w, y w, z w = x az tg(ϕ), y z tg(ϕ), z n ]. (f n)z ].

View frustum Transformation z coordinate: shift and scale Notice, that the homogeneous conversion which results the form [ ] [ ] x w, y w, z x w = az tg(ϕ), y z tg(ϕ), z n (f n)z reintroduces undesirable term ( 1 ) into the transformed z coordinated, z which breaks our conversion. Fortunately there is a quick x to restore the range for the z values: it is enough multiply the shift factor with the f value (because division by z introduced range [0, 1]) f 1 a tg(ϕ) 0 0 0 1 0 [x, y, z, 1] tg(ϕ) 0 0 1 0 0 1 f n nf 0 0 f n 0

View frustum Final matrix 1 a tg(ϕ) 0 0 0 1 0 [x, y, z, 1] tg(ϕ) 0 0 1 0 0 1 f n nf 0 0 0 f n [ ] [x, y, z, w x ] = a tg(ϕ), y (z n)f, tg(ϕ) f, n z ] [ ] w, y w, z x w = az tg(ϕ), y (z n)f, z tg(ϕ) (f n)z [ x

View frustum Final world Unfortunately the division by z introduces the non linearity of the z buer. This non linearity is usually sold as benecial for the precision of the z buer close to the camera, however it dramatically reduces the resolution of the z buer a bit further from the camera. For example, if the near plane is set to 1 and the far plane is set to 100 than when z is 40 the resulting transformed z is allready at 0.98, leaving only a small amount of resolution to the following 60% of the scene.

View frustum Convert to screen space coordinates Because our transformatio transforms the vertices to the range of [ 1, 1] we need to convert the range [ 1, 1] to the range [0, window width] for the x coordinate and to the range [0, window height] for the y coordinate. The window width and window height are expressed in pixel units. The formula for this conversion is x = xw 2 + w 2, y = yh 2 + h 2. The same expressed as a matrix [x, y, z, 1] w 2 0 0 0 h 0 2 0 0 0 0 1 0 w h 2 2 0 1.