@takram/three-clouds 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +5 -0
- package/README.md +1130 -0
- package/assets/local_weather.png +0 -0
- package/assets/shape.bin +1 -0
- package/assets/shape_detail.bin +1 -0
- package/assets/turbulence.png +0 -0
- package/build/index.cjs +583 -0
- package/build/index.cjs.map +1 -0
- package/build/index.js +728 -0
- package/build/index.js.map +1 -0
- package/build/r3f.cjs +2 -0
- package/build/r3f.cjs.map +1 -0
- package/build/r3f.js +205 -0
- package/build/r3f.js.map +1 -0
- package/build/shared.cjs +2189 -0
- package/build/shared.cjs.map +1 -0
- package/build/shared.js +3825 -0
- package/build/shared.js.map +1 -0
- package/package.json +77 -0
- package/src/CascadedShadowMaps.ts +288 -0
- package/src/CloudLayer.ts +85 -0
- package/src/CloudLayers.test.ts +61 -0
- package/src/CloudLayers.ts +181 -0
- package/src/CloudShape.ts +22 -0
- package/src/CloudShapeDetail.ts +22 -0
- package/src/CloudsEffect.ts +810 -0
- package/src/CloudsMaterial.ts +467 -0
- package/src/CloudsPass.ts +285 -0
- package/src/CloudsResolveMaterial.ts +108 -0
- package/src/DensityProfile.ts +38 -0
- package/src/LocalWeather.ts +21 -0
- package/src/PassBase.ts +28 -0
- package/src/Procedural3DTexture.ts +94 -0
- package/src/ProceduralTexture.ts +94 -0
- package/src/ShaderArrayPass.ts +32 -0
- package/src/ShadowMaterial.ts +141 -0
- package/src/ShadowPass.ts +185 -0
- package/src/ShadowResolveMaterial.ts +72 -0
- package/src/Turbulence.ts +21 -0
- package/src/bayer.ts +23 -0
- package/src/constants.ts +8 -0
- package/src/helpers/FrustumCorners.ts +138 -0
- package/src/helpers/setArrayRenderTargetLayers.ts +32 -0
- package/src/helpers/splitFrustum.ts +59 -0
- package/src/index.ts +14 -0
- package/src/qualityPresets.ts +117 -0
- package/src/r3f/CloudLayer.tsx +95 -0
- package/src/r3f/CloudLayers.tsx +54 -0
- package/src/r3f/Clouds.tsx +278 -0
- package/src/r3f/index.ts +2 -0
- package/src/shaders/catmullRomSampling.glsl +113 -0
- package/src/shaders/cloudShape.frag +78 -0
- package/src/shaders/cloudShapeDetail.frag +56 -0
- package/src/shaders/clouds.frag +996 -0
- package/src/shaders/clouds.glsl +190 -0
- package/src/shaders/clouds.vert +69 -0
- package/src/shaders/cloudsEffect.frag +11 -0
- package/src/shaders/cloudsResolve.frag +202 -0
- package/src/shaders/cloudsResolve.vert +10 -0
- package/src/shaders/localWeather.frag +83 -0
- package/src/shaders/parameters.glsl +64 -0
- package/src/shaders/perlin.glsl +211 -0
- package/src/shaders/shadow.frag +197 -0
- package/src/shaders/shadow.vert +16 -0
- package/src/shaders/shadowResolve.frag +76 -0
- package/src/shaders/shadowResolve.vert +10 -0
- package/src/shaders/structuredSampling.glsl +101 -0
- package/src/shaders/tileableNoise.glsl +88 -0
- package/src/shaders/turbulence.frag +51 -0
- package/src/shaders/types.glsl +18 -0
- package/src/shaders/varianceClipping.glsl +114 -0
- package/src/uniforms.ts +218 -0
- package/types/CascadedShadowMaps.d.ts +52 -0
- package/types/CloudLayer.d.ts +26 -0
- package/types/CloudLayers.d.ts +21 -0
- package/types/CloudShape.d.ts +5 -0
- package/types/CloudShapeDetail.d.ts +5 -0
- package/types/CloudsEffect.d.ts +170 -0
- package/types/CloudsMaterial.d.ts +86 -0
- package/types/CloudsPass.d.ts +44 -0
- package/types/CloudsResolveMaterial.d.ts +30 -0
- package/types/DensityProfile.d.ts +12 -0
- package/types/LocalWeather.d.ts +5 -0
- package/types/PassBase.d.ts +14 -0
- package/types/Procedural3DTexture.d.ts +20 -0
- package/types/ProceduralTexture.d.ts +24 -0
- package/types/ShaderArrayPass.d.ts +7 -0
- package/types/ShadowMaterial.d.ts +34 -0
- package/types/ShadowPass.d.ts +34 -0
- package/types/ShadowResolveMaterial.d.ts +20 -0
- package/types/Turbulence.d.ts +5 -0
- package/types/bayer.d.ts +4 -0
- package/types/constants.d.ts +6 -0
- package/types/helpers/FrustumCorners.d.ts +18 -0
- package/types/helpers/setArrayRenderTargetLayers.d.ts +3 -0
- package/types/helpers/splitFrustum.d.ts +9 -0
- package/types/index.d.ts +13 -0
- package/types/qualityPresets.d.ts +46 -0
- package/types/r3f/CloudLayer.d.ts +7 -0
- package/types/r3f/CloudLayers.d.ts +15 -0
- package/types/r3f/Clouds.d.ts +16 -0
- package/types/r3f/index.d.ts +2 -0
- package/types/uniforms.d.ts +66 -0
package/build/index.js
ADDED
@@ -0,0 +1,728 @@
|
|
1
|
+
import { C as w, a as R } from "./shared.js";
|
2
|
+
import { b as B, c as _, e as Y, D as q, g as V, f as X, h as k, i as j, d as K } from "./shared.js";
|
3
|
+
import { resolveIncludes as c } from "@takram/three-geospatial";
|
4
|
+
import { math as s } from "@takram/three-geospatial/shaders";
|
5
|
+
import { Camera as f, RawShaderMaterial as p, Uniform as v, GLSL3 as u, Mesh as y, PlaneGeometry as d, WebGL3DRenderTarget as E, RedFormat as I, LinearFilter as g, RepeatWrapping as i, NoColorSpace as T, WebGLRenderTarget as x, RGBAFormat as O, LinearMipMapLinearFilter as N } from "three";
|
6
|
+
class h {
|
7
|
+
constructor({ size: e, fragmentShader: o }) {
|
8
|
+
this.needsRender = !0, this.camera = new f(), this.size = e, this.material = new p({
|
9
|
+
glslVersion: u,
|
10
|
+
vertexShader: (
|
11
|
+
/* glsl */
|
12
|
+
`
|
13
|
+
in vec3 position;
|
14
|
+
out vec2 vUv;
|
15
|
+
void main() {
|
16
|
+
vUv = position.xy * 0.5 + 0.5;
|
17
|
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
18
|
+
}
|
19
|
+
`
|
20
|
+
),
|
21
|
+
fragmentShader: o,
|
22
|
+
uniforms: {
|
23
|
+
layer: new v(0)
|
24
|
+
}
|
25
|
+
}), this.mesh = new y(new d(2, 2), this.material), this.renderTarget = new E(e, e, e, {
|
26
|
+
depthBuffer: !1,
|
27
|
+
stencilBuffer: !1,
|
28
|
+
format: I
|
29
|
+
});
|
30
|
+
const n = this.renderTarget.texture;
|
31
|
+
n.minFilter = g, n.magFilter = g, n.wrapS = i, n.wrapT = i, n.wrapR = i, n.colorSpace = T, n.needsUpdate = !0;
|
32
|
+
}
|
33
|
+
dispose() {
|
34
|
+
this.renderTarget.dispose(), this.material.dispose();
|
35
|
+
}
|
36
|
+
render(e, o) {
|
37
|
+
if (!this.needsRender)
|
38
|
+
return;
|
39
|
+
this.needsRender = !1;
|
40
|
+
const n = e.getRenderTarget();
|
41
|
+
for (let r = 0; r < this.size; ++r)
|
42
|
+
this.material.uniforms.layer.value = r / this.size, e.setRenderTarget(this.renderTarget, r), e.render(this.mesh, this.camera);
|
43
|
+
e.setRenderTarget(n);
|
44
|
+
}
|
45
|
+
get texture() {
|
46
|
+
return this.renderTarget.texture;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
const S = `// Based on the following work with slight modifications.
|
50
|
+
// https://github.com/sebh/TileableVolumeNoise
|
51
|
+
|
52
|
+
/**
|
53
|
+
* The MIT License (MIT)
|
54
|
+
*
|
55
|
+
* Copyright(c) 2017 Sébastien Hillaire
|
56
|
+
*
|
57
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
58
|
+
* of this software and associated documentation files (the "Software"), to deal
|
59
|
+
* in the Software without restriction, including without limitation the rights
|
60
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
61
|
+
* copies of the Software, and to permit persons to whom the Software is
|
62
|
+
* furnished to do so, subject to the following conditions:
|
63
|
+
*
|
64
|
+
* The above copyright notice and this permission notice shall be included in
|
65
|
+
* all copies or substantial portions of the Software.
|
66
|
+
*
|
67
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
68
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
69
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
70
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
71
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
72
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
73
|
+
* SOFTWARE.
|
74
|
+
*/
|
75
|
+
|
76
|
+
precision highp float;
|
77
|
+
precision highp int;
|
78
|
+
|
79
|
+
#include "core/math"
|
80
|
+
#include "perlin"
|
81
|
+
#include "tileableNoise"
|
82
|
+
|
83
|
+
uniform float layer;
|
84
|
+
|
85
|
+
in vec2 vUv;
|
86
|
+
|
87
|
+
layout(location = 0) out float outputColor;
|
88
|
+
|
89
|
+
float getPerlinWorley(const vec3 point) {
|
90
|
+
int octaveCount = 3;
|
91
|
+
float frequency = 8.0;
|
92
|
+
float perlin = getPerlinNoise(point, frequency, octaveCount);
|
93
|
+
perlin = clamp(perlin, 0.0, 1.0);
|
94
|
+
|
95
|
+
float cellCount = 4.0;
|
96
|
+
vec3 noise = vec3(
|
97
|
+
1.0 - getWorleyNoise(point, cellCount * 2.0),
|
98
|
+
1.0 - getWorleyNoise(point, cellCount * 8.0),
|
99
|
+
1.0 - getWorleyNoise(point, cellCount * 14.0)
|
100
|
+
);
|
101
|
+
float fbm = dot(noise, vec3(0.625, 0.25, 0.125));
|
102
|
+
return remap(perlin, 0.0, 1.0, fbm, 1.0);
|
103
|
+
}
|
104
|
+
|
105
|
+
float getWorleyFbm(const vec3 point) {
|
106
|
+
float cellCount = 4.0;
|
107
|
+
vec4 noise = vec4(
|
108
|
+
1.0 - getWorleyNoise(point, cellCount * 2.0),
|
109
|
+
1.0 - getWorleyNoise(point, cellCount * 4.0),
|
110
|
+
1.0 - getWorleyNoise(point, cellCount * 8.0),
|
111
|
+
1.0 - getWorleyNoise(point, cellCount * 16.0)
|
112
|
+
);
|
113
|
+
vec3 fbm = vec3(
|
114
|
+
dot(noise.xyz, vec3(0.625, 0.25, 0.125)),
|
115
|
+
dot(noise.yzw, vec3(0.625, 0.25, 0.125)),
|
116
|
+
dot(noise.zw, vec2(0.75, 0.25))
|
117
|
+
);
|
118
|
+
return dot(fbm, vec3(0.625, 0.25, 0.125));
|
119
|
+
}
|
120
|
+
|
121
|
+
void main() {
|
122
|
+
vec3 point = vec3(vUv.x, vUv.y, layer);
|
123
|
+
float perlinWorley = getPerlinWorley(point);
|
124
|
+
float worleyFbm = getWorleyFbm(point);
|
125
|
+
outputColor = remap(perlinWorley, worleyFbm - 1.0, 1.0);
|
126
|
+
}
|
127
|
+
`, a = `// Ported from GLM: https://github.com/g-truc/glm/blob/master/glm/gtc/noise.inl
|
128
|
+
|
129
|
+
/**
|
130
|
+
* OpenGL Mathematics (GLM)
|
131
|
+
*
|
132
|
+
* GLM is licensed under The Happy Bunny License or MIT License
|
133
|
+
*
|
134
|
+
* The Happy Bunny License (Modified MIT License)
|
135
|
+
*
|
136
|
+
* Copyright (c) 2005 - G-Truc Creation
|
137
|
+
*
|
138
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
139
|
+
* of this software and associated documentation files (the "Software"), to deal
|
140
|
+
* in the Software without restriction, including without limitation the rights
|
141
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
142
|
+
* copies of the Software, and to permit persons to whom the Software is
|
143
|
+
* furnished to do so, subject to the following conditions:
|
144
|
+
*
|
145
|
+
* The above copyright notice and this permission notice shall be included in
|
146
|
+
* all copies or substantial portions of the Software.
|
147
|
+
*
|
148
|
+
* Restrictions:
|
149
|
+
* By making use of the Software for military purposes, you choose to make a
|
150
|
+
* Bunny unhappy.
|
151
|
+
*
|
152
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
153
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
154
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
155
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
156
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
157
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
158
|
+
* THE SOFTWARE.
|
159
|
+
*
|
160
|
+
* The MIT License
|
161
|
+
*
|
162
|
+
* Copyright (c) 2005 - G-Truc Creation
|
163
|
+
*
|
164
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
165
|
+
* of this software and associated documentation files (the "Software"), to deal
|
166
|
+
* in the Software without restriction, including without limitation the rights
|
167
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
168
|
+
* copies of the Software, and to permit persons to whom the Software is
|
169
|
+
* furnished to do so, subject to the following conditions:
|
170
|
+
*
|
171
|
+
* The above copyright notice and this permission notice shall be included in
|
172
|
+
* all copies or substantial portions of the Software.
|
173
|
+
*
|
174
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
175
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
176
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
177
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
178
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
179
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
180
|
+
* THE SOFTWARE.
|
181
|
+
*/
|
182
|
+
|
183
|
+
vec4 mod289(const vec4 x) {
|
184
|
+
return x - floor(x * (1.0 / 289.0)) * 289.0;
|
185
|
+
}
|
186
|
+
|
187
|
+
vec4 permute(const vec4 v) {
|
188
|
+
return mod289((v * 34.0 + 1.0) * v);
|
189
|
+
}
|
190
|
+
|
191
|
+
vec4 taylorInvSqrt(const vec4 r) {
|
192
|
+
return 1.79284291400159 - 0.85373472095314 * r;
|
193
|
+
}
|
194
|
+
|
195
|
+
vec4 fade(const vec4 v) {
|
196
|
+
return v * v * v * (v * (v * 6.0 - 15.0) + 10.0);
|
197
|
+
}
|
198
|
+
|
199
|
+
// Classic Perlin noise, periodic version
|
200
|
+
float perlin(const vec4 position, const vec4 rep) {
|
201
|
+
vec4 Pi0 = mod(floor(position), rep); // Integer part modulo rep
|
202
|
+
vec4 Pi1 = mod(Pi0 + 1.0, rep); // Integer part + 1 mod rep
|
203
|
+
vec4 Pf0 = fract(position); // Fractional part for interpolation
|
204
|
+
vec4 Pf1 = Pf0 - 1.0; // Fractional part - 1.0
|
205
|
+
vec4 ix = vec4(Pi0.x, Pi1.x, Pi0.x, Pi1.x);
|
206
|
+
vec4 iy = vec4(Pi0.y, Pi0.y, Pi1.y, Pi1.y);
|
207
|
+
vec4 iz0 = vec4(Pi0.z);
|
208
|
+
vec4 iz1 = vec4(Pi1.z);
|
209
|
+
vec4 iw0 = vec4(Pi0.w);
|
210
|
+
vec4 iw1 = vec4(Pi1.w);
|
211
|
+
|
212
|
+
vec4 ixy = permute(permute(ix) + iy);
|
213
|
+
vec4 ixy0 = permute(ixy + iz0);
|
214
|
+
vec4 ixy1 = permute(ixy + iz1);
|
215
|
+
vec4 ixy00 = permute(ixy0 + iw0);
|
216
|
+
vec4 ixy01 = permute(ixy0 + iw1);
|
217
|
+
vec4 ixy10 = permute(ixy1 + iw0);
|
218
|
+
vec4 ixy11 = permute(ixy1 + iw1);
|
219
|
+
|
220
|
+
vec4 gx00 = ixy00 / 7.0;
|
221
|
+
vec4 gy00 = floor(gx00) / 7.0;
|
222
|
+
vec4 gz00 = floor(gy00) / 6.0;
|
223
|
+
gx00 = fract(gx00) - 0.5;
|
224
|
+
gy00 = fract(gy00) - 0.5;
|
225
|
+
gz00 = fract(gz00) - 0.5;
|
226
|
+
vec4 gw00 = vec4(0.75) - abs(gx00) - abs(gy00) - abs(gz00);
|
227
|
+
vec4 sw00 = step(gw00, vec4(0));
|
228
|
+
gx00 -= sw00 * (step(0.0, gx00) - 0.5);
|
229
|
+
gy00 -= sw00 * (step(0.0, gy00) - 0.5);
|
230
|
+
|
231
|
+
vec4 gx01 = ixy01 / 7.0;
|
232
|
+
vec4 gy01 = floor(gx01) / 7.0;
|
233
|
+
vec4 gz01 = floor(gy01) / 6.0;
|
234
|
+
gx01 = fract(gx01) - 0.5;
|
235
|
+
gy01 = fract(gy01) - 0.5;
|
236
|
+
gz01 = fract(gz01) - 0.5;
|
237
|
+
vec4 gw01 = vec4(0.75) - abs(gx01) - abs(gy01) - abs(gz01);
|
238
|
+
vec4 sw01 = step(gw01, vec4(0.0));
|
239
|
+
gx01 -= sw01 * (step(0.0, gx01) - 0.5);
|
240
|
+
gy01 -= sw01 * (step(0.0, gy01) - 0.5);
|
241
|
+
|
242
|
+
vec4 gx10 = ixy10 / 7.0;
|
243
|
+
vec4 gy10 = floor(gx10) / 7.0;
|
244
|
+
vec4 gz10 = floor(gy10) / 6.0;
|
245
|
+
gx10 = fract(gx10) - 0.5;
|
246
|
+
gy10 = fract(gy10) - 0.5;
|
247
|
+
gz10 = fract(gz10) - 0.5;
|
248
|
+
vec4 gw10 = vec4(0.75) - abs(gx10) - abs(gy10) - abs(gz10);
|
249
|
+
vec4 sw10 = step(gw10, vec4(0.0));
|
250
|
+
gx10 -= sw10 * (step(0.0, gx10) - 0.5);
|
251
|
+
gy10 -= sw10 * (step(0.0, gy10) - 0.5);
|
252
|
+
|
253
|
+
vec4 gx11 = ixy11 / 7.0;
|
254
|
+
vec4 gy11 = floor(gx11) / 7.0;
|
255
|
+
vec4 gz11 = floor(gy11) / 6.0;
|
256
|
+
gx11 = fract(gx11) - 0.5;
|
257
|
+
gy11 = fract(gy11) - 0.5;
|
258
|
+
gz11 = fract(gz11) - 0.5;
|
259
|
+
vec4 gw11 = vec4(0.75) - abs(gx11) - abs(gy11) - abs(gz11);
|
260
|
+
vec4 sw11 = step(gw11, vec4(0.0));
|
261
|
+
gx11 -= sw11 * (step(0.0, gx11) - 0.5);
|
262
|
+
gy11 -= sw11 * (step(0.0, gy11) - 0.5);
|
263
|
+
|
264
|
+
vec4 g0000 = vec4(gx00.x, gy00.x, gz00.x, gw00.x);
|
265
|
+
vec4 g1000 = vec4(gx00.y, gy00.y, gz00.y, gw00.y);
|
266
|
+
vec4 g0100 = vec4(gx00.z, gy00.z, gz00.z, gw00.z);
|
267
|
+
vec4 g1100 = vec4(gx00.w, gy00.w, gz00.w, gw00.w);
|
268
|
+
vec4 g0010 = vec4(gx10.x, gy10.x, gz10.x, gw10.x);
|
269
|
+
vec4 g1010 = vec4(gx10.y, gy10.y, gz10.y, gw10.y);
|
270
|
+
vec4 g0110 = vec4(gx10.z, gy10.z, gz10.z, gw10.z);
|
271
|
+
vec4 g1110 = vec4(gx10.w, gy10.w, gz10.w, gw10.w);
|
272
|
+
vec4 g0001 = vec4(gx01.x, gy01.x, gz01.x, gw01.x);
|
273
|
+
vec4 g1001 = vec4(gx01.y, gy01.y, gz01.y, gw01.y);
|
274
|
+
vec4 g0101 = vec4(gx01.z, gy01.z, gz01.z, gw01.z);
|
275
|
+
vec4 g1101 = vec4(gx01.w, gy01.w, gz01.w, gw01.w);
|
276
|
+
vec4 g0011 = vec4(gx11.x, gy11.x, gz11.x, gw11.x);
|
277
|
+
vec4 g1011 = vec4(gx11.y, gy11.y, gz11.y, gw11.y);
|
278
|
+
vec4 g0111 = vec4(gx11.z, gy11.z, gz11.z, gw11.z);
|
279
|
+
vec4 g1111 = vec4(gx11.w, gy11.w, gz11.w, gw11.w);
|
280
|
+
|
281
|
+
vec4 norm00 = taylorInvSqrt(
|
282
|
+
vec4(dot(g0000, g0000), dot(g0100, g0100), dot(g1000, g1000), dot(g1100, g1100))
|
283
|
+
);
|
284
|
+
g0000 *= norm00.x;
|
285
|
+
g0100 *= norm00.y;
|
286
|
+
g1000 *= norm00.z;
|
287
|
+
g1100 *= norm00.w;
|
288
|
+
|
289
|
+
vec4 norm01 = taylorInvSqrt(
|
290
|
+
vec4(dot(g0001, g0001), dot(g0101, g0101), dot(g1001, g1001), dot(g1101, g1101))
|
291
|
+
);
|
292
|
+
g0001 *= norm01.x;
|
293
|
+
g0101 *= norm01.y;
|
294
|
+
g1001 *= norm01.z;
|
295
|
+
g1101 *= norm01.w;
|
296
|
+
|
297
|
+
vec4 norm10 = taylorInvSqrt(
|
298
|
+
vec4(dot(g0010, g0010), dot(g0110, g0110), dot(g1010, g1010), dot(g1110, g1110))
|
299
|
+
);
|
300
|
+
g0010 *= norm10.x;
|
301
|
+
g0110 *= norm10.y;
|
302
|
+
g1010 *= norm10.z;
|
303
|
+
g1110 *= norm10.w;
|
304
|
+
|
305
|
+
vec4 norm11 = taylorInvSqrt(
|
306
|
+
vec4(dot(g0011, g0011), dot(g0111, g0111), dot(g1011, g1011), dot(g1111, g1111))
|
307
|
+
);
|
308
|
+
g0011 *= norm11.x;
|
309
|
+
g0111 *= norm11.y;
|
310
|
+
g1011 *= norm11.z;
|
311
|
+
g1111 *= norm11.w;
|
312
|
+
|
313
|
+
float n0000 = dot(g0000, Pf0);
|
314
|
+
float n1000 = dot(g1000, vec4(Pf1.x, Pf0.y, Pf0.z, Pf0.w));
|
315
|
+
float n0100 = dot(g0100, vec4(Pf0.x, Pf1.y, Pf0.z, Pf0.w));
|
316
|
+
float n1100 = dot(g1100, vec4(Pf1.x, Pf1.y, Pf0.z, Pf0.w));
|
317
|
+
float n0010 = dot(g0010, vec4(Pf0.x, Pf0.y, Pf1.z, Pf0.w));
|
318
|
+
float n1010 = dot(g1010, vec4(Pf1.x, Pf0.y, Pf1.z, Pf0.w));
|
319
|
+
float n0110 = dot(g0110, vec4(Pf0.x, Pf1.y, Pf1.z, Pf0.w));
|
320
|
+
float n1110 = dot(g1110, vec4(Pf1.x, Pf1.y, Pf1.z, Pf0.w));
|
321
|
+
float n0001 = dot(g0001, vec4(Pf0.x, Pf0.y, Pf0.z, Pf1.w));
|
322
|
+
float n1001 = dot(g1001, vec4(Pf1.x, Pf0.y, Pf0.z, Pf1.w));
|
323
|
+
float n0101 = dot(g0101, vec4(Pf0.x, Pf1.y, Pf0.z, Pf1.w));
|
324
|
+
float n1101 = dot(g1101, vec4(Pf1.x, Pf1.y, Pf0.z, Pf1.w));
|
325
|
+
float n0011 = dot(g0011, vec4(Pf0.x, Pf0.y, Pf1.z, Pf1.w));
|
326
|
+
float n1011 = dot(g1011, vec4(Pf1.x, Pf0.y, Pf1.z, Pf1.w));
|
327
|
+
float n0111 = dot(g0111, vec4(Pf0.x, Pf1.y, Pf1.z, Pf1.w));
|
328
|
+
float n1111 = dot(g1111, Pf1);
|
329
|
+
|
330
|
+
vec4 fade_xyzw = fade(Pf0);
|
331
|
+
vec4 n_0w = mix(vec4(n0000, n1000, n0100, n1100), vec4(n0001, n1001, n0101, n1101), fade_xyzw.w);
|
332
|
+
vec4 n_1w = mix(vec4(n0010, n1010, n0110, n1110), vec4(n0011, n1011, n0111, n1111), fade_xyzw.w);
|
333
|
+
vec4 n_zw = mix(n_0w, n_1w, fade_xyzw.z);
|
334
|
+
vec2 n_yzw = mix(n_zw.xy, n_zw.zw, fade_xyzw.y);
|
335
|
+
float n_xyzw = mix(n_yzw.x, n_yzw.y, fade_xyzw.x);
|
336
|
+
return 2.2 * n_xyzw;
|
337
|
+
}
|
338
|
+
`, l = `// Based on the following work with slight modifications.
|
339
|
+
// https://github.com/sebh/TileableVolumeNoise
|
340
|
+
|
341
|
+
/**
|
342
|
+
* The MIT License (MIT)
|
343
|
+
*
|
344
|
+
* Copyright(c) 2017 Sébastien Hillaire
|
345
|
+
*
|
346
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
347
|
+
* of this software and associated documentation files (the "Software"), to deal
|
348
|
+
* in the Software without restriction, including without limitation the rights
|
349
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
350
|
+
* copies of the Software, and to permit persons to whom the Software is
|
351
|
+
* furnished to do so, subject to the following conditions:
|
352
|
+
*
|
353
|
+
* The above copyright notice and this permission notice shall be included in
|
354
|
+
* all copies or substantial portions of the Software.
|
355
|
+
*
|
356
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
357
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
358
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
359
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
360
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
361
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
362
|
+
* SOFTWARE.
|
363
|
+
*/
|
364
|
+
|
365
|
+
float hash(const float n) {
|
366
|
+
return fract(sin(n + 1.951) * 43758.5453);
|
367
|
+
}
|
368
|
+
|
369
|
+
float noise(const vec3 x) {
|
370
|
+
vec3 p = floor(x);
|
371
|
+
vec3 f = fract(x);
|
372
|
+
|
373
|
+
f = f * f * (3.0 - 2.0 * f);
|
374
|
+
float n = p.x + p.y * 57.0 + 113.0 * p.z;
|
375
|
+
return mix(
|
376
|
+
mix(mix(hash(n + 0.0), hash(n + 1.0), f.x), mix(hash(n + 57.0), hash(n + 58.0), f.x), f.y),
|
377
|
+
mix(
|
378
|
+
mix(hash(n + 113.0), hash(n + 114.0), f.x),
|
379
|
+
mix(hash(n + 170.0), hash(n + 171.0), f.x),
|
380
|
+
f.y
|
381
|
+
),
|
382
|
+
f.z
|
383
|
+
);
|
384
|
+
}
|
385
|
+
|
386
|
+
float getWorleyNoise(const vec3 p, const float cellCount) {
|
387
|
+
vec3 cell = p * cellCount;
|
388
|
+
float d = 1.0e10;
|
389
|
+
for (int x = -1; x <= 1; ++x) {
|
390
|
+
for (int y = -1; y <= 1; ++y) {
|
391
|
+
for (int z = -1; z <= 1; ++z) {
|
392
|
+
vec3 tp = floor(cell) + vec3(x, y, z);
|
393
|
+
tp = cell - tp - noise(mod(tp, cellCount / 1.0));
|
394
|
+
d = min(d, dot(tp, tp));
|
395
|
+
}
|
396
|
+
}
|
397
|
+
}
|
398
|
+
return clamp(d, 0.0, 1.0);
|
399
|
+
}
|
400
|
+
|
401
|
+
float getPerlinNoise(const vec3 point, const vec3 frequency, const int octaveCount) {
|
402
|
+
// Noise frequency factor between octave, forced to 2.
|
403
|
+
const float octaveFrequencyFactor = 2.0;
|
404
|
+
|
405
|
+
// Compute the sum for each octave.
|
406
|
+
float sum = 0.0;
|
407
|
+
float roughness = 0.5;
|
408
|
+
float weightSum = 0.0;
|
409
|
+
float weight = 1.0;
|
410
|
+
vec3 nextFrequency = frequency;
|
411
|
+
for (int i = 0; i < octaveCount; ++i) {
|
412
|
+
vec4 p = vec4(point.x, point.y, point.z, 0.0) * vec4(nextFrequency, 1.0);
|
413
|
+
float value = perlin(p, vec4(nextFrequency, 1.0));
|
414
|
+
sum += value * weight;
|
415
|
+
weightSum += weight;
|
416
|
+
weight *= roughness;
|
417
|
+
nextFrequency *= octaveFrequencyFactor;
|
418
|
+
}
|
419
|
+
|
420
|
+
return sum / weightSum; // Intentionally skip clamping.
|
421
|
+
}
|
422
|
+
|
423
|
+
float getPerlinNoise(const vec3 point, const float frequency, const int octaveCount) {
|
424
|
+
return getPerlinNoise(point, vec3(frequency), octaveCount);
|
425
|
+
}
|
426
|
+
`;
|
427
|
+
class F extends h {
|
428
|
+
constructor() {
|
429
|
+
super({
|
430
|
+
size: w,
|
431
|
+
fragmentShader: c(S, {
|
432
|
+
core: { math: s },
|
433
|
+
perlin: a,
|
434
|
+
tileableNoise: l
|
435
|
+
})
|
436
|
+
});
|
437
|
+
}
|
438
|
+
}
|
439
|
+
const A = `// Based on the following work with slight modifications.
|
440
|
+
// https://github.com/sebh/TileableVolumeNoise
|
441
|
+
|
442
|
+
/**
|
443
|
+
* The MIT License (MIT)
|
444
|
+
*
|
445
|
+
* Copyright(c) 2017 Sébastien Hillaire
|
446
|
+
*
|
447
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
448
|
+
* of this software and associated documentation files (the "Software"), to deal
|
449
|
+
* in the Software without restriction, including without limitation the rights
|
450
|
+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
451
|
+
* copies of the Software, and to permit persons to whom the Software is
|
452
|
+
* furnished to do so, subject to the following conditions:
|
453
|
+
*
|
454
|
+
* The above copyright notice and this permission notice shall be included in
|
455
|
+
* all copies or substantial portions of the Software.
|
456
|
+
*
|
457
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
458
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
459
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
460
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
461
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
462
|
+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
463
|
+
* SOFTWARE.
|
464
|
+
*/
|
465
|
+
|
466
|
+
precision highp float;
|
467
|
+
precision highp int;
|
468
|
+
|
469
|
+
#include "core/math"
|
470
|
+
#include "perlin"
|
471
|
+
#include "tileableNoise"
|
472
|
+
|
473
|
+
uniform float layer;
|
474
|
+
|
475
|
+
in vec2 vUv;
|
476
|
+
|
477
|
+
layout(location = 0) out float outputColor;
|
478
|
+
|
479
|
+
void main() {
|
480
|
+
vec3 point = vec3(vUv.x, vUv.y, layer);
|
481
|
+
float cellCount = 2.0;
|
482
|
+
vec4 noise = vec4(
|
483
|
+
1.0 - getWorleyNoise(point, cellCount * 1.0),
|
484
|
+
1.0 - getWorleyNoise(point, cellCount * 2.0),
|
485
|
+
1.0 - getWorleyNoise(point, cellCount * 4.0),
|
486
|
+
1.0 - getWorleyNoise(point, cellCount * 8.0)
|
487
|
+
);
|
488
|
+
vec3 fbm = vec3(
|
489
|
+
dot(noise.xyz, vec3(0.625, 0.25, 0.125)),
|
490
|
+
dot(noise.yzw, vec3(0.625, 0.25, 0.125)),
|
491
|
+
dot(noise.zw, vec2(0.75, 0.25))
|
492
|
+
);
|
493
|
+
outputColor = dot(fbm, vec3(0.625, 0.25, 0.125));
|
494
|
+
}
|
495
|
+
`;
|
496
|
+
class U extends h {
|
497
|
+
constructor() {
|
498
|
+
super({
|
499
|
+
size: R,
|
500
|
+
fragmentShader: c(A, {
|
501
|
+
core: { math: s },
|
502
|
+
perlin: a,
|
503
|
+
tileableNoise: l
|
504
|
+
})
|
505
|
+
});
|
506
|
+
}
|
507
|
+
}
|
508
|
+
class m {
|
509
|
+
constructor({ size: e, fragmentShader: o }) {
|
510
|
+
this.needsRender = !0, this.camera = new f(), this.size = e, this.material = new p({
|
511
|
+
glslVersion: u,
|
512
|
+
vertexShader: (
|
513
|
+
/* glsl */
|
514
|
+
`
|
515
|
+
in vec3 position;
|
516
|
+
out vec2 vUv;
|
517
|
+
void main() {
|
518
|
+
vUv = position.xy * 0.5 + 0.5;
|
519
|
+
gl_Position = vec4(position.xy, 0.0, 1.0);
|
520
|
+
}
|
521
|
+
`
|
522
|
+
),
|
523
|
+
fragmentShader: o,
|
524
|
+
uniforms: {
|
525
|
+
layer: new v(0)
|
526
|
+
}
|
527
|
+
}), this.mesh = new y(new d(2, 2), this.material), this.renderTarget = new x(e, e, {
|
528
|
+
depthBuffer: !1,
|
529
|
+
stencilBuffer: !1,
|
530
|
+
format: O
|
531
|
+
});
|
532
|
+
const n = this.renderTarget.texture;
|
533
|
+
n.generateMipmaps = !0, n.minFilter = N, n.magFilter = g, n.wrapS = i, n.wrapT = i, n.colorSpace = T, n.needsUpdate = !0;
|
534
|
+
}
|
535
|
+
dispose() {
|
536
|
+
this.renderTarget.dispose(), this.material.dispose();
|
537
|
+
}
|
538
|
+
render(e, o) {
|
539
|
+
if (!this.needsRender)
|
540
|
+
return;
|
541
|
+
this.needsRender = !1;
|
542
|
+
const n = e.getRenderTarget();
|
543
|
+
e.setRenderTarget(this.renderTarget), e.render(this.mesh, this.camera), e.setRenderTarget(n);
|
544
|
+
}
|
545
|
+
get texture() {
|
546
|
+
return this.renderTarget.texture;
|
547
|
+
}
|
548
|
+
}
|
549
|
+
const P = `precision highp float;
|
550
|
+
precision highp int;
|
551
|
+
|
552
|
+
#include "core/math"
|
553
|
+
#include "perlin"
|
554
|
+
#include "tileableNoise"
|
555
|
+
|
556
|
+
in vec2 vUv;
|
557
|
+
|
558
|
+
layout(location = 0) out vec4 outputColor;
|
559
|
+
|
560
|
+
float getWorleyFbm(
|
561
|
+
const vec3 point,
|
562
|
+
float frequency,
|
563
|
+
float amplitude,
|
564
|
+
const float lacunarity,
|
565
|
+
const float gain,
|
566
|
+
const int octaveCount
|
567
|
+
) {
|
568
|
+
float noise = 0.0;
|
569
|
+
for (int i = 0; i < octaveCount; ++i) {
|
570
|
+
noise += amplitude * (1.0 - getWorleyNoise(point, frequency));
|
571
|
+
frequency *= lacunarity;
|
572
|
+
amplitude *= gain;
|
573
|
+
}
|
574
|
+
return noise;
|
575
|
+
}
|
576
|
+
|
577
|
+
void main() {
|
578
|
+
vec3 point = vec3(vUv.x, vUv.y, 0.0);
|
579
|
+
|
580
|
+
// Mid clouds
|
581
|
+
{
|
582
|
+
float worley = getWorleyFbm(
|
583
|
+
point + vec3(0.5),
|
584
|
+
8.0, // frequency
|
585
|
+
0.4, // amplitude
|
586
|
+
2.0, // lacunarity
|
587
|
+
0.95, // gain
|
588
|
+
4 // octaveCount
|
589
|
+
);
|
590
|
+
worley = smoothstep(1.0, 1.4, worley);
|
591
|
+
outputColor.g = worley;
|
592
|
+
}
|
593
|
+
|
594
|
+
// Low clouds
|
595
|
+
{
|
596
|
+
float worley = getWorleyFbm(
|
597
|
+
point,
|
598
|
+
16.0, // frequency
|
599
|
+
0.4, // amplitude
|
600
|
+
2.0, // lacunarity
|
601
|
+
0.95, // gain
|
602
|
+
4 // octaveCount
|
603
|
+
);
|
604
|
+
worley = smoothstep(0.8, 1.4, worley);
|
605
|
+
outputColor.r = saturate(worley - outputColor.g);
|
606
|
+
}
|
607
|
+
|
608
|
+
// High clouds
|
609
|
+
{
|
610
|
+
float perlin = getPerlinNoise(
|
611
|
+
point,
|
612
|
+
vec3(6.0, 12.0, 1.0), // frequency
|
613
|
+
8 // octaveCount
|
614
|
+
);
|
615
|
+
perlin = smoothstep(-0.5, 0.5, perlin);
|
616
|
+
outputColor.b = perlin;
|
617
|
+
}
|
618
|
+
|
619
|
+
// Extra
|
620
|
+
{
|
621
|
+
float perlin = getPerlinNoise(
|
622
|
+
point + vec3(-19.1, 33.4, 47.2),
|
623
|
+
32.0, // frequency
|
624
|
+
4 // octaveCount
|
625
|
+
);
|
626
|
+
perlin = smoothstep(-0.5, 0.5, perlin);
|
627
|
+
outputColor.a = perlin;
|
628
|
+
}
|
629
|
+
|
630
|
+
outputColor.a = 1.0;
|
631
|
+
}
|
632
|
+
`;
|
633
|
+
class W extends m {
|
634
|
+
constructor() {
|
635
|
+
super({
|
636
|
+
size: 512,
|
637
|
+
fragmentShader: c(P, {
|
638
|
+
core: { math: s },
|
639
|
+
perlin: a,
|
640
|
+
tileableNoise: l
|
641
|
+
})
|
642
|
+
});
|
643
|
+
}
|
644
|
+
}
|
645
|
+
const z = `precision highp float;
|
646
|
+
precision highp int;
|
647
|
+
|
648
|
+
#include "core/math"
|
649
|
+
#include "perlin"
|
650
|
+
#include "tileableNoise"
|
651
|
+
|
652
|
+
in vec2 vUv;
|
653
|
+
|
654
|
+
layout(location = 0) out vec4 outputColor;
|
655
|
+
|
656
|
+
const vec3 frequency = vec3(12.0);
|
657
|
+
const int octaveCount = 3;
|
658
|
+
|
659
|
+
float perlin(const vec3 point) {
|
660
|
+
return getPerlinNoise(point, frequency, octaveCount);
|
661
|
+
}
|
662
|
+
|
663
|
+
vec3 perlin3d(const vec3 point) {
|
664
|
+
float perlin1 = perlin(point);
|
665
|
+
float perlin2 = perlin(point.yzx + vec3(-19.1, 33.4, 47.2));
|
666
|
+
float perlin3 = perlin(point.zxy + vec3(74.2, -124.5, 99.4));
|
667
|
+
return vec3(perlin1, perlin2, perlin3);
|
668
|
+
}
|
669
|
+
|
670
|
+
vec3 curl(vec3 point) {
|
671
|
+
const float delta = 0.1;
|
672
|
+
vec3 dx = vec3(delta, 0.0, 0.0);
|
673
|
+
vec3 dy = vec3(0.0, delta, 0.0);
|
674
|
+
vec3 dz = vec3(0.0, 0.0, delta);
|
675
|
+
|
676
|
+
vec3 px0 = perlin3d(point - dx);
|
677
|
+
vec3 px1 = perlin3d(point + dx);
|
678
|
+
vec3 py0 = perlin3d(point - dy);
|
679
|
+
vec3 py1 = perlin3d(point + dy);
|
680
|
+
vec3 pz0 = perlin3d(point - dz);
|
681
|
+
vec3 pz1 = perlin3d(point + dz);
|
682
|
+
|
683
|
+
float x = py1.z - py0.z - pz1.y + pz0.y;
|
684
|
+
float y = pz1.x - pz0.x - px1.z + px0.z;
|
685
|
+
float z = px1.y - px0.y - py1.x + py0.x;
|
686
|
+
|
687
|
+
const float divisor = 1.0 / (2.0 * delta);
|
688
|
+
return normalize(vec3(x, y, z) * divisor);
|
689
|
+
}
|
690
|
+
|
691
|
+
void main() {
|
692
|
+
vec3 point = vec3(vUv.x, vUv.y, 0.0);
|
693
|
+
outputColor.rgb = 0.5 * curl(point) + 0.5;
|
694
|
+
outputColor.a = 1.0;
|
695
|
+
}
|
696
|
+
`;
|
697
|
+
class D extends m {
|
698
|
+
constructor() {
|
699
|
+
super({
|
700
|
+
size: 128,
|
701
|
+
fragmentShader: c(z, {
|
702
|
+
core: { math: s },
|
703
|
+
perlin: a,
|
704
|
+
tileableNoise: l
|
705
|
+
})
|
706
|
+
});
|
707
|
+
}
|
708
|
+
}
|
709
|
+
export {
|
710
|
+
R as CLOUD_SHAPE_DETAIL_TEXTURE_SIZE,
|
711
|
+
w as CLOUD_SHAPE_TEXTURE_SIZE,
|
712
|
+
B as CloudLayer,
|
713
|
+
_ as CloudLayers,
|
714
|
+
F as CloudShape,
|
715
|
+
U as CloudShapeDetail,
|
716
|
+
Y as CloudsEffect,
|
717
|
+
q as DEFAULT_LOCAL_WEATHER_URL,
|
718
|
+
V as DEFAULT_SHAPE_DETAIL_URL,
|
719
|
+
X as DEFAULT_SHAPE_URL,
|
720
|
+
k as DEFAULT_TURBULENCE_URL,
|
721
|
+
j as DensityProfile,
|
722
|
+
W as LocalWeather,
|
723
|
+
h as Procedural3DTextureBase,
|
724
|
+
m as ProceduralTextureBase,
|
725
|
+
D as Turbulence,
|
726
|
+
K as cloudsPassOptionsDefaults
|
727
|
+
};
|
728
|
+
//# sourceMappingURL=index.js.map
|