1767b42e5c240f1e22f0768413e568bea0a5497d
[lighthouse] / sdr / sky.f.glsl
1 float pnoise(vec2 P, vec2 rep);
2 float pnoise_octaves();
3
4 void main()
5 {
6         float alt = min((gl_TexCoord[0].y + 0.29)* 2.0, 1.0);
7         float cloud_dens = 0.5; 
8
9         //const vec3 col_hor = vec3(0.96, 0.55, 0.98);
10         const vec3 col_hor = vec3(0.95, 0.38, 0.54);
11         const vec3 col_zen = vec3(0.05, 0.15, 0.32);
12
13         gl_FragColor.rgb = mix(col_hor, col_zen, alt);
14         gl_FragColor.a = 1.0;
15 }
16
17
18 //
19 // GLSL textureless classic 2D noise "cnoise",
20 // with an RSL-style periodic variant "pnoise".
21 // Author:  Stefan Gustavson (stefan.gustavson@liu.se)
22 // Version: 2011-08-22
23 //
24 // Many thanks to Ian McEwan of Ashima Arts for the
25 // ideas for permutation and gradient selection.
26 //
27 // Copyright (c) 2011 Stefan Gustavson. All rights reserved.
28 // Distributed under the MIT license. See LICENSE file.
29 // https://github.com/ashima/webgl-noise
30 //
31
32 vec4 mod289(vec4 x)
33 {
34   return x - floor(x * (1.0 / 289.0)) * 289.0;
35 }
36
37 vec4 permute(vec4 x)
38 {
39   return mod289(((x*34.0)+1.0)*x);
40 }
41
42 vec4 taylorInvSqrt(vec4 r)
43 {
44   return 1.79284291400159 - 0.85373472095314 * r;
45 }
46
47 vec2 fade(vec2 t) {
48   return t*t*t*(t*(t*6.0-15.0)+10.0);
49 }
50
51 // Classic Perlin noise, periodic variant
52 float pnoise(vec2 P, vec2 rep)
53 {
54   vec4 Pi = floor(P.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
55   vec4 Pf = fract(P.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
56   Pi = mod(Pi, rep.xyxy); // To create noise with explicit period
57   Pi = mod289(Pi);        // To avoid truncation effects in permutation
58   vec4 ix = Pi.xzxz;
59   vec4 iy = Pi.yyww;
60   vec4 fx = Pf.xzxz;
61   vec4 fy = Pf.yyww;
62
63   vec4 i = permute(permute(ix) + iy);
64
65   vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
66   vec4 gy = abs(gx) - 0.5 ;
67   vec4 tx = floor(gx + 0.5);
68   gx = gx - tx;
69
70   vec2 g00 = vec2(gx.x,gy.x);
71   vec2 g10 = vec2(gx.y,gy.y);
72   vec2 g01 = vec2(gx.z,gy.z);
73   vec2 g11 = vec2(gx.w,gy.w);
74
75   vec4 norm = taylorInvSqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
76   g00 *= norm.x;
77   g01 *= norm.y;
78   g10 *= norm.z;
79   g11 *= norm.w;
80
81   float n00 = dot(g00, vec2(fx.x, fy.x));
82   float n10 = dot(g10, vec2(fx.y, fy.y));
83   float n01 = dot(g01, vec2(fx.z, fy.z));
84   float n11 = dot(g11, vec2(fx.w, fy.w));
85
86   vec2 fade_xy = fade(Pf.xy);
87   vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
88   float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
89   return 2.3 * n_xy;
90 }
91
92 #pragma glslify: export(pnoise)