-
Notifications
You must be signed in to change notification settings - Fork 7
/
math_quat.vert
70 lines (52 loc) · 1.5 KB
/
math_quat.vert
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#ifdef GL_ES
precision mediump float;
#endif
uniform mat4 u_modelViewProjectionMatrix;
uniform mat4 u_projectionMatrix;
uniform mat4 u_modelMatrix;
uniform mat4 u_viewMatrix;
uniform mat3 u_normalMatrix;
uniform float u_time;
attribute vec4 a_position;
varying vec4 v_position;
#ifdef MODEL_VERTEX_COLOR
attribute vec4 a_color;
varying vec4 v_color;
#endif
#ifdef MODEL_VERTEX_NORMAL
attribute vec3 a_normal;
varying vec3 v_normal;
#endif
#ifdef MODEL_VERTEX_TEXCOORD
attribute vec2 a_texcoord;
#endif
varying vec2 v_texcoord;
#include "lygia/math/quat.glsl"
#include "lygia/math/quat/mul.glsl"
#include "lygia/math/quat/2mat3.glsl"
#include "lygia/math/quat/2mat4.glsl"
#include "lygia/math/quat/conj.glsl"
#include "lygia/math/quat/lerp.glsl"
void main(void) {
v_position = a_position;
v_texcoord = a_position.xy * 0.5 + 0.5;
QUAT Q = QUAT_IDENTITY;
QUAT up = quat(vec3(0.0, 0.75, 1.0));
QUAT down = quat(vec3(0.0, -0.75, 1.0));
QUAT spin = quat(vec3(0, 1, 0), u_time);
Q = quatLerp(up, down, sin(u_time) * 0.5 + 0.5);
Q = quatMul(Q, spin);
// Q = quatConj(Q);
mat3 M = quat2mat3(Q);
v_position.xyz = M * v_position.xyz;
#ifdef MODEL_VERTEX_NORMAL
v_normal = M * vec4(u_modelMatrix * vec4(a_normal, 0.0) ).xyz;
#endif
#ifdef MODEL_VERTEX_COLOR
v_color = a_color;
#endif
#ifdef MODEL_VERTEX_TEXCOORD
v_texcoord = a_texcoord;
#endif
gl_Position = u_projectionMatrix * u_viewMatrix * u_modelMatrix * v_position;
}