1 varying vec3 local_pos;
3 #define PI 3.141592653589793
4 #define TWO_PI (2.0 * PI)
6 float fbm(vec3 p, int octaves);
12 vec3 lpos = normalize(local_pos);
14 float cval = clouds(lpos * vec3(4.5, 4.5, 4.5));
15 float alt = min(lpos.y * 2.0 + 0.5, 1.0);
17 //const vec3 col_hor = vec3(0.96, 0.55, 0.98);
18 const vec3 col_hor = vec3(0.95, 0.38, 0.54);
19 const vec3 col_zen = vec3(0.08, 0.18, 0.4);
21 vec3 skycol = mix(col_hor, col_zen, alt);
23 gl_FragColor.rgb = mix(skycol, vec3(0.0, 0.0, 0.0), cval);
27 const float cloud_dens = 0.25;
28 const float cloud_smooth = 1.0;
29 const float cloud_alpha = 0.4;
33 float hor = clamp(p.y * 2.0, 0.0, 1.0);
34 float nval = fbm(p * vec3(0.2, 1.0, 0.2), 5);
35 float res = smoothstep(cloud_dens - cloud_smooth * 0.5,
36 cloud_dens + cloud_smooth * 0.5, nval);
37 return res * hor * cloud_alpha;
40 float fbm(vec3 p, int octaves)
46 for(int i=0; i<octaves; i++) {
47 res += snoise(p * freq) * s;
55 // Description : Array and textureless GLSL 2D/3D/4D simplex
57 // Author : Ian McEwan, Ashima Arts.
59 // Lastmod : 20110822 (ijm)
60 // License : Copyright (C) 2011 Ashima Arts. All rights reserved.
61 // Distributed under the MIT License. See LICENSE file.
62 // https://github.com/ashima/webgl-noise
66 return x - floor(x * (1.0 / 289.0)) * 289.0;
70 return x - floor(x * (1.0 / 289.0)) * 289.0;
73 vec4 permute(vec4 x) {
74 return mod289(((x*34.0)+1.0)*x);
77 vec4 taylorInvSqrt(vec4 r)
79 return 1.79284291400159 - 0.85373472095314 * r;
84 const vec2 C = vec2(1.0/6.0, 1.0/3.0) ;
85 const vec4 D = vec4(0.0, 0.5, 1.0, 2.0);
88 vec3 i = floor(v + dot(v, C.yyy) );
89 vec3 x0 = v - i + dot(i, C.xxx) ;
92 vec3 g = step(x0.yzx, x0.xyz);
94 vec3 i1 = min( g.xyz, l.zxy );
95 vec3 i2 = max( g.xyz, l.zxy );
97 // x0 = x0 - 0.0 + 0.0 * C.xxx;
98 // x1 = x0 - i1 + 1.0 * C.xxx;
99 // x2 = x0 - i2 + 2.0 * C.xxx;
100 // x3 = x0 - 1.0 + 3.0 * C.xxx;
101 vec3 x1 = x0 - i1 + C.xxx;
102 vec3 x2 = x0 - i2 + C.yyy; // 2.0*C.x = 1/3 = C.y
103 vec3 x3 = x0 - D.yyy; // -1.0+3.0*C.x = -0.5 = -D.y
107 vec4 p = permute( permute( permute(
108 i.z + vec4(0.0, i1.z, i2.z, 1.0 ))
109 + i.y + vec4(0.0, i1.y, i2.y, 1.0 ))
110 + i.x + vec4(0.0, i1.x, i2.x, 1.0 ));
112 // Gradients: 7x7 points over a square, mapped onto an octahedron.
113 // The ring size 17*17 = 289 is close to a multiple of 49 (49*6 = 294)
114 float n_ = 0.142857142857; // 1.0/7.0
115 vec3 ns = n_ * D.wyz - D.xzx;
117 vec4 j = p - 49.0 * floor(p * ns.z * ns.z); // mod(p,7*7)
119 vec4 x_ = floor(j * ns.z);
120 vec4 y_ = floor(j - 7.0 * x_ ); // mod(j,N)
122 vec4 x = x_ *ns.x + ns.yyyy;
123 vec4 y = y_ *ns.x + ns.yyyy;
124 vec4 h = 1.0 - abs(x) - abs(y);
126 vec4 b0 = vec4( x.xy, y.xy );
127 vec4 b1 = vec4( x.zw, y.zw );
129 //vec4 s0 = vec4(lessThan(b0,0.0))*2.0 - 1.0;
130 //vec4 s1 = vec4(lessThan(b1,0.0))*2.0 - 1.0;
131 vec4 s0 = floor(b0)*2.0 + 1.0;
132 vec4 s1 = floor(b1)*2.0 + 1.0;
133 vec4 sh = -step(h, vec4(0.0));
135 vec4 a0 = b0.xzyw + s0.xzyw*sh.xxyy ;
136 vec4 a1 = b1.xzyw + s1.xzyw*sh.zzww ;
138 vec3 p0 = vec3(a0.xy,h.x);
139 vec3 p1 = vec3(a0.zw,h.y);
140 vec3 p2 = vec3(a1.xy,h.z);
141 vec3 p3 = vec3(a1.zw,h.w);
143 //Normalise gradients
144 vec4 norm = taylorInvSqrt(vec4(dot(p0,p0), dot(p1,p1), dot(p2, p2), dot(p3,p3)));
150 // Mix final noise value
151 vec4 m = max(0.6 - vec4(dot(x0,x0), dot(x1,x1), dot(x2,x2), dot(x3,x3)), 0.0);
153 return 42.0 * dot( m*m, vec4( dot(p0,x0), dot(p1,x1),
154 dot(p2,x2), dot(p3,x3) ) );
157 #pragma glslify: export(snoise)