Shader Shader. Shader 4.1

Relevanta dokument
and Mathematical Statistics Gerold Jäger 9:00-15:00 T Compute the following matrix

Isometries of the plane

POSTKODVINSTER á kronor Inom nedanstående postkoder vinner följande 234 lottnummer kronor vardera:

Lösningsförslag obs. preliminärt, reservation för fel

Mekanik FK2002m. Vektorer

1. Compute the following matrix: (2 p) 2. Compute the determinant of the following matrix: (2 p)

Affina avbildningar och vektorgrafik

the standard scalar product, i.e. L E 4. Find the orthogonal projection of the vector w = (2, 1, 2, 1) on the orthogonal complement L of L (where

Repetition + lite av varje. Ulf Assarsson Department of Computer Engineering Chalmers University of Technology

Grafiska pipelinen. Edvin Fischer

Mekanik FK2002m. Kinematik i flera dimensioner

Tentamen i Matematik 3: M0031M.

Shaders. Gustav Taxén

POSTKODVINSTER á kronor Inom nedanstående postkoder vinner följande 307 lottnummer kronor vardera:

8 < x 1 + x 2 x 3 = 1, x 1 +2x 2 + x 4 = 0, x 1 +2x 3 + x 4 = 2. x 1 2x 12 1A är inverterbar, och bestäm i så fall dess invers.

Information från Medborgarkontoret Hösten 2013

, m 3 = 3. Determine for each real α and for each real β 0 the geometric meaning of the equation x 2 + 2y 2 + αz 2 + 2xz 4yz = β.

1. Find for each real value of a, the dimension of and a basis for the subspace

and u = och x + y z 2w = 3 (a) Finn alla lösningar till ekvationssystemet

Tentamen i Matematik 2: M0030M.

c d Z = och W = b a d c för några reella tal a, b, c och d. Vi har att a + c (b + d) b + d a + c ac bd ( ad bc)

1. Find an equation for the line λ which is orthogonal to the plane

2. Let the linear space which is spanned by the functions p 1, p 2, p 3, where p k (x) = x k, be equipped with the inner product p q = 1

1. Find the 4-tuples (a, b, c, d) that solves the system of linear equations

Koordinatsystem och Navigation

VECKANS LILLA POSTKODVINST á kronor Inom nedanstående postkoder vinner följande 245 lottnummer kronor vardera:

Kort introduktion till Matlab och användbara kommandon i TSFS06

is introduced. Determine the coefficients a ij in the expression for, knowing that the vectors (1, 0, 1), (1, 1, 1), (0, 1, 1) constitute an ON-basis.

For which values of α is the dimension of the subspace U V not equal to zero? Find, for these values of α, a basis for U V.

Shaders. Renderingssystem. Renderingssystem. Renderingssystem. Hårdvara för 3D-rendering. Hårdvara för 3D-rendering

MMA129 Linear Algebra academic year 2015/16

Tentamen i Matematik 2: M0030M.

VECKANS LILLA POSTKODVINST á kronor Inom nedanstående postkoder vinner följande 249 lottnummer kronor vardera:

Kursinformation i Partikeldynamik för M (TMME08)

Information Coding / Computer Graphics, ISY, LiTH. Bump mapping!

MATEMATISK FORMELSAMLING

is a basis for M. Also, find the coordinates of the matrix M = with respect to the basis M 1, M 2, M 3.

TBSK03 Teknik för avancerade Datorspel. Jens Ogniewski Information Coding Group Linköpings universitet

och v = 1 och vektorn Svar 11x 7y + z 2 = 0 Enligt uppgiftens information kan vi ta vektorerna 3x + 2y + 2z = 1 y z = 1 6x + 6y + 2z = 4

12.6 Heat equation, Wave equation

. Bestäm Rez och Imz. i. 1. a) Låt z = 1+i ( b) Bestäm inversen av matrisen A = (3p) x + 3y + 4z = 5, 3x + 2y + 7z = 3, 2x y + z = 4.

Kompletteringskompendium

denna del en poäng. 1. (Dugga 1.1) och v = (a) Beräkna u (2u 2u v) om u = . (1p) och som är parallell

Geometriska transformationer

for M, the matrix of the linear transformation F : R 3 M defined as x1 + x F ((x 1, x 2, x 3 )) = 2 + x 3 2x 1 + x 2 + 3x 3

DICOM MPPS/dos- SR Vad gäller?

UPPSALA UNIVERSITET Matematiska institutionen Michael Melgaard. Prov i matematik Prog: Datakand., Frist. kurser Derivator o integraler 1MA014

DEL I 15 poäng totalt inklusive bonus poäng.

Moment 4.11 Viktiga exempel 4.32, 4.33 Övningsuppgifter Ö4.18-Ö4.22, Ö4.30-Ö4.34. Planet Ett plan i rummet är bestämt då

Transformationer i 3D. Gustav Taxén

Grunderna i C++ T A. Skapad av Matz Johansson BergströmLIMY

drinkrecept från MATgeek på elon.se

2 Funktioner från R n till R m, linjära, inversa och implicita funktioner

Homogena koordinater och datorgrafik

Linjär algebra. Föreläsningar: Lektioner: Laborationer:

VECKANS LILLA POSTKODVINST á kronor Inom nedanstående postkoder vinner följande 270 lottnummer kronor vardera:

= = i K = 0, K =

CS 664 Slides #7 Visual Motion. Prof. Dan Huttenlocher Fall 2003

Linjära avbildningar. Låt R n vara mängden av alla vektorer med n komponenter, d.v.s. x 1 x 2. x = R n = x n

Enhetsvektorer. Basvektorer i två dimensioner: 1 1 Basvektorer i tre dimensioner: Enhetsvektor i riktningen v: v v

4 McLaurin- och Taylorpolynom

VECKANS LILLA POSTKODVINST á kronor Inom nedanstående postkoder vinner följande 229 lottnummer kronor vardera:

Gaussiska primtal. Christer Kiselman. Institut Mittag-Leffler & Uppsala universitet

VECKANS SMÅVINSTER - POSTKOD, 500 kronor vanns av följande postkoder:

Kursinformation. Matematiska metoder i nationalekonomi 730G77 Linnea Ingebrand

(D1.1) 1. (3p) Bestäm ekvationer i ett xyz-koordinatsystem för planet som innehåller punkterna

Läsanvisningar och övningsuppgifter i MAA150, period vt Erik Darpö

5 Linjär algebra. 5.1 Addition av matriser 5 LINJÄR ALGEBRA

AL State Rankings. AK State Rankings

0 2,5 5 7,5 10km Map: Översikt m avståndsringar, Print scale 1: , Map center RN East: North:

Repetition C-programmering

2D-grafik. Gustav Taxén

ett uttryck för en våg som beskrivs av Jonesvektorn: 2

Plan: M0030M, LP2, 2017

ASSEMBLY INSTRUCTIONS SCALE SQUARE - STANDARD

Pre-Test 1: M0030M - Linear Algebra.

MA2047 Algebra och diskret matematik

ax + y + 2z = 3 ay = b 3 (b 3) z = 0 har (a) entydig lösning, (b) oändligt många lösningar och (c) ingen lösning.

Vektorer. Paraplyt, vektorn Vädret behöver dessa Blåser sin lovsång. 1. Vad är vektorer? Räkneregler för vektorer Vektorgeometri..

UPG5 och UPG8 Miniprojekt 1: 2D datorgrafik

Linjen P Q tangerar cirkeln i P och enligt en sats i geometrin är OP vinkelrät. tan u = OP. tan(180 v) = RS. cos v = sin v = tan v, tan v = RS.

Medborgarnas synpunkter på skattesystemet, skattefusket och Skatteverkets kontroll Resultat från en riksomfattande undersökning hösten 2006

Avalanche Studios. OpenGL. Vår teknik. Våra spel. Lite inspiration... Stora, öppna spelvärldar. Sandbox-gameplay. Hög audiovisuell standard

Transformationer i R 2 och R 3

Finaltävling i Umeå den 18 november 2017

2. For which values of the parameters α and β has the linear system. dy/dt x + y

Veckoblad 3, Linjär algebra IT, VT2010

Tillämpad biomekanik, 5 poäng Övningsuppgifter

Introduktionskurs i matematik LÄSANVISNINGAR

POSTKODVINSTER á kronor Inom nedanstående postkoder vinner följande 244 lottnummer kronor vardera:

LINJÄR ALGEBRA HT2013. Kurslitteratur: Anton: Elementary Linear Algebra 10:e upplagan.

3D: transformationer:

Lösningsförslag TATM

Sidor i boken KB 6, 66

TNA004 Analys II Tentamen Lösningsskisser

KTH, Matematik. Del I. (totalt 15 poäng, inklusive bonuspoäng). (1) Betrakta följande mängder i R 3 :

VECKANS LILLA POSTKODVINST á kronor Inom nedanstående postkoder vinner följande 219 lottnummer kronor vardera:

L O. a r. l e d. l g. e s d. n a. t o. n a. n o. i a. t i l. t a l p. n e. e d. r v. n e. k e d. l l. r vä. Tävlingen arrangeras av S UASH CENTER

Geometry shaders! och Tesselation shaders!

bruksanvisning/ user manual

Transkript:

d d 3 9 Shader Shader ( Shader ) ) ) ) ) 4.1 S 4.1

4.2 p p 4.2 Cartesian Coordinate System René Descartes 4.2 f t g V o X 41

4.2 4.3 x y 4.3 x y 30 x y 2.3.4 OpenGL DirectX 4.4 f 1, 2 1 3 4.5 1 C./ - 8 o ex f U. 50% 3 4.6 42 ( U

4.2 3 basis vector 3 1 orthonormal basis 1 orthogonal basis 4.6 left-handed coordinate space right-handed coordinate space 43

4.2 x y 4.4 4.4 OpenGL DirectX 180 y x x 4.6 +z +z x y handedness A B L. +x +y +z 4.7 4.8 ) 3 forward 44

4.2 x y z z left-hand rule right-hand rule (( 30 4 4.9 3.9 ~ ) 2 ~? 4.10 45

4.2 e ( 4.11 e X 3 4.11 x 1 z 4 60 +z x 1 z 4 60 z z 5C Unity 4.6 Unity Scene 4.12 right up forward x y z 46

4.2 5C e O P Unity z z 4.13 5C w Unity 4.5.9 d ) 1 3ds Max x y z 2 0, 0, 1 y +90 0, 0, 1 y +90 3 Unity 0, 1, 10 Rotation (0, 0, 0) Scale 1, 1, 1 (0, 1, 0) 4.14 O P w O P z z 47

4.3 4.3 point n 2 3 P (P x, P y ) P (P x, P y, P z ) vector scalar n magnitude direction velocity 80km/h 80km/h distance 200 200 v (x, y) v (x, y, z) v (x, y, z, w) a b x y z θ α a b u v A B S M R 4.15 head tail 4.15 100km/h 100km/h displacement ~ 4.16 48

4.3 f o ( b ) c / kv (kv x, kv y, kv z ) v (x, y, z) 1 k k k (x, y, z) x k, y k, z,k 0 k 2(1, 2, 3) (2, 4, 6) 3.5(2, 0) ( 7, 0) (1,2,3) (0.5,1,1.5) 2 v k v k : 2 k < 0 4.17 49

4.3 a + b (a x + b x, a y + b y, a z + b z ) a b (a x - b x, a y - b y, a z - b z ) (1, 2, 3) + (4, 5, 6) (5, 7, 9) (5, 2, 7) - (3, 8, 4) (2, -6, 3) a b a b a b a b a+b triangle rule 4.18 ) f i c f a b a b b a b a 4.19 ( ( v v + v + v 2 2 2 x y z (1,2,3) 1 2 + 2 2 + 3 2 1+ 4 + 9 14 3.742 2 2 (3,4) 3 + 4 9 + 16 25 5 4.20 50

4.3 n 9 4.20 51

4.3 ( unit vector 1 normalized vector normalization v v ^v ^ v v,v v (3, 4) (3, 4) (3, 4) (3, 4) 3 2 + ( 4) 2 25 (3, 4) 3 5 5, 4 (0.6, 0.8) 5 0 v (0, 0, 0) 0 4.21 ( dot product inner product cross product outer product ~ Shader Unity Shader dot(a, b) a b f s V 52

4.3 a b (a x, a y, a z ) (b x, b y, b z ) a x b x + a y b y + a z b z (1, 2, 3) (0.5, 4, 2.5) 0.5 + 8 + 7.5 16 (-3, 4, 0) (5, -1, 7) -15 + -4 + 0-19 a b b a projection ^a b b ^a ( ^a b b ^a ( ^a b ^a b ^a 4.22 ^a b 90 0 90 0 90 0 4.23 3 9 V ^a a b b a a Shader. (ka) b a (kb) k(a b) :: a (b + c) a b + a c c c 53

4.3 v v v x v x + v y v y + v z v z v 2 a b a b cosθ ^a ^b 4.24 ^b 1 cosθ ^a ^b cosθ 4.24 ^a ^b cosθ a b ( a ^a ) ( b ^b ) a b ( ^a ^b ) a b cosθ 90 cosθ > 0 90 cosθ 0 90 cosθ < 0 0 180 arcos ( θ arcos( ^a ^b ) ^a ^b cross product outer product a b a b (a x, a y, a z ) (b x, b y, b z ) (a y b z - a z b y, a z b x - a x b z, a x b y - a y b x ) 4.25 54

4.3 U X e o n co f f c (1, 2, 3) ( 2, 1, 4) ((2)(4) (3)( 1), (3)( 2) (1)(4), (1)( 1) (2)( 2)) (8 ( 3), ( 6) 4, ( 1) ( 4)) (11, 10, 3) a b b a a b (b a) (a b) c a (b c). a b a b a b a b sinθ. 4.26 a b b h h a θ A b h b ( a sinθ) a b sinθ a b a b 0 a b 0 0. 4.27 ( 9 ) 55

4.3 a b a b a b a b 4.28 a b! ) d )! 1 1 2 3 2 1 (2, 7, 3) 2 2.5(5, 4, 10) 3 (3,4) 2 4 (5, 12) 5 (1, 1, 1) 6 (7, 4) + (3, 5) 7 (9, 4, 13) (15, 3, 11) 3 (10, 13, 11) (2, 1, 1) 4 1 (4, 7) (3, 9) 2 (2, 5, 6) (3, 1, 2) 10 56

4.3 3 0.5( 3, 4) ( 2, 5) 4 (3, 1, 2) ( 5, 4, 1) 5 ( 5, 4, 1) (3, 1, 2) 5 a b a 4 b 6 60 57

4.4 1 a b 3 2 a b sin 60 0.866 cos60 1 0.5 2 2 6 NPC p forward v 1 x NPC 2 1 p (4, 2), v ( 3, 4), x (10, 6) 3 NPC φ φ NPC 2 NPC x 4 3 NPC 7 3 p 1 p 2 p 3 p 1 p 2 p 3 xy z 0 z z 4.29 4.4 matrix The Matrix matrix matrix The Matrix ( 1 ( a U U g V g 58

4.4 1 0.5 3 2 2.3 5 3 10 4 8 11 5 m n row column 3 4 3 3 M m m m 11 12 13 m21 m22 m23 m m m 31 32 33 m ij M i j n 1 column matrix 1 n row matrix n v (3, 8, 6) [3 8 6] 3 8 6 Shader c 3 3 59

4.4 m11 m12 m13 km11 km12 km13 kmm k k m m m km km km 21 22 23 21 22 23 m31 m32 m 33 km31 km32 km 33 c r n A n c B AB r c A 4 3 B 3 6 AB 4 6 r n A n c B r c C AB C c ij A i B j c ij a i1 b 1j + a i2 b 2j + + a in b nj c ij A i B j c ij 4.30 A 4 2 B 2 4 C c 23 A 2 B 3 c 23 a 21 b 13 + a 22 b 23 Shader 4 4 AB BA (AB)C A(BC) ABCDE ((A(BC))D)E (AB)(CD)E ~ n k 1 ab ik kj 60

4.4 Shader. 1 square matrix 3 3 4 4 diagonal elements m 11 m 22 m 33 ( 0 diagonal matrix 4 4 3 0 0 0 0 2 0 0 0 0 1 0 0 0 0 7 identity matrix I n 3 3 I 3 1 0 0 0 1 0 0 0 1 MI IM M 1 3 transposed matrix r c M M T c r i i j j M T ij M 6 7 T 6 2 10 3 2 5 7 5 4 9 10 4 3 9 ji 61

4.4 z x [ x y z] T y T x y [ x y z] z (M T ) T M (AB) T B T A T 4 inverse matrix M M 1 M M -1 MM 1 M 1 M I 0 0 invertible nonsingular noninvertible singular determinant 0 Shader C++ Eigen Unity Unity Unity 4.8 M (M 1 ) 1 M I 1 I 62

4.4 (M T ) 1 (M 1 ) T (AB) 1 B 1 A 1 (ABCD) 1 D 1 C 1 B 1 A 1 4.5 M v M 1 M 1 (Mv) (M 1 M)v Iv v orthogonal matrix M orthogonal M MM T M T M I. M M T M 1. MM T I 3 3 c1 T MM c c c c 2 1 2 3 c3 c1 c1 c1 c2 c1 c3 c2 c1 c2 c2 c2 c3 c 3 c1 c3 c2 c3 c3 1 0 0 0 1 0 I 0 0 1 63

4.4 9 c 1 c 1 1 c 1 c 2 0 c 1 c 3 0 c 2 c 1 0 c 2 c 2 1 c 2 c 3 0 c 3 c 1 0 c 3 c 2 0 c 3 c 3 1 ~ c 1 c 2 c 3 1 c 1 c 2 c 3 0 ~ M M T 4.2.2 4.6.2. orthogonal basis 1 1 orthonormal basis 1. v (x, y, z) v [x y z] v [x y z] T M m m m M m m m m m m 11 12 13 21 22 23 31 32 33 M M M vm [ xm + ym + zm xm + ym + zm xm + ym + zm ] 11 21 31 12 22 32 13 23 33 xm 11 + ym 12 + zm 13 Mv xm 21 + ym 22 + zm 23 xm 31 + ym 32 + zm 33 64

4.4 Unity CBAv ( C( B( Av ))) v A B C T T T T T T va B C ((( va ) B ) C ) ) 3 ( d 1 1 1 3 1 5 2 4 0 2 1 5 2 2 4 3 0 2 2 1 4 3 10 4 5 1 2 3 5 3 5 1 4 4 6 0 3 8 2 1 0 0 1 1 0 0 1 0 0 1 0 0 0 0 1 0 0 2 0 0 1 0 0 0 0 1 cosθ sinθ 0 3 sinθ cosθ 0 0 0 1 65

4.5 as 3 (3, 2, 6) 1 0 0 1 0 1 0 0 0 1 1 0 2 2 0 1 3 0 0 3 2 1 3 3 1 5 3 3 3 4 4.5 as ( ( ~ : 30? transform. linear transform ( f(x) + f(y) f(x + y) kf(x) f(kx) scale ( f(x) 2x 2 :. x f(x) 2x rotation ( ( 3 3 ( 66

4.5 as ( : shear mirroring reflection orthographic projection : ( f(x) x + (1, 2, 3) ( 既不 也 x (1, 1, 1) f(x) + f(x) (4, 6, 8) f(x + x) (3, 4, 5) 3 3 affine transform ( 4 4 homogeneous space 4.1 4.1 N Y N Y Y N Y Y Y Y Y Y Y Y : : Y Y Y N Y Y Y N Y Y Y Y Y Y N N N N N N : 4.6.7 ~ 3 3 4 4 homogeneous coordinate w 1 w 0 4 4 :. 4 4 : 67

4.5 as : 4 M 0 t 3 3 3 1 13 1 M 3 3 : t 3 1 0 1 3 0 1 3 [0 0 0] 1 4 4 : 1 0 0 tx x x+ tx 0 1 0 t y y y+ ty 0 0 1 t z z z+ t z 0 0 0 1 1 1 x y z 3D (x, y, z) (t x, t y, t z ) 1 0 0 tx x x 0 1 0 t y y y 0 0 1 t z z z 0 0 0 1 0 0 t 3 1 M 3 3 I 3 1 0 0 t x 0 1 0 t y 0 0 1 t z 0 0 0 1 x y z : : 68

4.5 as kx 0 0 0 x kxx 0 ky 0 0 y kyy 0 0 kz 0 z kzz 0 0 0 1 1 1 : kx 0 0 0 x kxx 0 ky 0 0 y kyy 0 0 kz 0 z kzz 0 0 0 1 0 0 : k x k y k z : uniform scale nonuniform scale : : : : ( : 4.7 : : : 1 0 0 0 kx 1 0 0 0 k y 1 0 0 0 kz 0 0 0 1 : : : : : : ( x y z x θ 1 0 0 0 0 cosθ sinθ 0 R x ( θ) 0 sinθ cosθ 0 0 0 0 1 y 69

4.5 as cosθ 0 sinθ 0 0 1 0 0 R y ( θ ) sinθ 0 cosθ 0 0 0 0 1 z 70

4.5 as R z cosθ sinθ 0 0 sinθ cosθ 0 0 ( θ ) 0 0 1 0 0 0 0 1 ) : (2, 2, 2) : y 30 z 4 p new M translation M rotation M scale p old : : : (0, 0, 5) 5 2 2 (0, 0, 10): 2 : y : 1 0 0 t x cosθ 0 sinθ 0 k x 0 0 0 0 1 0 t M translation M rotation M scale y 0 1 0 00 k y 0 0 0 0 1 t z sinθ 0 cosθ 0 0 0 k z 0 0 0 0 1 0 0 0 1 0 0 0 1 k x cosθ 0 k z sinθ t x 0 k y 0 t y k x sinθ 0 k z cosθ t z 0 0 0 1 : 71

4.6 cosθ 0 sinθ 0 k x 0 0 0 1 0 0 t x 0 1 0 0 M rotation M scale M translation 0 k y 0 00 1 0 t y sinθ 0 cosθ 0 0 0 k z 00 0 1 t z 0 0 0 1 0 0 0 1 0 0 0 1 k x cosθ 0 k z sinθ t x k x cosθ + t z k z sinθ 0 k y 0 t y k y k x sinθ 0 k z cosθ t x k x sinθ + t z k z cosθ 0 0 0 1 4.5.6 x y z x y z (θ x, θ y, θ z ) Unity zxy API (θ x, θ y, θ z ) cosθ z sinθ z 0 0 1 0 0 0 cosθ y 0 sinθ y 0 sinθ M rotatez M rotatex M rotatey z cosθ z 0 00 cosθ x sinθ x 0 0 1 0 0 0 0 1 0 0 sinθ x cosθ x 0 sinθ y 0 cosθ y 0 0 0 0 1 0 0 0 1 0 0 0 1 zxy (θ x, θ y, θ z ) E z θ z E y θ y E x θ x E z θ z E z θ z E' y θ y E' y θ y E'' x θ x zxy yxz Unity ) 4.6. : 2 ( ( 72

4.6.,. ( X Shader? Shader? 3 4.6.5 800 50. 50 100 ~ (. ( ( 3 73

4.6 parent P C 3 A c A p B p B c A p M c p A c B c M p c B p M c p M p c M c p (a, b, c) 4 1 2 x a 3 y b 4 z c 4 C 3 P x c y c z c O c A c (a,b,c) 4 A n. O. x O + ax c O + ax + by c c c c c p O + ax + by + cz c c c c. M c p A O + ax + by + cz p c c c c 74

75 4.6 A p O c + ax c + by c + cz c (x Oc, y Oc, z Oc ) + a(x xc, y xc, z xc ) + b(x yc, y yc, z yc ) + c(x zc, y zc, z zc ) (x Oc, y Oc, z Oc ) + x xc x yc x zc y xc y yc y zc z xc z yc z zc a b c (x Oc, y Oc, z Oc ) + x c y c z c a b c. 3 3 A p (x Oc, y Oc, z Oc,1) + 0 x c y c z c 0 0 0 0 0 1 a b c 1 1 0 0 x Oc 0 1 0 y Oc 0 0 1 z Oc 0 0 0 1 0 x c y c z c 0 0 0 0 0 1 a b c 1 x Oc x c y c z c y Oc z Oc 0 0 0 1 a b c 1 x c y c z c O c 0 0 0 1 a b c 1 M c p 0 0 0 1 c c c c c p x y z O M M c p M p c C

4.6 P P C M c p C P 3 3 0 1 3 x c y c z c : 4 4 : x y z M c p C P C x (1, 0, 0, 0) M c p [1 0 0 0] T M c p 3 3 Mc p xc yc zc Shader 3 3 ( M p c M c p M p c M p c M c p M c p 1 T M p c x p y p z p M c p M c p x c y c z c M c p x c y c z c x p y p z p M c p M A B A x B B x A B x y z A A B 76

4.6. P C C P A B. B x y z A x B y B z B A B M A B MA B xb yb z B M A B x B B x (1,0,0) B x (1, 0, 0) MA Bx B xb yb zb x xb xb xb 1 MA Bx B B B 0 B y xb y x z B zb xb 0. ( (., 4.6.4 4.6.8 4.31 B 77

4.6 O P V O P V ( model space object space local space. forward back left right up down 4.2.4 Unity +x +y +z x y z Unity Hierarchy 3? Unity (0, 2, 4) p (0, 2, 4, 1) 4.32 ( world space 78

4.6 Unity x y z Unity Transform Position Transform parent Transform 4.33 Transform Rotation Scale model transform Transform 4.34 79

4.6 5C 4 9CG D o 4 9CG D L0 G M 2DG DC W e O L,D MP T p 2DG DC n Transform (2, 2, 2) : (0, 150, 0) (5, 0, 25) : 1 0 0 t x cosθ 0 sinθ 0 k x 0 0 0 0 1 0 t M model y 0 1 0 0 0 k y 0 0 0 0 1 t z sinθ 0 cosθ 0 0 0 k z 0 0 0 0 1 0 0 0 1 0 0 0 1 1 0 0 5 0.866 0 0.5 0 2 0 0 0 0 1 0 0 0 1 0 00 2 0 0 0 0 1 25 0.5 0 0.866 0 0 0 2 0 0 0 0 1 0 0 0 1 0 0 0 1 1.732 0 1 5 0 2 0 0 1 0 1.732 25 0 0 0 1 P world M model P model 1.732 0 1 5 0 9 0 2 0 0 2 4 1 0 1.732 254 18.072 0 0 0 1 1 1 (9, 4, 18.072) 3 Unity 80

4.6 ( ( view space camera space ~ ~ Unity Unity +x +y +z ~ +z Unity OpenGL -z Unity Unity Camera.camera ToWorldMatrix Camera.worldToCameraMatrix 4.6.8. projection view transform Transform 4.35 g O e P 5C e W e p n 4.6.2 81

4.6 Transform (30, 0, 0) (0, 10, 10) (0, 10, 10) ( 30, 0, 0) 1 0 0 0 1 0 0 t x 0 cosθ sinθ 0 M view 0 1 0 t y 0 sinθ cosθ 0 0 0 1 t z 0 0 0 1 0 0 0 1 1 0 0 0 1 0 0 0 0 0.866 0.5 0 0 1 0 10 0 0.5 0.866 00 0 1 10 0 0 0 1 0 0 0 1 1 0 0 0 0 0.866 0.5 3.66 0 0.5 0.866 13.66 0 0 0 1 z, M view 1 0 0 0 1 0 0 0 0 1 0 0 0 0.866 0.5 3.66 0 0 1 00 0.5 0.866 13.66 0 0 0 1 0 0 0 1 1 0 0 0 0 0.866 0.5 3.66 0 0.5 0.866 13.66 0 0 0 1 M negate z M view P view M view P world 1 0 0 0 9 9 0 0.866 0.5 3.66 4 8.84 0 0.5 0.866 13.6618.072 27.31 0 0 0 1 1 1 (9, 8.84, 27.31) 82

4.6 () clip space clip matrix projection matrix view frustum clip planes orthographic projection perspective projection ( O P O ö入 门 精 要 4.36 P W e èé ìå 3D near øý 6 far clip plane ¼ òí clip plane 2D º HUD 4.37 ) w e w e w 83

4.6 homogeneous division. w 4.6.8 x y z : 6. : w x y z w 1 w 0. 4. 6 6 Unity Camera Game 4.38 4.38 Camera Field of View FOV w Clipping Planes Near Far FOV nearclipplaneheight 2 Near tan 2 FOV farclipplaneheight 2 Far tan 2 ; Unity 84

4.6 Game Viewport Rect W H Unity Camera.aspect ~ Aspect nearclipplanewidth Aspect nearclipplaneheight Aspect farclipplanewidth farclipplaneheight Near Far FOV Aspect M frustum FOV cot 2 0 0 0 Aspect FOV 0 cot 0 0 2 Far + Near 2 Near Far 0 0 Far Near Far Near 0 0 1 0 Unity z [-w, w] DirectX z [0, w] ~!!"#$!!"#$%#&!!"#$ cot!"# 2!"#$%& 0 0 0 0 cot!"# 2 0 0 0 0!"# +!"#$ 2!"#$!"#!"#!"#$!!"!"#$ 0 0 1 0!"# cot! 2!"#$%&!cot!"# 2!"# +!"#$ 2!"#$!"#!!"#!"#$!"#!"#$! x y z : z : w 1 z, w x w!!! 1 85

4.6 w y w w z w 4.39. e e n i o 4.39 z 6 Unity Camera Game 4.40 Camera Size Clipping Planes Near Far w nearclipplaneheight 2 Size farclipplaneheight nearclipplaneheight ; Aspect nearclipplanewidth Aspect nearclipplaneheight farclipplanewidth nearclipplanewidth 86

4.6 Near Far Size Aspect 1 0 0 0 Aspect Size 1 0 0 0 M ortho Size 2 Far + Near 0 0 Far Near Far Near 0 0 0 1 Unity P clip 1 0 0 0 Aspect Size x 1 0 0 0 y Size z 2 Far + Near 0 0 1 Far Near Far Near 0 0 0 1 x Aspect Size y Size 2z Far + Near Far Near Far Near 1 M ortho P view w 1 [0 0 1 0] [0 0 0 1] 4.41... 4.6.6. (9, 8.84, -27.31) 3D Game 4.42 87

4.6 e e n i o FOV 60 Near 5 Far 40 Aspect 4/3 1.333 88

4.6 cot FOV 2 0 0 0 Aspect M frustum 0 cot FOV 0 0 2 Far + Near 0 0 Far Near 0 0 1 0 1.299 0 0 0 0 1.732 0 0 0 0 1.286 11.429 0 0 1 0 2 Near Far Far Near P clip 1.299 0 0 0 9 11.691 0 1.732 0 0 8.84 15.311 0 0 1.286 11.429 27.31 23.692 0 0 1 0 1 27.31 M frustum P view (11.691, 15.311, 23.692, 27.31) Unity w x w 27.31 11.691 27.31 w x y 27.31 15.311 27.31 w z w 27.31 23.692 27.31 (. screen space. 2D homogeneous division perspective division w x y z OpenGL Normalized Device Coordinates NDC. NDC.. OpenGL x y z [ 1, 1] DirectX API z [0, 1] Unity OpenGL 4.43 89

4.6 s w.. w 1 x y z 4.44 s w. x y Unity 0, 0 (pixelwidth, pixelheight) x y [ 1, 1] : 90

4.6 clipx pixelwidth pixelwidth screenx + 2 clip 2 screen y w clipy pixelheight pixelheight + 2 clip 2 w x y z z clip z clip w clip w. NDC Unity (11.691, 15.311, 23.692, 27.31), 400 300 NDC clipx pixelwidth pixelwidth screenx + 2 clip 2 screen y 11.691 400 400 + 2 27.31 2 285.617 clipy pixelheight pixelheight + 2 clip 2 15.311 300 300 + 2 27.31 2 234.096 (285.617, 234.096) ( w w 4.45 4.45 4.9.3 Unity 4.46 Unity 4.46 Unity tangent space ( ( 4.7 91

4.6 ( 5C 92

4.7 4.7 ( normal normal vector. ( ( ( 4 4 3 3 M A B A B ( ( tangent tangent vector ( ( ( 4.47 ( ( 3 3 M A B ) h 3 3 ( ( ( T B M A B T A T A T B A B ( M A B ( ( 4.48 s X ( ( T A ( N A T A N A 0 M A B. T B M A B T A G ( N A ( 93

4.8 Unity Shader O P ( T B N B (M A B T A ) (GN A ) 0 T T T T T ( M T ) ( GN ) ( M T ) ( GN ) T M GN T ( M G) N 0 A B A A A B A A A A B A A A B A T A N A 0 M T A BG I T 1 1 T G ( M ) ( M ) ( A B A B M A B M 1 M T T 1 ( M ) M A B A B A B A B ( : : T : k M A B ( MA B) M A B k ( 4.8 Unity Shader O P 1 1 Unity Shader Unity UnityShaderVariables.cginc 4.2 Unity 5.2 float4x4 Unity Unity Unity 5.2 4.x 4.2 Unity UNITY_MATRIX_MVP UNITY_MATRIX_MV UNITY_MATRIX_V UNITY_MATRIX_P UNITY_MATRIX_VP UNITY_MATRIX_T_MV UNITY_MATRIX_IT_MV _Object2World _World2Object / / / / / UNITY_MATRIX_MV UNITY_MATRIX_MV ( UNITY_MATRIX_MV / _Object2World / 4.2 4.6.2 UNITY_MATRIX_T_MV 94

4.8 Unity Shader O P UNITY_MATRIX_MV UNITY_MATRIX_T_MV UNITY_MATRIX_T_MV UNITY_MATRIX_MV 4.5 : UNITY_MATRIX_MV : : k UNITY_MATRIX_MV : 1 k : UNITY_MATRIX_MV 1 k UNITY_MATRIX_T_MV UNITY_MATRIX_T_MV : : UNITY_MATRIX_IT_MV 4.7. ( UNITY_MATRIX_IT_MV ( UNITY_MATRIX_MV // S transpose UNITY_MATRIX_IT_MV // UNITY_MATRIX_MV c // float4 modelpos mul(transpose(unity_matrix_it_mv), viewpos); // fsx transpose mul c // float4 modelpos mul(viewpos, UNITY_MATRIX_IT_MV); mul 4.9.2 Unity Camera 4.3 Unity 5.2 4.3 Unity _WorldSpaceCameraPos float3 _ProjectionParams _ScreenParams _ZBufferParams float4 float4 float4 x 1.0 1.0 y Near z Far w 1.0 + 1.0/Far Near Far x width y height z 1.0 + 1.0/width w 1.0 + 1.0/height width height render target x 1 Far/Near y Far/Near z x/far w y/far ( Z 13.1 95

4.9 unity_orthoparams float4 x width y heigth z w 1.0 w 0.0 width height unity_cameraprojection float4x4 unity_camerainvprojection float4x4 unity_cameraworldclipplanes[6] float4 6 4.9. ) ( : 3 3 4 4 4 4 w 1 3 3, Unity Shader Cg Cg float Cg float3x3 float4x4 float3 float4 1 x n n x 1 float4 a float4(1.0, 2.0, 3.0, 4.0); float4 b float4(1.0, 2.0, 3.0, 4.0); // y float result dot(a, b); Cg mul float4 v float4(1.0, 2.0, 3.0, 4.0); float4x4 M float4x4(1.0, 0.0, 0.0, 0.0, 0.0, 2.0, 0.0, 0.0, 0.0, 0.0, 3.0, 0.0, 0.0, 0.0, 0.0, 4.0); // v M c float4 column_mul_result mul(m, v); // v M c float4 row_mul_result mul(v, M); // Scolumn_mul_result X g row_mul_result S // mul(m,v) mul(v, tranpose(m)) // mul(v,m) mul(tranpose(m), v) 96

4.9 Unity UNITY_MATRIX_MVP Cg Cg float4x4 3 4 12 (1, 2, 3, 4, 5, 6, 7, 8, 9) 3 x 3 1 2 3 4 5 6 7 8 9 1 4 7 2 5 8 3 6 9 Cg Cg // r M float3x3 M float3x3(1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0); // M (1.0, 2.0, 3.0) float3 row M[0]; // M 2 1 4.0 float ele M[1][0]; Unity Shader Cg Cg Unity API Unity Matrix4x4 Unity Shader 5C S,D 3 C2DG 6213 7213 4.6.8 Shader / VPOS WPOS 5.4 VPOS HLSL WPOS Cg Unity Shader HLSL/Cg / / VPOS WPOS 97

4.9 fixed4 frag(float4 sp : VPOS) : SV_Target { // o _ScreenParams.xy return fixed4(sp.xy/_screenparams.xy,0.0,1.0); } 4.49 VPOS/WPOS float4. xy 400 x 300 x [0.5, 400.5] y [0.5, 300.5] OpenGL DirectX 10 0.5 zw Unity VPOS/WPOS z [0,1] z 0 z 1 w w 1 1, Near Far Near Far Camera w 1. w viewport space (0, 0) (1, 1) xy Unity ComputeScreenPos UnityCG.cginc ComputeScreenPos struct vertout { float4 pos : SV_POSITION; float4 scrpos : TEXCOORD0; }; vertout vert(appdata_base v) { vertout o; o.pos mul (UNITY_MATRIX_MVP, v.vertex); // S ComputeScreenPos scrpos o.scrpos ComputeScreenPos(o.pos); return o; } fixed4 frag(vertout i) : SV_Target { // f S scrpos.xy o scrpos.w float2 wcoord (i.scrpos.xy/i.scrpos.w); return fixed4(wcoord,0.0,1.0); } 4.49 3.6.8. 98

4.9 viewport viewport x y clipx 1 + 2 clip 2 w clipy 1 + 2 clip 2 [-1, 1] NDC [0, 1] ComputeScreenPos UnityCG.cginc ComputeScreenPos inline float4 ComputeScreenPos (float4 pos) { float4 o pos * 0.5f; #if defined(unity_half_texel_offset) o.xy float2(o.x, o.y*_projectionparams.x) + o.w * _ScreenParams.zw; #else o.xy float2(o.x, o.y*_projectionparams.x) + o.w; #endif } o.zw pos.zw; return o; ComputeScreenPos pos. MVP UNITY_HALF_TEXEL_OFFSET Unity DirectX #else _ProjectionParams.x 1 1 Output Output x Output Output y z w w clipx clip + 2 2 clipy clip + 2 2 clipz clip w xy w ComputeScreenPos w Unity ComputeScreenPos w Unity 2.3.6 x y w x w y w w w x w y w ( (. xy [0, 1] zw zw zw 99

4.11 d z [-Near, Far] w [Near, Far] z [ 1, 1] w 1 4.10 [1][2] [3 ] ( [4] [1] Fletcher Dunn, Ian Parberry. 3D Math Primer for Graphics and Game Development (2nd Edition). November 2, 2011 by A K Peters/CRC Press [2] Eric Lengyel. Mathematics for 3D game programming and computer graphics (3rd Edition). 2011 by Charles River Media. [3] David Eberly. Conversion of Left-Handed Coordinates to Right-Handed Coordinates [4] http://www.humus.name/temp/linearize%20depth.txt 4.11 d 4.2.5 1 2 (1, 0, 0) (1, 0, 0) 4.50 m g O P O P X u p e z (0, 0, 1) (0, 0, 1) y 90 4.51 100

4.11 d X 3 10 10 Unity z z 10 z z 10 4.3.3 1 1 2 3 a b (a x, a y, a z ) (b x, b y, b z ) (a y b z a z b y, a z b x a x b z, a x b y a y b x ) 2 1 62 7.874 2 (12.5, 10, 25) 3 (1.5, 2) 4 5 12 0.385 0.923 13 13 5 1 1 1 0.577 0.577 0.577 3 3 3 6 (10, 9) 7 ( 6, 1, 2) 3 308 17.55 101

4.11 d 4 1 75 2 13 3 13 4 ( 9, 13, 7) 5 (9, 13, 7) 4 5 1 12 2 12 3 20.785 6 1 x - p v x NPC (x p) v v x p cosθ θ x - p v 0 θ < 90 x NPC 0 θ > 90 x NPC 0 θ 90 x NPC 2 (x p) v ((10, 6) (4, 2)) ( 3, 4) (6, 4) ( 3, 4) 18 + 16 2 < 0 x NPC φ φ φ 3 cosθ cos cos θ > cos θ < NPC 2 2 2 φ φ cosθ < cos θ > NPC cosθ 2 2 ( x p) v cosθ x p v cos φ 2 4 p 7 u p 2 - p 1 v p 3 - p 1 xy u (u x, u y, 0), v (v x, v y, 0) u v (0, 0, u x v y u y v x ) u x v y u y v x 3 4.52 102

4.11 d 4.4.6 1. 1 3 1 5 (1)( 1) + (3)(0) (1)(5) + (3)(2) 1 11 1 2 4 0 2 (2)( 1) + (4)(0) (2)(5) + (4)(2) 2 18 2 2 3 4 2 1 2 3 5 (1)( 5) + ( 2)(4) + (3)(8) 11 3 5 1 4 4 (5)( 5) (1)(4) (4)(8) 11 + + 6 0 3 8 (6)( 5) + (0)(4) + (3)(8) 6 2 1 2 3 z θ 3 1 0 0 (3)(1) + (2)(0) + (6)(0) 1 [3 2 6] 0 1 0 (3)(0) (2)(1) (6)(0) + + [3 2 6] 0 0 1 (3)(0) + (2)(0) + (6)(1) 1 0 0 3 (1)(3) + (0)(2) + (0)(6) 3 0 1 0 2 (0)(3) (1)(2) (0)(6) 2 + + 0 0 1 6 (3)(0)(3) + (0)(2) + (1)(6) 6 (3, 2, 6) 2 103

4.11 d 1 0 2 (3)(1) + (2)(0) + (6)(0) [3 2 6] 0 1 3 (3)(0) (2)(1) (6)(0) + + [3 2 18] 0 0 3 (3)(2) + (2)( 3) + (6)(3) 1 0 2 3 (1)(3) + (0)(2) + (2)(6) 15 0 1 3 2 (0)(3) (1)(2) ( 3)(6) 16 + + 0 0 3 6 (0)(3) + (0)(2) + (3)(6) 18 T 1 0 2 1 0 0 [3 2 6] 0 1 3 [3 2 6] 0 1 0 0 0 3 2 3 3 (3)(1) + (2)(0) + (6)(2) (3)(0) (2)(1) (6)( 3) + + [ 15 16 18] (3)(0) + (2)(0) + (6)(3) 3 2 1 3 (3)(2) + (2)( 1) + (6)(3) [3 2 6] 1 5 3 (3)( 1) (2)(5) (6)( 3) + + [22 11 27] 3 3 4 (3)(3) + (2)( 3) + (6)(4) 2 1 3 3 (2)(3)+(-1)(2)+(3)(6) 22 1 5 32 ( 1)(3)+(5)(2)+( 3)(6) 11 3 3 4 6 (3)(3)+( 3)(2)+(4)(6) 27 (22, 11, 27) symmetric matrix 104