diff options
Diffstat (limited to 'assets/shaders/Water2.frag.glsl')
-rw-r--r-- | assets/shaders/Water2.frag.glsl | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/assets/shaders/Water2.frag.glsl b/assets/shaders/Water2.frag.glsl new file mode 100644 index 00000000..39b6aa55 --- /dev/null +++ b/assets/shaders/Water2.frag.glsl | |||
@@ -0,0 +1,66 @@ | |||
1 | #ifdef GL_ES | ||
2 | precision highp float; | ||
3 | #endif | ||
4 | |||
5 | uniform sampler2D u_tex0; | ||
6 | uniform float u_time; | ||
7 | uniform vec2 u_resolution; | ||
8 | const float PI = 3.1415926535897932; | ||
9 | |||
10 | //speed | ||
11 | const float speed = 0.2; | ||
12 | const float speed_x = 0.3; | ||
13 | const float speed_y = 0.3; | ||
14 | |||
15 | // geometry | ||
16 | const float intensity = 3.; | ||
17 | const int steps = 8; | ||
18 | const float frequency = 4.0; | ||
19 | const int angle = 7; // better when a prime | ||
20 | |||
21 | // reflection and emboss | ||
22 | const float delta = 20.; | ||
23 | const float intence = 400.; | ||
24 | const float emboss = 0.3; | ||
25 | |||
26 | //---------- crystals effect | ||
27 | |||
28 | float col(vec2 coord) | ||
29 | { | ||
30 | float delta_theta = 2.0 * PI / float(angle); | ||
31 | float col = 0.0; | ||
32 | float theta = 0.0; | ||
33 | for (int i = 0; i < steps; i++) | ||
34 | { | ||
35 | vec2 adjc = coord; | ||
36 | theta = delta_theta*float(i); | ||
37 | adjc.x += cos(theta)*u_time*speed + u_time * speed_x; | ||
38 | adjc.y -= sin(theta)*u_time*speed - u_time * speed_y; | ||
39 | col = col + cos( (adjc.x*cos(theta) - adjc.y*sin(theta))*frequency)*intensity; | ||
40 | } | ||
41 | |||
42 | return cos(col); | ||
43 | } | ||
44 | |||
45 | //---------- main | ||
46 | |||
47 | void main(void) | ||
48 | { | ||
49 | vec2 p = (gl_FragCoord.xy) / u_resolution.xy, c1 = p, c2 = p; | ||
50 | float cc1 = col(c1); | ||
51 | |||
52 | c2.x += u_resolution.x/delta; | ||
53 | float dx = emboss*(cc1-col(c2))/delta; | ||
54 | |||
55 | c2.x = p.x; | ||
56 | c2.y += u_resolution.y/delta; | ||
57 | float dy = emboss*(cc1-col(c2))/delta; | ||
58 | |||
59 | c1.x += dx; | ||
60 | c1.y = -(c1.y+dy); | ||
61 | |||
62 | float alpha = 1.+dot(dx,dy)*intence; | ||
63 | gl_FragColor = texture2D(u_tex0,c1)*(alpha); | ||
64 | // gl_FragColor = vec4(col(p),0,0,1); | ||
65 | |||
66 | } | ||