-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
64 lines (50 loc) · 1.61 KB
/
index.html
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
<link rel="stylesheet" href="styles.scss">
<script id="2d-fragment-shader" type="x-shader/x-fragment">
#ifdef GL_ES
precision mediump float;
#endif
#define PI 3.14159265359
uniform sampler2D u_image;
varying vec2 v_texCoord;
uniform vec2 u_resolution;
uniform vec2 u_mouse;
uniform float u_mass;
uniform float u_time;
uniform float u_clickedTime;
vec2 rotate(vec2 mt, vec2 st, float angle){
float cos = cos((angle + u_clickedTime) * PI); // try replacing * 1.0 with * PI
float sin = sin(angle * 0.0); // try removing the * 0.0
float nx = (cos * (st.x - mt.x)) + (sin * (st.y - mt.y)) + mt.x;
float ny = (cos * (st.y - mt.y)) - (sin * (st.x - mt.x)) + mt.y;
return vec2(nx, ny);
}
void main() {
vec2 st = vec2(gl_FragCoord.x, u_resolution.y - gl_FragCoord.y)/u_resolution;
vec2 mt = vec2(u_mouse.x, u_resolution.y - u_mouse.y)/u_resolution;
float dx = st.x - mt.x;
float dy = st.y - mt.y;
float dist = sqrt(dx * dx + dy * dy);
float pull = u_mass / (dist * dist);
vec3 color = vec3(0.0);
vec2 r = rotate(mt,st,pull);
vec4 imgcolor = texture2D(u_image, r);
color = vec3(
(imgcolor.x - (pull * 0.25)),
(imgcolor.y - (pull * 0.25)),
(imgcolor.z - (pull * 0.25))
);
gl_FragColor = vec4(color,1.);
}
</script>
<script id="2d-vertex-shader" type="x-shader/x-vertex">
attribute vec2 a_position;
attribute vec2 a_texCoord;
varying vec2 v_texCoord;
void main() {
gl_Position = vec4(a_position, 0, 1);
v_texCoord = a_texCoord;
}
</script>
<canvas id="glscreen"></canvas>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="index.js"></script>