deeptwins-engine-3d 0.1.65 → 0.1.67
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/dist/esm/constant.d.ts +10 -0
- package/dist/esm/constant.js +10 -1
- package/dist/esm/drawCommand/viewShed/RectangularSensorPrimitive.d.ts +1 -0
- package/dist/esm/drawCommand/viewShed/ViewShedAnalyserLayer.d.ts +1 -0
- package/dist/esm/drawer/common.d.ts +1 -0
- package/dist/esm/drawer/coordinate.d.ts +1 -0
- package/dist/esm/drawer/index.d.ts +1 -1
- package/dist/esm/drawer/shape/BaseShape.d.ts +1 -0
- package/dist/esm/graphicLayer/BaseLayer.d.ts +23 -0
- package/dist/esm/graphicLayer/BaseLayer.js +387 -65
- package/dist/esm/graphicLayer/BasePrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/BasePrimitiveInstance.js +0 -7
- package/dist/esm/graphicLayer/BaseSource.d.ts +1 -1
- package/dist/esm/graphicLayer/BoxPrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/BoxPrimitiveInstance.js +4 -8
- package/dist/esm/graphicLayer/EllipsePrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/EllipsePrimitiveInstance.js +5 -9
- package/dist/esm/graphicLayer/EllipsoidPrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/EllipsoidPrimitiveInstance.js +5 -9
- package/dist/esm/graphicLayer/GraphicLayerCollection.js +20 -27
- package/dist/esm/graphicLayer/ModelPrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/ModelPrimitiveInstance.js +0 -7
- package/dist/esm/graphicLayer/PolygonGroundPrimitiveImageMaterialInstance.js +5 -2
- package/dist/esm/graphicLayer/PolygonPrimitiveImageMaterialInstance.js +5 -2
- package/dist/esm/graphicLayer/PolygonPrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/PolygonPrimitiveInstance.js +5 -9
- package/dist/esm/graphicLayer/PolylineGroundPrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/PolylineGroundPrimitiveInstance.js +4 -8
- package/dist/esm/graphicLayer/PolylinePrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/PolylinePrimitiveInstance.js +4 -8
- package/dist/esm/graphicLayer/PolylineVolumePrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/PolylineVolumePrimitiveInstance.js +4 -8
- package/dist/esm/graphicLayer/WallPrimitiveInstance.d.ts +0 -1
- package/dist/esm/graphicLayer/WallPrimitiveInstance.js +4 -8
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +6 -2
- package/dist/esm/map/Map.d.ts +9 -0
- package/dist/esm/map/Map.js +115 -2
- package/dist/esm/material/AtmosphericDispersion.d.ts +71 -0
- package/dist/esm/material/AtmosphericDispersion.js +485 -33
- package/dist/esm/material/GlobalVolumetricCloud.d.ts +117 -0
- package/dist/esm/material/GlobalVolumetricCloud.js +219 -223
- package/dist/esm/material/WeatherEffects.d.ts +64 -14
- package/dist/esm/material/WeatherEffects.js +279 -95
- package/dist/esm/material/entity/ImageMaterialProperty.d.ts +1 -0
- package/dist/esm/material/shader/AtmosphericShader.glsl +244 -0
- package/dist/esm/material/shader/RainShader.glsl +44 -6
- package/dist/esm/material/shader/lightning.glsl +70 -0
- package/dist/esm/measure/BaseDraw.d.ts +1 -0
- package/dist/esm/measure/types.d.ts +1 -0
- package/dist/esm/measure/utils.d.ts +1 -0
- package/dist/esm/sceneFusion/Airway.d.ts +0 -0
- package/dist/esm/sceneFusion/Airway.js +692 -0
- package/dist/esm/tileLayer/ArcGisLayer.d.ts +1 -0
- package/dist/esm/tileLayer/ImageryLayer.d.ts +1 -0
- package/dist/esm/tileLayer/MvtVectorLoad.d.ts +13 -0
- package/dist/esm/tileLayer/MvtVectorLoad.js +245 -49
- package/dist/esm/tool/common.d.ts +1 -0
- package/dist/esm/tool/utils.d.ts +1 -0
- package/dist/esm/typings.d.ts +8 -0
- package/dist/esm/visualization/BaseHeatmap.d.ts +5 -0
- package/dist/esm/visualization/BaseHeatmap.js +54 -12
- package/dist/esm/visualization/Heatmap2d.d.ts +1 -0
- package/dist/esm/visualization/Heatmap2d.js +17 -26
- package/dist/esm/visualization/Heatmap3d.d.ts +8 -2
- package/dist/esm/visualization/Heatmap3d.js +195 -59
- package/dist/umd/deeptwins-engine-3d.min.js +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,244 @@
|
|
|
1
|
+
precision highp float;
|
|
2
|
+
uniform sampler2D colorTexture;
|
|
3
|
+
uniform sampler2D depthTexture;
|
|
4
|
+
uniform float u_threshold;
|
|
5
|
+
uniform float u_blendFactor;
|
|
6
|
+
uniform float u_lightIntensity;
|
|
7
|
+
uniform float u_scatterStrength;
|
|
8
|
+
uniform float u_tonemapExposure;
|
|
9
|
+
uniform float u_mieExtinctionStrength;
|
|
10
|
+
uniform float u_fogOpacity;
|
|
11
|
+
uniform float u_fogPower;
|
|
12
|
+
uniform float u_clearMixBias;
|
|
13
|
+
in vec2 v_textureCoordinates;
|
|
14
|
+
const float PI = 3.14159265359;
|
|
15
|
+
const float TWO_PI = PI * 2.0;
|
|
16
|
+
const float FOUR_PI = PI * 4.0;
|
|
17
|
+
const float SCATTER_VISIBILITY_SCALE = 30000.0;
|
|
18
|
+
const float MAX_EXPOSURE_RESPONSE = 1.8;
|
|
19
|
+
const float MAX_LIGHT_RESPONSE = 3.0;
|
|
20
|
+
|
|
21
|
+
const vec3 betaR = vec3(5.5e-6, 13.0e-6, 22.4e-6);
|
|
22
|
+
|
|
23
|
+
const vec3 betaM = vec3(21e-6);
|
|
24
|
+
|
|
25
|
+
const float hR = 10e3;
|
|
26
|
+
const float hM = 3.8e3;
|
|
27
|
+
const int num_samples = 16;
|
|
28
|
+
const int num_samples_light = 4;
|
|
29
|
+
#ifdef GL_ES
|
|
30
|
+
#define _in(T) const in T
|
|
31
|
+
#define _inout(T) inout T
|
|
32
|
+
#define _out(T) out T
|
|
33
|
+
#define _begin(type) type (
|
|
34
|
+
#define _end )
|
|
35
|
+
#define mul(a, b) (a) * (b)
|
|
36
|
+
#endif
|
|
37
|
+
|
|
38
|
+
struct ray_t {
|
|
39
|
+
vec3 origin;
|
|
40
|
+
vec3 direction;
|
|
41
|
+
};
|
|
42
|
+
struct sphere_t {
|
|
43
|
+
vec3 origin;
|
|
44
|
+
float radius;
|
|
45
|
+
int material;
|
|
46
|
+
};
|
|
47
|
+
struct plane_t {
|
|
48
|
+
vec3 direction;
|
|
49
|
+
float distance;
|
|
50
|
+
int material;
|
|
51
|
+
};
|
|
52
|
+
plane_t plane;
|
|
53
|
+
mat3 rotate_around_x(_in(float) angle_degrees) {
|
|
54
|
+
float angle = radians(angle_degrees);
|
|
55
|
+
float _sin = sin(angle);
|
|
56
|
+
float _cos = cos(angle);
|
|
57
|
+
return mat3(1, 0, 0, 0, _cos, -_sin, 0, _sin, _cos);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
bool isect_sphere(_in(ray_t) ray, _in(sphere_t) sphere, _inout(float) t0, _inout(float) t1) {
|
|
61
|
+
vec3 rc = sphere.origin - ray.origin;
|
|
62
|
+
float radius2 = sphere.radius * sphere.radius;
|
|
63
|
+
float tca = dot(rc, ray.direction);
|
|
64
|
+
float d2 = dot(rc, rc) - tca * tca;
|
|
65
|
+
if (d2 > radius2) return false;
|
|
66
|
+
float thc = sqrt(radius2 - d2);
|
|
67
|
+
t0 = tca - thc;
|
|
68
|
+
t1 = tca + thc;
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
float rayleigh_phase_func(float mu) {
|
|
72
|
+
return
|
|
73
|
+
3. * (1. + mu * mu)
|
|
74
|
+
/
|
|
75
|
+
(16. * PI);
|
|
76
|
+
}
|
|
77
|
+
const float g = 0.76;
|
|
78
|
+
float henyey_greenstein_phase_func(float mu) {
|
|
79
|
+
return
|
|
80
|
+
(1. - g * g)
|
|
81
|
+
/
|
|
82
|
+
((4. * PI) * pow(1. + g * g - 2. * g * mu, 1.5));
|
|
83
|
+
}
|
|
84
|
+
const float k = 1.55 * g - 0.55 * (g * g * g);
|
|
85
|
+
float schlick_phase_func(float mu) {
|
|
86
|
+
return
|
|
87
|
+
(1. - k * k)
|
|
88
|
+
/
|
|
89
|
+
(4. * PI * (1. + k * mu) * (1. + k * mu));
|
|
90
|
+
}
|
|
91
|
+
const sphere_t atmosphere = _begin(sphere_t)
|
|
92
|
+
vec3(0, 0, 0), 6420e3, 0
|
|
93
|
+
_end;
|
|
94
|
+
|
|
95
|
+
bool get_sun_light(
|
|
96
|
+
_in(ray_t) ray, _inout(float) optical_depthR, _inout(float) optical_depthM
|
|
97
|
+
) {
|
|
98
|
+
float t0, t1;
|
|
99
|
+
isect_sphere(ray, atmosphere, t0, t1);
|
|
100
|
+
float march_pos = 0.;
|
|
101
|
+
float march_step = t1 / float(num_samples_light);
|
|
102
|
+
for (int i = 0; i < num_samples_light; i++) {
|
|
103
|
+
vec3 s = ray.origin +
|
|
104
|
+
ray.direction * (march_pos + 0.5 * march_step);
|
|
105
|
+
float height = length(s) - 6360e3;
|
|
106
|
+
if (height < 0.)
|
|
107
|
+
return false;
|
|
108
|
+
optical_depthR += exp(-height / hR) * march_step;
|
|
109
|
+
optical_depthM += exp(-height / hM) * march_step;
|
|
110
|
+
march_pos += march_step;
|
|
111
|
+
}
|
|
112
|
+
return true;
|
|
113
|
+
}
|
|
114
|
+
vec4 get_incident_light(_in(ray_t) ray) {
|
|
115
|
+
vec3 dir = ray.direction;
|
|
116
|
+
vec3 start = ray.origin;
|
|
117
|
+
float a = dot(dir, dir);
|
|
118
|
+
float b = 2.0 * dot(dir, start);
|
|
119
|
+
float radius2 = atmosphere.radius * atmosphere.radius;
|
|
120
|
+
float c = dot(start, start) - radius2;
|
|
121
|
+
float d = (b * b) - 4.0 * a * c;
|
|
122
|
+
if (d < 0.0) return vec4(0.0);
|
|
123
|
+
float squaredD = sqrt(d);
|
|
124
|
+
vec2 ray_length = vec2(
|
|
125
|
+
max((-b - squaredD) / (2.0 * a), 0.0), min((-b + squaredD) / (2.0 * a), plane.distance)
|
|
126
|
+
);
|
|
127
|
+
if (ray_length.x > ray_length.y) return vec4(0.0);
|
|
128
|
+
float march_step = (ray_length.y - ray_length.x) / float(num_samples);
|
|
129
|
+
float mu = dot(ray.direction, normalize(czm_sunPositionWC));
|
|
130
|
+
float phaseR = rayleigh_phase_func(mu);
|
|
131
|
+
float phaseM =
|
|
132
|
+
#if 1
|
|
133
|
+
henyey_greenstein_phase_func(mu);
|
|
134
|
+
#else
|
|
135
|
+
schlick_phase_func(mu);
|
|
136
|
+
#endif
|
|
137
|
+
|
|
138
|
+
float optical_depthR = 0.;
|
|
139
|
+
float optical_depthM = 0.;
|
|
140
|
+
vec3 sumR = vec3(0);
|
|
141
|
+
vec3 sumM = vec3(0);
|
|
142
|
+
float march_pos = 0.;
|
|
143
|
+
for (int i = 0; i < num_samples; i++) {
|
|
144
|
+
vec3 s = ray.origin +
|
|
145
|
+
ray.direction * (march_pos + 0.5 * march_step);
|
|
146
|
+
float height = length(s) - 6360e3;
|
|
147
|
+
|
|
148
|
+
float hr = exp(-height / hR) * march_step;
|
|
149
|
+
float hm = exp(-height / hM) * march_step;
|
|
150
|
+
optical_depthR += hr;
|
|
151
|
+
optical_depthM += hm;
|
|
152
|
+
|
|
153
|
+
ray_t light_ray = _begin(ray_t)
|
|
154
|
+
s, normalize(czm_sunPositionWC)
|
|
155
|
+
_end;
|
|
156
|
+
float optical_depth_lightR = 0.;
|
|
157
|
+
float optical_depth_lightM = 0.;
|
|
158
|
+
bool overground = get_sun_light(
|
|
159
|
+
light_ray,
|
|
160
|
+
optical_depth_lightR,
|
|
161
|
+
optical_depth_lightM);
|
|
162
|
+
|
|
163
|
+
if (overground) {
|
|
164
|
+
|
|
165
|
+
vec3 tau =
|
|
166
|
+
betaR * (optical_depthR + optical_depth_lightR) +
|
|
167
|
+
betaM * u_mieExtinctionStrength * (optical_depthM + optical_depth_lightM);
|
|
168
|
+
vec3 attenuation = exp(-tau);
|
|
169
|
+
sumR += hr * attenuation;
|
|
170
|
+
sumM += hm * attenuation;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
march_pos += march_step;
|
|
174
|
+
}
|
|
175
|
+
vec3 transmittance = exp(-((betaM * optical_depthM * u_mieExtinctionStrength)
|
|
176
|
+
+ (betaR * optical_depthR)) * 4.);
|
|
177
|
+
float attenuation = clamp(dot(transmittance, vec3(0.3333333)), 0.0, 1.0);
|
|
178
|
+
|
|
179
|
+
return vec4(
|
|
180
|
+
u_scatterStrength *
|
|
181
|
+
(sumR * phaseR * betaR +
|
|
182
|
+
sumM * phaseM * betaM), 1.0 - attenuation);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
void main() {
|
|
186
|
+
vec4 rawColor = texture(colorTexture, v_textureCoordinates);
|
|
187
|
+
float depth = czm_unpackDepth(texture(depthTexture, v_textureCoordinates));
|
|
188
|
+
|
|
189
|
+
vec4 positionEC = czm_windowToEyeCoordinates(gl_FragCoord.xy, depth);
|
|
190
|
+
vec4 positionWC = czm_inverseView * positionEC;
|
|
191
|
+
positionWC.xyz = positionWC.xyz / positionWC.w;
|
|
192
|
+
|
|
193
|
+
vec3 lVector = positionWC.xyz - czm_viewerPositionWC;
|
|
194
|
+
ray_t ray;
|
|
195
|
+
ray.origin = czm_viewerPositionWC;
|
|
196
|
+
ray.direction = normalize(lVector);
|
|
197
|
+
plane.distance = length(lVector);
|
|
198
|
+
|
|
199
|
+
vec4 atmosphereColor = get_incident_light(ray);
|
|
200
|
+
float lightControl = clamp(u_lightIntensity / 4.0, 0.0, 1.0);
|
|
201
|
+
float lightStrength = MAX_LIGHT_RESPONSE * (
|
|
202
|
+
1.0 - exp(-2.6 * pow(lightControl, 1.6))
|
|
203
|
+
);
|
|
204
|
+
vec3 scatterColor = atmosphereColor.rgb * lightStrength;
|
|
205
|
+
float exposureControl = clamp(u_tonemapExposure / 3.0, 0.0, 1.0);
|
|
206
|
+
float exposureStrength = pow(exposureControl, 1.25) * MAX_EXPOSURE_RESPONSE;
|
|
207
|
+
float mieVisualFactor = mix(
|
|
208
|
+
0.6,
|
|
209
|
+
1.8,
|
|
210
|
+
clamp(u_mieExtinctionStrength / 2.0, 0.0, 1.0)
|
|
211
|
+
);
|
|
212
|
+
vec3 visibleScatter = 1.0 - exp(
|
|
213
|
+
-max(scatterColor * SCATTER_VISIBILITY_SCALE, 0.0) * exposureStrength
|
|
214
|
+
);
|
|
215
|
+
visibleScatter *= mieVisualFactor;
|
|
216
|
+
float brightness = dot(visibleScatter, vec3(0.299, 0.587, 0.114));
|
|
217
|
+
float thresholdMask = u_threshold > 0.0
|
|
218
|
+
? smoothstep(0.0, u_threshold, brightness)
|
|
219
|
+
: 1.0;
|
|
220
|
+
visibleScatter *= thresholdMask;
|
|
221
|
+
float fogSignal = clamp(atmosphereColor.a * 2.5, 0.0, 1.0);
|
|
222
|
+
float fogAlpha = clamp(
|
|
223
|
+
pow(fogSignal, u_fogPower) * u_fogOpacity * mieVisualFactor,
|
|
224
|
+
0.0,
|
|
225
|
+
1.0
|
|
226
|
+
);
|
|
227
|
+
float clearPreserve = clamp(1.0 - u_clearMixBias, 0.0, 1.0);
|
|
228
|
+
float fogMix = fogAlpha * clearPreserve * 0.85;
|
|
229
|
+
vec3 foggedBase = mix(
|
|
230
|
+
rawColor.rgb,
|
|
231
|
+
rawColor.rgb * (1.0 - fogAlpha * 0.35),
|
|
232
|
+
fogMix
|
|
233
|
+
);
|
|
234
|
+
vec3 overlayColor = visibleScatter *
|
|
235
|
+
(0.55 + fogAlpha * 1.25) *
|
|
236
|
+
mix(1.0, 0.6, u_clearMixBias);
|
|
237
|
+
vec3 finalColor = mix(
|
|
238
|
+
rawColor.rgb,
|
|
239
|
+
foggedBase + overlayColor,
|
|
240
|
+
u_blendFactor
|
|
241
|
+
);
|
|
242
|
+
|
|
243
|
+
out_FragColor = vec4(clamp(finalColor, 0.0, 1.0), rawColor.a);
|
|
244
|
+
}
|
|
@@ -4,6 +4,10 @@ uniform sampler2D colorTexture;
|
|
|
4
4
|
uniform float direction;
|
|
5
5
|
uniform float size;
|
|
6
6
|
uniform float speed;
|
|
7
|
+
uniform float density;
|
|
8
|
+
uniform float opacity;
|
|
9
|
+
uniform float gloominess;
|
|
10
|
+
uniform vec4 rainColor;
|
|
7
11
|
in vec2 v_textureCoordinates;
|
|
8
12
|
out vec4 fragColor;
|
|
9
13
|
|
|
@@ -11,18 +15,52 @@ float hash(float x) {
|
|
|
11
15
|
return fract(sin(x * 133.3) * 13.13);
|
|
12
16
|
}
|
|
13
17
|
|
|
18
|
+
float rainLayer(vec2 uv, float time, float densityFactor, float scaleFactor, float seed) {
|
|
19
|
+
vec2 warpedUv = uv;
|
|
20
|
+
warpedUv *= scaleFactor;
|
|
21
|
+
|
|
22
|
+
float v = 1.0 - sin(hash(floor((warpedUv.x + seed) * 100.0 * densityFactor)) * 2.0);
|
|
23
|
+
float b = clamp(
|
|
24
|
+
abs(sin((20.0 + seed * 2.5) * time * v + warpedUv.y * (5.0 / (2.0 + v)))) - 0.95,
|
|
25
|
+
0.0,
|
|
26
|
+
1.0
|
|
27
|
+
) * (18.0 + densityFactor * 2.0);
|
|
28
|
+
|
|
29
|
+
return v * b;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
vec3 applyGloominess(vec3 sceneColor) {
|
|
33
|
+
float gloomFactor = clamp(gloominess, 0.0, 1.0);
|
|
34
|
+
float luminance = dot(sceneColor, vec3(0.299, 0.587, 0.114));
|
|
35
|
+
vec3 mutedScene = mix(sceneColor, vec3(luminance), gloomFactor * 0.45);
|
|
36
|
+
return mutedScene * (1.0 - gloomFactor * 0.55);
|
|
37
|
+
}
|
|
38
|
+
|
|
14
39
|
void main() {
|
|
15
40
|
float time = czm_frameNumber / speed;
|
|
16
41
|
vec2 resolution = czm_viewport.zw;
|
|
17
42
|
vec2 uv = (gl_FragCoord.xy * 2.0 - resolution) / min(resolution.x, resolution.y);
|
|
18
|
-
vec3 c = vec3(0.6, 0.7, 0.8);
|
|
19
43
|
float a = direction;
|
|
20
44
|
float si = sin(a), co = cos(a);
|
|
21
45
|
uv *= mat2(co, -si, si, co);
|
|
22
|
-
uv *= length(uv + vec2(0.0, 4.9)) * size + 1.0;
|
|
23
|
-
float v = 1.0 - sin(hash(floor(uv.x * 100.0)) * 2.0);
|
|
24
|
-
float b = clamp(abs(sin(20.0 * time * v + uv.y * (5.0 / (2.0 + v)))) - 0.95, 0.0, 1.0) * 20.0;
|
|
25
|
-
c *= v * b;
|
|
26
46
|
|
|
27
|
-
|
|
47
|
+
vec2 primaryUv = uv;
|
|
48
|
+
primaryUv *= length(primaryUv + vec2(0.0, 4.9)) * size + 1.0;
|
|
49
|
+
|
|
50
|
+
float densityFactor = mix(0.65, 2.1, clamp(density / 100.0, 0.0, 1.0));
|
|
51
|
+
float primaryLayer = rainLayer(primaryUv, time, densityFactor, 1.0, 0.0);
|
|
52
|
+
|
|
53
|
+
vec2 secondaryUv = primaryUv * 1.35;
|
|
54
|
+
secondaryUv.x += time * 0.25;
|
|
55
|
+
secondaryUv.y += hash(floor(primaryUv.x * 8.0) + 17.0) * 0.75;
|
|
56
|
+
float secondaryLayer = rainLayer(secondaryUv, time * 1.15, densityFactor * 0.85, 1.0, 3.7) * 0.65;
|
|
57
|
+
|
|
58
|
+
float rainMask = clamp(primaryLayer + secondaryLayer, 0.0, 1.0);
|
|
59
|
+
|
|
60
|
+
vec4 scene = texture(colorTexture, v_textureCoordinates);
|
|
61
|
+
vec3 baseScene = applyGloominess(scene.rgb);
|
|
62
|
+
vec3 rainLayerColor = rainColor.rgb * rainMask * opacity;
|
|
63
|
+
vec3 finalColor = clamp(baseScene + rainLayerColor, 0.0, 1.0);
|
|
64
|
+
|
|
65
|
+
fragColor = vec4(finalColor, scene.a);
|
|
28
66
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
precision highp float;
|
|
2
|
+
|
|
3
|
+
float hash(float x)
|
|
4
|
+
{
|
|
5
|
+
return fract(21654.6512 * sin(385.51 * x));
|
|
6
|
+
}
|
|
7
|
+
float hash(vec2 p)
|
|
8
|
+
{
|
|
9
|
+
return fract(1654.65157 * sin(15.5134763 * p.x + 45.5173247 * p.y + 5.21789));
|
|
10
|
+
}
|
|
11
|
+
vec2 hash2(vec2 p)
|
|
12
|
+
{
|
|
13
|
+
return vec2(hash(p * .754), hash(1.5743 * p + 4.5476351));
|
|
14
|
+
}
|
|
15
|
+
const vec2 hashAdd = vec2(1.0, 0.0);
|
|
16
|
+
vec2 noise2(vec2 x)
|
|
17
|
+
{
|
|
18
|
+
vec2 p = floor(x);
|
|
19
|
+
vec2 f = fract(x);
|
|
20
|
+
f = f * f * (3.0 - 2.0 * f);
|
|
21
|
+
vec2 res = mix(mix(hash2(p),
|
|
22
|
+
hash2(p + hashAdd.xy), f.x),
|
|
23
|
+
mix(hash2(p + hashAdd.yx), hash2(p + hashAdd.xx), f.x), f.y);
|
|
24
|
+
return res;
|
|
25
|
+
}
|
|
26
|
+
vec2 fbm2(vec2 x)
|
|
27
|
+
{
|
|
28
|
+
vec2 r = vec2(0.0);
|
|
29
|
+
float a = 1.0;
|
|
30
|
+
for (int i = 0; i < 8; i++)
|
|
31
|
+
{
|
|
32
|
+
r += noise2(x) * a;
|
|
33
|
+
x *= 2.;
|
|
34
|
+
a *= .5;
|
|
35
|
+
}
|
|
36
|
+
return r;
|
|
37
|
+
}
|
|
38
|
+
float dseg(vec2 ba, vec2 pa)
|
|
39
|
+
{
|
|
40
|
+
float h = clamp(dot(pa, ba) / dot(ba, ba), -0.2, 1.);
|
|
41
|
+
return length(pa - ba * h);
|
|
42
|
+
}
|
|
43
|
+
uniform sampler2D colorTexture;
|
|
44
|
+
uniform float fall_interval;
|
|
45
|
+
uniform float mix_factor;
|
|
46
|
+
in vec2 v_textureCoordinates;
|
|
47
|
+
out vec4 fragColor;
|
|
48
|
+
void main(void){
|
|
49
|
+
float iTime = czm_frameNumber * fall_interval * clamp(fall_interval * 0.1, 0.01, 0.1);
|
|
50
|
+
vec2 p = gl_FragCoord.xy / czm_viewport.zw;
|
|
51
|
+
vec2 d;
|
|
52
|
+
vec2 tgt = vec2(1., -1.);
|
|
53
|
+
vec3 col = vec3(0.);
|
|
54
|
+
float mdist = 100000.;
|
|
55
|
+
float t = hash(floor(5. * iTime));
|
|
56
|
+
tgt += 4. * hash2(tgt + t) - 1.5;
|
|
57
|
+
if (hash(t + 2.3) > .6)
|
|
58
|
+
for (int i = 0; i < 100; i++) {
|
|
59
|
+
vec2 dtgt = tgt - p;
|
|
60
|
+
d = .05 * (vec2(-.5, -1.) + hash2(vec2(float(i), t)));
|
|
61
|
+
float dist = dseg(d, dtgt);
|
|
62
|
+
mdist = min(mdist, dist);
|
|
63
|
+
tgt -= d;
|
|
64
|
+
float bolt = exp(-1.2 * dist) + exp(-55. * mdist);
|
|
65
|
+
col = max(col, bolt * vec3(.7, .8, 1.));
|
|
66
|
+
}
|
|
67
|
+
vec4 scene = texture(colorTexture, v_textureCoordinates);
|
|
68
|
+
vec3 finalColor = clamp(scene.rgb + col * mix_factor, 0.0, 1.0);
|
|
69
|
+
fragColor = vec4(finalColor, scene.a);
|
|
70
|
+
}
|
|
File without changes
|