ゲームグラフィックス特論 第5回
Post on 25-Jun-2015
2.094 Views
Preview:
DESCRIPTION
TRANSCRIPT
5 (3)
2
3
4
(0, 0)
(1, 1)
s
t
CPU
5
ccoossφφcosφy
O x x
z
OO θccoossθθcosθ
ssiinnθθsinθ
φ
ssiinnφφsinφ
ssiinnφφsinφ
#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; !}
6
7
y
O x x
z
OO θccoossθθcosθ
ssiinnθθsinθ
h
#version 150 core !in vec2 parameter; // CPU !uniform mat4 mc; // !!void main(void) !{ ! float th = 6.283185 * parameter.s; // [0,1]→[0,2π] ! float y = parameter.t * 2.0 - 1.0; // [0,1]→[-1,1] !! vec4 p = vec3(cos(th), y, sin(th), 1.0); !! gl_Position = mc * p; !} !
8
9
• •
• •
•
• • •
• • CPU
• (attribute)
GPU
10
• •
•
11
P0
P1
t = t0t = t1
P(t)t
12
t0 t1 t
P0
P1
P(t)
t ∈ t0, t1[ ]s t( ) = t − t0( ) t1 − t0( )P t( ) = 1− s t( )( )P0 + s t( )P1
#version 150 core !in vec4 p0, p1; // !uniform float t; // !uniform mat4 mc; // !void main(void) !{ ! gl_Position = mc * mix(p0, p1, t); !} !!
13
// program = glCreateProgram(); ! … ( , , ) // in (attribute) p1 -1GLint p1Loc = glGetAttribLocation(program, "p1"); !!// p1 GLuint p1Buf; !glGenBuffers(1, &p1Buf); !glBindBuffer(GL_ARRAY_BUFFER, p1Buf); !glBufferData(GL_ARRAY_BUFFER, ! sizeof (GLfloat[3]) * vertices, p1, GL_STATIC_DRAW); !
attribute
14
// 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); !
15
Pi
P1
Pk
PN PDiDk
D1
16
Di = Pi −PN
PN: Pi: Di: wi: i
P = PN + wiDii=1
k
∑
17
M1
M2
•
18
•
•
•
•
19
M1
M2
��������
•
•
•
20
M1
M2
BlendM1 and M2
•
• M1 M2
• M1
M2
21
O
1
z
x
M1
M0
B1(t)
B0(t)
P u(t)
22
M0, M1 B0(t), B1(t)
23
O
z
xB1(t) PM1
B0(t) PM0
P u(t)z
x
PM0
O
PM1
u(t) = w0B0(t)M0 P + w1B1(t)M1 P
w0
w1
P
24
•
• c • d w
•
• n
w =1
(d+ 1)c
u (t) =n�1X
i=0
wiB (t)M�1i P
n�1X
i=0
wi = 1, wi � 0P0
P1
d
P
P0
P1
P0
P1
P
P
t
t > 1d
d
25
V1 = P1 −P0V2 = P−P0
t = V1 ⋅V2V12
d = V2 −V1t
d =V2
V2 −V1tV2 −V1
"
#$
%$
t ≤ 0( )0 < t <1( )t ≥1( )
#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 = -16.0; // !!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 -= v1 * clamp(dot(v1, v2) / l, 0.0, 1.0); ! u += pow(length(v2) + 1.0, exponent) * blendMatrix[i] * p; // ! } ! gl_Position = projectionMatrix * u; !} !
26
GLSL • 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
27
• P0, P1 P d
28
V1 = P1 −P0V2 = P−P0
t = V1 ⋅V2V12
d = V2 −V1t V2
V1
Pt
dQ
P0
P1
•
• https://github.com/tokoik/ggsample05
• cylinder.h p0
• p1
• main.cpp p1 GPU simple.vert
• main.cpp simple.vert
• tokoi@sys.wakayama-u.ac.jp
29
30
top related