@antv/l7-layers 2.22.5 → 2.22.6

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.
Files changed (101) hide show
  1. package/es/core/BaseLayer.d.ts +19 -0
  2. package/es/core/BaseLayer.js +56 -0
  3. package/es/core/interface.d.ts +4 -3
  4. package/es/earth/models/atmosphere.js +1 -1
  5. package/es/earth/models/base.js +1 -1
  6. package/es/earth/models/bloomsphere.js +1 -1
  7. package/es/earth/shaders/atmosphere/atmosphere_frag.glsl +6 -9
  8. package/es/earth/shaders/base/base_frag.glsl +3 -3
  9. package/es/earth/shaders/bloomshpere/bloomsphere_frag.glsl +5 -6
  10. package/es/geometry/models/billboard.js +1 -1
  11. package/es/geometry/models/sprite.js +1 -1
  12. package/es/geometry/shaders/billboard_frag.glsl +4 -4
  13. package/es/geometry/shaders/sprite_frag.glsl +2 -4
  14. package/es/heatmap/models/heatmap.js +3 -3
  15. package/es/heatmap/shaders/heatmap/heatmap_3d_frag.glsl +6 -7
  16. package/es/heatmap/shaders/heatmap/heatmap_frag.glsl +24 -36
  17. package/es/heatmap/shaders/heatmap/heatmap_framebuffer_frag.glsl +5 -5
  18. package/es/line/models/flow.js +1 -1
  19. package/es/line/shaders/flow/flow_line_frag.glsl +0 -1
  20. package/es/plugins/LayerMaskPlugin.js +1 -1
  21. package/es/plugins/ShaderUniformPlugin.js +26 -8
  22. package/es/point/models/billboard_point.js +1 -1
  23. package/es/point/models/extrude.js +1 -1
  24. package/es/point/models/fill.js +1 -1
  25. package/es/point/models/image.js +1 -1
  26. package/es/point/models/normal.js +1 -1
  27. package/es/point/shaders/billboard/billboard_point_frag.glsl +6 -8
  28. package/es/point/shaders/extrude/extrude_frag.glsl +1 -3
  29. package/es/point/shaders/fill/fill_frag.glsl +14 -17
  30. package/es/point/shaders/image/image_frag.glsl +15 -12
  31. package/es/point/shaders/normal/normal_frag.glsl +1 -1
  32. package/es/polygon/models/extrude.js +3 -3
  33. package/es/polygon/models/extrusion.js +1 -1
  34. package/es/polygon/models/fill.js +1 -1
  35. package/es/polygon/models/ocean.js +1 -1
  36. package/es/polygon/models/water.js +1 -1
  37. package/es/polygon/shaders/extrude/polygon_extrude_frag.glsl +5 -6
  38. package/es/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -8
  39. package/es/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +4 -3
  40. package/es/polygon/shaders/extrusion/polygon_extrusion_frag.glsl +0 -2
  41. package/es/polygon/shaders/fill/fill_linear_frag.glsl +4 -2
  42. package/es/polygon/shaders/ocean/ocean_frag.glsl +212 -182
  43. package/es/polygon/shaders/water/polygon_water_frag.glsl +25 -20
  44. package/es/raster/index.js +2 -1
  45. package/es/raster/models/raster.js +1 -1
  46. package/es/raster/models/rasterRgb.js +1 -1
  47. package/es/raster/models/rasterTerrainRgb.js +1 -1
  48. package/es/raster/shaders/raster/raster_2d_frag.glsl +10 -7
  49. package/es/raster/shaders/rgb/raster_rgb_frag.glsl +16 -13
  50. package/es/raster/shaders/terrain/terrain_rgb_frag.glsl +18 -21
  51. package/lib/core/BaseLayer.d.ts +19 -0
  52. package/lib/core/BaseLayer.js +56 -0
  53. package/lib/core/interface.d.ts +4 -3
  54. package/lib/earth/models/atmosphere.js +1 -1
  55. package/lib/earth/models/base.js +1 -1
  56. package/lib/earth/models/bloomsphere.js +1 -1
  57. package/lib/earth/shaders/atmosphere/atmosphere_frag.glsl +6 -9
  58. package/lib/earth/shaders/base/base_frag.glsl +3 -3
  59. package/lib/earth/shaders/bloomshpere/bloomsphere_frag.glsl +5 -6
  60. package/lib/geometry/models/billboard.js +1 -1
  61. package/lib/geometry/models/sprite.js +1 -1
  62. package/lib/geometry/shaders/billboard_frag.glsl +4 -4
  63. package/lib/geometry/shaders/sprite_frag.glsl +2 -4
  64. package/lib/heatmap/models/heatmap.js +3 -3
  65. package/lib/heatmap/shaders/heatmap/heatmap_3d_frag.glsl +6 -7
  66. package/lib/heatmap/shaders/heatmap/heatmap_frag.glsl +24 -36
  67. package/lib/heatmap/shaders/heatmap/heatmap_framebuffer_frag.glsl +5 -5
  68. package/lib/line/models/flow.js +1 -1
  69. package/lib/line/shaders/flow/flow_line_frag.glsl +0 -1
  70. package/lib/plugins/LayerMaskPlugin.js +1 -1
  71. package/lib/plugins/ShaderUniformPlugin.js +26 -8
  72. package/lib/point/models/billboard_point.js +1 -1
  73. package/lib/point/models/extrude.js +1 -1
  74. package/lib/point/models/fill.js +1 -1
  75. package/lib/point/models/image.js +1 -1
  76. package/lib/point/models/normal.js +1 -1
  77. package/lib/point/shaders/billboard/billboard_point_frag.glsl +6 -8
  78. package/lib/point/shaders/extrude/extrude_frag.glsl +1 -3
  79. package/lib/point/shaders/fill/fill_frag.glsl +14 -17
  80. package/lib/point/shaders/image/image_frag.glsl +15 -12
  81. package/lib/point/shaders/normal/normal_frag.glsl +1 -1
  82. package/lib/polygon/models/extrude.js +3 -3
  83. package/lib/polygon/models/extrusion.js +1 -1
  84. package/lib/polygon/models/fill.js +1 -1
  85. package/lib/polygon/models/ocean.js +1 -1
  86. package/lib/polygon/models/water.js +1 -1
  87. package/lib/polygon/shaders/extrude/polygon_extrude_frag.glsl +5 -6
  88. package/lib/polygon/shaders/extrude/polygon_extrude_picklight_frag.glsl +7 -8
  89. package/lib/polygon/shaders/extrude/polygon_extrudetex_frag.glsl +4 -3
  90. package/lib/polygon/shaders/extrusion/polygon_extrusion_frag.glsl +0 -2
  91. package/lib/polygon/shaders/fill/fill_linear_frag.glsl +4 -2
  92. package/lib/polygon/shaders/ocean/ocean_frag.glsl +212 -182
  93. package/lib/polygon/shaders/water/polygon_water_frag.glsl +25 -20
  94. package/lib/raster/index.js +2 -1
  95. package/lib/raster/models/raster.js +1 -1
  96. package/lib/raster/models/rasterRgb.js +1 -1
  97. package/lib/raster/models/rasterTerrainRgb.js +1 -1
  98. package/lib/raster/shaders/raster/raster_2d_frag.glsl +10 -7
  99. package/lib/raster/shaders/rgb/raster_rgb_frag.glsl +16 -13
  100. package/lib/raster/shaders/terrain/terrain_rgb_frag.glsl +18 -21
  101. package/package.json +6 -6
@@ -38,18 +38,30 @@ class ShaderUniformPlugin {
38
38
  let uniformBuffer;
39
39
  if (!this.rendererService.uniformBuffers[0]) {
40
40
  // Create a Uniform Buffer Object(UBO).
41
+ // Size calculation: 4 mat4 (64) + 1 vec4 (4) + 4 vec3->vec4 (16) + 3 vec4 packed (12) = 96 floats
41
42
  uniformBuffer = this.rendererService.createBuffer({
42
- data: new Float32Array(16 * 4 + 4 * 7),
43
+ data: new Float32Array(96),
43
44
  isUBO: true,
44
45
  label: 'renderUniformBuffer'
45
46
  });
46
47
  this.rendererService.uniformBuffers[0] = uniformBuffer;
47
48
  }
48
49
  layer.hooks.beforeRender.tap('ShaderUniformPlugin', () => {
49
- // @ts-ignore
50
- const offset = layer.getLayerConfig().tileOrigin;
50
+ // 获取图层的相对坐标原点
51
+ const layerRelativeOrigin = layer.getRelativeOrigin && layer.getRelativeOrigin();
52
+ const relativeOrigin = layerRelativeOrigin || [0, 0];
53
+
51
54
  // 重新计算坐标系参数
52
- this.coordinateSystemService.refresh(offset);
55
+ this.coordinateSystemService.refresh();
56
+
57
+ // 特殊处理:如果图层启用了相对坐标,强制设置ViewportCenter为RelativeOrigin
58
+ // 这样可以避免shader中的精度问题
59
+ const isUsingRelativeCoords = relativeOrigin && (Math.abs(relativeOrigin[0]) > 0.0001 || Math.abs(relativeOrigin[1]) > 0.0001);
60
+ if (isUsingRelativeCoords && this.coordinateSystemService.getCoordinateSystem() === 2) {
61
+ // COORDINATE_SYSTEM_LNGLAT_OFFSET
62
+ // 强制设置ViewportCenter为RelativeOrigin,避免shader中的大数计算
63
+ this.coordinateSystemService.setViewportCenter(relativeOrigin);
64
+ }
53
65
  const {
54
66
  width,
55
67
  height
@@ -57,7 +69,7 @@ class ShaderUniformPlugin {
57
69
  const {
58
70
  data,
59
71
  uniforms
60
- } = this.generateUBO(width, height);
72
+ } = this.generateUBO(width, height, relativeOrigin);
61
73
  if (this.layerService.alreadyInRendering && this.rendererService.uniformBuffers[0]) {
62
74
  const renderUniformBuffer = this.rendererService.uniformBuffers[0];
63
75
  // Update only once since all models can share one UBO.
@@ -81,7 +93,7 @@ class ShaderUniformPlugin {
81
93
  }
82
94
  });
83
95
  }
84
- generateUBO(width, height) {
96
+ generateUBO(width, height, offset) {
85
97
  const u_ProjectionMatrix = this.cameraService.getProjectionMatrix();
86
98
  const u_ViewMatrix = this.cameraService.getViewMatrix();
87
99
  const u_ViewProjectionMatrix = this.cameraService.getViewProjectionMatrix();
@@ -98,6 +110,7 @@ class ShaderUniformPlugin {
98
110
  const u_ViewportCenter = this.coordinateSystemService.getViewportCenter();
99
111
  const u_ViewportSize = [width, height];
100
112
  const u_FocalDistance = this.cameraService.getFocalDistance();
113
+ const u_RelativeOrigin = offset && offset.length >= 2 ? [offset[0], offset[1]] : [0, 0];
101
114
  const data = [...u_ViewMatrix,
102
115
  // 16
103
116
  ...u_ProjectionMatrix,
@@ -122,7 +135,10 @@ class ShaderUniformPlugin {
122
135
  // 4
123
136
  u_FocalDistance,
124
137
  // 1
125
- 0, 0, 0];
138
+ ...u_RelativeOrigin,
139
+ // 2
140
+ 0 // padding
141
+ ];
126
142
  return {
127
143
  data,
128
144
  uniforms: {
@@ -144,7 +160,9 @@ class ShaderUniformPlugin {
144
160
  // 其他参数,例如视口大小、DPR 等
145
161
  u_ViewportSize: u_ViewportSize,
146
162
  u_ModelMatrix,
147
- u_DevicePixelRatio: u_DevicePixelRatio
163
+ u_DevicePixelRatio: u_DevicePixelRatio,
164
+ // 相对原点坐标
165
+ u_RelativeOrigin: u_RelativeOrigin
148
166
  }
149
167
  };
150
168
  }
@@ -11,7 +11,7 @@ var _l7Core = require("@antv/l7-core");
11
11
  var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
12
12
  var _l7Utils = require("@antv/l7-utils");
13
13
  /* babel-plugin-inline-import '../shaders/billboard/billboard_point_frag.glsl' */
14
- const simplePointFrag = "\nlayout(std140) uniform commonUniorm {\n vec4 u_stroke_color;\n float u_additive;\n float u_stroke_opacity;\n float u_stroke_width;\n};\n\nin vec4 v_color;\nin float v_blur;\nin float v_innerRadius;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n vec2 center = vec2(0.5);\n\n // Tip: \u7247\u5143\u5230\u4E2D\u5FC3\u70B9\u7684\u8DDD\u79BB 0 - 1\n float fragmengTocenter = distance(center, gl_PointCoord) * 2.0;\n // Tip: \u7247\u5143\u7684\u526A\u5207\u6210\u5706\u5F62\n float circleClipOpacity = 1.0 - smoothstep(v_blur, 1.0, fragmengTocenter);\n\n\n if(v_innerRadius < 0.99) {\n // \u5F53\u5B58\u5728 stroke \u4E14 stroke > 0.01\n float blurWidth = (1.0 - v_blur)/2.0;\n vec4 stroke = vec4(u_stroke_color.rgb, u_stroke_opacity);\n if(fragmengTocenter > v_innerRadius + blurWidth) {\n outputColor = stroke;\n } else if(fragmengTocenter > v_innerRadius - blurWidth){\n float mixR = (fragmengTocenter - (v_innerRadius - blurWidth)) / (blurWidth * 2.0);\n outputColor = mix(v_color, stroke, mixR);\n } else {\n outputColor = v_color;\n }\n } else {\n // \u5F53\u4E0D\u5B58\u5728 stroke \u6216 stroke <= 0.01\n outputColor = v_color;\n }\n\n outputColor = filterColor(outputColor);\n \n if(u_additive > 0.0) {\n outputColor *= circleClipOpacity;\n } else {\n outputColor.a *= circleClipOpacity;\n }\n\n}\n";
14
+ const simplePointFrag = "layout(std140) uniform commonUniorm {\n vec4 u_stroke_color;\n float u_additive;\n float u_stroke_opacity;\n float u_stroke_width;\n};\n\nin vec4 v_color;\nin float v_blur;\nin float v_innerRadius;\n\nout vec4 outputColor;\n\n#pragma include \"picking\"\nvoid main() {\n vec2 center = vec2(0.5);\n\n // Tip: \u7247\u5143\u5230\u4E2D\u5FC3\u70B9\u7684\u8DDD\u79BB 0 - 1\n float fragmengTocenter = distance(center, gl_PointCoord) * 2.0;\n // Tip: \u7247\u5143\u7684\u526A\u5207\u6210\u5706\u5F62\n float circleClipOpacity = 1.0 - smoothstep(v_blur, 1.0, fragmengTocenter);\n\n if (v_innerRadius < 0.99) {\n // \u5F53\u5B58\u5728 stroke \u4E14 stroke > 0.01\n float blurWidth = (1.0 - v_blur) / 2.0;\n vec4 stroke = vec4(u_stroke_color.rgb, u_stroke_opacity);\n if (fragmengTocenter > v_innerRadius + blurWidth) {\n outputColor = stroke;\n } else if (fragmengTocenter > v_innerRadius - blurWidth) {\n float mixR = (fragmengTocenter - (v_innerRadius - blurWidth)) / (blurWidth * 2.0);\n outputColor = mix(v_color, stroke, mixR);\n } else {\n outputColor = v_color;\n }\n } else {\n // \u5F53\u4E0D\u5B58\u5728 stroke \u6216 stroke <= 0.01\n outputColor = v_color;\n }\n\n outputColor = filterColor(outputColor);\n\n if (u_additive > 0.0) {\n outputColor *= circleClipOpacity;\n } else {\n outputColor.a *= circleClipOpacity;\n }\n\n}\n";
15
15
  /* babel-plugin-inline-import '../shaders/billboard/billboard_point_vert.glsl' */
16
16
  const simplePointVert = "\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\n\nlayout(std140) uniform commonUniorm {\n vec4 u_stroke_color;\n float u_additive;\n float u_stroke_opacity;\n float u_stroke_width;\n};\n\nout vec4 v_color;\nout float v_blur;\nout float v_innerRadius;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"project\"\nvoid main() {\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n v_blur = 1.0 - max(2.0 / a_Size, 0.05);\n v_innerRadius = max((a_Size - u_stroke_width) / a_Size, 0.0);\n\n vec2 offset = project_pixel(u_offsets);\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n gl_Position = project_common_position_to_clipspace(vec4(vec2(project_pos.xy+offset),project_pos.z,project_pos.w));\n\n gl_PointSize = a_Size * 2.0 * u_DevicePixelRatio;\n setPickingColor(a_PickingColor);\n}\n";
17
17
  function PointTriangulation(feature) {
@@ -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/extrude/extrude_frag.glsl' */
15
- const pointExtrudeFrag = "\nin vec4 v_color;\nin float v_lightWeight;\nout vec4 outputColor;\n\nlayout(std140) uniform commonUniforms {\n float u_pickLight;\n float u_heightfixed;\n float u_r;\n float u_linearColor;\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_opacitylinear;\n float u_opacitylinear_dir;\n float u_lightEnable;\n};\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n\n outputColor = v_color;\n // \u5F00\u542F\u900F\u660E\u5EA6\u6E10\u53D8\n // picking\n if(u_pickLight > 0.0) {\n outputColor = filterColorAlpha(outputColor, v_lightWeight);\n } else {\n outputColor = filterColor(outputColor);\n }\n}\n";
15
+ const pointExtrudeFrag = "in vec4 v_color;\nin float v_lightWeight;\nout vec4 outputColor;\n\nlayout(std140) uniform commonUniforms {\n float u_pickLight;\n float u_heightfixed;\n float u_r;\n float u_linearColor;\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_opacitylinear;\n float u_opacitylinear_dir;\n float u_lightEnable;\n};\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n outputColor = v_color;\n // \u5F00\u542F\u900F\u660E\u5EA6\u6E10\u53D8\n // picking\n if (u_pickLight > 0.0) {\n outputColor = filterColorAlpha(outputColor, v_lightWeight);\n } else {\n outputColor = filterColor(outputColor);\n }\n}\n";
16
16
  /* babel-plugin-inline-import '../shaders/extrude/extrude_vert.glsl' */
17
17
  const pointExtrudeVert = "#define pi (3.1415926535)\n\nlayout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in vec3 a_Size;\nlayout(location = ATTRIBUTE_LOCATION_EXTRUDE) in vec4 a_Extrude;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\n\nlayout(std140) uniform commonUniforms {\n float u_pickLight;\n float u_heightfixed;\n float u_r;\n float u_linearColor;\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_opacitylinear;\n float u_opacitylinear_dir;\n float u_lightEnable;\n};\nout vec4 v_color;\nout float v_lightWeight;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nfloat getYRadian(float x, float z) {\n if (x > 0.0 && z > 0.0) {\n return atan(x / z);\n } else if (x > 0.0 && z <= 0.0) {\n return atan(-z / x) + pi / 2.0;\n } else if (x <= 0.0 && z <= 0.0) {\n return pi + atan(x / z); //atan(x/z) +\n } else {\n return atan(z / -x) + pi * 3.0 / 2.0;\n }\n}\n\nfloat getXRadian(float y, float r) {\n return atan(y / r);\n}\n\nvoid main() {\n vec3 size = a_Size * a_Position;\n\n vec3 offset = size; // \u63A7\u5236\u5706\u67F1\u4F53\u7684\u5927\u5C0F - \u4ECE\u6807\u51C6\u5355\u4F4D\u5706\u67F1\u4F53\u8FDB\u884C\u504F\u79FB\n\n if (u_heightfixed < 1.0) {\n // \u5706\u67F1\u4F53\u4E0D\u56FA\u5B9A\u9AD8\u5EA6\n } else {\n // \u5706\u67F1\u4F53\u56FA\u5B9A\u9AD8\u5EA6 \uFF08 \u5904\u7406 mapbox \uFF09\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n offset *= 4.0 / pow(2.0, 21.0 - u_Zoom);\n }\n }\n\n vec2 positions = a_Extrude.xy;\n vec2 positions64Low = a_Extrude.zw;\n vec4 project_pos = project_position(vec4(positions, 0.0, 1.0), positions64Low);\n\n // u_r \u63A7\u5236\u5706\u67F1\u7684\u751F\u957F\n vec4 pos = vec4(project_pos.xy + offset.xy, offset.z * u_r, 1.0);\n\n // // \u5706\u67F1\u5149\u7167\u6548\u679C\n float lightWeight = 1.0;\n\n if (u_lightEnable > 0.0) {\n // \u53D6\u6D88\u4E09\u5143\u8868\u8FBE\u5F0F\uFF0C\u589E\u5F3A\u5065\u58EE\u6027\n lightWeight = calc_lighting(pos);\n }\n\n v_lightWeight = lightWeight;\n\n v_color = a_Color;\n\n // \u8BBE\u7F6E\u5706\u67F1\u7684\u5E95\u8272\n if (u_linearColor == 1.0) {\n // \u4F7F\u7528\u6E10\u53D8\u989C\u8272\n v_color = mix(u_sourceColor, u_targetColor, a_Position.z);\n v_color.a = v_color.a * opacity;\n } else {\n v_color = vec4(a_Color.rgb * lightWeight, a_Color.w * opacity);\n }\n\n if (u_opacitylinear > 0.0) {\n v_color.a *= u_opacitylinear_dir > 0.0 ? 1.0 - a_Position.z : a_Position.z;\n }\n\n gl_Position = project_common_position_to_clipspace(pos);\n\n setPickingColor(a_PickingColor);\n}\n";
18
18
  class ExtrudeModel extends _BaseModel.default {
@@ -11,7 +11,7 @@ var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
11
11
  var _triangulation = require("../../core/triangulation");
12
12
  var _interface = require("../../core/interface");
13
13
  /* babel-plugin-inline-import '../shaders/fill/fill_frag.glsl' */
14
- const pointFillFrag = "\nlayout(std140) uniform commonUniforms {\n vec3 u_blur_height_fixed;\n float u_stroke_width;\n float u_additive;\n float u_stroke_opacity;\n float u_size_unit;\n float u_time;\n vec4 u_animate;\n};\n\nin vec4 v_color;\nin vec4 v_stroke;\nin vec4 v_data;\nin float v_radius;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"sdf_2d\"\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n int shape = int(floor(v_data.w + 0.5));\n lowp float antialiasblur = v_data.z;\n float r = v_radius / (v_radius + u_stroke_width);\n\n float outer_df;\n float inner_df;\n // 'circle', 'triangle', 'square', 'pentagon', 'hexagon', 'octogon', 'hexagram', 'rhombus', 'vesica'\n if (shape == 0) {\n outer_df = sdCircle(v_data.xy, 1.0);\n inner_df = sdCircle(v_data.xy, r);\n } else if (shape == 1) {\n outer_df = sdEquilateralTriangle(1.1 * v_data.xy);\n inner_df = sdEquilateralTriangle(1.1 / r * v_data.xy);\n } else if (shape == 2) {\n outer_df = sdBox(v_data.xy, vec2(1.));\n inner_df = sdBox(v_data.xy, vec2(r));\n } else if (shape == 3) {\n outer_df = sdPentagon(v_data.xy, 0.8);\n inner_df = sdPentagon(v_data.xy, r * 0.8);\n } else if (shape == 4) {\n outer_df = sdHexagon(v_data.xy, 0.8);\n inner_df = sdHexagon(v_data.xy, r * 0.8);\n } else if (shape == 5) {\n outer_df = sdOctogon(v_data.xy, 1.0);\n inner_df = sdOctogon(v_data.xy, r);\n } else if (shape == 6) {\n outer_df = sdHexagram(v_data.xy, 0.52);\n inner_df = sdHexagram(v_data.xy, r * 0.52);\n } else if (shape == 7) {\n outer_df = sdRhombus(v_data.xy, vec2(1.0));\n inner_df = sdRhombus(v_data.xy, vec2(r));\n } else if (shape == 8) {\n outer_df = sdVesica(v_data.xy, 1.1, 0.8);\n inner_df = sdVesica(v_data.xy, r * 1.1, r * 0.8);\n }\n\n float opacity_t = smoothstep(0.0, antialiasblur, outer_df);\n\n float color_t = u_stroke_width < 0.01 ? 0.0 : smoothstep(\n antialiasblur,\n 0.0,\n inner_df\n );\n\n float PI = 3.14159;\n float N_RINGS = 3.0;\n float FREQ = 1.0;\n\n if(u_stroke_width < 0.01) {\n outputColor = v_color;\n } else {\n outputColor = mix(v_color, v_stroke * u_stroke_opacity, color_t);\n }\n float intensity = 1.0;\n if(u_time!=-1.0){\n //wave\u76F8\u5173\u903B\u8F91\n float d = length(v_data.xy);\n if(d > 0.5) {\n discard;\n }\n intensity = clamp(cos(d * PI), 0.0, 1.0) * clamp(cos(2.0 * PI * (d * 2.0 * u_animate.z - u_animate.y * u_time)), 0.0, 1.0);\n }\n\n if(u_additive > 0.0) {\n outputColor *= opacity_t;\n outputColor *= intensity;//wave\n outputColor = filterColorAlpha(outputColor, outputColor.a);\n } else {\n outputColor.a *= opacity_t;\n outputColor.a *= intensity;//wave \n outputColor = filterColor(outputColor);\n }\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if(outputColor.a < 0.01) {\n discard;\n } \n}\n";
14
+ const pointFillFrag = "layout(std140) uniform commonUniforms {\n vec3 u_blur_height_fixed;\n float u_stroke_width;\n float u_additive;\n float u_stroke_opacity;\n float u_size_unit;\n float u_time;\n vec4 u_animate;\n};\n\nin vec4 v_color;\nin vec4 v_stroke;\nin vec4 v_data;\nin float v_radius;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"sdf_2d\"\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n int shape = int(floor(v_data.w + 0.5));\n lowp float antialiasblur = v_data.z;\n float r = v_radius / (v_radius + u_stroke_width);\n\n float outer_df;\n float inner_df;\n // 'circle', 'triangle', 'square', 'pentagon', 'hexagon', 'octogon', 'hexagram', 'rhombus', 'vesica'\n if (shape == 0) {\n outer_df = sdCircle(v_data.xy, 1.0);\n inner_df = sdCircle(v_data.xy, r);\n } else if (shape == 1) {\n outer_df = sdEquilateralTriangle(1.1 * v_data.xy);\n inner_df = sdEquilateralTriangle(1.1 / r * v_data.xy);\n } else if (shape == 2) {\n outer_df = sdBox(v_data.xy, vec2(1.0));\n inner_df = sdBox(v_data.xy, vec2(r));\n } else if (shape == 3) {\n outer_df = sdPentagon(v_data.xy, 0.8);\n inner_df = sdPentagon(v_data.xy, r * 0.8);\n } else if (shape == 4) {\n outer_df = sdHexagon(v_data.xy, 0.8);\n inner_df = sdHexagon(v_data.xy, r * 0.8);\n } else if (shape == 5) {\n outer_df = sdOctogon(v_data.xy, 1.0);\n inner_df = sdOctogon(v_data.xy, r);\n } else if (shape == 6) {\n outer_df = sdHexagram(v_data.xy, 0.52);\n inner_df = sdHexagram(v_data.xy, r * 0.52);\n } else if (shape == 7) {\n outer_df = sdRhombus(v_data.xy, vec2(1.0));\n inner_df = sdRhombus(v_data.xy, vec2(r));\n } else if (shape == 8) {\n outer_df = sdVesica(v_data.xy, 1.1, 0.8);\n inner_df = sdVesica(v_data.xy, r * 1.1, r * 0.8);\n }\n\n float opacity_t = smoothstep(0.0, antialiasblur, outer_df);\n\n float color_t = u_stroke_width < 0.01 ? 0.0 : smoothstep(antialiasblur, 0.0, inner_df);\n\n float PI = 3.14159;\n float N_RINGS = 3.0;\n float FREQ = 1.0;\n\n if (u_stroke_width < 0.01) {\n outputColor = v_color;\n } else {\n outputColor = mix(v_color, v_stroke * u_stroke_opacity, color_t);\n }\n float intensity = 1.0;\n if (u_time != -1.0) {\n //wave\u76F8\u5173\u903B\u8F91\n float d = length(v_data.xy);\n if (d > 0.5) {\n discard;\n }\n intensity =\n clamp(cos(d * PI), 0.0, 1.0) *\n clamp(cos(2.0 * PI * (d * 2.0 * u_animate.z - u_animate.y * u_time)), 0.0, 1.0);\n }\n\n if (u_additive > 0.0) {\n outputColor *= opacity_t;\n outputColor *= intensity; //wave\n outputColor = filterColorAlpha(outputColor, outputColor.a);\n } else {\n outputColor.a *= opacity_t;\n outputColor.a *= intensity; //wave\n outputColor = filterColor(outputColor);\n }\n // \u4F5C\u4E3A mask \u6A21\u677F\u65F6\u9700\u8981\u4E22\u5F03\u900F\u660E\u7684\u50CF\u7D20\n if (outputColor.a < 0.01) {\n discard;\n }\n}\n";
15
15
  /* babel-plugin-inline-import '../shaders/fill/fill_vert.glsl' */
16
16
  const pointFillVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_SHAPE) in float a_Shape;\nlayout(location = ATTRIBUTE_LOCATION_EXTRUDE) in vec3 a_Extrude;\n\nlayout(std140) uniform commonUniforms {\n vec3 u_blur_height_fixed;\n float u_stroke_width;\n float u_additive;\n float u_stroke_opacity;\n float u_size_unit;\n float u_time;\n vec4 u_animate;\n};\n\nout vec4 v_color;\nout vec4 v_stroke;\nout vec4 v_data;\nout float v_radius;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n#pragma include \"rotation_2d\"\n\nvoid main() {\n // \u900F\u660E\u5EA6\u8BA1\u7B97\n v_stroke = stroke;\n vec3 extrude = a_Extrude;\n float shape_type = a_Shape;\n /*\n * setPickingSize \u8BBE\u7F6E\u62FE\u53D6\u5927\u5C0F\n * u_meter2coord \u5728\u7B49\u9762\u79EF\u5927\u5C0F\u7684\u65F6\u5019\u8BBE\u7F6E\u5355\u4F4D\n */\n float newSize = setPickingSize(a_Size);\n // float newSize = setPickingSize(a_Size) * 0.00001038445708445579;\n\n\n\n // unpack color(vec2)\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n\n if(u_size_unit == 1.0) {\n newSize = newSize * u_PixelsPerMeter.z;\n }\n\n v_radius = newSize;\n\n // anti-alias\n // float antialiased_blur = -max(u_blur, antialiasblur);\n float antialiasblur = -max(2.0 / u_DevicePixelRatio / newSize, u_blur_height_fixed.x);\n\n vec2 offset = (extrude.xy * (newSize + u_stroke_width) + u_offsets);\n\n offset = project_pixel(offset);\n offset = rotate_matrix(offset,rotation);\n\n // TODP: /abs(extrude.x) \u662F\u4E3A\u4E86\u517C\u5BB9\u5730\u7403\u6A21\u5F0F\n v_data = vec4(extrude.x/abs(extrude.x), extrude.y/abs(extrude.y), antialiasblur,shape_type);\n\n vec4 project_pos = project_position(vec4(a_Position.xy, 0.0, 1.0), a_Position64Low);\n // gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, project_pixel(setPickingOrder(0.0)), 1.0));\n\n float raisingHeight = u_blur_height_fixed.y;\n\n if(u_blur_height_fixed.z < 1.0) { // false\n raisingHeight = project_pixel(u_blur_height_fixed.y);\n } else {\n if(u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n raisingHeight = u_blur_height_fixed.y * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, raisingHeight, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
17
17
  class FillModel extends _BaseModel.default {
@@ -12,7 +12,7 @@ var _l7Core = require("@antv/l7-core");
12
12
  var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
13
13
  var _triangulation = require("../../core/triangulation");
14
14
  /* babel-plugin-inline-import '../shaders/image/image_frag.glsl' */
15
- const pointImageFrag = "layout(std140) uniform commonUniforms {\n vec2 u_textSize;\n float u_raisingHeight;\n float u_heightfixed;\n};\n\nuniform sampler2D u_texture;\n\nin vec4 v_color;\nin vec2 v_uv;\nin float v_opacity;\n\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main(){\n vec2 pos = v_uv / u_textSize + gl_PointCoord / u_textSize * 64.;\n vec4 textureColor;\n\n // Y = 0.299R + 0.587G + 0.114B // \u4EAE\u5EA6\u63D0\u53D6\n \n textureColor = texture(SAMPLER_2D(u_texture), pos);\n\n // Tip: \u53BB\u9664\u8FB9\u7F18\u90E8\u5206 mipmap \u5BFC\u81F4\u7684\u6DF7\u5408\u53D8\u6697\n float fragmengTocenter = distance(vec2(0.5), gl_PointCoord);\n if(fragmengTocenter >= 0.5) {\n float luma = 0.299 * textureColor.r + 0.587 * textureColor.g + 0.114 * textureColor.b;\n textureColor.a *= luma;\n }\n \n if(all(lessThan(v_color, vec4(1.0+0.00001))) && all(greaterThan(v_color, vec4(1.0-0.00001))) || v_color==vec4(1.0)){\n outputColor= textureColor;\n }else {\n outputColor= step(0.01, textureColor.z) * v_color;\n }\n outputColor.a *= v_opacity;\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n}\n";
15
+ const pointImageFrag = "layout(std140) uniform commonUniforms {\n vec2 u_textSize;\n float u_raisingHeight;\n float u_heightfixed;\n};\n\nuniform sampler2D u_texture;\n\nin vec4 v_color;\nin vec2 v_uv;\nin float v_opacity;\n\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n vec2 pos = v_uv / u_textSize + gl_PointCoord / u_textSize * 64.0;\n vec4 textureColor;\n\n // Y = 0.299R + 0.587G + 0.114B // \u4EAE\u5EA6\u63D0\u53D6\n\n textureColor = texture(SAMPLER_2D(u_texture), pos);\n\n // Tip: \u53BB\u9664\u8FB9\u7F18\u90E8\u5206 mipmap \u5BFC\u81F4\u7684\u6DF7\u5408\u53D8\u6697\n float fragmengTocenter = distance(vec2(0.5), gl_PointCoord);\n if (fragmengTocenter >= 0.5) {\n float luma = 0.299 * textureColor.r + 0.587 * textureColor.g + 0.114 * textureColor.b;\n textureColor.a *= luma;\n }\n\n if (\n all(lessThan(v_color, vec4(1.0 + 0.00001))) && all(greaterThan(v_color, vec4(1.0 - 0.00001))) ||\n v_color == vec4(1.0)\n ) {\n outputColor = textureColor;\n } else {\n outputColor = step(0.01, textureColor.z) * v_color;\n }\n outputColor.a *= v_opacity;\n if (outputColor.a < 0.01) {\n discard;\n }\n outputColor = filterColor(outputColor);\n}\n";
16
16
  /* babel-plugin-inline-import '../shaders/image/image_vert.glsl' */
17
17
  const pointImageVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_Uv;\n\nlayout(std140) uniform commonUniforms {\n vec2 u_textSize;\n float u_raisingHeight;\n float u_heightfixed;\n};\n\nout vec4 v_color;\nout vec2 v_uv;\nout float v_opacity;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n v_color = a_Color;\n v_opacity = opacity;\n v_uv = a_Uv;\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n\n vec2 offset = project_pixel(offsets);\n\n float raisingHeight = u_raisingHeight;\n if (u_heightfixed < 1.0) {\n // false\n raisingHeight = project_pixel(u_raisingHeight);\n } else {\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);\n raisingHeight = u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xy + offset, raisingHeight, 1.0));\n\n gl_PointSize = a_Size * 2.0 * u_DevicePixelRatio;\n setPickingColor(a_PickingColor);\n}\n";
18
18
  class ImageModel extends _BaseModel.default {
@@ -10,7 +10,7 @@ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/
10
10
  var _l7Core = require("@antv/l7-core");
11
11
  var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
12
12
  /* babel-plugin-inline-import '../shaders/normal/normal_frag.glsl' */
13
- const normalFrag = "in vec4 v_color;\nout vec4 outputColor;\nvoid main() {\n outputColor = v_color;\n}";
13
+ const normalFrag = "in vec4 v_color;\nout vec4 outputColor;\nvoid main() {\n outputColor = v_color;\n}\n";
14
14
  /* babel-plugin-inline-import '../shaders/normal/normal_vert.glsl' */
15
15
  const normalVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\n\nlayout(std140) uniform u_Common {\n float u_size_scale;\n};\n\nout vec4 v_color;\n\n#pragma include \"projection\"\n#pragma include \"project\"\n\nvoid main() {\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n gl_Position = project_common_position_to_clipspace(project_pos);\n\n gl_PointSize = a_Size * u_size_scale * 2.0 * u_DevicePixelRatio;\n}\n";
16
16
  function PointTriangulation(feature) {
@@ -1,4 +1,3 @@
1
-
2
1
  layout(std140) uniform commonUniorm {
3
2
  vec4 u_stroke_color;
4
3
  float u_additive;
@@ -21,14 +20,13 @@ void main() {
21
20
  // Tip: 片元的剪切成圆形
22
21
  float circleClipOpacity = 1.0 - smoothstep(v_blur, 1.0, fragmengTocenter);
23
22
 
24
-
25
- if(v_innerRadius < 0.99) {
23
+ if (v_innerRadius < 0.99) {
26
24
  // 当存在 stroke 且 stroke > 0.01
27
- float blurWidth = (1.0 - v_blur)/2.0;
25
+ float blurWidth = (1.0 - v_blur) / 2.0;
28
26
  vec4 stroke = vec4(u_stroke_color.rgb, u_stroke_opacity);
29
- if(fragmengTocenter > v_innerRadius + blurWidth) {
27
+ if (fragmengTocenter > v_innerRadius + blurWidth) {
30
28
  outputColor = stroke;
31
- } else if(fragmengTocenter > v_innerRadius - blurWidth){
29
+ } else if (fragmengTocenter > v_innerRadius - blurWidth) {
32
30
  float mixR = (fragmengTocenter - (v_innerRadius - blurWidth)) / (blurWidth * 2.0);
33
31
  outputColor = mix(v_color, stroke, mixR);
34
32
  } else {
@@ -40,8 +38,8 @@ void main() {
40
38
  }
41
39
 
42
40
  outputColor = filterColor(outputColor);
43
-
44
- if(u_additive > 0.0) {
41
+
42
+ if (u_additive > 0.0) {
45
43
  outputColor *= circleClipOpacity;
46
44
  } else {
47
45
  outputColor.a *= circleClipOpacity;
@@ -1,4 +1,3 @@
1
-
2
1
  in vec4 v_color;
3
2
  in float v_lightWeight;
4
3
  out vec4 outputColor;
@@ -19,11 +18,10 @@ layout(std140) uniform commonUniforms {
19
18
  #pragma include "picking"
20
19
 
21
20
  void main() {
22
-
23
21
  outputColor = v_color;
24
22
  // 开启透明度渐变
25
23
  // picking
26
- if(u_pickLight > 0.0) {
24
+ if (u_pickLight > 0.0) {
27
25
  outputColor = filterColorAlpha(outputColor, v_lightWeight);
28
26
  } else {
29
27
  outputColor = filterColor(outputColor);
@@ -1,4 +1,3 @@
1
-
2
1
  layout(std140) uniform commonUniforms {
3
2
  vec3 u_blur_height_fixed;
4
3
  float u_stroke_width;
@@ -35,7 +34,7 @@ void main() {
35
34
  outer_df = sdEquilateralTriangle(1.1 * v_data.xy);
36
35
  inner_df = sdEquilateralTriangle(1.1 / r * v_data.xy);
37
36
  } else if (shape == 2) {
38
- outer_df = sdBox(v_data.xy, vec2(1.));
37
+ outer_df = sdBox(v_data.xy, vec2(1.0));
39
38
  inner_df = sdBox(v_data.xy, vec2(r));
40
39
  } else if (shape == 3) {
41
40
  outer_df = sdPentagon(v_data.xy, 0.8);
@@ -59,42 +58,40 @@ void main() {
59
58
 
60
59
  float opacity_t = smoothstep(0.0, antialiasblur, outer_df);
61
60
 
62
- float color_t = u_stroke_width < 0.01 ? 0.0 : smoothstep(
63
- antialiasblur,
64
- 0.0,
65
- inner_df
66
- );
61
+ float color_t = u_stroke_width < 0.01 ? 0.0 : smoothstep(antialiasblur, 0.0, inner_df);
67
62
 
68
63
  float PI = 3.14159;
69
64
  float N_RINGS = 3.0;
70
65
  float FREQ = 1.0;
71
66
 
72
- if(u_stroke_width < 0.01) {
67
+ if (u_stroke_width < 0.01) {
73
68
  outputColor = v_color;
74
69
  } else {
75
70
  outputColor = mix(v_color, v_stroke * u_stroke_opacity, color_t);
76
71
  }
77
72
  float intensity = 1.0;
78
- if(u_time!=-1.0){
73
+ if (u_time != -1.0) {
79
74
  //wave相关逻辑
80
75
  float d = length(v_data.xy);
81
- if(d > 0.5) {
76
+ if (d > 0.5) {
82
77
  discard;
83
78
  }
84
- intensity = clamp(cos(d * PI), 0.0, 1.0) * clamp(cos(2.0 * PI * (d * 2.0 * u_animate.z - u_animate.y * u_time)), 0.0, 1.0);
79
+ intensity =
80
+ clamp(cos(d * PI), 0.0, 1.0) *
81
+ clamp(cos(2.0 * PI * (d * 2.0 * u_animate.z - u_animate.y * u_time)), 0.0, 1.0);
85
82
  }
86
83
 
87
- if(u_additive > 0.0) {
84
+ if (u_additive > 0.0) {
88
85
  outputColor *= opacity_t;
89
- outputColor *= intensity;//wave
86
+ outputColor *= intensity; //wave
90
87
  outputColor = filterColorAlpha(outputColor, outputColor.a);
91
88
  } else {
92
89
  outputColor.a *= opacity_t;
93
- outputColor.a *= intensity;//wave
90
+ outputColor.a *= intensity; //wave
94
91
  outputColor = filterColor(outputColor);
95
92
  }
96
- // 作为 mask 模板时需要丢弃透明的像素
97
- if(outputColor.a < 0.01) {
93
+ // 作为 mask 模板时需要丢弃透明的像素
94
+ if (outputColor.a < 0.01) {
98
95
  discard;
99
- }
96
+ }
100
97
  }
@@ -14,29 +14,32 @@ in float v_opacity;
14
14
 
15
15
  out vec4 outputColor;
16
16
 
17
- void main(){
18
- vec2 pos = v_uv / u_textSize + gl_PointCoord / u_textSize * 64.;
17
+ void main() {
18
+ vec2 pos = v_uv / u_textSize + gl_PointCoord / u_textSize * 64.0;
19
19
  vec4 textureColor;
20
20
 
21
21
  // Y = 0.299R + 0.587G + 0.114B // 亮度提取
22
-
22
+
23
23
  textureColor = texture(SAMPLER_2D(u_texture), pos);
24
24
 
25
25
  // Tip: 去除边缘部分 mipmap 导致的混合变暗
26
26
  float fragmengTocenter = distance(vec2(0.5), gl_PointCoord);
27
- if(fragmengTocenter >= 0.5) {
28
- float luma = 0.299 * textureColor.r + 0.587 * textureColor.g + 0.114 * textureColor.b;
29
- textureColor.a *= luma;
27
+ if (fragmengTocenter >= 0.5) {
28
+ float luma = 0.299 * textureColor.r + 0.587 * textureColor.g + 0.114 * textureColor.b;
29
+ textureColor.a *= luma;
30
30
  }
31
-
32
- if(all(lessThan(v_color, vec4(1.0+0.00001))) && all(greaterThan(v_color, vec4(1.0-0.00001))) || v_color==vec4(1.0)){
33
- outputColor= textureColor;
34
- }else {
35
- outputColor= step(0.01, textureColor.z) * v_color;
31
+
32
+ if (
33
+ all(lessThan(v_color, vec4(1.0 + 0.00001))) && all(greaterThan(v_color, vec4(1.0 - 0.00001))) ||
34
+ v_color == vec4(1.0)
35
+ ) {
36
+ outputColor = textureColor;
37
+ } else {
38
+ outputColor = step(0.01, textureColor.z) * v_color;
36
39
  }
37
40
  outputColor.a *= v_opacity;
38
41
  if (outputColor.a < 0.01) {
39
- discard;
42
+ discard;
40
43
  }
41
44
  outputColor = filterColor(outputColor);
42
45
  }
@@ -2,4 +2,4 @@ in vec4 v_color;
2
2
  out vec4 outputColor;
3
3
  void main() {
4
4
  outputColor = v_color;
5
- }
5
+ }
@@ -14,15 +14,15 @@ var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
14
14
  var _triangulation = require("../../core/triangulation");
15
15
  var _loadImage = require("../../utils/load-image");
16
16
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_frag.glsl' */
17
- const polygonExtrudeFrag = "layout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n\n outputColor = v_Color;\n \n outputColor = filterColor(outputColor);\n}\n";
17
+ const polygonExtrudeFrag = "layout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n // top face\n if (u_topsurface < 1.0) {\n discard;\n }\n\n outputColor = v_Color;\n\n outputColor = filterColor(outputColor);\n}\n";
18
18
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_picklight_frag.glsl' */
19
- const polygonExtrudePickLightFrag = "\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\nout vec4 outputColor;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n float isSide = v_texture_data.x;\n float sidey = v_uvs[2];\n float lightWeight = v_texture_data.y;\n\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if(isSide < 0.999) {\n // side face\n if(u_sidesurface < 1.0) {\n discard;\n }\n \n if( u_linearColor == 1.0) {\n // side use linear\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n // side notuse linear\n outputColor = v_Color;\n }\n } else {\n // top face\n if(u_topsurface < 1.0) {\n discard;\n }\n outputColor = v_Color;\n }\n\n outputColor = filterColorAlpha(outputColor, lightWeight);\n}\n";
19
+ const polygonExtrudePickLightFrag = "layout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\nout vec4 outputColor;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n float isSide = v_texture_data.x;\n float sidey = v_uvs[2];\n float lightWeight = v_texture_data.y;\n\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {\n // side face\n if (u_sidesurface < 1.0) {\n discard;\n }\n\n if (u_linearColor == 1.0) {\n // side use linear\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n // side notuse linear\n outputColor = v_Color;\n }\n } else {\n // top face\n if (u_topsurface < 1.0) {\n discard;\n }\n outputColor = v_Color;\n }\n\n outputColor = filterColorAlpha(outputColor, lightWeight);\n}\n";
20
20
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_picklight_vert.glsl' */
21
21
  const polygonExtrudePickLightVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\nout vec3 v_uvs;\nout vec2 v_texture_data;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n v_uvs = a_uvs;\n // cal style mapping - \u6570\u636E\u7EB9\u7406\u6620\u5C04\u90E8\u5206\u7684\u8BA1\u7B97\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos, a_Position64Low);\n\n if (u_heightfixed > 0.0) {\n // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n float lightWeight = calc_lighting(project_pos);\n v_texture_data = vec2(a_Position.z, lightWeight);\n\n v_Color = vec4(a_Color.rgb * lightWeight, a_Color.w * opacity);\n\n setPickingColor(a_PickingColor);\n}\n";
22
22
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrude_vert.glsl' */
23
23
  const polygonExtrudeVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n float isSide = a_Position.z;\n float topU = a_uvs[0];\n float topV = 1.0 - a_uvs[1];\n float sidey = a_uvs[2];\n\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n\n vec4 project_pos = project_position(pos, a_Position64Low);\n float lightWeight = calc_lighting(project_pos);\n\n if (u_heightfixed > 0.0) {\n // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {\n // side face\n // if(u_sidesurface < 1.0) {\n // discard;\n // }\n\n if (u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n v_Color = linearColor;\n } else {\n v_Color = a_Color;\n }\n\n } else {\n v_Color = a_Color;\n }\n\n v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);\n\n setPickingColor(a_PickingColor);\n}\n";
24
24
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrudetex_frag.glsl' */
25
- const polygonExtrudeTexFrag = "uniform sampler2D u_texture;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n float opacity = u_opacity;\n float isSide = v_texture_data.x;\n float lightWeight = v_texture_data.y;\n float topU = v_uvs[0];\n float topV = 1.0 - v_uvs[1];\n float sidey = v_uvs[2];\n\n outputColor = texture(SAMPLER_2D(u_texture), vec2(topU, topV));\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {// \u662F\u5426\u662F\u8FB9\u7F18\n // side face\n if (u_sidesurface < 1.0) {\n discard;\n }\n\n if (u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n outputColor = v_Color;\n }\n } else {\n // top face\n if (u_topsurface < 1.0) {\n discard;\n }\n }\n \n outputColor.a *= opacity;\n outputColor = filterColor(outputColor);\n}\n";
25
+ const polygonExtrudeTexFrag = "uniform sampler2D u_texture;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nin vec4 v_Color;\nin vec3 v_uvs;\nin vec2 v_texture_data;\n\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nout vec4 outputColor;\n\nvoid main() {\n float opacity = u_opacity;\n float isSide = v_texture_data.x;\n float lightWeight = v_texture_data.y;\n float topU = v_uvs[0];\n float topV = 1.0 - v_uvs[1];\n float sidey = v_uvs[2];\n\n outputColor = texture(SAMPLER_2D(u_texture), vec2(topU, topV));\n // Tip: \u90E8\u5206\u673A\u578B GPU \u8BA1\u7B97\u7CBE\u5EA6\u517C\u5BB9\n if (isSide < 0.999) {\n // \u662F\u5426\u662F\u8FB9\u7F18\n // side face\n if (u_sidesurface < 1.0) {\n discard;\n }\n\n if (u_linearColor == 1.0) {\n vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);\n linearColor.rgb *= lightWeight;\n outputColor = linearColor;\n } else {\n outputColor = v_Color;\n }\n } else {\n // top face\n if (u_topsurface < 1.0) {\n discard;\n }\n }\n\n outputColor.a *= opacity;\n outputColor = filterColor(outputColor);\n}\n";
26
26
  /* babel-plugin-inline-import '../shaders/extrude/polygon_extrudetex_vert.glsl' */
27
27
  const polygonExtrudeTexVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec3 a_uvs;\n\nlayout(std140) uniform commonUniforms {\n vec4 u_sourceColor;\n vec4 u_targetColor;\n float u_linearColor;\n float u_topsurface;\n float u_sidesurface;\n float u_heightfixed; // \u9ED8\u8BA4\u4E0D\u56FA\u5B9A\n float u_raisingHeight;\n};\n\nout vec4 v_Color;\nout vec3 v_uvs;\nout vec2 v_texture_data;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size, 1.0);\n vec4 project_pos = project_position(pos, a_Position64Low);\n float lightWeight = calc_lighting(project_pos);\n v_uvs = a_uvs;\n v_Color = a_Color;\n v_Color.a *= opacity;\n\n v_texture_data = vec2(a_Position.z, lightWeight);\n\n if (u_heightfixed > 0.0) {\n // \u5224\u65AD\u51E0\u4F55\u4F53\u662F\u5426\u56FA\u5B9A\u9AD8\u5EA6\n project_pos.z = a_Position.z * a_Size;\n project_pos.z += u_raisingHeight;\n\n if (\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT ||\n u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET\n ) {\n float mapboxZoomScale = 4.0 / pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
28
28
  class ExtrudeModel extends _BaseModel.default {
@@ -12,7 +12,7 @@ var _l7Core = require("@antv/l7-core");
12
12
  var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
13
13
  var _triangulation = require("../../core/triangulation");
14
14
  /* babel-plugin-inline-import '../shaders/extrusion/polygon_extrusion_frag.glsl' */
15
- const polygonExtrudeFrag = "\nin vec4 v_Color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n\n outputColor = v_Color;\n outputColor = filterColor(outputColor);\n}\n";
15
+ const polygonExtrudeFrag = "in vec4 v_Color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n outputColor = v_Color;\n outputColor = filterColor(outputColor);\n}\n";
16
16
  /* babel-plugin-inline-import '../shaders/extrusion/polygon_extrusion_vert.glsl' */
17
17
  const polygonExtrudeVert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_SIZE) in float a_Size;\nlayout(location = ATTRIBUTE_LOCATION_NORMAL) in vec3 a_Normal;\n\nout vec4 v_Color;\n\n#pragma include \"projection\"\n#pragma include \"light\"\n#pragma include \"picking\"\n\nvoid main() {\n vec4 pos = vec4(a_Position.xy, a_Position.z * a_Size + (1.0 - a_Position.z) * extrusionBase, 1.0);\n\n vec4 project_pos = project_position(pos, a_Position64Low);\n float lightWeight = calc_lighting(project_pos);\n v_Color = a_Color;\n v_Color = vec4(v_Color.rgb * lightWeight, v_Color.w * opacity);\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n\n setPickingColor(a_PickingColor);\n}\n";
18
18
  class ExtrusionModel extends _BaseModel.default {
@@ -13,7 +13,7 @@ var _triangulation = require("../../core/triangulation");
13
13
  /* babel-plugin-inline-import '../shaders/fill/fill_frag.glsl' */
14
14
  const polygon_frag = "in vec4 v_color;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\nout vec4 outputColor;\nvoid main() {\n outputColor = v_color;\n outputColor = filterColor(outputColor);\n}\n";
15
15
  /* babel-plugin-inline-import '../shaders/fill/fill_linear_frag.glsl' */
16
- const polygon_linear_frag = "\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n float u_opacitylinear;\n float u_dir;\n};\n\nin vec4 v_color;\nin vec3 v_linear;\nin vec2 v_pos;\nout vec4 outputColor;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n outputColor = v_color;\n if (u_opacitylinear > 0.0) {\n outputColor.a *= u_dir == 1.0 ? 1.0 - length(v_pos - v_linear.xy)/v_linear.z : length(v_pos - v_linear.xy)/v_linear.z;\n }\n outputColor = filterColor(outputColor);\n}\n";
16
+ const polygon_linear_frag = "layout(std140) uniform commonUniforms {\n float u_raisingHeight;\n float u_opacitylinear;\n float u_dir;\n};\n\nin vec4 v_color;\nin vec3 v_linear;\nin vec2 v_pos;\nout vec4 outputColor;\n#pragma include \"scene_uniforms\"\n#pragma include \"picking\"\n\nvoid main() {\n outputColor = v_color;\n if (u_opacitylinear > 0.0) {\n outputColor.a *=\n u_dir == 1.0\n ? 1.0 - length(v_pos - v_linear.xy) / v_linear.z\n : length(v_pos - v_linear.xy) / v_linear.z;\n }\n outputColor = filterColor(outputColor);\n}\n";
17
17
  /* babel-plugin-inline-import '../shaders/fill/fill_linear_vert.glsl' */
18
18
  const polygon_linear_vert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_POSITION_64LOW) in vec2 a_Position64Low;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_LINEAR) in vec3 a_linear;\n\nlayout(std140) uniform commonUniforms {\n float u_raisingHeight;\n float u_opacitylinear;\n float u_dir;\n};\n\nout vec4 v_color;\nout vec3 v_linear;\nout vec2 v_pos;\n\n#pragma include \"projection\"\n#pragma include \"picking\"\n\nvoid main() {\n if (u_opacitylinear > 0.0) {\n v_linear = a_linear;\n v_pos = a_Position.xy;\n }\n v_color = vec4(a_Color.xyz, a_Color.w * opacity);\n vec4 project_pos = project_position(vec4(a_Position, 1.0), a_Position64Low);\n project_pos.z += u_raisingHeight;\n\n if (u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT || u_CoordinateSystem == COORDINATE_SYSTEM_LNGLAT_OFFSET) {\n float mapboxZoomScale = 4.0/pow(2.0, 21.0 - u_Zoom);\n project_pos.z *= mapboxZoomScale;\n project_pos.z += u_raisingHeight * mapboxZoomScale;\n }\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n setPickingColor(a_PickingColor);\n}\n";
19
19
  /* babel-plugin-inline-import '../shaders/fill/fill_vert.glsl' */
@@ -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/ocean/ocean_frag.glsl' */
16
- const ocean_frag = "\nlayout(std140) uniform commonUniforms {\n vec4 u_watercolor;\n vec4 u_watercolor2;\n float u_time;\n};\n\nin vec2 v_uv;\nin float v_opacity;\nout vec4 outputColor;\n\nfloat coast2water_fadedepth = 0.10;\nfloat large_waveheight = .750; // change to adjust the \"heavy\" waves\nfloat large_wavesize = 3.4; // factor to adjust the large wave size\nfloat small_waveheight = 0.6; // change to adjust the small random waves\nfloat small_wavesize = 0.5; // factor to ajust the small wave size\nfloat water_softlight_fact = 15.; // range [1..200] (should be << smaller than glossy-fact)\nfloat water_glossylight_fact= 120.; // range [1..200]\nfloat particle_amount = 70.;\n\nvec3 water_specularcolor = vec3(1.3, 1.3, 0.9); // specular Color (RGB) of the water-highlights\n#define light vec3(-0., sin(u_time*0.5)*.5 + .35, 2.8) // position of the sun\n\nuniform sampler2D u_texture1;\nuniform sampler2D u_texture2;\nuniform sampler2D u_texture3;\n\n \n\nfloat hash( float n ) {\n return fract(sin(n)*43758.5453123);\n}\n\n// 2d noise function\nfloat noise1( in vec2 x ) {\n vec2 p = floor(x);\n vec2 f = smoothstep(0.0, 1.0, fract(x));\n float n = p.x + p.y*57.0;\n return mix(mix( hash(n+ 0.0), hash(n+ 1.0),f.x),\n mix( hash(n+ 57.0), hash(n+ 58.0),f.x),f.y);\n}\n\nfloat noise(vec2 p) {\n return texture(SAMPLER_2D(u_texture2),p*vec2(1./256.)).x;\n}\n\nvec4 highness(vec2 p) {\n vec4 t = texture(SAMPLER_2D(u_texture1),fract(p));\n float clipped = -2.0-smoothstep(3.,10.,t.a)*6.9-smoothstep(10.,100.,t.a)*89.9-smoothstep(0.,10000.,t.a)*10000.0;\n 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);\n}\n\nfloat height_map( vec2 p ) {\n vec4 height=highness(p);\n /*\n height = -0.5+\n 0.5*smoothstep(-100.,0.,-height)+\n 2.75*smoothstep(0.,2.,height)+\n 1.75*smoothstep(2.,4.,height)+\n 2.75*smoothstep(4.,16.,height)+\n 1.5*smoothstep(16.,1000.,height);\n */\n\n mat2 m = mat2( 0.9563*1.4, -0.2924*1.4, 0.2924*1.4, 0.9563*1.4 );\n //p = p*6.;\n float f = 0.6000*noise1( p ); p = m*p*1.1*6.;\n f += 0.2500*noise( p ); p = m*p*1.32;\n f += 0.1666*noise( p ); p = m*p*1.11;\n f += 0.0834*noise( p ); p = m*p*1.12;\n f += 0.0634*noise( p ); p = m*p*1.13;\n f += 0.0444*noise( p ); p = m*p*1.14;\n f += 0.0274*noise( p ); p = m*p*1.15;\n f += 0.0134*noise( p ); p = m*p*1.16;\n f += 0.0104*noise( p ); p = m*p*1.17;\n f += 0.0084*noise( p );\n f = .25*f+dot(height,vec4(-.03125,-.125,.25,.25))*.5;\n const float FLAT_LEVEL = 0.92525;\n //f = f*0.25+height*0.75;\n if (f<FLAT_LEVEL)\n f = f;\n else\n f = pow((f-FLAT_LEVEL)/(1.-FLAT_LEVEL), 2.)*(1.-FLAT_LEVEL)*2.0+FLAT_LEVEL; // makes a smooth coast-increase\n return clamp(f, 0., 10.);\n}\n\nvec3 plasma_quintic( float x ) {\n x = clamp( x, 0.0, 1.0);\n vec4 x1 = vec4( 1.0, x, x * x, x * x * x ); // 1 x x2 x3\n vec4 x2 = x1 * x1.w * x; // x4 x5 x6 x7\n return vec3(\n dot( x1.xyzw, vec4( +0.063861086, +1.992659096, -1.023901152, -0.490832805 ) ) + dot( x2.xy, vec2( +1.308442123, -0.914547012 ) ),\n dot( x1.xyzw, vec4( +0.049718590, -0.791144343, +2.892305078, +0.811726816 ) ) + dot( x2.xy, vec2( -4.686502417, +2.717794514 ) ),\n dot( x1.xyzw, vec4( +0.513275779, +1.580255060, -5.164414457, +4.559573646 ) ) + dot( x2.xy, vec2( -1.916810682, +0.570638854 ) ) );\n}\n\nvec4 color(vec2 p){\n vec4 c1 = vec4(1.7,1.6,.9,1);\n vec4 c2 = vec4(.2,.94,.1,1);\n vec4 c3 = vec4(.3,.2,.0,1);\n vec4 c4 = vec4(.99,.99,1.6,1);\n vec4 v = highness(p);\n float los = smoothstep(0.1,1.1,v.b);\n float his = smoothstep(3.5,6.5,v.b);\n float ces = smoothstep(1.,5.,v.a);\n vec4 lo = mix(c1,c2,los);\n vec4 hi = mix(c3,c4,his);\n vec4 ce = mix(lo,hi,ces);\n\n return vec4(plasma_quintic(ces),1).ragb;\n}\n\nvec3 terrain_map( vec2 p )\n{\n return color(p).rgb*0.75+0.25*vec3(0.7, .55, .4)+texture(SAMPLER_2D(u_texture3), fract(p*5.)).rgb*.5; // test-terrain is simply 'sandstone'\n}\n\nconst mat2 m = mat2( 0.72, -1.60, 1.60, 0.72 );\n\nfloat water_map( vec2 p, float height ) {\n vec2 p2 = p*large_wavesize;\n vec2 shift1 = 0.001*vec2( u_time*160.0*2.0, u_time*120.0*2.0 );\n vec2 shift2 = 0.001*vec2( u_time*190.0*2.0, -u_time*130.0*2.0 );\n\n // coarse crossing 'ocean' waves...\n float f = 0.6000*noise( p );\n f += 0.2500*noise( p*m );\n f += 0.1666*noise( p*m*m );\n float wave = sin(p2.x*0.622+p2.y*0.622+shift2.x*4.269)*large_waveheight*f*height*height ;\n\n p *= small_wavesize;\n f = 0.;\n float amp = 1.0, s = .5;\n for (int i=0; i<9; i++)\n { p = m*p*.947; f -= amp*abs(sin((noise( p+shift1*s )-.5)*2.)); amp = amp*.59; s*=-1.329; }\n \n return wave+f*small_waveheight;\n}\n\nfloat nautic(vec2 p) {\n p *= 18.;\n float f = 0.;\n float amp = 1.0, s = .5;\n for (int i=0; i<3; i++)\n { p = m*p*1.2; f += amp*abs(smoothstep(0., 1., noise( p+u_time*s ))-.5); amp = amp*.5; s*=-1.227; }\n return pow(1.-f, 5.);\n}\n\nfloat particles(vec2 p) {\n p *= 200.;\n float f = 0.;\n float amp = 1.0, s = 1.5;\n for (int i=0; i<3; i++)\n { p = m*p*1.2; f += amp*noise( p+u_time*s ); amp = amp*.5; s*=-1.227; }\n return pow(f*.35, 7.)*particle_amount;\n}\n\nfloat test_shadow( vec2 xy, float height) {\n vec3 r0 = vec3(xy, height);\n vec3 rd = normalize( light - r0 );\n \n float hit = 1.0;\n float t = 0.001;\n for (int j=1; j<25; j++)\n {\n vec3 p = r0 + t*rd;\n float h = height_map( p.xy );\n float height_diff = p.z - h;\n if (height_diff<0.0)\n {\n return 0.0;\n }\n t += 0.01+height_diff*.02;\n hit = min(hit, 2.*height_diff/t); // soft shaddow \n }\n return hit;\n}\n\nvec3 CalcTerrain(vec2 uv, float height) {\n vec3 col = terrain_map( uv );\n vec2 iResolution = vec2(512.);\n float h1 = height_map(uv-vec2(0., 0.5)/ iResolution.xy);\n float h2 = height_map(uv+vec2(0., 0.5)/ iResolution.xy);\n float h3 = height_map(uv-vec2(0.5, 0.)/ iResolution.xy);\n float h4 = height_map(uv+vec2(0.5, 0.)/ iResolution.xy);\n vec3 norm = normalize(vec3(h3-h4, h1-h2, 1.));\n vec3 r0 = vec3(uv, height);\n vec3 rd = normalize( light - r0 );\n float grad = dot(norm, rd);\n col *= grad+pow(grad, 8.);\n float terrainshade = test_shadow( uv, height );\n col = mix(col*.25, col, terrainshade);\n return col;\n}\n\n\nvoid main() {\n vec3 watercolor = u_watercolor.rgb;\n vec3 watercolor2 = u_watercolor2.rgb;\n vec2 uv = v_uv;\n float WATER_LEVEL = 0.84; // Water level (range: 0.0 - 2.0)\n float deepwater_fadedepth = 0.4 + coast2water_fadedepth;\n float height = height_map( uv );\n vec3 col;\n\n float waveheight = clamp(WATER_LEVEL*3.-1.5, 0., 1.);\n float level = WATER_LEVEL + .2*water_map(uv*15. + vec2(u_time*.1), waveheight);\n if (height > level)\n {\n col = CalcTerrain(uv, height);\n }\n if (height <= level)\n {\n vec2 dif = vec2(.0, .01);\n vec2 pos = uv*15. + vec2(u_time*.01);\n float h1 = water_map(pos-dif,waveheight);\n float h2 = water_map(pos+dif,waveheight);\n float h3 = water_map(pos-dif.yx,waveheight);\n float h4 = water_map(pos+dif.yx,waveheight);\n vec3 normwater = normalize(vec3(h3-h4, h1-h2, .125)); // norm-vector of the 'bumpy' water-plane\n uv += normwater.xy*.002*(level-height);\n \n col = CalcTerrain(uv, height);\n\n float coastfade = clamp((level-height)/coast2water_fadedepth, 0., 1.);\n float coastfade2= clamp((level-height)/deepwater_fadedepth, 0., 1.);\n float intensity = col.r*.2126+col.g*.7152+col.b*.0722;\n watercolor = mix(watercolor*intensity, watercolor2, smoothstep(0., 1., coastfade2));\n\n vec3 r0 = vec3(uv, WATER_LEVEL);\n vec3 rd = normalize( light - r0 ); // ray-direction to the light from water-position\n float grad = dot(normwater, rd); // dot-product of norm-vector and light-direction\n float specular = pow(grad, water_softlight_fact); // used for soft highlights \n float specular2= pow(grad, water_glossylight_fact); // used for glossy highlights\n float gradpos = dot(vec3(0., 0., 1.), rd);\n float specular1= smoothstep(0., 1., pow(gradpos, 5.)); // used for diffusity (some darker corona around light's specular reflections...) \n float watershade = test_shadow( uv, level );\n watercolor *= 2.2+watershade;\n watercolor += (.2+.8*watershade) * ((grad-1.0)*.5+specular) * .25;\n watercolor /= (1.+specular1*1.25);\n watercolor += watershade*specular2*water_specularcolor;\n watercolor += watershade*coastfade*(1.-coastfade2)*(vec3(.5, .6, .7)*nautic(uv)+vec3(1., 1., 1.)*particles(uv));\n \n col = mix(col, watercolor, coastfade);\n }\n \n outputColor = vec4(col, v_opacity); \n}\n";
16
+ const ocean_frag = "layout(std140) uniform commonUniforms {\n vec4 u_watercolor;\n vec4 u_watercolor2;\n float u_time;\n};\n\nin vec2 v_uv;\nin float v_opacity;\nout vec4 outputColor;\n\nfloat coast2water_fadedepth = 0.1;\nfloat large_waveheight = 0.75; // change to adjust the \"heavy\" waves\nfloat large_wavesize = 3.4; // factor to adjust the large wave size\nfloat small_waveheight = 0.6; // change to adjust the small random waves\nfloat small_wavesize = 0.5; // factor to ajust the small wave size\nfloat water_softlight_fact = 15.0; // range [1..200] (should be << smaller than glossy-fact)\nfloat water_glossylight_fact = 120.0; // range [1..200]\nfloat particle_amount = 70.0;\n\nvec3 water_specularcolor = vec3(1.3, 1.3, 0.9); // specular Color (RGB) of the water-highlights\n#define light (vec3(-0.0, sin(u_time * 0.5) * 0.5 + 0.35, 2.8)) // position of the sun\n\nuniform sampler2D u_texture1;\nuniform sampler2D u_texture2;\nuniform sampler2D u_texture3;\n\nfloat hash(float n) {\n return fract(sin(n) * 43758.5453123);\n}\n\n// 2d noise function\nfloat noise1(vec2 x) {\n vec2 p = floor(x);\n vec2 f = smoothstep(0.0, 1.0, fract(x));\n float n = p.x + p.y * 57.0;\n 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);\n}\n\nfloat noise(vec2 p) {\n return texture(SAMPLER_2D(u_texture2), p * vec2(1.0 / 256.0)).x;\n}\n\nvec4 highness(vec2 p) {\n vec4 t = texture(SAMPLER_2D(u_texture1), fract(p));\n float clipped =\n -2.0 -\n smoothstep(3.0, 10.0, t.a) * 6.9 -\n smoothstep(10.0, 100.0, t.a) * 89.9 -\n smoothstep(0.0, 10000.0, t.a) * 10000.0;\n 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);\n}\n\nfloat height_map(vec2 p) {\n vec4 height = highness(p);\n /*\n height = -0.5+\n 0.5*smoothstep(-100.,0.,-height)+\n 2.75*smoothstep(0.,2.,height)+\n 1.75*smoothstep(2.,4.,height)+\n 2.75*smoothstep(4.,16.,height)+\n 1.5*smoothstep(16.,1000.,height);\n */\n\n mat2 m = mat2(0.9563 * 1.4, -0.2924 * 1.4, 0.2924 * 1.4, 0.9563 * 1.4);\n //p = p*6.;\n float f = 0.6 * noise1(p);\n p = m * p * 1.1 * 6.0;\n f += 0.25 * noise(p);\n p = m * p * 1.32;\n f += 0.1666 * noise(p);\n p = m * p * 1.11;\n f += 0.0834 * noise(p);\n p = m * p * 1.12;\n f += 0.0634 * noise(p);\n p = m * p * 1.13;\n f += 0.0444 * noise(p);\n p = m * p * 1.14;\n f += 0.0274 * noise(p);\n p = m * p * 1.15;\n f += 0.0134 * noise(p);\n p = m * p * 1.16;\n f += 0.0104 * noise(p);\n p = m * p * 1.17;\n f += 0.0084 * noise(p);\n f = 0.25 * f + dot(height, vec4(-0.03125, -0.125, 0.25, 0.25)) * 0.5;\n const float FLAT_LEVEL = 0.92525;\n //f = f*0.25+height*0.75;\n if (f < FLAT_LEVEL) f = f;\n 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\n return clamp(f, 0.0, 10.0);\n}\n\nvec3 plasma_quintic(float x) {\n x = clamp(x, 0.0, 1.0);\n vec4 x1 = vec4(1.0, x, x * x, x * x * x); // 1 x x2 x3\n vec4 x2 = x1 * x1.w * x; // x4 x5 x6 x7\n return vec3(\n dot(x1.xyzw, vec4(+0.063861086, +1.992659096, -1.023901152, -0.490832805)) +\n dot(x2.xy, vec2(+1.308442123, -0.914547012)),\n dot(x1.xyzw, vec4(+0.04971859, -0.791144343, +2.892305078, +0.811726816)) +\n dot(x2.xy, vec2(-4.686502417, +2.717794514)),\n dot(x1.xyzw, vec4(+0.513275779, +1.58025506, -5.164414457, +4.559573646)) +\n dot(x2.xy, vec2(-1.916810682, +0.570638854))\n );\n}\n\nvec4 color(vec2 p) {\n vec4 c1 = vec4(1.7, 1.6, 0.9, 1);\n vec4 c2 = vec4(0.2, 0.94, 0.1, 1);\n vec4 c3 = vec4(0.3, 0.2, 0.0, 1);\n vec4 c4 = vec4(0.99, 0.99, 1.6, 1);\n vec4 v = highness(p);\n float los = smoothstep(0.1, 1.1, v.b);\n float his = smoothstep(3.5, 6.5, v.b);\n float ces = smoothstep(1.0, 5.0, v.a);\n vec4 lo = mix(c1, c2, los);\n vec4 hi = mix(c3, c4, his);\n vec4 ce = mix(lo, hi, ces);\n\n return vec4(plasma_quintic(ces), 1).ragb;\n}\n\nvec3 terrain_map(vec2 p) {\n return color(p).rgb * 0.75 +\n 0.25 * vec3(0.7, 0.55, 0.4) +\n texture(SAMPLER_2D(u_texture3), fract(p * 5.0)).rgb * 0.5; // test-terrain is simply 'sandstone'\n}\n\nconst mat2 m = mat2(\n 0.72, -1.6 ,\n 1.6 , 0.72\n);\n\nfloat water_map(vec2 p, float height) {\n vec2 p2 = p * large_wavesize;\n vec2 shift1 = 0.001 * vec2(u_time * 160.0 * 2.0, u_time * 120.0 * 2.0);\n vec2 shift2 = 0.001 * vec2(u_time * 190.0 * 2.0, -u_time * 130.0 * 2.0);\n\n // coarse crossing 'ocean' waves...\n float f = 0.6 * noise(p);\n f += 0.25 * noise(p * m);\n f += 0.1666 * noise(p * m * m);\n float wave =\n sin(p2.x * 0.622 + p2.y * 0.622 + shift2.x * 4.269) * large_waveheight * f * height * height;\n\n p *= small_wavesize;\n f = 0.0;\n float amp = 1.0,\n s = 0.5;\n for (int i = 0; i < 9; i++) {\n p = m * p * 0.947;\n f -= amp * abs(sin((noise(p + shift1 * s) - 0.5) * 2.0));\n amp = amp * 0.59;\n s *= -1.329;\n }\n\n return wave + f * small_waveheight;\n}\n\nfloat nautic(vec2 p) {\n p *= 18.0;\n float f = 0.0;\n float amp = 1.0,\n s = 0.5;\n for (int i = 0; i < 3; i++) {\n p = m * p * 1.2;\n f += amp * abs(smoothstep(0.0, 1.0, noise(p + u_time * s)) - 0.5);\n amp = amp * 0.5;\n s *= -1.227;\n }\n return pow(1.0 - f, 5.0);\n}\n\nfloat particles(vec2 p) {\n p *= 200.0;\n float f = 0.0;\n float amp = 1.0,\n s = 1.5;\n for (int i = 0; i < 3; i++) {\n p = m * p * 1.2;\n f += amp * noise(p + u_time * s);\n amp = amp * 0.5;\n s *= -1.227;\n }\n return pow(f * 0.35, 7.0) * particle_amount;\n}\n\nfloat test_shadow(vec2 xy, float height) {\n vec3 r0 = vec3(xy, height);\n vec3 rd = normalize(light - r0);\n\n float hit = 1.0;\n float t = 0.001;\n for (int j = 1; j < 25; j++) {\n vec3 p = r0 + t * rd;\n float h = height_map(p.xy);\n float height_diff = p.z - h;\n if (height_diff < 0.0) {\n return 0.0;\n }\n t += 0.01 + height_diff * 0.02;\n hit = min(hit, 2.0 * height_diff / t); // soft shaddow\n }\n return hit;\n}\n\nvec3 CalcTerrain(vec2 uv, float height) {\n vec3 col = terrain_map(uv);\n vec2 iResolution = vec2(512.0);\n float h1 = height_map(uv - vec2(0.0, 0.5) / iResolution.xy);\n float h2 = height_map(uv + vec2(0.0, 0.5) / iResolution.xy);\n float h3 = height_map(uv - vec2(0.5, 0.0) / iResolution.xy);\n float h4 = height_map(uv + vec2(0.5, 0.0) / iResolution.xy);\n vec3 norm = normalize(vec3(h3 - h4, h1 - h2, 1.0));\n vec3 r0 = vec3(uv, height);\n vec3 rd = normalize(light - r0);\n float grad = dot(norm, rd);\n col *= grad + pow(grad, 8.0);\n float terrainshade = test_shadow(uv, height);\n col = mix(col * 0.25, col, terrainshade);\n return col;\n}\n\nvoid main() {\n vec3 watercolor = u_watercolor.rgb;\n vec3 watercolor2 = u_watercolor2.rgb;\n vec2 uv = v_uv;\n float WATER_LEVEL = 0.84; // Water level (range: 0.0 - 2.0)\n float deepwater_fadedepth = 0.4 + coast2water_fadedepth;\n float height = height_map(uv);\n vec3 col;\n\n float waveheight = clamp(WATER_LEVEL * 3.0 - 1.5, 0.0, 1.0);\n float level = WATER_LEVEL + 0.2 * water_map(uv * 15.0 + vec2(u_time * 0.1), waveheight);\n if (height > level) {\n col = CalcTerrain(uv, height);\n }\n if (height <= level) {\n vec2 dif = vec2(0.0, 0.01);\n vec2 pos = uv * 15.0 + vec2(u_time * 0.01);\n float h1 = water_map(pos - dif, waveheight);\n float h2 = water_map(pos + dif, waveheight);\n float h3 = water_map(pos - dif.yx, waveheight);\n float h4 = water_map(pos + dif.yx, waveheight);\n vec3 normwater = normalize(vec3(h3 - h4, h1 - h2, 0.125)); // norm-vector of the 'bumpy' water-plane\n uv += normwater.xy * 0.002 * (level - height);\n\n col = CalcTerrain(uv, height);\n\n float coastfade = clamp((level - height) / coast2water_fadedepth, 0.0, 1.0);\n float coastfade2 = clamp((level - height) / deepwater_fadedepth, 0.0, 1.0);\n float intensity = col.r * 0.2126 + col.g * 0.7152 + col.b * 0.0722;\n watercolor = mix(watercolor * intensity, watercolor2, smoothstep(0.0, 1.0, coastfade2));\n\n vec3 r0 = vec3(uv, WATER_LEVEL);\n vec3 rd = normalize(light - r0); // ray-direction to the light from water-position\n float grad = dot(normwater, rd); // dot-product of norm-vector and light-direction\n float specular = pow(grad, water_softlight_fact); // used for soft highlights\n float specular2 = pow(grad, water_glossylight_fact); // used for glossy highlights\n float gradpos = dot(vec3(0.0, 0.0, 1.0), rd);\n float specular1 = smoothstep(0.0, 1.0, pow(gradpos, 5.0)); // used for diffusity (some darker corona around light's specular reflections...)\n float watershade = test_shadow(uv, level);\n watercolor *= 2.2 + watershade;\n watercolor += (0.2 + 0.8 * watershade) * ((grad - 1.0) * 0.5 + specular) * 0.25;\n watercolor /= 1.0 + specular1 * 1.25;\n watercolor += watershade * specular2 * water_specularcolor;\n watercolor +=\n watershade *\n coastfade *\n (1.0 - coastfade2) *\n (vec3(0.5, 0.6, 0.7) * nautic(uv) + vec3(1.0, 1.0, 1.0) * particles(uv));\n\n col = mix(col, watercolor, coastfade);\n }\n\n outputColor = vec4(col, v_opacity);\n}\n";
17
17
  /* babel-plugin-inline-import '../shaders/ocean/ocean_vert.glsl' */
18
18
  const ocean_vert = "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_watercolor;\n vec4 u_watercolor2;\n float u_time;\n};\n\nout vec2 v_uv;\nout float v_opacity;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_uv = a_uv;\n v_opacity = opacity;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n}\n\n";
19
19
  class OceanModel extends _BaseModel.default {
@@ -12,7 +12,7 @@ var _l7Core = require("@antv/l7-core");
12
12
  var _BaseModel = _interopRequireDefault(require("../../core/BaseModel"));
13
13
  var _triangulation = require("../../core/triangulation");
14
14
  /* babel-plugin-inline-import '../shaders/water/polygon_water_frag.glsl' */
15
- const water_frag = "uniform sampler2D u_texture;\nlayout(std140) uniform commonUniforms {\n float u_speed;\n float u_time;\n};\n\nout vec4 outputColor;\n\n\nin vec4 v_Color;\nin vec2 v_uv;\n\nfloat rand(vec2 n) { return 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233)))* 43758.5453); }\n\nfloat water(vec3 p) {\n float t = u_time * u_speed;\n p.z += t * 2.; p.x += t * 2.;\n vec3 c1 = texture(SAMPLER_2D(u_texture), p.xz / 30.).xyz;\n p.z += t * 3.; p.x += t * 0.52;\n vec3 c2 = texture(SAMPLER_2D(u_texture), p.xz / 30.).xyz;\n p.z += t * 4.; p.x += t * 0.8;\n vec3 c3 = texture(SAMPLER_2D(u_texture), p.xz / 30.).xyz;\n c1 += c2 - c3;\n float z = (c1.x + c1.y + c1.z) / 3.;\n return p.y + z / 4.;\n}\n\nfloat map(vec3 p) {\n float d = 100.0;\n d = water(p);\n return d;\n}\n\nfloat intersect(vec3 ro, vec3 rd) {\n float d = 0.0;\n for (int i = 0; i <= 100; i++) {\n float h = map(ro + rd * d);\n if (h < 0.1) return d;\n d += h;\n }\n return 0.0;\n}\n\nvec3 norm(vec3 p) {\n float eps = .1;\n return normalize(vec3(\n map(p + vec3(eps, 0, 0)) - map(p + vec3(-eps, 0, 0)),\n map(p + vec3(0, eps, 0)) - map(p + vec3(0, -eps, 0)),\n map(p + vec3(0, 0, eps)) - map(p + vec3(0, 0, -eps))\n ));\n} \n\nfloat calSpc() {\n vec3 l1 = normalize(vec3(1, 1, 1));\n vec3 ro = vec3(-3, 20, -8);\n vec3 rc = vec3(0, 0, 0);\n vec3 ww = normalize(rc - ro);\n vec3 uu = normalize(cross(vec3(0,1,0), ww));\n vec3 vv = normalize(cross(rc - ro, uu));\n vec3 rd = normalize(uu * v_uv.x + vv * v_uv.y + ww);\n float d = intersect(ro, rd);\n vec3 p = ro + rd * d;\n vec3 n = norm(p);\n float spc = pow(max(0.0, dot(reflect(l1, n), rd)), 30.0);\n return spc;\n}\n\nvoid main() {\n\n outputColor = v_Color;\n float spc = calSpc();\n outputColor += spc * 0.4;\n}\n";
15
+ const water_frag = "uniform sampler2D u_texture;\nlayout(std140) uniform commonUniforms {\n float u_speed;\n float u_time;\n};\n\nout vec4 outputColor;\n\nin vec4 v_Color;\nin vec2 v_uv;\n\nfloat rand(vec2 n) {\n return 0.5 + 0.5 * fract(sin(dot(n.xy, vec2(12.9898, 78.233))) * 43758.5453);\n}\n\nfloat water(vec3 p) {\n float t = u_time * u_speed;\n p.z += t * 2.0;\n p.x += t * 2.0;\n vec3 c1 = texture(SAMPLER_2D(u_texture), p.xz / 30.0).xyz;\n p.z += t * 3.0;\n p.x += t * 0.52;\n vec3 c2 = texture(SAMPLER_2D(u_texture), p.xz / 30.0).xyz;\n p.z += t * 4.0;\n p.x += t * 0.8;\n vec3 c3 = texture(SAMPLER_2D(u_texture), p.xz / 30.0).xyz;\n c1 += c2 - c3;\n float z = (c1.x + c1.y + c1.z) / 3.0;\n return p.y + z / 4.0;\n}\n\nfloat map(vec3 p) {\n float d = 100.0;\n d = water(p);\n return d;\n}\n\nfloat intersect(vec3 ro, vec3 rd) {\n float d = 0.0;\n for (int i = 0; i <= 100; i++) {\n float h = map(ro + rd * d);\n if (h < 0.1) return d;\n d += h;\n }\n return 0.0;\n}\n\nvec3 norm(vec3 p) {\n float eps = 0.1;\n return normalize(\n vec3(\n map(p + vec3(eps, 0, 0)) - map(p + vec3(-eps, 0, 0)),\n map(p + vec3(0, eps, 0)) - map(p + vec3(0, -eps, 0)),\n map(p + vec3(0, 0, eps)) - map(p + vec3(0, 0, -eps))\n )\n );\n}\n\nfloat calSpc() {\n vec3 l1 = normalize(vec3(1, 1, 1));\n vec3 ro = vec3(-3, 20, -8);\n vec3 rc = vec3(0, 0, 0);\n vec3 ww = normalize(rc - ro);\n vec3 uu = normalize(cross(vec3(0, 1, 0), ww));\n vec3 vv = normalize(cross(rc - ro, uu));\n vec3 rd = normalize(uu * v_uv.x + vv * v_uv.y + ww);\n float d = intersect(ro, rd);\n vec3 p = ro + rd * d;\n vec3 n = norm(p);\n float spc = pow(max(0.0, dot(reflect(l1, n), rd)), 30.0);\n return spc;\n}\n\nvoid main() {\n outputColor = v_Color;\n float spc = calSpc();\n outputColor += spc * 0.4;\n}\n";
16
16
  /* babel-plugin-inline-import '../shaders/water/polygon_water_vert.glsl' */
17
17
  const water_vert = "layout(location = ATTRIBUTE_LOCATION_POSITION) in vec3 a_Position;\nlayout(location = ATTRIBUTE_LOCATION_COLOR) in vec4 a_Color;\nlayout(location = ATTRIBUTE_LOCATION_UV) in vec2 a_uv;\n\nlayout(std140) uniform commonUniforms {\n float u_speed;\n float u_time;\n};\nout vec4 v_Color;\nout vec2 v_uv;\n\n#pragma include \"projection\"\n\nvoid main() {\n v_uv = a_uv;\n v_Color = a_Color;\n v_Color.a *= opacity;\n vec4 project_pos = project_position(vec4(a_Position, 1.0));\n\n gl_Position = project_common_position_to_clipspace(vec4(project_pos.xyz, 1.0));\n}\n\n";
18
18
  class WaterModel extends _BaseModel.default {
@@ -13,13 +13,12 @@ in vec4 v_Color;
13
13
  #pragma include "picking"
14
14
  out vec4 outputColor;
15
15
  void main() {
16
+ // top face
17
+ if (u_topsurface < 1.0) {
18
+ discard;
19
+ }
16
20
 
17
- // top face
18
- if(u_topsurface < 1.0) {
19
- discard;
20
- }
21
+ outputColor = v_Color;
21
22
 
22
- outputColor = v_Color;
23
-
24
23
  outputColor = filterColor(outputColor);
25
24
  }
@@ -1,4 +1,3 @@
1
-
2
1
  layout(std140) uniform commonUniforms {
3
2
  vec4 u_sourceColor;
4
3
  vec4 u_targetColor;
@@ -18,29 +17,29 @@ out vec4 outputColor;
18
17
  #pragma include "picking"
19
18
 
20
19
  void main() {
21
- float isSide = v_texture_data.x;
20
+ float isSide = v_texture_data.x;
22
21
  float sidey = v_uvs[2];
23
22
  float lightWeight = v_texture_data.y;
24
23
 
25
24
  // Tip: 部分机型 GPU 计算精度兼容
26
- if(isSide < 0.999) {
25
+ if (isSide < 0.999) {
27
26
  // side face
28
- if(u_sidesurface < 1.0) {
27
+ if (u_sidesurface < 1.0) {
29
28
  discard;
30
29
  }
31
-
32
- if( u_linearColor == 1.0) {
30
+
31
+ if (u_linearColor == 1.0) {
33
32
  // side use linear
34
33
  vec4 linearColor = mix(u_targetColor, u_sourceColor, sidey);
35
34
  linearColor.rgb *= lightWeight;
36
35
  outputColor = linearColor;
37
36
  } else {
38
37
  // side notuse linear
39
- outputColor = v_Color;
38
+ outputColor = v_Color;
40
39
  }
41
40
  } else {
42
41
  // top face
43
- if(u_topsurface < 1.0) {
42
+ if (u_topsurface < 1.0) {
44
43
  discard;
45
44
  }
46
45
  outputColor = v_Color;
@@ -29,7 +29,8 @@ void main() {
29
29
 
30
30
  outputColor = texture(SAMPLER_2D(u_texture), vec2(topU, topV));
31
31
  // Tip: 部分机型 GPU 计算精度兼容
32
- if (isSide < 0.999) {// 是否是边缘
32
+ if (isSide < 0.999) {
33
+ // 是否是边缘
33
34
  // side face
34
35
  if (u_sidesurface < 1.0) {
35
36
  discard;
@@ -43,12 +44,12 @@ void main() {
43
44
  outputColor = v_Color;
44
45
  }
45
46
  } else {
46
- // top face
47
+ // top face
47
48
  if (u_topsurface < 1.0) {
48
49
  discard;
49
50
  }
50
51
  }
51
-
52
+
52
53
  outputColor.a *= opacity;
53
54
  outputColor = filterColor(outputColor);
54
55
  }