ゲームグラフィックス特論 第10回

9,993 views

Published on

環境光, 環境マッピング, 放射照度マップ, 放射照度マップの球面調和関数近似

Published in: Technology, Sports
0 Comments
10 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
9,993
On SlideShare
0
From Embeds
0
Number of Embeds
2,828
Actions
Shares
0
Downloads
100
Comments
0
Likes
10
Embeds 0
No embeds

No notes for slide

ゲームグラフィックス特論 第10回

  1. 1. 10
  2. 2. 2
  3. 3. •  l dωi t, b, n •  •  n l θi dωi 3 Li(l) = dE d!icos✓i dE = Li(l)d!icos✓i Ω E = Z ⌦ Li(l) cos ✓id!i
  4. 4. •  BRDF •  v Lo(v) •  vl n t φiφo φ θoθi 4 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
  5. 5. •  n v θiL EL lL ωL n vLL Lo(v) = Z !L f(l, v) ⌦ LL cos ✓id!i ⇡ f(lL, v) ⌦ EL cos ✓iL 5
  6. 6. •  •  6 cdiff Lo(v) = cdiff ⇡ E E = Z !L LLcos✓id!i ⇡ ELcos✓iL
  7. 7. e(p) p n Θ p l Li(p, l) p e Θ p : p l 7 Li(p, l) e(p) = Z ⇥ Li(p, l)ld!i
  8. 8. e(p) p n p (n ) 8 E(p, n) E(p, n) = n · e(p) E(p, n) = n · e(p) E(p, n) = 0
  9. 9. •  •  •  •  •  •  •  pL rL ( LL) pL p l rL 9 l = e(p) |e(p)| , EL = cL|e(p)| l = pL p |pL p| , EL = ⇡r2 L r2 LL r
  10. 10. •  •  → LA •  •  LA 10
  11. 11. 11
  12. 12. •  n v •  12 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
  13. 13. •  BRDF •  RA(v) 13 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
  14. 14. •  camb 14 Lo(v) = camb ⌦ LA + nX k=1 f(lk, v)ELk cos✓ik cdiff cdiff cspec
  15. 15. 15
  16. 16. (Environment Mapping) •  •  •  (Reflection Mapping) •  •  •  •  •  Blinn Newell •  Sphere Mapping •  Cube Mapping •  Dual Paraboloid Mapping 16
  17. 17. Environment Mapping v r n r = 2 n⋅v( )n − v 17
  18. 18. Blinn Newell •  •  •  x yn 0 /2 0 /2 /2 r = (rx, ry, rz)v 18 r = (rx, ry, rz) = 2(n · v)n v ⇢ = acos( rz) = atan2(ry, rx)
  19. 19. #version 150 core! in vec4 pv; // ! in vec3 nv; // ! uniform mat4 mw; // ! 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);! … 19
  20. 20. Sphere Mapping •  •  •  •  •  20
  21. 21. Sphere Mapping u = (ux,ux,ux) h = (hx,hx,hx) v = (vx,vx,vx) z x y O n n' r z' y' v' 21 Ms = 0 B B @ hx hy hz 0 ux uy uz 0 vx vy vz 0 0 0 0 1 1 C C A Sphere Mapping v0 = (0, 0, 1) n0 = Msn r = 2(n0 · v0 )n0 v0
  22. 22. O v' = (0, 0, 1) z' y' n' = (n'x, n'y, n'z) r v h (n'x, n'y) 22 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 ◆
  23. 23. n' n'x n'y y' x'O -1 -1 1 1 O 1 1 u v u v 23 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
  24. 24. #version 150 core! in vec4 pv; // ! in vec3 nv; // ! uniform mat4 mw; // ! uniform mat3 mg; // ! uniform mat3 ms; // Sphere Mapping ! out vec2 t; // ! void main(void)! {! t = normalize(ms * n).xy * 0.5 + 0.5;! …! 24
  25. 25. Cubic Environment Mapping •  •  •  25
  26. 26. 26
  27. 27. 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); 27
  28. 28. #version 150 core! …! ! uniform samplerCube cubemap; // Cube Map sampler! …! ! in vec3 r; // ! …! ! void main(void)! {! vec4 rcolor = texture(cubemap, r); // ! …! 28
  29. 29. Dual Paraboloid Mapping •  •  •  •  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 θ$ 29 d = p u2 + v2 ✓ = arctan ✓ d 0.25 d2 ◆
  30. 30. 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 Paraboloid Mapping •  30 r = (rx, ry, rz)
  31. 31. 31
  32. 32. OpenGL •  (rx, ry, 1, rz)T •  •  •  •  •  •  •  32
  33. 33. GLSL ( ) #version 150 core! …! ! uniform sampler2D front; // ! uniform sampler2D back; // ! …! ! in vec3 r; // ! …! ! main()! {! vec2 uv = r.xy * 0.5 / (1.0 + abs(r.z)) + 0.5;! vec4 rcolor = texture(r.z >= 0.0 ? front : back, uv);! …! 34
  34. 34. 35
  35. 35. •  •  Z (0,0,1) •  1 ≤ x, y ≤ 1 z2 = 1 x2 y2 •  z2 > 0 (x, y, z) •  (0.5x + 0.5, 0.5y + 0.5) •  Sphere Mapping 36
  36. 36. 37
  37. 37. •  •  •  (x, y, z) xy x2 + y2 1 38
  38. 38. •  •  •  BRDF 39
  39. 39. •  •  •  40
  40. 40. 41
  41. 41. 42 Ω n v Li(l) l v θiL EL lL 42n E = Z ⌦ Li(l) cos ✓id!iE = ELcos✓iL
  42. 42. 43 Ω : p n : p l : n θi Li(l) : l n En θi Li(l) Ω p l p En = Z ⌦ Li(l) cos ✓id!i n En En n
  43. 43. 44 ×(1 Rspec)× + Rspec×
  44. 44. Cube Map 45
  45. 45. 48
  46. 46. 49
  47. 47. •  •  •  fi x( ), fj x( ) = fi x( ) fj x( )dx∫ fi n( ), fj n( ) = fi n( ) fj n( )dωΘ ∫ n dω Θ fi ( ), fj ( ) = 0 i ≠ j 1 i = j " # $ Θ# dω$ n 50
  48. 48. •  ftarget() fj() •  ftarget() kj = ftarget ( ), fj ( ) ftarget ( ) ≈ kj fj ( ) j=1 n ∑ 51
  49. 49. •  •  •  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( ) P1 0 x( )= x P0 0 x( )=1 52
  50. 50. m n = 0 n = 1 n = 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 ( ) 53
  51. 51. Pl m(x) -5 -4 -3 -2 -1 0 1 2 3 -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 54
  52. 52. Pi m x( )−1 +1 ∫ Pj m x( )dx = 0 i ≠ j 2 2n +1 n + m( )! n − m( )! i = j = n $ % & ' & 55
  53. 53. 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 (✓)) 56
  54. 54. |Yl m (θ, φ)| l = 0 l = 1 l = 2 l = 3 m = 0 m = 1 m = 2 m = 3 57
  55. 55. Yl m (θ, φ) l = 0 l = 1 l = 2 l = 3 m = 0 m = 1 m = 2 m = 3m = -1m = -2m = -3 58
  56. 56. 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{ 59
  57. 57. 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 π ∫−π +π ∫ light probe φ (x, y) sinθ = x2 + y2 cosθ = z = 1− x2 − y2 60
  58. 58. •  E •  (x, y, z) n •  Idiff 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 63
  59. 59. •  Lambert •  https://github.com/tokoik/ggsample10 •  •  uniform sh •  sh[0] = c0 0, sh[1] = c1 -1, sh[2] = c1 0, sh[3] = c1 1, sh[4] = c2 -2, sh[5] = c2 -1, sh[6] = c2 0, sh[7] = c2 1, sh[8] = c2 2 •  •  simple.vert •  tokoi@sys.wakayama-u.ac.jp 64
  60. 60. Lambert 65

×