Like this presentation? Why not share!

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

## on Jun 25, 2012

• 1,173 views

### Views

Total Views
1,173
Views on SlideShare
1,170
Embed Views
3

Likes
4
Downloads
71
Comments
0

### 1 Embed3

 https://twitter.com 3

### Upload Details

Uploaded via as Adobe PDF

### Report content

• Comment goes here.
Are you sure you want to
Your message goes here
Edit your comment

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

• 10
• 2
• •  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
• •  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
• •  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 cdiff Lo(v) = cdiff ⇡ E E = Z !L LLcos✓id!i ⇡ ELcos✓iL
• 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
• 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
• •  •  •  •  •  •  •  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
• •  •  → LA •  •  LA 10
• 11
• •  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
• •  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
• •  camb 14 Lo(v) = camb ⌦ LA + nX k=1 f(lk, v)ELk cos✓ik cdiff cdiff cspec
• 15
• (Environment Mapping) •  •  •  (Reflection Mapping) •  •  •  •  •  Blinn Newell •  Sphere Mapping •  Cube Mapping •  Dual Paraboloid Mapping 16
• Environment Mapping v r n r = 2 n⋅v( )n − v 17
• 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)
• #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
• Sphere Mapping •  •  •  •  •  20
• 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
• 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 ◆
• 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
• #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
• Cubic Environment Mapping •  •  •  25
• 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); 27
• #version 150 core! …! ! uniform samplerCube cubemap; // Cube Map sampler! …! ! in vec3 r; // ! …! ! void main(void)! {! vec4 rcolor = texture(cubemap, r); // ! …! 28
• 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 ◆
• 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
• OpenGL •  (rx, ry, 1, rz)T •  •  •  •  •  •  •  32
• 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
• 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
• 37
• •  •  •  (x, y, z) xy x2 + y2 1 38
• •  •  •  BRDF 39
• •  •  •  40
• 41
• 42 Ω n v Li(l) l v θiL EL lL 42n E = Z ⌦ Li(l) cos ✓id!iE = ELcos✓iL
• 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
• 44 ×(1 Rspec)× + Rspec×
• Cube Map 45
• 48
• 49
• •  •  •  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
• •  ftarget() fj() •  ftarget() kj = ftarget ( ), fj ( ) ftarget ( ) ≈ kj fj ( ) j=1 n ∑ 51
• •  •  •  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
• 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
• 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
• Pi m x( )−1 +1 ∫ Pj m x( )dx = 0 i ≠ j 2 2n +1 n + m( )! n − m( )! i = j = n \$ % & ' & 55
• 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
• |Yl m (θ, φ)| l = 0 l = 1 l = 2 l = 3 m = 0 m = 1 m = 2 m = 3 57
• Yl m (θ, φ) l = 0 l = 1 l = 2 l = 3 m = 0 m = 1 m = 2 m = 3m = -1m = -2m = -3 58
• 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
• 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
• •  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
• •  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
• Lambert 65