1 uniform vec3 horiz_color, mid_color, zenith_color, fog_color;
3 const float mid_point = 0.25;
4 const float horiz_scale = 20.0;
6 vec3 sky_grad(float t, float mid);
7 float pnoise(float p, float rep);
8 float fbm(float p, int octaves, float rep);
12 float tx = gl_TexCoord[0].x;
13 float ty = 1.0 - gl_TexCoord[0].y;
14 vec3 color = sky_grad(ty, mid_point);
16 float horiz = ty + fbm(tx * horiz_scale, 4, horiz_scale) * 0.035;
17 color = mix(fog_color, color, smoothstep(0.034, 0.035, horiz));
19 gl_FragColor.rgb = color;
23 vec3 sky_grad(float t, float mid)
25 float t_low = min(t / mid, 1.0);
26 float t_high = min((1.0 - t) / (1.0 - mid), 1.0);
28 return mix(zenith_color, mix(horiz_color, mid_color, t_low), t_high);
31 float pnoise(vec2 p, vec2 rep);
33 float pnoise(float p, float rep)
35 return pnoise(vec2(p, 0.0), vec2(rep, rep));
38 float fbm(float p, int octaves, float rep)
44 for(int i=0; i<octaves; i++) {
45 res += pnoise(p * freq, rep * freq) * scale;
53 // GLSL textureless classic 2D noise "cnoise",
54 // with an RSL-style periodic variant "pnoise".
55 // Author: Stefan Gustavson (stefan.gustavson@liu.se)
56 // Version: 2011-08-22
58 // Many thanks to Ian McEwan of Ashima Arts for the
59 // ideas for permutation and gradient selection.
61 // Copyright (c) 2011 Stefan Gustavson. All rights reserved.
62 // Distributed under the MIT license. See LICENSE file.
63 // https://github.com/stegu/webgl-noise
68 return x - floor(x * (1.0 / 289.0)) * 289.0;
73 return mod289(((x*34.0)+1.0)*x);
76 vec4 taylor_inv_sqrt(vec4 r)
78 return 1.79284291400159 - 0.85373472095314 * r;
82 return t*t*t*(t*(t*6.0-15.0)+10.0);
85 // Classic perlin noise
88 vec4 pi = floor(p.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
89 vec4 pf = fract(p.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
90 pi = mod289(pi); // To avoid truncation effects in permutation
96 vec4 i = permute(permute(ix) + iy);
98 vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
99 vec4 gy = abs(gx) - 0.5 ;
100 vec4 tx = floor(gx + 0.5);
103 vec2 g00 = vec2(gx.x,gy.x);
104 vec2 g10 = vec2(gx.y,gy.y);
105 vec2 g01 = vec2(gx.z,gy.z);
106 vec2 g11 = vec2(gx.w,gy.w);
108 vec4 norm = taylor_inv_sqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
114 float n00 = dot(g00, vec2(fx.x, fy.x));
115 float n10 = dot(g10, vec2(fx.y, fy.y));
116 float n01 = dot(g01, vec2(fx.z, fy.z));
117 float n11 = dot(g11, vec2(fx.w, fy.w));
119 vec2 fade_xy = fade(pf.xy);
120 vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
121 float n_xy = mix(n_x.x, n_x.y, fade_xy.y);
125 // Classic perlin noise, periodic variant
126 float pnoise(vec2 p, vec2 rep)
128 vec4 pi = floor(p.xyxy) + vec4(0.0, 0.0, 1.0, 1.0);
129 vec4 pf = fract(p.xyxy) - vec4(0.0, 0.0, 1.0, 1.0);
130 pi = mod(pi, rep.xyxy); // To create noise with explicit period
131 pi = mod289(pi); // To avoid truncation effects in permutation
137 vec4 i = permute(permute(ix) + iy);
139 vec4 gx = fract(i * (1.0 / 41.0)) * 2.0 - 1.0 ;
140 vec4 gy = abs(gx) - 0.5 ;
141 vec4 tx = floor(gx + 0.5);
144 vec2 g00 = vec2(gx.x,gy.x);
145 vec2 g10 = vec2(gx.y,gy.y);
146 vec2 g01 = vec2(gx.z,gy.z);
147 vec2 g11 = vec2(gx.w,gy.w);
149 vec4 norm = taylor_inv_sqrt(vec4(dot(g00, g00), dot(g01, g01), dot(g10, g10), dot(g11, g11)));
155 float n00 = dot(g00, vec2(fx.x, fy.x));
156 float n10 = dot(g10, vec2(fx.y, fy.y));
157 float n01 = dot(g01, vec2(fx.z, fy.z));
158 float n11 = dot(g11, vec2(fx.w, fy.w));
160 vec2 fade_xy = fade(pf.xy);
161 vec2 n_x = mix(vec2(n00, n01), vec2(n10, n11), fade_xy.x);
162 float n_xy = mix(n_x.x, n_x.y, fade_xy.y);