@antv/l7-layers 2.22.5 → 2.22.7
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/es/core/BaseLayer.d.ts +19 -0
- package/es/core/BaseLayer.js +56 -0
- package/es/core/interface.d.ts +4 -3
- package/es/earth/models/atmosphere.js +1 -1
- package/es/earth/models/base.js +1 -1
- package/es/earth/models/bloomsphere.js +1 -1
- package/es/earth/shaders/atmosphere/atmosphere_frag.glsl +6 -9
- package/es/earth/shaders/base/base_frag.glsl +3 -3
- package/es/earth/shaders/bloomshpere/bloomsphere_frag.glsl +5 -6
- package/es/geometry/models/billboard.js +1 -1
- package/es/geometry/models/sprite.js +1 -1
- package/es/geometry/shaders/billboard_frag.glsl +4 -4
- package/es/geometry/shaders/sprite_frag.glsl +2 -4
- package/es/heatmap/models/heatmap.js +3 -3
- package/es/heatmap/shaders/heatmap/heatmap_3d_frag.glsl +6 -7
- package/es/heatmap/shaders/heatmap/heatmap_frag.glsl +24 -36
- package/es/heatmap/shaders/heatmap/heatmap_framebuffer_frag.glsl +5 -5
- package/es/line/models/flow.js +1 -1
- package/es/line/shaders/flow/flow_line_frag.glsl +0 -1
- package/es/plugins/LayerMaskPlugin.js +1 -1
- package/es/plugins/ShaderUniformPlugin.js +26 -8
- package/es/point/models/billboard_point.js +1 -1
- package/es/point/models/extrude.js +1 -1
- package/es/point/models/fill.js +1 -1
- package/es/point/models/image.js +1 -1
- package/es/point/models/normal.js +1 -1
- package/es/point/shaders/billboard/billboard_point_frag.glsl +6 -8
- package/es/point/shaders/extrude/extrude_frag.glsl +1 -3
- package/es/point/shaders/fill/fill_frag.glsl +14 -17
- package/es/point/shaders/image/image_frag.glsl +15 -12
- package/es/point/shaders/normal/normal_frag.glsl +1 -1
- package/es/polygon/models/extrude.js +3 -3
- package/es/polygon/models/extrusion.js +1 -1
- package/es/polygon/models/fill.js +1 -1
- package/es/polygon/models/ocean.js +1 -1
- package/es/polygon/models/water.js +1 -1
- package/es/polygon/shaders/extrude/polygon_extrude_frag.glsl +5 -6
- package/es/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -8
- package/es/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +4 -3
- package/es/polygon/shaders/extrusion/polygon_extrusion_frag.glsl +0 -2
- package/es/polygon/shaders/fill/fill_linear_frag.glsl +4 -2
- package/es/polygon/shaders/ocean/ocean_frag.glsl +212 -182
- package/es/polygon/shaders/water/polygon_water_frag.glsl +25 -20
- package/es/raster/index.js +2 -1
- package/es/raster/models/raster.js +1 -1
- package/es/raster/models/rasterRgb.js +1 -1
- package/es/raster/models/rasterTerrainRgb.js +1 -1
- package/es/raster/shaders/raster/raster_2d_frag.glsl +10 -7
- package/es/raster/shaders/rgb/raster_rgb_frag.glsl +16 -13
- package/es/raster/shaders/terrain/terrain_rgb_frag.glsl +18 -21
- package/lib/core/BaseLayer.d.ts +19 -0
- package/lib/core/BaseLayer.js +56 -0
- package/lib/core/interface.d.ts +4 -3
- package/lib/earth/models/atmosphere.js +1 -1
- package/lib/earth/models/base.js +1 -1
- package/lib/earth/models/bloomsphere.js +1 -1
- package/lib/earth/shaders/atmosphere/atmosphere_frag.glsl +6 -9
- package/lib/earth/shaders/base/base_frag.glsl +3 -3
- package/lib/earth/shaders/bloomshpere/bloomsphere_frag.glsl +5 -6
- package/lib/geometry/models/billboard.js +1 -1
- package/lib/geometry/models/sprite.js +1 -1
- package/lib/geometry/shaders/billboard_frag.glsl +4 -4
- package/lib/geometry/shaders/sprite_frag.glsl +2 -4
- package/lib/heatmap/models/heatmap.js +3 -3
- package/lib/heatmap/shaders/heatmap/heatmap_3d_frag.glsl +6 -7
- package/lib/heatmap/shaders/heatmap/heatmap_frag.glsl +24 -36
- package/lib/heatmap/shaders/heatmap/heatmap_framebuffer_frag.glsl +5 -5
- package/lib/line/models/flow.js +1 -1
- package/lib/line/shaders/flow/flow_line_frag.glsl +0 -1
- package/lib/plugins/LayerMaskPlugin.js +1 -1
- package/lib/plugins/ShaderUniformPlugin.js +26 -8
- package/lib/point/models/billboard_point.js +1 -1
- package/lib/point/models/extrude.js +1 -1
- package/lib/point/models/fill.js +1 -1
- package/lib/point/models/image.js +1 -1
- package/lib/point/models/normal.js +1 -1
- package/lib/point/shaders/billboard/billboard_point_frag.glsl +6 -8
- package/lib/point/shaders/extrude/extrude_frag.glsl +1 -3
- package/lib/point/shaders/fill/fill_frag.glsl +14 -17
- package/lib/point/shaders/image/image_frag.glsl +15 -12
- package/lib/point/shaders/normal/normal_frag.glsl +1 -1
- package/lib/polygon/models/extrude.js +3 -3
- package/lib/polygon/models/extrusion.js +1 -1
- package/lib/polygon/models/fill.js +1 -1
- package/lib/polygon/models/ocean.js +1 -1
- package/lib/polygon/models/water.js +1 -1
- package/lib/polygon/shaders/extrude/polygon_extrude_frag.glsl +5 -6
- package/lib/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -8
- package/lib/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +4 -3
- package/lib/polygon/shaders/extrusion/polygon_extrusion_frag.glsl +0 -2
- package/lib/polygon/shaders/fill/fill_linear_frag.glsl +4 -2
- package/lib/polygon/shaders/ocean/ocean_frag.glsl +212 -182
- package/lib/polygon/shaders/water/polygon_water_frag.glsl +25 -20
- package/lib/raster/index.js +2 -1
- package/lib/raster/models/raster.js +1 -1
- package/lib/raster/models/rasterRgb.js +1 -1
- package/lib/raster/models/rasterTerrainRgb.js +1 -1
- package/lib/raster/shaders/raster/raster_2d_frag.glsl +10 -7
- package/lib/raster/shaders/rgb/raster_rgb_frag.glsl +16 -13
- package/lib/raster/shaders/terrain/terrain_rgb_frag.glsl +18 -21
- package/package.json +6 -6
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
layout(std140) uniform commonUniforms {
|
|
3
2
|
float u_raisingHeight;
|
|
4
3
|
float u_opacitylinear;
|
|
@@ -15,7 +14,10 @@ out vec4 outputColor;
|
|
|
15
14
|
void main() {
|
|
16
15
|
outputColor = v_color;
|
|
17
16
|
if (u_opacitylinear > 0.0) {
|
|
18
|
-
outputColor.a *=
|
|
17
|
+
outputColor.a *=
|
|
18
|
+
u_dir == 1.0
|
|
19
|
+
? 1.0 - length(v_pos - v_linear.xy) / v_linear.z
|
|
20
|
+
: length(v_pos - v_linear.xy) / v_linear.z;
|
|
19
21
|
}
|
|
20
22
|
outputColor = filterColor(outputColor);
|
|
21
23
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
layout(std140) uniform commonUniforms {
|
|
3
2
|
vec4 u_watercolor;
|
|
4
3
|
vec4 u_watercolor2;
|
|
@@ -9,50 +8,51 @@ in vec2 v_uv;
|
|
|
9
8
|
in float v_opacity;
|
|
10
9
|
out vec4 outputColor;
|
|
11
10
|
|
|
12
|
-
float coast2water_fadedepth = 0.
|
|
13
|
-
float large_waveheight
|
|
14
|
-
float large_wavesize
|
|
15
|
-
float small_waveheight
|
|
16
|
-
float small_wavesize
|
|
17
|
-
float water_softlight_fact
|
|
18
|
-
float water_glossylight_fact= 120
|
|
19
|
-
float particle_amount
|
|
11
|
+
float coast2water_fadedepth = 0.1;
|
|
12
|
+
float large_waveheight = 0.75; // change to adjust the "heavy" waves
|
|
13
|
+
float large_wavesize = 3.4; // factor to adjust the large wave size
|
|
14
|
+
float small_waveheight = 0.6; // change to adjust the small random waves
|
|
15
|
+
float small_wavesize = 0.5; // factor to ajust the small wave size
|
|
16
|
+
float water_softlight_fact = 15.0; // range [1..200] (should be << smaller than glossy-fact)
|
|
17
|
+
float water_glossylight_fact = 120.0; // range [1..200]
|
|
18
|
+
float particle_amount = 70.0;
|
|
20
19
|
|
|
21
|
-
vec3 water_specularcolor
|
|
22
|
-
#define light
|
|
20
|
+
vec3 water_specularcolor = vec3(1.3, 1.3, 0.9); // specular Color (RGB) of the water-highlights
|
|
21
|
+
#define light (vec3(-0.0, sin(u_time * 0.5) * 0.5 + 0.35, 2.8)) // position of the sun
|
|
23
22
|
|
|
24
23
|
uniform sampler2D u_texture1;
|
|
25
24
|
uniform sampler2D u_texture2;
|
|
26
25
|
uniform sampler2D u_texture3;
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
float hash( float n ) {
|
|
31
|
-
return fract(sin(n)*43758.5453123);
|
|
27
|
+
float hash(float n) {
|
|
28
|
+
return fract(sin(n) * 43758.5453123);
|
|
32
29
|
}
|
|
33
30
|
|
|
34
31
|
// 2d noise function
|
|
35
|
-
float noise1(
|
|
36
|
-
vec2 p
|
|
37
|
-
vec2 f
|
|
38
|
-
float n = p.x + p.y*57.0;
|
|
39
|
-
return mix(mix(
|
|
40
|
-
mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);
|
|
32
|
+
float noise1(vec2 x) {
|
|
33
|
+
vec2 p = floor(x);
|
|
34
|
+
vec2 f = smoothstep(0.0, 1.0, fract(x));
|
|
35
|
+
float n = p.x + p.y * 57.0;
|
|
36
|
+
return 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);
|
|
41
37
|
}
|
|
42
38
|
|
|
43
39
|
float noise(vec2 p) {
|
|
44
|
-
|
|
40
|
+
return texture(SAMPLER_2D(u_texture2), p * vec2(1.0 / 256.0)).x;
|
|
45
41
|
}
|
|
46
42
|
|
|
47
43
|
vec4 highness(vec2 p) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
vec4 t = texture(SAMPLER_2D(u_texture1), fract(p));
|
|
45
|
+
float clipped =
|
|
46
|
+
-2.0 -
|
|
47
|
+
smoothstep(3.0, 10.0, t.a) * 6.9 -
|
|
48
|
+
smoothstep(10.0, 100.0, t.a) * 89.9 -
|
|
49
|
+
smoothstep(0.0, 10000.0, t.a) * 10000.0;
|
|
50
|
+
return clamp(t, 0.0, 3.0) + clamp(t / 3.0 - 1.0, 0.0, 1.0) + clamp(t / 16.0 - 1.0, 0.0, 1.0);
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
-
float height_map(
|
|
54
|
-
|
|
55
|
-
|
|
53
|
+
float height_map(vec2 p) {
|
|
54
|
+
vec4 height = highness(p);
|
|
55
|
+
/*
|
|
56
56
|
height = -0.5+
|
|
57
57
|
0.5*smoothstep(-100.,0.,-height)+
|
|
58
58
|
2.75*smoothstep(0.,2.,height)+
|
|
@@ -61,187 +61,217 @@ float height_map( vec2 p ) {
|
|
|
61
61
|
1.5*smoothstep(16.,1000.,height);
|
|
62
62
|
*/
|
|
63
63
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
64
|
+
mat2 m = mat2(0.9563 * 1.4, -0.2924 * 1.4, 0.2924 * 1.4, 0.9563 * 1.4);
|
|
65
|
+
//p = p*6.;
|
|
66
|
+
float f = 0.6 * noise1(p);
|
|
67
|
+
p = m * p * 1.1 * 6.0;
|
|
68
|
+
f += 0.25 * noise(p);
|
|
69
|
+
p = m * p * 1.32;
|
|
70
|
+
f += 0.1666 * noise(p);
|
|
71
|
+
p = m * p * 1.11;
|
|
72
|
+
f += 0.0834 * noise(p);
|
|
73
|
+
p = m * p * 1.12;
|
|
74
|
+
f += 0.0634 * noise(p);
|
|
75
|
+
p = m * p * 1.13;
|
|
76
|
+
f += 0.0444 * noise(p);
|
|
77
|
+
p = m * p * 1.14;
|
|
78
|
+
f += 0.0274 * noise(p);
|
|
79
|
+
p = m * p * 1.15;
|
|
80
|
+
f += 0.0134 * noise(p);
|
|
81
|
+
p = m * p * 1.16;
|
|
82
|
+
f += 0.0104 * noise(p);
|
|
83
|
+
p = m * p * 1.17;
|
|
84
|
+
f += 0.0084 * noise(p);
|
|
85
|
+
f = 0.25 * f + dot(height, vec4(-0.03125, -0.125, 0.25, 0.25)) * 0.5;
|
|
86
|
+
const float FLAT_LEVEL = 0.92525;
|
|
87
|
+
//f = f*0.25+height*0.75;
|
|
88
|
+
if (f < FLAT_LEVEL) f = f;
|
|
89
|
+
else f = pow((f - FLAT_LEVEL) / (1.0 - FLAT_LEVEL), 2.0) * (1.0 - FLAT_LEVEL) * 2.0 + FLAT_LEVEL; // makes a smooth coast-increase
|
|
90
|
+
return clamp(f, 0.0, 10.0);
|
|
84
91
|
}
|
|
85
92
|
|
|
86
|
-
vec3 plasma_quintic(
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
93
|
+
vec3 plasma_quintic(float x) {
|
|
94
|
+
x = clamp(x, 0.0, 1.0);
|
|
95
|
+
vec4 x1 = vec4(1.0, x, x * x, x * x * x); // 1 x x2 x3
|
|
96
|
+
vec4 x2 = x1 * x1.w * x; // x4 x5 x6 x7
|
|
97
|
+
return vec3(
|
|
98
|
+
dot(x1.xyzw, vec4(+0.063861086, +1.992659096, -1.023901152, -0.490832805)) +
|
|
99
|
+
dot(x2.xy, vec2(+1.308442123, -0.914547012)),
|
|
100
|
+
dot(x1.xyzw, vec4(+0.04971859, -0.791144343, +2.892305078, +0.811726816)) +
|
|
101
|
+
dot(x2.xy, vec2(-4.686502417, +2.717794514)),
|
|
102
|
+
dot(x1.xyzw, vec4(+0.513275779, +1.58025506, -5.164414457, +4.559573646)) +
|
|
103
|
+
dot(x2.xy, vec2(-1.916810682, +0.570638854))
|
|
104
|
+
);
|
|
94
105
|
}
|
|
95
106
|
|
|
96
|
-
vec4 color(vec2 p){
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
107
|
+
vec4 color(vec2 p) {
|
|
108
|
+
vec4 c1 = vec4(1.7, 1.6, 0.9, 1);
|
|
109
|
+
vec4 c2 = vec4(0.2, 0.94, 0.1, 1);
|
|
110
|
+
vec4 c3 = vec4(0.3, 0.2, 0.0, 1);
|
|
111
|
+
vec4 c4 = vec4(0.99, 0.99, 1.6, 1);
|
|
112
|
+
vec4 v = highness(p);
|
|
113
|
+
float los = smoothstep(0.1, 1.1, v.b);
|
|
114
|
+
float his = smoothstep(3.5, 6.5, v.b);
|
|
115
|
+
float ces = smoothstep(1.0, 5.0, v.a);
|
|
116
|
+
vec4 lo = mix(c1, c2, los);
|
|
117
|
+
vec4 hi = mix(c3, c4, his);
|
|
118
|
+
vec4 ce = mix(lo, hi, ces);
|
|
119
|
+
|
|
120
|
+
return vec4(plasma_quintic(ces), 1).ragb;
|
|
110
121
|
}
|
|
111
122
|
|
|
112
|
-
vec3 terrain_map(
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
vec3 terrain_map(vec2 p) {
|
|
124
|
+
return color(p).rgb * 0.75 +
|
|
125
|
+
0.25 * vec3(0.7, 0.55, 0.4) +
|
|
126
|
+
texture(SAMPLER_2D(u_texture3), fract(p * 5.0)).rgb * 0.5; // test-terrain is simply 'sandstone'
|
|
115
127
|
}
|
|
116
128
|
|
|
117
|
-
const mat2 m = mat2(
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
129
|
+
const mat2 m = mat2(
|
|
130
|
+
0.72, -1.6 ,
|
|
131
|
+
1.6 , 0.72
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
float water_map(vec2 p, float height) {
|
|
135
|
+
vec2 p2 = p * large_wavesize;
|
|
136
|
+
vec2 shift1 = 0.001 * vec2(u_time * 160.0 * 2.0, u_time * 120.0 * 2.0);
|
|
137
|
+
vec2 shift2 = 0.001 * vec2(u_time * 190.0 * 2.0, -u_time * 130.0 * 2.0);
|
|
138
|
+
|
|
139
|
+
// coarse crossing 'ocean' waves...
|
|
140
|
+
float f = 0.6 * noise(p);
|
|
141
|
+
f += 0.25 * noise(p * m);
|
|
142
|
+
f += 0.1666 * noise(p * m * m);
|
|
143
|
+
float wave =
|
|
144
|
+
sin(p2.x * 0.622 + p2.y * 0.622 + shift2.x * 4.269) * large_waveheight * f * height * height;
|
|
145
|
+
|
|
146
|
+
p *= small_wavesize;
|
|
147
|
+
f = 0.0;
|
|
148
|
+
float amp = 1.0,
|
|
149
|
+
s = 0.5;
|
|
150
|
+
for (int i = 0; i < 9; i++) {
|
|
151
|
+
p = m * p * 0.947;
|
|
152
|
+
f -= amp * abs(sin((noise(p + shift1 * s) - 0.5) * 2.0));
|
|
153
|
+
amp = amp * 0.59;
|
|
154
|
+
s *= -1.329;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return wave + f * small_waveheight;
|
|
137
158
|
}
|
|
138
159
|
|
|
139
160
|
float nautic(vec2 p) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
161
|
+
p *= 18.0;
|
|
162
|
+
float f = 0.0;
|
|
163
|
+
float amp = 1.0,
|
|
164
|
+
s = 0.5;
|
|
165
|
+
for (int i = 0; i < 3; i++) {
|
|
166
|
+
p = m * p * 1.2;
|
|
167
|
+
f += amp * abs(smoothstep(0.0, 1.0, noise(p + u_time * s)) - 0.5);
|
|
168
|
+
amp = amp * 0.5;
|
|
169
|
+
s *= -1.227;
|
|
170
|
+
}
|
|
171
|
+
return pow(1.0 - f, 5.0);
|
|
146
172
|
}
|
|
147
173
|
|
|
148
174
|
float particles(vec2 p) {
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
175
|
+
p *= 200.0;
|
|
176
|
+
float f = 0.0;
|
|
177
|
+
float amp = 1.0,
|
|
178
|
+
s = 1.5;
|
|
179
|
+
for (int i = 0; i < 3; i++) {
|
|
180
|
+
p = m * p * 1.2;
|
|
181
|
+
f += amp * noise(p + u_time * s);
|
|
182
|
+
amp = amp * 0.5;
|
|
183
|
+
s *= -1.227;
|
|
184
|
+
}
|
|
185
|
+
return pow(f * 0.35, 7.0) * particle_amount;
|
|
155
186
|
}
|
|
156
187
|
|
|
157
|
-
float test_shadow(
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
{
|
|
170
|
-
return 0.0;
|
|
171
|
-
}
|
|
172
|
-
t += 0.01+height_diff*.02;
|
|
173
|
-
hit = min(hit, 2.*height_diff/t); // soft shaddow
|
|
188
|
+
float test_shadow(vec2 xy, float height) {
|
|
189
|
+
vec3 r0 = vec3(xy, height);
|
|
190
|
+
vec3 rd = normalize(light - r0);
|
|
191
|
+
|
|
192
|
+
float hit = 1.0;
|
|
193
|
+
float t = 0.001;
|
|
194
|
+
for (int j = 1; j < 25; j++) {
|
|
195
|
+
vec3 p = r0 + t * rd;
|
|
196
|
+
float h = height_map(p.xy);
|
|
197
|
+
float height_diff = p.z - h;
|
|
198
|
+
if (height_diff < 0.0) {
|
|
199
|
+
return 0.0;
|
|
174
200
|
}
|
|
175
|
-
|
|
201
|
+
t += 0.01 + height_diff * 0.02;
|
|
202
|
+
hit = min(hit, 2.0 * height_diff / t); // soft shaddow
|
|
203
|
+
}
|
|
204
|
+
return hit;
|
|
176
205
|
}
|
|
177
206
|
|
|
178
207
|
vec3 CalcTerrain(vec2 uv, float height) {
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
208
|
+
vec3 col = terrain_map(uv);
|
|
209
|
+
vec2 iResolution = vec2(512.0);
|
|
210
|
+
float h1 = height_map(uv - vec2(0.0, 0.5) / iResolution.xy);
|
|
211
|
+
float h2 = height_map(uv + vec2(0.0, 0.5) / iResolution.xy);
|
|
212
|
+
float h3 = height_map(uv - vec2(0.5, 0.0) / iResolution.xy);
|
|
213
|
+
float h4 = height_map(uv + vec2(0.5, 0.0) / iResolution.xy);
|
|
214
|
+
vec3 norm = normalize(vec3(h3 - h4, h1 - h2, 1.0));
|
|
215
|
+
vec3 r0 = vec3(uv, height);
|
|
216
|
+
vec3 rd = normalize(light - r0);
|
|
217
|
+
float grad = dot(norm, rd);
|
|
218
|
+
col *= grad + pow(grad, 8.0);
|
|
219
|
+
float terrainshade = test_shadow(uv, height);
|
|
220
|
+
col = mix(col * 0.25, col, terrainshade);
|
|
221
|
+
return col;
|
|
193
222
|
}
|
|
194
223
|
|
|
195
|
-
|
|
196
224
|
void main() {
|
|
197
225
|
vec3 watercolor = u_watercolor.rgb;
|
|
198
226
|
vec3 watercolor2 = u_watercolor2.rgb;
|
|
199
227
|
vec2 uv = v_uv;
|
|
200
228
|
float WATER_LEVEL = 0.84; // Water level (range: 0.0 - 2.0)
|
|
201
|
-
float deepwater_fadedepth
|
|
202
|
-
float height = height_map(
|
|
229
|
+
float deepwater_fadedepth = 0.4 + coast2water_fadedepth;
|
|
230
|
+
float height = height_map(uv);
|
|
203
231
|
vec3 col;
|
|
204
232
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
233
|
+
float waveheight = clamp(WATER_LEVEL * 3.0 - 1.5, 0.0, 1.0);
|
|
234
|
+
float level = WATER_LEVEL + 0.2 * water_map(uv * 15.0 + vec2(u_time * 0.1), waveheight);
|
|
235
|
+
if (height > level) {
|
|
236
|
+
col = CalcTerrain(uv, height);
|
|
237
|
+
}
|
|
238
|
+
if (height <= level) {
|
|
239
|
+
vec2 dif = vec2(0.0, 0.01);
|
|
240
|
+
vec2 pos = uv * 15.0 + vec2(u_time * 0.01);
|
|
241
|
+
float h1 = water_map(pos - dif, waveheight);
|
|
242
|
+
float h2 = water_map(pos + dif, waveheight);
|
|
243
|
+
float h3 = water_map(pos - dif.yx, waveheight);
|
|
244
|
+
float h4 = water_map(pos + dif.yx, waveheight);
|
|
245
|
+
vec3 normwater = normalize(vec3(h3 - h4, h1 - h2, 0.125)); // norm-vector of the 'bumpy' water-plane
|
|
246
|
+
uv += normwater.xy * 0.002 * (level - height);
|
|
247
|
+
|
|
248
|
+
col = CalcTerrain(uv, height);
|
|
249
|
+
|
|
250
|
+
float coastfade = clamp((level - height) / coast2water_fadedepth, 0.0, 1.0);
|
|
251
|
+
float coastfade2 = clamp((level - height) / deepwater_fadedepth, 0.0, 1.0);
|
|
252
|
+
float intensity = col.r * 0.2126 + col.g * 0.7152 + col.b * 0.0722;
|
|
253
|
+
watercolor = mix(watercolor * intensity, watercolor2, smoothstep(0.0, 1.0, coastfade2));
|
|
254
|
+
|
|
255
|
+
vec3 r0 = vec3(uv, WATER_LEVEL);
|
|
256
|
+
vec3 rd = normalize(light - r0); // ray-direction to the light from water-position
|
|
257
|
+
float grad = dot(normwater, rd); // dot-product of norm-vector and light-direction
|
|
258
|
+
float specular = pow(grad, water_softlight_fact); // used for soft highlights
|
|
259
|
+
float specular2 = pow(grad, water_glossylight_fact); // used for glossy highlights
|
|
260
|
+
float gradpos = dot(vec3(0.0, 0.0, 1.0), rd);
|
|
261
|
+
float specular1 = smoothstep(0.0, 1.0, pow(gradpos, 5.0)); // used for diffusity (some darker corona around light's specular reflections...)
|
|
262
|
+
float watershade = test_shadow(uv, level);
|
|
263
|
+
watercolor *= 2.2 + watershade;
|
|
264
|
+
watercolor += (0.2 + 0.8 * watershade) * ((grad - 1.0) * 0.5 + specular) * 0.25;
|
|
265
|
+
watercolor /= 1.0 + specular1 * 1.25;
|
|
266
|
+
watercolor += watershade * specular2 * water_specularcolor;
|
|
267
|
+
watercolor +=
|
|
268
|
+
watershade *
|
|
269
|
+
coastfade *
|
|
270
|
+
(1.0 - coastfade2) *
|
|
271
|
+
(vec3(0.5, 0.6, 0.7) * nautic(uv) + vec3(1.0, 1.0, 1.0) * particles(uv));
|
|
272
|
+
|
|
273
|
+
col = mix(col, watercolor, coastfade);
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
outputColor = vec4(col, v_opacity);
|
|
247
277
|
}
|
|
@@ -6,23 +6,27 @@ layout(std140) uniform commonUniforms {
|
|
|
6
6
|
|
|
7
7
|
out vec4 outputColor;
|
|
8
8
|
|
|
9
|
-
|
|
10
9
|
in vec4 v_Color;
|
|
11
10
|
in vec2 v_uv;
|
|
12
11
|
|
|
13
|
-
float rand(vec2 n) {
|
|
12
|
+
float rand(vec2 n) {
|
|
13
|
+
return 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233))) * 43758.5453);
|
|
14
|
+
}
|
|
14
15
|
|
|
15
16
|
float water(vec3 p) {
|
|
16
17
|
float t = u_time * u_speed;
|
|
17
|
-
p.z += t * 2
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
p.
|
|
22
|
-
vec3
|
|
18
|
+
p.z += t * 2.0;
|
|
19
|
+
p.x += t * 2.0;
|
|
20
|
+
vec3 c1 = texture(SAMPLER_2D(u_texture), p.xz / 30.0).xyz;
|
|
21
|
+
p.z += t * 3.0;
|
|
22
|
+
p.x += t * 0.52;
|
|
23
|
+
vec3 c2 = texture(SAMPLER_2D(u_texture), p.xz / 30.0).xyz;
|
|
24
|
+
p.z += t * 4.0;
|
|
25
|
+
p.x += t * 0.8;
|
|
26
|
+
vec3 c3 = texture(SAMPLER_2D(u_texture), p.xz / 30.0).xyz;
|
|
23
27
|
c1 += c2 - c3;
|
|
24
|
-
float z = (c1.x + c1.y + c1.z) / 3
|
|
25
|
-
return p.y + z / 4
|
|
28
|
+
float z = (c1.x + c1.y + c1.z) / 3.0;
|
|
29
|
+
return p.y + z / 4.0;
|
|
26
30
|
}
|
|
27
31
|
|
|
28
32
|
float map(vec3 p) {
|
|
@@ -35,27 +39,29 @@ float intersect(vec3 ro, vec3 rd) {
|
|
|
35
39
|
float d = 0.0;
|
|
36
40
|
for (int i = 0; i <= 100; i++) {
|
|
37
41
|
float h = map(ro + rd * d);
|
|
38
|
-
if (h < 0.1) return
|
|
42
|
+
if (h < 0.1) return d;
|
|
39
43
|
d += h;
|
|
40
44
|
}
|
|
41
45
|
return 0.0;
|
|
42
46
|
}
|
|
43
47
|
|
|
44
48
|
vec3 norm(vec3 p) {
|
|
45
|
-
float eps = .1;
|
|
46
|
-
return normalize(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
float eps = 0.1;
|
|
50
|
+
return normalize(
|
|
51
|
+
vec3(
|
|
52
|
+
map(p + vec3(eps, 0, 0)) - map(p + vec3(-eps, 0, 0)),
|
|
53
|
+
map(p + vec3(0, eps, 0)) - map(p + vec3(0, -eps, 0)),
|
|
54
|
+
map(p + vec3(0, 0, eps)) - map(p + vec3(0, 0, -eps))
|
|
55
|
+
)
|
|
56
|
+
);
|
|
57
|
+
}
|
|
52
58
|
|
|
53
59
|
float calSpc() {
|
|
54
60
|
vec3 l1 = normalize(vec3(1, 1, 1));
|
|
55
61
|
vec3 ro = vec3(-3, 20, -8);
|
|
56
62
|
vec3 rc = vec3(0, 0, 0);
|
|
57
63
|
vec3 ww = normalize(rc - ro);
|
|
58
|
-
vec3 uu = normalize(cross(vec3(0,1,0), ww));
|
|
64
|
+
vec3 uu = normalize(cross(vec3(0, 1, 0), ww));
|
|
59
65
|
vec3 vv = normalize(cross(rc - ro, uu));
|
|
60
66
|
vec3 rd = normalize(uu * v_uv.x + vv * v_uv.y + ww);
|
|
61
67
|
float d = intersect(ro, rd);
|
|
@@ -66,7 +72,6 @@ float calSpc() {
|
|
|
66
72
|
}
|
|
67
73
|
|
|
68
74
|
void main() {
|
|
69
|
-
|
|
70
75
|
outputColor = v_Color;
|
|
71
76
|
float spc = calSpc();
|
|
72
77
|
outputColor += spc * 0.4;
|
package/lib/raster/index.js
CHANGED
|
@@ -37,7 +37,8 @@ class RasterLayer extends _BaseLayer.default {
|
|
|
37
37
|
// 根据 source 的类型判断 model type
|
|
38
38
|
const parserType = this.layerSource.getParserType();
|
|
39
39
|
switch (parserType) {
|
|
40
|
-
case 'raster'
|
|
40
|
+
case 'raster':
|
|
41
|
+
case 'ndi':
|
|
41
42
|
return 'raster';
|
|
42
43
|
case 'rasterRgb':
|
|
43
44
|
return 'rasterRgb';
|
|
@@ -13,7 +13,7 @@ var _l7Utils = require("@antv/l7-utils");
|
|
|
13
13
|
var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
|
|
14
14
|
var _triangulation = require("../../core/triangulation");
|
|
15
15
|
/* babel-plugin-inline-import '../shaders/raster/raster_2d_frag.glsl' */
|
|
16
|
-
const rasterFrag = "layout(std140) uniform commonUniforms {\n vec2 u_domain;\n float u_opacity;\n float u_noDataValue;\n float u_clampLow;\n float u_clampHigh;\n};\n\nuniform sampler2D u_rasterTexture;\nuniform sampler2D u_colorTexture;\n\nin vec2 v_texCoord;\n\nbool isnan_emu(float x) {
|
|
16
|
+
const rasterFrag = "layout(std140) uniform commonUniforms {\n vec2 u_domain;\n float u_opacity;\n float u_noDataValue;\n float u_clampLow;\n float u_clampHigh;\n};\n\nuniform sampler2D u_rasterTexture;\nuniform sampler2D u_colorTexture;\n\nin vec2 v_texCoord;\n\nbool isnan_emu(float x) {\n return x > 0.0 || x < 0.0\n ? x != x\n : x != 0.0;\n}\n\nout vec4 outputColor;\n\nvoid main() {\n // Can use any component here since u_rasterTexture is under luminance format.\n float value = texture(SAMPLER_2D(u_rasterTexture), vec2(v_texCoord.x, v_texCoord.y)).r;\n if (value == u_noDataValue || isnan_emu(value)) {\n discard;\n } else if (u_clampLow < 0.5 && value < u_domain[0] || u_clampHigh < 0.5 && value > u_domain[1]) {\n discard;\n } else {\n float normalisedValue = (value - u_domain[0]) / (u_domain[1] - u_domain[0]);\n vec4 color = texture(SAMPLER_2D(u_colorTexture), vec2(normalisedValue, 0));\n\n outputColor = color;\n outputColor.a = outputColor.a * u_opacity;\n if (outputColor.a < 0.01) discard;\n }\n}\n";
|
|
17
17
|
/* babel-plugin-inline-import '../shaders/raster/raster_2d_vert.glsl' */
|
|
18
18
|
const rasterVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n vec2 u_domain;\n float u_opacity;\n float u_noDataValue;\n float u_clampLow;\n float u_clampHigh;\n};\n\nout vec2 v_texCoord;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_texCoord = a_Uv;\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, 0.0, 1.0));\n}\n";
|
|
19
19
|
class RasterModel extends _BaseModel.default {
|
|
@@ -15,7 +15,7 @@ var _triangulation = require("../../core/triangulation");
|
|
|
15
15
|
const _excluded = ["data"],
|
|
16
16
|
_excluded2 = ["rasterData"];
|
|
17
17
|
/* babel-plugin-inline-import '../shaders/rgb/raster_rgb_frag.glsl' */
|
|
18
|
-
const rasterFrag = "uniform sampler2D u_texture;\nlayout(std140) uniform commonUniforms {\n
|
|
18
|
+
const rasterFrag = "uniform sampler2D u_texture;\nlayout(std140) uniform commonUniforms {\n vec2 u_rminmax;\n vec2 u_gminmax;\n vec2 u_bminmax;\n float u_opacity;\n float u_noDataValue;\n};\n\nin vec2 v_texCoord;\n\nout vec4 outputColor;\n\nvoid main() {\n vec3 rgb = texture(SAMPLER_2D(u_texture), vec2(v_texCoord.x, v_texCoord.y)).rgb;\n\n if (rgb == vec3(u_noDataValue)) {\n outputColor = vec4(0.0, 0, 0, 0.0);\n } else {\n outputColor = vec4(\n rgb.r / (u_rminmax.y - u_rminmax.x),\n rgb.g / (u_gminmax.y - u_gminmax.x),\n rgb.b / (u_bminmax.y - u_bminmax.x),\n u_opacity\n );\n }\n\n if (outputColor.a < 0.01) discard;\n\n}\n";
|
|
19
19
|
/* babel-plugin-inline-import '../shaders/rgb/raster_rgb_vert.glsl' */
|
|
20
20
|
const rasterVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n vec2 u_rminmax;\n vec2 u_gminmax;\n vec2 u_bminmax;\n float u_opacity;\n float u_noDataValue;\n};\n\nout vec2 v_texCoord;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_texCoord = a_Uv;\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, 0.0, 1.0));\n}\n";
|
|
21
21
|
class RasterModel extends _BaseModel.default {
|
|
@@ -12,7 +12,7 @@ var _l7Utils = require("@antv/l7-utils");
|
|
|
12
12
|
var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
|
|
13
13
|
var _triangulation = require("../../core/triangulation");
|
|
14
14
|
/* babel-plugin-inline-import '../shaders/terrain/terrain_rgb_frag.glsl' */
|
|
15
|
-
const Raster_terrainFrag = "uniform sampler2D u_texture;\nuniform sampler2D u_colorTexture;\n\nlayout(std140) uniform commonUniforms {\n
|
|
15
|
+
const Raster_terrainFrag = "uniform sampler2D u_texture;\nuniform sampler2D u_colorTexture;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_unpack;\n vec2 u_domain;\n float u_opacity;\n float u_noDataValue;\n float u_clampLow;\n float u_clampHigh;\n};\n\nin vec2 v_texCoord;\nout vec4 outputColor;\n\nfloat getElevation(vec2 coord, float bias) {\n // Convert encoded elevation value to meters\n vec4 data = texture(SAMPLER_2D(u_texture), coord, bias) * 255.0;\n data.a = -1.0;\n return dot(data, u_unpack);\n}\n\nvec4 getColor(float value) {\n float normalisedValue = (value - u_domain[0]) / (u_domain[1] - u_domain[0]);\n vec2 coord = vec2(normalisedValue, 0);\n return texture(SAMPLER_2D(u_colorTexture), coord);\n}\n\nvoid main() {\n float value = getElevation(v_texCoord, 0.0);\n if (value == u_noDataValue) {\n outputColor = vec4(0.0, 0, 0, 0.0);\n } else if (u_clampLow < 0.5 && value < u_domain[0] || u_clampHigh < 0.5 && value > u_domain[1]) {\n outputColor = vec4(0.0, 0, 0, 0.0);\n } else {\n outputColor = getColor(value);\n outputColor.a = outputColor.a * u_opacity;\n if (outputColor.a < 0.01) discard;\n }\n}\n";
|
|
16
16
|
/* babel-plugin-inline-import '../shaders/terrain/terrain_rgb_vert.glsl' */
|
|
17
17
|
const Raster_terrainVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_unpack;\n vec2 u_domain;\n float u_opacity;\n float u_noDataValue;\n float u_clampLow;\n float u_clampHigh;\n};\nout vec2 v_texCoord;\n#pragma include \"projection\"\n\nvoid main() {\n v_texCoord = a_Uv;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy, 0.0, 1.0));\n}\n";
|
|
18
18
|
class RasterTerrainRGB extends _BaseModel.default {
|