1uniform float u_Time;
2uniform sampler2D u_Tex0;
3uniform sampler2D u_Tex1;
4uniform sampler2D u_Tex2;
5varying vec2 v_TexCoord;
6varying vec2 v_TexCoord2; // for the auxiliar texture
7uniform mat3 u_TextureMatrix;
8uniform vec2 u_MapCoords;
9uniform vec2 u_Resolution;
10const float PI = 3.1415926535897932;
11
12float speed = 3.0;
13float intensity = 0.75;
14float delta = 0.15;
15
16const float sampleDist = 0.8;
17const float sampleStrength = 1.1;
18
19float breathingImageCut = 0.2;
20
21const float heatSpeed = 0.05;
22const float speed_x = 0.04;
23const float speed_y = 0.03;
24
25// geometry
26const float heatIntensity = 20.;
27const int steps = 2;
28const float frequency = 3.0;
29const int angle = 20; // better when a prime
30
31// reflection and emboss
32const float heatDelta = 350.;
33const float intence = 100.0;
34const float emboss = 0.8;
35
36vec4 grayscale(vec4 color)
37{
38 float gray = dot(color.rgb, vec3(0.299, 0.587, 0.114));
39 return vec4(gray, gray, gray, 1);
40}
41
42//---------- crystals effect
43float col(vec2 coord)
44{
45 float delta_theta = 2.0 * PI / float(angle);
46 float col = 0.0;
47 float theta = 0.0;
48 for(int i = 0; i < steps; i++) {
49 vec2 adjc = coord;
50 theta = delta_theta*float(i);
51 adjc.x += cos(theta)*u_Time*heatSpeed + u_Time * speed_x;
52 adjc.y -= sin(theta)*u_Time*heatSpeed - u_Time * speed_y;
53 col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*heatIntensity;
54 }
55 return cos(col);
56}
57
58void main(void)
59{
60 vec2 auxTexCoord2 = v_TexCoord2;
61
62 breathingImageCut *= abs(sin(speed * 0.5 * u_Time) * delta);
63
64 // lets create a breathing effect
65 // lets cut out breathingImageCut of the image
66 auxTexCoord2.x *= (1.0 - breathingImageCut);
67 auxTexCoord2.y *= (1.0 - breathingImageCut);
68
69 auxTexCoord2.x += breathingImageCut/2.0;
70 auxTexCoord2.y += breathingImageCut/2.0;
71
72 // 0.5,0.5 is the center of the screen
73 // so substracting v_TexCoord from it will result in
74 // a vector pointing to the middle of the screen
75 vec2 dir = 0.5 - auxTexCoord2;
76
77 // calculate the distance to the center of the screen
78 float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
79
80 // normalize the direction (reuse the distance)
81 dir = dir/dist;
82
83 vec3 bgcol = grayscale(texture2D(u_Tex0, v_TexCoord)).xyz;
84 vec3 icycol = texture2D(u_Tex1, auxTexCoord2).xyz;
85
86 float t = dist * sampleStrength;
87 t = clamp(t ,0.0,1.0); //0 <= t <= 1
88
89 vec2 p = auxTexCoord2, c1 = p, c2 = p;
90 float cc1 = col(c1);
91
92 c2.x += u_Resolution.x/heatDelta;
93 float dx = emboss*(cc1-col(c2))/heatDelta;
94
95 c2.x = p.x;
96 c2.y += u_Resolution.y/heatDelta;
97 float dy = emboss*(cc1-col(c2))/heatDelta;
98
99 c1.x += dx;
100 c1.y += dy;
101
102 vec3 shadercol = texture2D(u_Tex1, c1).xyz;
103
104 intensity += sin(speed * u_Time) * delta;
105 vec3 col = mix(bgcol, shadercol, t * intensity);
106
107 gl_FragColor = vec4(col, 1.0);
108}
109