Comments
Description
Transcript
ゲームグラフィックス特論
10 2 3 • l dωi t, b, n dE Li (l) = d!i cos✓i • dE = Li (l)d!i cos✓i • E= Z n Li (l) cos ✓i d!i θi ⌦ Ω l dωi 4 • BRDF n dLo (v) f (l, v) = dE(l) Lo (v) = Z Lo(v) ⌦ φ φo φi f (l, v) ⌦ Li (l) cos ✓i d!i t • Lo (✓o , o) θo θi dE = Li (l)d!i cos✓i • v v l = Z 2⇡ i =0 Z ⇡/2 f (✓i , ✓i =0 i , ✓o , o) ⌦ Li (✓i , i ) cos ✓i sin ✓i d✓i d i (d!i = sin ✓i d✓i d i ) 5 • ωL n v LL Lo (v) = EL Z !L n lL θ i L f (l, v) ⌦ LL cos ✓i d!i ⇡ f (lL , v) ⌦ EL cos ✓iL v 6 • cdif f Lo (v) = E ⇡ • E = Z cdiff LL cos✓i d!i !L ⇡ EL cos✓iL 7 e(p) l n p p Li(p, l) Θ p Li (p, l) : p Θ p e(p) = Z e l Li (p, l)ld!i ⇥ 8 e(p) p E(p, n) E(p, n) = n · e(p) E(p, n) = 0 E(p, n) = n · e(p) (n ) n p 9 • • • • • • e(p) l= , EL = cL |e(p)| |e(p)| • pL pL l= |pL rL p , EL = p| ( 2 ⇡rL LL 2 r rL pL L L) r l p 10 • • → LA • • LA 11 12 • Lo (v) = Z n ⌦ v f (l, v) ⌦ Li (l) cos ✓i d!i cdif f = ⌦ LA ⇡ Z cos ✓i d!i ⌦ = cdif f ⌦ LA • Lo (v) cdif f = ⌦ ⇡ ⇡LA + n X k=1 ELk cos✓ik ! 13 • BRDF Z n X Lo (v) = LA f (l, v) cos ✓i d!i + f (lk , v)ELk cos✓ik ⌦ RA(v) • RA (v) = Z f (l, v) cos ✓i d!i ⌦ k=1 14 • camb cdiff cdiff cspec Lo (v) = camb ⌦ LA + n X k=1 f (lk , v)ELk cos✓ik 15 16 (Environment Mapping) • • • (Reflection Mapping) • • • • • Blinn Newell • Sphere Mapping • Cube Mapping • Dual Paraboloid Mapping 17 Environment Mapping v n r r = 2 (n ⋅ v) n − v 18 Blinn Newell • • • r = (rx , ry , rz ) = 2(n · v)n v n y v ⇢ = acos( rz ) = atan2(ry , rx ) r = (rx, ry, rz) /2 x 0 /2 0 /2 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);! … ! ! 20 Sphere Mapping • • • • • 21 Sphere Mapping v = (vx,vx,vx) u = (ux,ux,ux) y Sphere Mapping 0 n hx B ux Ms = B @ vx 0 h = (hx,hx,hx) hy uy vy 0 hz uz vz 0 y' O r x 1 0 0 C C 0 A 1 n' z v0 n0 r v' = (0, 0, 1) = Ms n = 2(n0 · v0 )n0 z' v0 22 y' r n' = (n'x, n'y, n'z) r = (rx , ry , rz ) (n'x, n'y) h v O v' = (0, 0, 1) v0 = (0, 0, 1) z' 0 q m = rx2 + ry2 + (rz + 1)2 h =q 0 n = (rx , ry , rz + 1) rx2 + ry2 + (rz + 1)2 ✓ r x ry r z + 1 , , m m m ◆ = n0 23 1 y' v 1 n'y v n' -1 O -1 1 n'x x' O q m = rx2 + ry2 + (rz + 1)2 1 rx 1 n0x + = + u= 2 2 2m 2 n0y 1 ry 1 u= + = + 2 2 2m 2 u 1 u 24 #version 150 core! in vec4 pv; in vec3 nv; uniform mat4 mw; uniform mat3 mg; uniform mat3 ms; out vec2 t; void main(void)! {! t = normalize(ms …! // ! // ! // // ! // Sphere Mapping // ! ! * n).xy * 0.5 + 0.5;! ! 25 Cubic Environment Mapping • • • 26 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); ! ! ! ! ! ! 28 #version 150 core! …! ! uniform samplerCube cubemap; …! // Cube Map sampler! ! in vec3 r; …! // ! ! void main(void)! {! vec4 rcolor = texture(cubemap, r); …! // ! 29 Dual Paraboloid Mapping • • • • p d = u2 +✓v 2 1 d 0.25 d2 ✓ = arctan 1.5 0 0.25 1 1 θ$ 0.5 -0.4 y = x2 -1 -0.2 d 0.2 -0.5 -1 -1.5 ◆ 0.4 30 Paraboloid Mapping r = (rx , ry , rz ) • 0 8 > < u= rz < 0 8 > < u= rz rx + 0.5 2(1 + rz ) ry > v = + 0.5 : 2(1 + rz ) > : v= rx 2(1 2(1 ry rz ) rz ) + 0.5 + 0.5 0 1 B 0 )B @ 0 0 0 1 B 0 )B @ 0 0 0 1 0 0 0 1 0 0 1 1 0 2 1 1 0 2 10 1 1 rx B C 1 C C B ry C 0 A @ rz A 2 1 10 1 1 rx B C 1 C C B ry C 0 A @ rz A 2 1 31 32 OpenGL (rx, ry, rz, 1)T • • • • • • • • 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 35 • Z (0,0,1) • 1 ≤ x, y ≤ 1 • z2 > 0 (x, y, z) • • • Sphere Mapping z2 = 1 x2 y2 (0.5x + 0.5, 0.5y + 0.5) 36 37 • • (x, y, z) • x2 + y2 1 xy 38 • • • BRDF 39 • • • 40 41 EL lL θ i Li(l) n41 L n l v v Ω E = EL cos✓iL E= Z Li (l) cos ✓i d!i ⌦ 42 En Ω n l Li(l) :p :p :n : n p l θi p θi l Li(l) n Ω En = Z En n En Li (l) cos ✓i d!i ⌦ 43 ×(1 Rspec)× + Rspec× 44 Cube Map 47 48 49 • fi (x), fj (x) = ∫ f (x) f (x) dx i j • fi (n), fj (n) = ∫ f (n) fj (n) dω Θ i • n dω Θ dω$ " 0 i≠ j fi ( ), fj ( ) = # $ 1 i= j n Θ# 50 ftarget() • kj = ftarget ( ), fj ( ) • ftarget() n ftarget ( ) ≈ ∑ kj fj ( ) j=1 fj() 51 • n 1 dn 2 Pn ( x ) = n x −1) n ( 2 n! dx • m n P ( x ) = (−1) m (1− x ) 2 m 2 dm P x m n( ) dx • m m (n − m) Pnm ( x ) = x (2n −1) Pn−1 ( x ) − (n + m −1) Pn−2 ( x) m Pmm ( x ) = (−1) ( 2m −1)!!(1− x m m Pm+1 x = x 2m +1 P ( ) ( ) m ( x) m 2 2 ) P00 ( x ) = 1 P10 ( x ) = x 52 n=0 m n=1 0 P00 ( x ) = 1 1 P10 ( x ) = x P11 ( x ) = − 1− x 2 2 1 P ( x ) = (3x 2 −1) 2 P21 ( x ) = −3x 1− x 2 0 2 n=2 P22 ( x ) = 3 (1− x 2 ) 53 3 l = 0, m = 0 Plm(x) l = 1, m = 0 l = 1, m = 1 2 l = 2, m = 0 l = 2, m = 1 l = 2, m = 2 1 -5 -4 -3 -2 -1 0 -1 -2 -3 1 2 3 54 $ 0 i≠ j & +1 m m ∫ −1 Pi (x)Pj (x) dx = % 2 (n + m)! i = j = n & 2n +1 (n − m)! ' 55 Yl,m (✓, ) = ( 1) m+|m| 2 Klm eim |m| Pl 2l +1 (l − m )! K = 4π (l + m )! m l (x, y, z) = (sinθ cos φ, sinθ sin φ, cosθ) (cos (✓)) 56 m=0 |Ylm (θ, φ)| l=0 l=1 l=2 l=3 m=1 m=2 m=3 57 Ylm (θ, φ) m = -3 l=0 l=1 l=2 l=3 m = -2 m = -1 m=0 m=1 m=2 m=3 58 +π +1 −π −1 ∫ ∫ = Yl m (θ , φ) Yl!m! (θ , φ) d (cosθ) d φ +π π −π 0 ∫ ∫ Yl m (θ , φ) Yl!m! (θ , φ) sin θ dθ d φ = { 1 l = l!, m = m! 0 59 sin θ = x2 + y2 cosθ = z = 1− x2 − y2 ∞ +l f (θ , φ) = ∑ ∑ clmYl m (θ , φ) (x, y) l=0 m=−l m l +π +1 −π −1 +π π −π 0 ∫ ∫ =∫ ∫ c = φ f (θ , φ) Yl m (θ , φ)d (cosθ) dφ f (θ , φ) Yl m (θ , φ) sin θ dθ d φ light probe 62 E • 2 1 2 2 2 0 2 3 2 0 4 0 0 5 2 E = k c (x − y ) + k c z + k c − k c +2k1 (c2−2 xy + c12 xz + c2−1 yz) +2k2 (c11 x + c1−1 y + c10 z) • (x, y, z) n n = (x, y, z) = (sin θ cos φ, sin θ sin φ, cosθ) • Idiff Idiff = (Kdiff ⊗ E) fscale 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] = c00, sh[1] = c1-1, sh[2] = c10, sh[3] = c11, sh[4] = c2-2, sh[5] = c2-1, sh[6] = c20, sh[7] = c21, sh[8] = c22 • • simple.vert • [email protected] 64 Lambert