map_magma.frag

main 103 lines · 2.8 KB Raw
Alex Alex Commit Client Upload Part 1 19/10/2026 00:04
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
36//---------- crystals effect
37float col(vec2 coord)
38{
39 float delta_theta = 2.0 * PI / float(angle);
40 float col = 0.0;
41 float theta = 0.0;
42 for(int i = 0; i < steps; i++) {
43 vec2 adjc = coord;
44 theta = delta_theta*float(i);
45 adjc.x += cos(theta)*u_Time*heatSpeed + u_Time * speed_x;
46 adjc.y -= sin(theta)*u_Time*heatSpeed - u_Time * speed_y;
47 col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*heatIntensity;
48 }
49 return cos(col);
50}
51
52void main(void)
53{
54 vec2 auxTexCoord2 = v_TexCoord2;
55
56 breathingImageCut *= abs(sin(speed * 0.5 * u_Time) * delta);
57
58 // lets create a breathing effect
59 // lets cut out breathingImageCut of the image
60 auxTexCoord2.x *= (1.0 - breathingImageCut);
61 auxTexCoord2.y *= (1.0 - breathingImageCut);
62
63 auxTexCoord2.x += breathingImageCut/2.0;
64 auxTexCoord2.y += breathingImageCut/2.0;
65
66 // 0.5,0.5 is the center of the screen
67 // so substracting v_TexCoord from it will result in
68 // a vector pointing to the middle of the screen
69 vec2 dir = 0.5 - auxTexCoord2;
70
71 // calculate the distance to the center of the screen
72 float dist = sqrt(dir.x*dir.x + dir.y*dir.y);
73
74 // normalize the direction (reuse the distance)
75 dir = dir/dist;
76
77 vec3 bgcol = texture2D(u_Tex0, v_TexCoord).xyz;
78 vec3 icycol = texture2D(u_Tex1, auxTexCoord2).xyz;
79
80 float t = dist * sampleStrength;
81 t = clamp(t ,0.0,1.0); //0 &lt;= t &lt;= 1
82
83 vec2 p = auxTexCoord2, c1 = p, c2 = p;
84 float cc1 = col(c1);
85
86 c2.x += u_Resolution.x/heatDelta;
87 float dx = emboss*(cc1-col(c2))/heatDelta;
88
89 c2.x = p.x;
90 c2.y += u_Resolution.y/heatDelta;
91 float dy = emboss*(cc1-col(c2))/heatDelta;
92
93 c1.x += dx;
94 c1.y += dy;
95
96 vec3 shadercol = texture2D(u_Tex1, c1).xyz;
97
98 intensity += sin(speed * u_Time) * delta;
99 vec3 col = mix(bgcol, shadercol, t * intensity);
100
101 gl_FragColor = vec4(col, 1.0);
102}
103
Top