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

1,890 views
1,852 views

Published on

陰影付け

0 Comments
6 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,890
On SlideShare
0
From Embeds
0
Number of Embeds
53
Actions
Shares
0
Downloads
100
Comments
0
Likes
6
Embeds 0
No embeds

No notes for slide

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

  1. 1. 6
  2. 2. 2
  3. 3. • , photon • • • 3
  4. 4. 4
  5. 5. (Omni Lights) • • • • • • • • (Omni Light) • • 5
  6. 6. 6
  7. 7. 7 • • • • • •
  8. 8. 8
  9. 9. • • • • • • • 9
  10. 10. • • • • • • • 10
  11. 11. Lambert d / cosθi d θi N L 11 θi cosθi θi cosθi
  12. 12. 12 ⊗ Idiff: Kdiff: Ldiff: : N L π / 2 0: Idiff = max N⋅L, 0( )Kdiff ⊗ Ldiff Idiff = cosθiKdiff ⊗ Ldiff = N⋅L( )Kdiff ⊗ Ldiff
  13. 13. 13
  14. 14. 14 N L V R
  15. 15. • • • • • • • • 15
  16. 16. N L V θr N L 2(N L)N L R = 2(N L)N L 16
  17. 17. 17 (Phong ) Ispec = cosKshi θrKspec ⊗ Lspec = R⋅V( ) Kshi Kspec ⊗ Lspec Ispec: Kspec: Kshi: R V π / 2 0: Lspec: Ispec = max R⋅V, 0( ) Kshi Kspec ⊗ Lspec
  18. 18. (Phong) 18
  19. 19. θh N L H = L + V |L + V| V 19
  20. 20. (Blinn ) 20 Ispec = cosKshi θhKspec ⊗ Lspec = N⋅H( ) Kshi Kspec ⊗ Lspec Ispec: Kspec: Kshi: N H π / 2 0: Lspec: Ispec = max N⋅H, 0( ) Kshi Kspec ⊗ Lspec OpenGL , Blinn-Phong
  21. 21. (Blinn) 21
  22. 22. 22
  23. 23. 23 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 θ
  24. 24. 24 Kshi Kshi = 10 Kshi = 50 Kshi = 90
  25. 25. • Schlick • t 25 t = cosθr or t = cosθh Ispec = t Kshi −tKshi +t Kspec ⊗ Lspec Ispec = max N⋅H, 0( )−t#$ %&Kspec ⊗ Lspec
  26. 26. 26
  27. 27. • • • • • • 27
  28. 28. 28 Iamb = Kamb ⊗ Lamb Iamb: Kamb: Lamb:
  29. 29. 29
  30. 30. 30 Iamb Idiff Ispec Itot = Iamb + Idiff + Ispec
  31. 31. • r • (distance falloff) d 31 Pl P L r r = |Pl P| d = 1 r2
  32. 32. • OpenGL/DirectX • • 32 Itot = Iamb + d Idiff + Ispec( ) sc,sl,sq( )= 1,0,0( ) (0,1,0) (0,0,1) ! " # $ # d = 1 sc + slr + sqr2 d = 8 >< >: 1 r  rstart rend r rend rstart rstart < r < rend 0 r rend (1, 0, 0) (0, 0, 1) O d rrstart rend (0, 1, 0) 1 1
  33. 33. Pixar d = fmaxe k0k1 r rc( ) r ≤ rc fc rc r " # $ % & ' se r > rc ( ) ** + * * fc r = rc sc r > rc fmax r < rc k0 = log( fc / fmax) k1 = se / k0 33 Advanced Renderman P. 395
  34. 34. • • 34 cspot = max −L⋅Ldir,0( ) Lexp Itot = cspot Iamb + d Idiff + Ispec( )( ) Pl P Ldir L
  35. 35. (spotlights) • OpenGL • DirectX θs θp θu S -L 35 cspot = ⇢ cossexp ✓s ✓s  ✓u 0 ✓s > ✓u cspot = 8 < : 1 cos ✓s cos ✓p cossexp ✓s cos ✓u < cos ✓u < cos ✓p 0 cos ✓s  cos ✓u
  36. 36. • (Projective Texture) • 36
  37. 37. • • Lglob • • Lemi • • n 37 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 ∑
  38. 38. • • 38 Ispec = max N⋅H, 0( )Kspec ⊗ Lspec Ispec = cos π max N⋅H, 0( )( )Kspec ⊗ Lspec
  39. 39. 39
  40. 40. 40
  41. 41. 41
  42. 42. • • • • • • • • Light Mapping 42
  43. 43. Light Mapping Light Mapping Light Mapping 43
  44. 44. 44
  45. 45. 45
  46. 46. 46 • • (Flat) • • flat • • (Gouraud) • • • • (Phong) • •
  47. 47. (Flat) • • • OpenGL • • • 47
  48. 48. (Gouraud) • • • • • • 48
  49. 49. 49 (Phong) • • • • •
  50. 50. 50
  51. 51. 51
  52. 52. P C P C P C P C P ,P ,P C ,C ,C • (P0, P1, P2, gl_Position ) (C0, C1, C2, ) • P C 52
  53. 53. • P = (x, y) u = P1 P0, v = P2 P0 (u, v) 53 xx + yy = uu+ vv + P0 x = 1,0( ) y = 0,1( ) u = xu, yu( ) v = xv, yv( )x y O u v x y u=P P v=P P (x, y) = (u, v) P
  54. 54. C C C C u v 54 C = u C1 −C0( )+ v C2 −C0( )+C0 = 1−u− v( )C0 +uC1 + vC2 • • u, v x = uxu + vxv + x0 y = uyu + vyv + y0 ! " # u = x − x0( )yv − y − y0( )xv xuyv − xv yu v = y − y0( )xu − x − x0( )yu xuyv − xv yu " # $ $ % $ $
  55. 55. 55
  56. 56. • P AB Q 56 xq = xa za 1−t( )+ xb zb t 1 za 1−t( )+ 1 zb t zq = 1 1 za 1−t( )+ 1 zb t O x z A=(xa,za) B=(xb,zb) C P D Q=(xq,zq) y = h h t 1−t
  57. 57. P =(x1 ,y1 ,z1 ,w1 ) C P =(x0 ,y0 ,z0 ,w0 ) C P =(x2 ,y2 ,z2 ,w2 ) C C u v 57 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
  58. 58. 58
  59. 59. // GLuint program = glCreateProgram(); … ( , , ) // glBindAttribLocation(program, 0, "pv"); glBindFragDataLocation(program, 0, "fc"); glLinkProgram(program); … // uniform mc -1 GLint mcLoc = glGetUniformLocation(program, "mc"); 59
  60. 60. // GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); 60
  61. 61. // GLuint vbo[1]; glGenBuffers(1, vbo); 61
  62. 62. // static const GLfloat pv[][3] = { { -1.0f, -0.8660254f, 0.0f }, { 1.0f, -0.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); // index == 0 in glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); 62
  63. 63. // glUseProgram(program); // uniform mc ( ) glUniformMatrix4fv(mcLoc, 1, GL_FALSE, mc); // glBindVertexArray(vao); // glDrawArrays(GL_TRIANGLES, 0, points); 63
  64. 64. #version 150 core in vec4 pv; uniform mat4 mc; void main(void) { gl_Position = mc * pv; } #version 150 core out vec4 fc; void main(void) { fc = vec4(1.0, 0.0, 0.0, 1.0); } 64
  65. 65. in (attribute) // GLuint program = glCreateProgram(); … ( , , ) glLinkProgram(program); … // in (attribute) cv -1 GLint cvLoc = glGetAttribLocation(program, ”cv"); // uniform mc -1 GLint mcLoc = glGetUniformLocation(program, "mc"); 65
  66. 66. // GLuint vao; glGenVertexArrays(1, &vao); glBindVertexArray(vao); 66
  67. 67. // GLuint vbo[2]; glGenBuffers(2, vbo); 67
  68. 68. // static const GLfloat pv[][3] = { { -1.0f, -0.8660254f, 0.0f }, { 1.0f, -0.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); // index == 0 in glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(0); 68
  69. 69. // static const GLfloat cv[][3] = { { 1.0f, 0.0f, 0.0f }, // { 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); // index == cvLoc in glVertexAttribPointer(cvLoc, 3, GL_FLOAT, GL_FALSE, 0, 0); glEnableVertexAttribArray(cvLoc); 69
  70. 70. // glUseProgram(program); // uniform mc ( ) glUniformMatrix4fv(mcLoc, 1, GL_FALSE, mc); // glBindVertexArray(vao); // glDrawArrays(GL_TRIANGLES, 0, points); 70
  71. 71. #version 150 core in vec4 pv; in vec4 cv; uniform mat4 mc; out vec4 vc; void main(void) { vc = cv; gl_Position = mc * pv; } #version 150 core in vec4 vc; out vec4 fc; void main(void) { fc = vc; } 71
  72. 72. #version 150 core out vec4 c1; smooth out vec4 c2; noperspective out vec4 c3; flat out vec4 c4; #version 150 core in vec4 c1; smooth in vec4 c2; noperspective in vec4 c3; flat in vec4 c4; 72
  73. 73. • attribute • https://github.com/tokoik/ggsample06 • c n out vc • 30 20 Blinn • simple.vert • simple.vert • tokoi@sys.wakayama-u.ac.jp 73
  74. 74. main.cpp // static const GLfloat cv[][3] = { { 1.0f, 0.0f, 0.0f }, // { 0.0f, 1.0f, 0.0f }, // { 0.0f, 0.0f, 1.0f } // }; // static const GLfloat nv[][3] = { { -0.086172748f, -0.049751860f, 0.99503719f }, { 0.086172748f, -0.049751860f, 0.99503719f }, { 0.0f, 0.099503719f, 0.99503719f } }; // cv glBindBuffer(GL_ARRAY_BUFFER, vbo[1]); // cv nv glBufferData(GL_ARRAY_BUFFER, sizeof cv, cv, GL_STATIC_DRAW); 74
  75. 75. GLSL • normalize(v) • v h = normalize(l + v); // h l v • v3 = v1 * v2; // v1 v2 • float f; v2 = v1 * f; // v1 f • v2 = v1 * 2.0 + 1.0; // v1 2 1 • swizzling vec4 v1 = vec4(4.0, 3.0, 2.0, 1.0); vec3 v2 = v1.wxy; // v2.x←v1.w,v2.y←v1.x,v2.z←v1.y 75
  76. 76. 76

×