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

764 views

Published on

モーフィング、バーテックスブレンディング

Published in: Education
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
764
On SlideShare
0
From Embeds
0
Number of Embeds
17
Actions
Shares
0
Downloads
38
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

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

  1. 1. 128 9 9.1 in (attribute) gl_Position gl_Position 102 103 (a)
  2. 2. 129 103 float*parameter[(SLICES*+*1)***(STACKS*+*1)][2];* * for*(int*j*=*0;*j*<=*STACKS;*++j)* {* **for*(int*i*=*0;*i*<=*SLICES;*++i)* **{* ****int*k*=*i*+*j***(SLICES*+*1);* ****float*s*=*(float)i*/*(float)SLICES;* ****float*t*=*(float)j*/*(float)STACKS;* * ****attribute[k][0]*=*s;**//*[0,1]* * ****attribute[k][1]*=*t;**//*[0,1]* * **}* }* parameter (VBO) GLuint*parameterBuf;* glGenBuffers(1,*&parameterBuf);* glBindBuffer(GL_ARRAY_BUFFER,*parameterBuf);* glBufferData(GL_ARRAY_BUFFER,*sizeof*parameter,*parameter,*GL_STATIC_DRAW);* //*in*(attribute)* *parameter* * GLint*parameterLoc*=*glGetAttribLocation(program,*"p1");* * //* * glBindVertexArray(vao);* ** //* * glBindBuffer(GL_ARRAY_BUFFER,*parameterBuf);* glVertexAttribPointer(parameterLoc,*2,*GL_FLOAT,*GL_FALSE,*0,*0);* glEnableVertexAttribArray(parameterLoc);* (0, 0) (1, 1) (a) GPUに送る頂点属性 (b) 描画する図形 s t SLICES STACKS
  3. 3. 130 * //* * glDrawArrays(GL_POINTS,*0,*(SLICES*+*1)***(STACKS*+*1));* program [0, 1] s t [0, 2π], [0, π] 104 #version*150*core* in*vec2*parameter;*******//*CPU* * uniform*mat4*mc;*********//* * * void*main(void)* {* **float*th*=*6.283185***parameter.s;**//*[0,1] [0,2 ]* **float*ph*=*3.141593***parameter.t;**//*[0,1] [0, ]* **float*r*=*sin(ph);* * **vec4*p*=*vec4(r***cos(th),*cos(ph),*r***sin(th),*1.0);* * **gl_Position*=*mc***p;* }* [0, 1] s t [0, 2π], [-1, 1] s t ccoossφφcosφ y O x x z OO θ ccoossθθcosθ ssiinnθθsinθ φ ssiinnφφsinφ ssiinnφφsinφ
  4. 4. 131 105 #version*150*core* in*vec2*parameter;*******//*CPU* *attribute* uniform*mat4*mc;*********//* * ** *void*main(void)* *{* ***float*th*=*6.283185***parameter.s;**//*[0,1] [0,2 ]* ***float*y*=*parameter.t***2.0*K*1.0;**//*[0,1] [K1,1]* ** ***vec4*p*=*vec3(cos(th),*y,*sin(th),*1.0);* ** ***gl_Position*=*mc***p;* *}* ** 9.2 glDrawArrays() glDrawElements() uniform (CPU) GPU GPU 9.2.1 y O x x z OO θ ccoossθθcosθ ssiinnθθsinθ h
  5. 5. 132 106 106 t0 P0 v P1 t P(t) (72) 0 s(t) 1 t0 = 0, t1 = 1 mix(p0, p1, t) GLSL p0 * (1 − t) + p1 * t #version*150*core* in*vec4*p0,*p1;*********//* * uniform*float*t;********//* * uniform*mat4*mc;********//* * void*main(void)* {* **gl_Position*=*mc***mix(p0,*p1,*t);* }* gl_Position p0, p1 p0 t0 = 0 ( ) (VBO) t1 = 1 ( ) p1 vertices //*p1* * GLuint*p1Buf;* glGenBuffers(1,*&p1Buf);* glBindBuffer(GL_ARRAY_BUFFER,*p1Buf);* glBufferData(GL_ARRAY_BUFFER,* **sizeof*(GLfloat[3])***vertices,*p1,*GL_STATIC_DRAW);* P0 P1 t = t0 t = t1 P(t) t t 2 [t0, t1] s(t) = t t0 t1 t0 P(t) = (1 s(t))P0 + s(t)P1
  6. 6. 133 program in p1 //*in*(attribute)* *p1* *K1 * GLint*p1Loc*=*glGetAttribLocation(program,*"p1");* p0 p1 in p1 lines //* * glBindVertexArray(vao);* * //* *in*(attribute)* *p1* * glBindBuffer(GL_ARRAY_BUFFER,*p1Buf);* glVertexAttribPointer(p1Loc,*3,*GL_FLOAT,*GL_FALSE,*0,*0);* glEnableVertexAttribArray(p1Loc);* * //* * glDrawElements(GL_LINES,*lines,*GL_UNSIGNED_INT,*0);* 9.2.2 ( ) 107 PN i Pi Pi P1 Pk PN P Di Dk D1
  7. 7. 134 Di (73) P wi i (74) 9.3 CG 9.3.1 ( ) 108 M1, M2 108 ( ) Di = Pi PN P = PN + kX i=1 wiDi M1 M2
  8. 8. 135 109 9.3.2 110 M0, M1 M0, M1 Z 1 111 111 M0, M1 ( ) B0(t), B1(t) t M1 M2 M1 M2 Blend M1 and M2
  9. 9. 136 111 P u(t) P M0 -1 , M1 -1 ( 112) 112 B0(t), B1(t) P ( 113) O 1 z x M1 M0 B1(t) B0(t) P u(t) O z x P z x PM0 O PM1
  10. 10. 137 113 w0, w1 u(t) (75) n u(t) (76) wi (77) wi P i P i 114 114 (a) P0, P1 O z x B1(t) PM1 B0(t) PM0 u(t) z xO w0 w1 u(t) = w0B0(t)M 1 0 P + w1B1(t)M 1 1 P u(t) = n 1X i=0 wiBi(t)M 1 i P n 1X i=0 wi = 1, wi 0 P0 P1 P0 P1 P P t t >1d d (a) 点とボーンの軸との距離 (b) 点とボーンの端点との距離
  11. 11. 138 P d (78) 114 (b) P P0P1 d P d t (79) t [0, 1] (t < 0 t = 0, t > 1 t = 1) GLSL clamp(x, min, max) clamp(t, 0, 1) d wi (80) d 1 (…) 0 c 16 64 c P wi (77) P Bi(t)Mi -1 P w 1 (76) u(t) w wi u(t) wi (77) (81) " wi #version*150*core* in*vec4*position;* //* * uniform*mat4*modelViewMatrix;* //* * uniform*mat4*projectionMatrix;* //* * * //* * const*int*MAXBONES*=*8;* uniform*int*numberOfBones;* //* * uniform*vec4*p0[MAXBONES];* //* *( )* uniform*vec4*p1[MAXBONES];* //* *( )* uniform*mat4*blendMatrix[MAXBONES];* //*Bi***inverse(Mi)*(CPU )* const*float*exponent*=*K16.0;* //* * V1 = P1 P0 V2 = P P0 t = V1 · V2 V2 1 d = |V2 V1t| , d = 8 < : |V2| (t  0) |V2 V1t| (0 < t < 1) |V2 V1| (t 1) wi = (d + 1) c u(t) = X i wi 0 B B @ xi yi zi 1 1 C C A = 0 B B @ P i wixiP i wiyiP i wiziP i wi 1 C C A ) 0 B @ P i wiP i wi xi P i wiP i wi yi P i wiP i wi zi 1 C A
  12. 12. 139 * void*main()* {* **vec4*p*=*modelViewMatrix***position,*u*=*vec4(0.0);* **for*(int*i*=*0;*i*<*numberOfBones;*++i)* **{* ****vec4*v1*=*p1[i]*–*p0[i],*v2*=*p*–*p0[i];* ****float*l*=*dot(v1,*v1);* ****if*(l*>*0.0)*v2*K=*v1***clamp(dot(v1,*v2)*/*l,*0.0,*1.0);**//*v2*–*v1*t* ****u*+=*pow(length(v2)*+*1.0,*exponent)***blendMatrix[i]***p;*//* * **}* **gl_Position*=*projectionMatrix***u;* }* " sin(x), cos(x) , x (radian) pow(x, y) , xy mix(v1, v2, t) v1 v2 t v1 * (1 - t) + v2 * t dot(v1, v2) v1, v2 cross(v1, v2) length(v) v clamp(v, min, max) v < min min, v > max max, v

×