ゲームグラフィックス特論 第6回 講義ノート

1,068
-1

Published on

シェーディング

Published in: Education
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,068
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
33
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

ゲームグラフィックス特論 第6回 講義ノート

  1. 1. 140 10 10.1 10.1.1 ( 115) 115 10.1.2 3DCG 反射光がないとき 反射光があるとき
  2. 2. 141 ( 116) Omni Light ( ) CG ( ) 116 10.1.3 " (diffuse) ( 117) 平行光線 点光源 スポットライト
  3. 3. 142 117 ( 118) 118
  4. 4. 143 ( ) d ( ) 119 Lambert θi d d / cos θi ( 119) cos θi Lambert N L cos θi = N L Kdiff Ldiff Idiff (82) RGB Kdiff, Ldiff, Idiff RGB RGB Ldiff N L π / 2 cos θi = N L < 0 0 (83) 120 d / cosθi d θi N L Idiff = cos ✓iKdiff ⌦ Ldiff = (N · L)Kdiff ⌦ Ldiff Idiff = max(N · L, 0)Kdiff ⌦ Ldiff
  5. 5. 144 120 " (specular) 121 122 N L L R (84) N L V R R = 2(N · L)N L
  6. 6. 145 122 R V θr R V cos θr = R V Kspec Lspec Ispec Phong (85) Kshi (shininess) R V π / 2 cos θr = R V < 0 0 (86) 123 N L V θr N L 2(N L)N L R = 2(N L)N L Ispec = cosKshi ✓iKspec ⌦ Lspec = (R · V)Kshi Kspec ⌦ Lspec Ispec = max(R · V, 0)Kshi Kspec ⌦ Lspec
  7. 7. 146 123 Phong 124 L V H N θh H (87) 124 H N θh N H cos θh = N H Blinn-Phong Blinn (88) N H π / 2 cos θh = R V < 0 0 (89) OpenGL H = L + V |L + V| θh N L H = L + V |L + V| V Ispec = cosKshi ✓iKspec ⌦ Lspec = (N · H)Kshi Kspec ⌦ Lspec Ispec = max(N · H, 0)Kshi Kspec ⌦ Lspec
  8. 8. 147 125 125 Blinn Phong Blinn Phong Blinn " (shininess) 126 物体表面が滑らかなとき 物体表面が粗いとき
  9. 9. 148 126 ( ) cosn θ cosine Kshi 127 cosine Kshi 128 10.1.4 " Shlick (90) 0 0.2 0.4 0.6 0.8 1 -1.5 -1 -0.5 0 0.5 1 1.5 Kshi = 1 Kshi = 10 Kshi = 50 Kshi = 90 θ cos θKshi Kshi = 10 Kshi = 50 Kshi = 90 Kshi 大小 t = cosθr or t = cosθh Ispec = t Kshi −tKshi +t Kspec ⊗ Lspec
  10. 10. 149 " t (91) " (ambient) Ispec = max N⋅H, 0( )−t#$ %&Kspec ⊗ Lspec
  11. 11. 150 129 Kamb Lamb (92) Kamb Kdiff 130 130 " Itot Idiff Ispec Iamb (93) Iamb = Kamb ⌦ Lamb Itot = Iamb + Idiff + Ispec
  12. 12. 151 131 10.1.5 132 P Pl ( 132) P ( ) d (94) (95) Iamb Idiff Ispec + Pl P L r r = |Pl P| d = 1 r2
  13. 13. 152 (96) sc sl sq sc = 1, sl = 0, sq = 0 sc = 0, sl = 1, sq = 0 sc = 0, sl = 0, sq = 1 (97) 10.1.6 Phong cosine 133 P L Ldir cspot Lexp (98) (99) 10.1.7 Iamb d = 1 sc + slr + sqr2 Itot = Iamb + d(Idiff + Ispec) Pl P Ldir L cspot = max( L · Ldir, 0)Lexp Itot = cspot(Iamb + d(idiff + Ispec))
  14. 14. 153 ( ) Lglob Kamb (100) n (101) 10.2 10.2.1 " " 10.2.2 gl_Position out 134 (P0, C0), (P1, C1), (P2, C2) Itot = Kamb ⊗ Lglob + Lemi +cspot Iamb + d Idiff + Ispec( ){ } Itot = Kamb ⊗ Lglob + Lemi + cspot k Iamb k + dk Idiff k + Ispec k ( ){ } k=1 n ∑
  15. 15. 154 134 P0, P1, P2 P C0, C1, C2 C P1 − P0, P2 − P0 u, v ( 135) (102) 135 P P0 u, v (103) x = (1, 0), y = (0, 1), u = (xu, yu), v = (xv, yv), P0 = (x0, y0) (103) P2 C2 P C P1 C1 P0 C0 ⇢ u = P1 P0 v = P2 P0 x y O u v x y v = P2 - P0 (x, y) = (u, v) P0 u = P1 - P0 P P1 P = xx + yy = uu + vv + P0
  16. 16. 155 (104) u, v (105) u, v P0, P1, P2 C0, C1, C2 ( 136) (106) 136 137 137 ⇢ x = uxu + vxv + x0 y = uyu + vyv + y0 8 >< >: u = (x x0)yv (y y0)xv xuyv xvyu v = (y y0)xu (x x0)yu xuyv xvyu C = u(C1 C0) + v(C2 C0) + C0 = (1 u v)C0 + uC1 + vC2 C1 C1 C2 C u v
  17. 17. 156 138 138 A = (xa, za) B = (xb, zb) AB z = h CD t : (1 − t) P AB Q = (xq, zq) (107) zq za, zb xq xa, xb za, zb zq (x, y, z, w) (x / w, y / w, z / w) C0, C1, C2 w u, v w u, v ( 139) (108) O x z A=(xa, za) B=(xb, zb) Q=(xq, zq) z = h h t 1−t C P D 8 >>>>>>>< >>>>>>>: xq = xa za (1 t) + xb zb t 1 za (1 t) + 1 zb t zq = 1 1 za (1 t) + 1 zb t C = w ⇢ (1 u v) C0 w0 + u C1 w1 + v C2 w2 w = 1 (1 u v) 1 w0 + u 1 w1 + v 1 w2
  18. 18. 157 139 10.2.3 ( shading) CG GPU CPU uniform GPU GPU 10.2.4 in pv cv out vc #version*150*core* in*vec4*pv;* in*vec4*cv;* uniform*mat4*mc;* out*vec4*vc;* void*main(void)* {* **vc*=*cv;* **gl_Position*=*mc***pv;* }* C2 C u v P2 = (x2, y2, z2, w2) C0P0 = (x0, y0, z0, w0) C1P1 = (x1, y1, z1, w1) 2, y2, z2, w2 1, y1, z1, w1 0, y0, z0, w0
  19. 19. 158 in vc out fc #version*150*core* in*vec4*vc;* out*vec4*fc;* void*main(void)* {* **fc*=*vc;* }* out vc in vc ( 140) in out 140 glCreateShader() in 0 //* * GLuint*program*=*glCreateProgram();* * *( ,* ,* )* * //* * glBindAttribLocation(program,*0,*"pv");****//*in* * glBindFragDataLocation(program,*0,*"fc");**//* * glLinkProgram(program);* in glGetAttribLocation() pv cv VC VC VC VC フラグメント シェーダの in 変数 バーテックス シェーダの out 変数
  20. 20. 159 cvLoc //*in*(attribute)* *cv* *K1 * GLint*cvLoc*=*glGetAttribLocation(program,*”cv");* uniform glGetUniformLocation() //*uniform* *mc* *K1 * GLint*mcLoc*=*glGetUniformLocation(program,*"mc");* (Vertex Array Object, VAO) //* * GLuint*vao;* glGenVertexArrays(1,*&vao);* glBindVertexArray(vao);* pv cv //* * GLuint*vbo[2];* glGenBuffers(2,*vbo);* //* * static*const*GLfloat*pv[][3]*=* {* **{*K1.0f,*K0.8660254f,*0.0f*},* **{**1.0f,*K0.8660254f,*0.0f*},* **{**0.0f,**0.8660254f,*0.0f*},* };* * //* * static*const*int*points*=*sizeof*pv*/*sizeof*pv[0];* * //* * glBindBuffer(GL_ARRAY_BUFFER,*vbo[0]);**//* * glBufferData(GL_ARRAY_BUFFER,*sizeof*pv,*pv,*GL_STATIC_DRAW);* 0 in in pv 0 //* *index*==*0* *in* * glVertexAttribPointer(0,*3,*GL_FLOAT,*GL_FALSE,*0,*0);* glEnableVertexAttribArray(0);* //* * static*const*GLfloat*cv[][3]*=* {* **{*1.0f,*0.0f,*0.0f*},**//* *
  21. 21. 160 **{*0.0f,*1.0f,*0.0f*},**//* * **{*0.0f,*0.0f,*1.0f*},**//* * };* * //* * glBindBuffer(GL_ARRAY_BUFFER,*vbo[1]);**//* * glBufferData(GL_ARRAY_BUFFER,*sizeof*cv,*cv,*GL_STATIC_DRAW);* cvLoc in cvLoc in cv //* *index*==*cvLoc* *in* * glVertexAttribPointer(cvLoc,*3,*GL_FLOAT,*GL_FALSE,*0,*0);* glEnableVertexAttribArray(cvLoc);* //* * glUseProgram(program);* * //*uniform* *mc*( )* * glUniformMatrix4fv(mcLoc,*1,*GL_FALSE,*mc);* * //* * glBindVertexArray(vao);* * //* * glDrawArrays(GL_TRIANGLES,*0,*points);* 141
  22. 22. 161 141 10.2.5 OpenGL OpenGL / GLSL out / in noperspective ( smooth) flat noperspective*out*vec4*vc;**//* * noperspective*in*vec4*vc;***//* *

×