forked from patriciogonzalezvivo/thebookofshaders
-
Notifications
You must be signed in to change notification settings - Fork 0
/
matrices.frag
83 lines (71 loc) · 1.83 KB
/
matrices.frag
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
71
72
73
74
75
76
77
78
79
80
81
82
83
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.1415926535897932384626433832795
#define PI_2 1.57079632679489661923
#define PI_4 0.785398163397448309616
#define PI180 .017453293
float PHI = (1.0+sqrt(5.0))/2.0;
float sind(float a){return sin(a * PI180);}
float cosd(float a){return cos(a * PI180);}
uniform vec2 u_resolution;
uniform float u_time;
mat2 rotate2D(float angle){
return mat2(cos(angle),-sin(angle),
sin(angle),cos(angle));
}
mat3 rotateX3D(float phi){
return mat3(
vec3(1.,0.,0.),
vec3(0.,cos(phi),-sin(phi)),
vec3(0.,sin(phi),cos(phi)));
}
mat4 rotateX4D(float phi){
return mat4(
vec4(1.,0.,0.,0),
vec4(0.,cos(phi),-sin(phi),0.),
vec4(0.,sin(phi),cos(phi),0.),
vec4(0.,0.,0.,1.));
}
mat3 rotateY3D(float theta){
return mat3(
vec3(cos(theta),0.,-sin(theta)),
vec3(0.,1.,0.),
vec3(sin(theta),0.,cos(theta)));
}
mat4 rotateY4D(float theta){
return mat4(
vec4(cos(theta),0.,-sin(theta),0),
vec4(0.,1.,0.,0.),
vec4(sin(theta),0.,cos(theta),0.),
vec4(0.,0.,0.,1.));
}
mat3 rotateZ3D(float psi){
return mat3(
vec3(cos(psi),-sin(psi),0.),
vec3(sin(psi),cos(psi),0.),
vec3(0.,0.,1.));
}
mat4 rotateZ4D(float psi){
return mat4(
vec4(cos(psi),-sin(psi),0.,0),
vec4(sin(psi),cos(psi),0.,0.),
vec4(0.,0.,1.,0.),
vec4(0.,0.,0.,1.));
}
mat4 scale4D(float x, float y, float z){
return mat4(
vec4(x, 0.0, 0.0, 0.0),
vec4(0.0, y, 0.0, 0.0),
vec4(0.0, 0.0, z, 0.0),
vec4(0.0, 0.0, 0.0, 1.0)
);
}
mat4 translate4D(float x, float y, float z){
return mat4(
vec4(1.0, 0.0, 0.0, 0.0),
vec4(0.0, 1.0, 0.0, 0.0),
vec4(0.0, 0.0, 1.0, 0.0),
vec4(x, y, z, 1.0)
);
}