Successfully reported this slideshow.
Upcoming SlideShare
×

# ゲームグラフィックス特論 第１０回

12,552 views

Published on

Published in: Technology, Sports
• Full Name
Comment goes here.

Are you sure you want to Yes No
• Be the first to comment

### ゲームグラフィックス特論 第１０回

1. 1. j
2. 2. • ! "#\$ l %, ', (m • • f z n l qi dwi z Li(l) = dE d!icos✓i dE = Li(l)d!icos✓i Ω E = Z ⌦ Li(l) cos ✓id!i e cos ,\$ v
3. 3. • 2@46 • _ -. / • vl n t fifo f qoqi Lo(✓o, o) = Z 2⇡ i=0 Z ⇡/2 ✓i=0 f(✓i, i, ✓o, o) ⌦ Li(✓i, i) cos ✓i sin ✓id✓id i (d!i = sin ✓id✓id i) f(l, v) = dLo(v) dE(l) dE = Li(l)d!icos✓i Lo(v) = Z ⌦ f(l, v) ⌦ Li(l) cos ✓id!i "0\$ cos ,\$
4. 4. • n v qiL EL lL wL n vLL k Lo(v) = Z !L f(l, v) ⌦ LL cos ✓id!i ⇡ f(lL, v) ⌦ EL cos ✓iL vz
5. 5. • • f cdiff z Lo(v) = cdiff ⇡ E E = Z !L LLcos✓id!i ⇡ ELcos✓iL WLO[]
6. 6. p l Li(p, l) e(p) p n Θ 1 i v 2 z l m Q p . p z lLi(p, l) e(p) = Z ⇥ Li(p, l)ld!i
7. 7. p e(p) p n ( z vE(p, n) E(p, n) = n · e(p) E(p, n) = n · e(p) E(p, n) = 0
8. 8. • • x • • • • • 13 43 -3 pL p l rL l = e(p) |e(p)| , EL = cL|e(p)| l = pL p |pL p| , EL = ⇡r2 L r2 LL 53 r
9. 9. • u • p -6 • v j× v • v LA
10. 10. u
11. 11. • ( / • j × x Lo(v) = cdiff ⇡ ⌦ ⇡LA + nX k=1 ELk cos✓ik ! Lo(v) = Z ⌦ f(l, v) ⌦ Li(l) cos ✓id!i = cdiff ⇡ ⌦ LA Z ⌦ cos ✓id!i = cdiff ⌦ LA 7
12. 12. • 2@46 • 86 / Lo(v) = LA Z ⌦ f(l, v) cos ✓id!i + nX k=1 f(lk, v)ELk cos✓ik RA(v) = Z ⌦ f(l, v) cos ✓id!i 2@46
13. 13. • 59:; Lo(v) = camb ⌦ LA + nX k=1 f(lk, v)ELk cos✓ik cdiff v z cdiff cspec
14. 14. ×
15. 15. × 5 _S[Y WO ] ZZS • l m × • • × @OPVOM]SY ZZS • • z • z f w • • 2VS =O OVV • AZRO[O ZZS • 3 LO ZZS • 4 V [ LYVYSN ZZS
16. 16. 5 _S[Y WO ] ZZS v r n r = 2 n⋅v( )n − v v v
17. 17. 2VS =O OVV • • j • n o x yn ρ φ φ ρ 0 −π /2 0 π /2 π π /2 π r = (rx, ry, rz)v −π r = (rx, ry, rz) = 2(n · v)n v ⇢ = acos( rz) = atan2(ry, rx)
18. 18. j j #version 150 core in vec4 pv; // in vec3 nv; // uniform mat4 mw; // j uniform mat3 mg; // out vec2 t; // const float PI = 3.141593; void main(void) { vec3 v = -normalize(mw * pv).xyz; // vec3 r = reflect(v, normalize(mg * nv)); // float s = -acos(r.z) / PI; float t = atan(r.y, r.x) * 0.5 / PI + 0.5; t = vec2(s, t); … [OPVOM] _ 7 A ] 3 ]
19. 19. AZRO[O ZZS • w • • w • z • v
20. 20. AZRO[O ZZS u = (ux,ux,ux) h = (hx,hx,hx) v = (vx,vx,vx) z x y O n n' r z' y' v' _. Ms = 0 B B @ hx hy hz 0 ux uy uz 0 vx vy vz 0 0 0 0 1 1 C C A AZRO[O ZZS v0 = (0, 0, 1) n0 = Msn r = 2(n0 · v0 )n0 v0 c _ w
21. 21. O v' = (0, 0, 1) z' y' n' = (n'x, n'y, n'z) r v h (n'x, n'y) v0 = (0, 0, 1) r = (rx, ry, rz) h0 = (rx, ry, rz + 1) q r2 x + r2 y + (rz + 1)2 = n0 m = q r2 x + r2 y + (rz + 1)2 n0 = ✓ rx m , ry m , rz + 1 m ◆ < x (>? @, >′B) x
22. 22. n' n'x n'y y' x'O -1 -1 1 1 O 1 1 u v u v ab (>? @, >′B) x v m = q r2 x + r2 y + (rz + 1)2 u = n0 x 2 + 1 2 = rx 2m + 1 2 u = n0 y 2 + 1 2 = ry 2m + 1 2
23. 23. j j #version 150 core in vec4 pv; // in vec3 nv; // uniform mat4 mw; // j uniform mat3 mg; // uniform mat3 ms; // Sphere Mapping out vec2 t; // void main(void) { t = normalize(ms * n).xy * 0.5 + 0.5; … AZRO[O ZZS W W W p W v
24. 24. 3 LSM 5 _S[Y WO ] ZZS • • s w • u z
25. 25. z
26. 26. × glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, internal, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, textureNX); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, internal, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texturePX); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, internal, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, textureNY); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, internal, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texturePY); glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, internal, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, textureNZ); glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, internal, WIDTH, HEIGHT, 0, GL_RGB, GL_UNSIGNED_BYTE, texturePZ); S ]O[ V j E 4B8 85 78B 7 J@72 7 JC=A 7=54J2FB5 j
27. 27. × j #version 150 core … uniform samplerCube cubemap; // Cube Map sampler … in vec3 r; // j j y … void main(void) { vec4 rcolor = texture(cubemap, r); // … [ v
28. 28. 4 V [ LYVYSN ZZS • w • r w • × • × x v 1 -1 10 y = x2 0.25 -0.4 -0.2 0.2 0.4 -1.5 -1 -0.5 0.5 1 1.5 d q d = p u2 + v2 ✓ = arctan ✓ d 0.25 d2 ◆
29. 29. rz 0 8 >< >: u = rx 2(1 + rz) + 0.5 v = ry 2(1 + rz) + 0.5 ) 0 B B @ 1 0 1 1 0 1 1 1 0 0 0 0 0 0 2 2 1 C C A 0 B B @ rx ry rz 1 1 C C A rz < 0 8 >< >: u = rx 2(1 rz) + 0.5 v = ry 2(1 rz) + 0.5 ) 0 B B @ 1 0 1 1 0 1 1 1 0 0 0 0 0 0 2 2 1 C C A 0 B B @ rx ry rz 1 1 C C A [ LYVYSN ZZS • r = (rx, ry, rz)
30. 30. r
31. 31. ZO 7 • (rx, ry, rz, 1)T • • • f × • u f w • l m y f z • w vz v t j v • v ×
32. 32. 7 A × j #version 150 core … uniform sampler2D front; // uniform sampler2D back; // … in vec3 r; // j j y … main() { vec2 uv = r.xy * 0.5 / (1.0 + abs(r.z)) + 0.5; vec4 rcolor = texture(r.z >= 0.0 ? front : back, uv); …
33. 33. Environment Map Bump Mapping × × × ×
34. 34. ×
35. 35. × • × • G (0,0,1) • −1 ≤ H, I ≤ 1 JK = 1 − HK − IK • JK > 0 (H, I, J) • (0.5H + 0.5, 0.5I + 0.5) • AZRO[O ZZS
36. 36. v
37. 37. • w w z • l mz • × h (H, I, J) HI HK + IK
38. 38. × • • z • 2@46 ARS S O ×
39. 39. × • z • •
40. 40. × z
41. 41. W n v Li(l) l v qiL EL lL n E = Z ⌦ Li(l) cos ✓id!iE = ELcos✓iL
42. 42. Ω . p n . p l . n θi Li(l) . l n En θi Li(l) Ω p l p z v En = Z ⌦ Li(l) cos ✓id!i n v En En n
43. 43. × d(1 − 8QRST)d × +8QRSTd × × × ×
44. 44. 3 LO Z
45. 45. "-. U\$, U., V. = W XQ U\$, V\$, U., V. -\$ U\$, V\$ cos ,\$ "# Z "[
46. 46. • 2@46 • • 2AA@46 • X U, V\$, V. = "-.(U, V]) "^(U, V_) XQ U\$, V\$, U., V. = "-.(U., V]) "Φ(U\$, V_) |U. − U\$|
47. 47. b v "-. U\$, U., V. = W XQ U\$, V\$, U., V. -\$ U\$, V\$ cos ,\$ "# Z "[ -. U., V. = W W XQ U\$, V\$, U], V. -\$ U\$, V\$ cos ,\$ "# Z "[ c
48. 48. 2AA@46 XQ U\$, V\$, U., V. = 1 7 de(f, V.)8g(U\$, U.)de(f, V\$) U\$ z U. d. d\$
49. 49. -. U., V. = d\$d. 7 W 8g(U\$, U.) W -\$ U\$, V\$ cos ,\$ "# Z c "[ ^ U\$, (\$U\$ y = d\$d. 7 W 8g(U\$, U.)^ U\$, (\$ c "[
50. 50. b U. bh bi W 8g(U\$, U.)^ U\$, (\$ c "[ = W 8g(U\$, U.)^(U\$, (\$)"[ cj + W 8g(U\$, U.)^(U\$, (\$)"[ ck bh U.
51. 51. U. bh • ^ U\$, (\$ ^ U., (. • w • XQ U\$, V\$, U., V. |U. − U\$| • v • • U\$ v b W 8g(U\$, U.)^(U\$, (\$)"[ cj ≈ ^ U., (. W 8g U\$, U. "[ cj z
52. 52. U. y ^ U., (. = W -\$ U., Vm cos ,m "# Z ^ U., (. = W n U., Vm -Sho Vm max (. ⋅ Vm, 0 "# Z U. yv V\$ fu
53. 53. ^ U.,(. j× ^ U., (. = 47 > u v U. + 4mVm -Sho Vm max (. ⋅ Vm, 0 h mwx l U. Ø × × Ø max (. ⋅ Vm, 0 l v
54. 54. U. bi • ^ U\$, (\$ ^9:; v • U. z • ∫ 8g(U\$, U.) "[ ck ze v • bi ^9:; U. W 8g(U\$, U.)^(U\$, (\$)"[ ck ≈ ^9:;ze
55. 55. • • • fi x( ), fj x( ) = fi x( ) fj x( )dx∫ fi n( ), fj n( ) = fi n( ) fj n( )dωΘ ∫ n dw Q fi ( ), fj ( ) = 0 i ≠ j 1 i = j " # \$ Q dw n f t
56. 56. • w Xe9{Se() Xm() • Xe9{Se() kj = ftarget ( ), fj ( ) ftarget ( ) ≈ kj fj ( ) j=1 n ∑
57. 57. × • × l m • × • Pn x( )= 1 2n n! dn dxn x2 −1( ) n Pn m x( )= −1( ) m 1− x2 ( ) m 2 dm dxm Pn x( ) n − m( )Pn m x( )= x 2n −1( )Pn−1 m x( )− n + m −1( )Pn−2 m x( ) Pm m x( )= −1( ) m 2m −1( )!! 1− x2 ( ) m 2 Pm+1 m x( )= x 2m +1( )Pm m x( ) >. NO [OO |. Y[NO[ |H| ≤ 1, ||| ≤ >, > = 0, 1, 2, … P1 0 x( )= x P0 0 x( )=1 | = 0
58. 58. × Ä : H Å | = 0 | = 1 | = 2 0 1 2 P1 1 x( )= − 1− x2 P0 0 x( )=1 P1 0 x( )= x P2 0 x( )= 1 2 3x2 −1( ) P2 1 x( )= −3x 1− x2 P2 2 x( )= 3 1− x2 ( )
59. 59. Ä : H -5 -4 -3 -2 -1 0 1 2 3 4 5 -3 -2 -1 1 2 3 l = 0, m = 0 l = 1, m = 0 l = 1, m = 1 l = 2, m = 0 l = 2, m = 1 l = 2, m = 2
60. 60. × Pi m x( )−1 +1 ∫ Pj m x( )dx = 0 i ≠ j 2 2n +1 n + m( )! n − m( )! i = j = n \$ % & ' &
61. 61. Kl m = 2l +1 4π l − m( )! l + m( )! x, y, z( ) = sinθ cosφ, sinθ sinφ, cosθ( ) Yl,m (✓, ) = ( 1) m+|m| 2 Km l eim P |m| l (cos (✓))
62. 62. Yl m (q, f) l = 0 l = 1 l = 2 l = 3 m = 0 m = 1 m = 2 m = 3m = -1m = -2m = -3
63. 63. Yl m θ,φ( )Y!l !m θ,φ( )d cosθ( )dφ−1 +1 ∫−π +π ∫ = Yl m θ,φ( )Y!l !m θ,φ( )sinθdθ dφ0 π ∫−π +π ∫ = 1 l = !l ,m = !m 0{
64. 64. f θ,φ( ) = cl m Yl m θ,φ( ) m=−l +l ∑ l=0 ∞ ∑ cl m = f θ,φ( )Yl m θ,φ( )−1 +1 ∫−π +π ∫ d cosθ( )dφ = f θ,φ( )Yl m θ,φ( )sinθdθ dφ0 π ∫−π +π ∫ VS R] Z[YLO f (x, y) sinθ = x2 + y2 cosθ = z = 1− x2 − y2
65. 65. Robin Green, “Spherical Harmonic Lighting: The Gritty Details”
66. 66. • z ^ • (H, I, J) ( • Çg\$ii Idiff = Kdiff ⊗ E( ) fscale n = x, y, z( ) = sinθ cosφ, sinθ sinφ, cosθ( ) E = k1c2 2 x2 − y2 ( )+ k3c2 0 z2 + k4c0 0 − k5c2 0 +2k1 c2 −2 xy+c2 1 xz +c2 −1 yz( ) +2k2 c1 1 x +c1 −1 y+c1 0 z( ) k1 = 0.429043 k2 = 0.511664 k3 = 0.743125 k4 = 0.886227 k5 = 0.247708 ^ u f84@l × m × × x vl u m f j XQT9ÄS z g
67. 67. • vg • WLO[] g • R]]Z . S]R L MYW ]YUYSU WZVO • v vg • SPY[W R v g • RH I / M RH I / M RH I / M RH(I / M RH)I / M RH I / M RH I / M RH,I / M RH-I / M • j x g • SWZVO _O[] j vg • ]YUYS0 b U b W M TZ
68. 68. WLO[]