@antv/g-webgpu 1.7.66 → 1.7.68

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.umd.js CHANGED
@@ -5135,6 +5135,15 @@
5135
5135
  };
5136
5136
  return RenderCache;
5137
5137
  }();
5138
+ var ToneMapping;
5139
+ (function (ToneMapping) {
5140
+ ToneMapping["NONE"] = "none";
5141
+ ToneMapping["LINEAR"] = "LinearToneMapping";
5142
+ ToneMapping["REINHARD"] = "ReinhardToneMapping";
5143
+ ToneMapping["CINEON"] = "OptimizedCineonToneMapping";
5144
+ ToneMapping["ACES_FILMIC"] = "ACESFilmicToneMapping";
5145
+ ToneMapping["CUSTOM"] = "CustomToneMapping";
5146
+ })(ToneMapping || (ToneMapping = {}));
5138
5147
  var RGAttachmentSlot;
5139
5148
  (function (RGAttachmentSlot) {
5140
5149
  RGAttachmentSlot[RGAttachmentSlot["Color0"] = 0] = "Color0";
@@ -6594,13 +6603,15 @@
6594
6603
  return RenderInstManager;
6595
6604
  }();
6596
6605
  var RenderHelper = /*#__PURE__*/function () {
6597
- function RenderHelper() {
6606
+ function RenderHelper(parameters) {
6607
+ this.parameters = void 0;
6598
6608
  this.renderCache = void 0;
6599
6609
  this.renderGraph = void 0;
6600
6610
  this.renderInstManager = void 0;
6601
6611
  this.uniformBuffer = void 0;
6602
6612
  // debugThumbnails: DebugThumbnailDrawer;
6603
6613
  this.device = void 0;
6614
+ this.parameters = parameters;
6604
6615
  }
6605
6616
  var _proto = RenderHelper.prototype;
6606
6617
  _proto.getDevice = function getDevice() {
@@ -6641,6 +6652,13 @@
6641
6652
  _proto.getCache = function getCache() {
6642
6653
  return this.renderCache;
6643
6654
  };
6655
+ _proto.getDefines = function getDefines() {
6656
+ var _this$parameters, _this$parameters2, _this$parameters3;
6657
+ return {
6658
+ USE_TONEMAPPING: ((_this$parameters = this.parameters) === null || _this$parameters === void 0 ? void 0 : _this$parameters.toneMapping) && ((_this$parameters2 = this.parameters) === null || _this$parameters2 === void 0 ? void 0 : _this$parameters2.toneMapping) !== ToneMapping.NONE,
6659
+ toneMapping: (_this$parameters3 = this.parameters) === null || _this$parameters3 === void 0 ? void 0 : _this$parameters3.toneMapping
6660
+ };
6661
+ };
6644
6662
  return RenderHelper;
6645
6663
  }();
6646
6664
  var RGRenderTargetDescription = /*#__PURE__*/function () {
@@ -6945,24 +6963,17 @@
6945
6963
  var object = e.target;
6946
6964
  var attrName = e.attrName,
6947
6965
  newValue = e.newValue;
6948
- _this.batchManager.updateAttribute(object, attrName, newValue);
6966
+ if (attrName === 'zIndex') {
6967
+ object.parentNode.forEach(function (child) {
6968
+ _this.batchManager.changeRenderOrder(child, child.sortable.renderOrder);
6969
+ });
6970
+ } else {
6971
+ _this.batchManager.updateAttribute(object, attrName, newValue);
6972
+ }
6949
6973
  };
6950
6974
  var handleBoundsChanged = function handleBoundsChanged(e) {
6951
6975
  var object = e.target;
6952
- // const { affectChildren } = e.detail;
6953
- // if (affectChildren) {
6954
- // object.forEach(() => {
6955
- // this.batchManager.updateAttribute(object, 'modelMatrix', null);
6956
- // });
6957
- // } else {
6958
6976
  _this.batchManager.updateAttribute(object, 'modelMatrix', null);
6959
- // }
6960
- };
6961
-
6962
- var handleRenderOrderChanged = function handleRenderOrderChanged(e) {
6963
- var object = e.target;
6964
- var renderOrder = e.detail.renderOrder;
6965
- _this.batchManager.changeRenderOrder(object, renderOrder);
6966
6977
  };
6967
6978
  renderingService.hooks.init.tapPromise(RenderGraphPlugin.tag, /*#__PURE__*/_asyncToGenerator$1( /*#__PURE__*/_regeneratorRuntime$1().mark(function _callee() {
6968
6979
  var $canvas, _this$context$config, width, height;
@@ -6973,16 +6984,15 @@
6973
6984
  canvas.addEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
6974
6985
  canvas.addEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
6975
6986
  canvas.addEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
6976
- canvas.addEventListener(gLite.ElementEvent.RENDER_ORDER_CHANGED, handleRenderOrderChanged);
6977
6987
  _this.context.config.renderer.getConfig().enableDirtyRectangleRendering = false;
6978
6988
  $canvas = _this.context.contextService.getDomElement();
6979
6989
  _this$context$config = _this.context.config, width = _this$context$config.width, height = _this$context$config.height;
6980
6990
  _this.context.contextService.resize(width, height);
6981
6991
  // create swap chain and get device
6982
6992
  // @ts-ignore
6983
- _context.next = 11;
6993
+ _context.next = 10;
6984
6994
  return _this.context.deviceContribution.createSwapChain($canvas);
6985
- case 11:
6995
+ case 10:
6986
6996
  _this.swapChain = _context.sent;
6987
6997
  _this.device = _this.swapChain.getDevice();
6988
6998
  _this.renderHelper.setDevice(_this.device);
@@ -6994,7 +7004,7 @@
6994
7004
  _this.batchManager.attach(_extends({
6995
7005
  device: _this.device
6996
7006
  }, context));
6997
- case 18:
7007
+ case 17:
6998
7008
  case "end":
6999
7009
  return _context.stop();
7000
7010
  }
@@ -7006,7 +7016,6 @@
7006
7016
  canvas.removeEventListener(gLite.ElementEvent.UNMOUNTED, handleUnmounted);
7007
7017
  canvas.removeEventListener(gLite.ElementEvent.ATTR_MODIFIED, handleAttributeChanged);
7008
7018
  canvas.removeEventListener(gLite.ElementEvent.BOUNDS_CHANGED, handleBoundsChanged);
7009
- canvas.removeEventListener(gLite.ElementEvent.RENDER_ORDER_CHANGED, handleRenderOrderChanged);
7010
7019
  });
7011
7020
  /**
7012
7021
  * build frame graph at the beginning of each frame
@@ -7416,28 +7425,12 @@
7416
7425
  * render order start from 0, our default camera's Z is 500
7417
7426
  */
7418
7427
  var RENDER_ORDER_SCALE = 1 / 200;
7419
- var counter = 1;
7420
7428
  /**
7421
7429
  * A container for multiple display objects with the same `style`,
7422
7430
  * eg. 1000 Circles with the same stroke color, but their position, radius can be different
7423
7431
  */
7424
7432
  var Batch = /*#__PURE__*/function () {
7425
7433
  function Batch() {
7426
- // @inject(RenderHelper)
7427
- // protected renderHelper: RenderHelper;
7428
- // @inject(TexturePool)
7429
- // protected texturePool: TexturePool;
7430
- // @inject(DefaultCamera)
7431
- // protected camera: ICamera;
7432
- // @inject(LightPool)
7433
- // protected lightPool: LightPool;
7434
- // @inject(BatchManager)
7435
- // protected batchManager: BatchManager;
7436
- // @inject(MeshFactory)
7437
- // protected meshFactory: (shape: string) => Instanced;
7438
- // device: Device;
7439
- // renderingService: RenderingService;
7440
- this.id = counter++;
7441
7434
  /**
7442
7435
  * describe render insts used in this draw call
7443
7436
  * eg. a Polygon with stroke will use 2 renderInsts
@@ -8011,7 +8004,7 @@
8011
8004
  return v !== undefined;
8012
8005
  }));
8013
8006
  };
8014
- var counter$1 = 1;
8007
+ var counter = 1;
8015
8008
  var FILL_TEXTURE_MAPPING = 'FillTextureMapping';
8016
8009
  /**
8017
8010
  * WebGPU has max vertex attribute num(8)
@@ -8061,8 +8054,13 @@
8061
8054
  /**
8062
8055
  * unique ID
8063
8056
  */
8064
- this.id = counter$1++;
8057
+ this.id = counter++;
8065
8058
  this.renderer = void 0;
8059
+ /**
8060
+ * assigned by user which help BatchManager deciding whether to merge,
8061
+ * e.g. `will-change` property in CSS
8062
+ */
8063
+ this.key = void 0;
8066
8064
  /**
8067
8065
  * index in renderer.meshes
8068
8066
  */
@@ -8368,7 +8366,7 @@
8368
8366
  var oldDefines = _extends({}, this.material.defines);
8369
8367
  this.material.defines.USE_FOG = useFog;
8370
8368
  this.material.defines.USE_LIGHT = useLight;
8371
- this.material.defines = _extends({}, this.material.defines, this.lightPool.getDefines());
8369
+ this.material.defines = _extends({}, this.material.defines, this.lightPool.getDefines(), this.renderHelper.getDefines());
8372
8370
  // re-upload textures
8373
8371
  if (this.material.textureDirty) {
8374
8372
  this.textureMappings = [];
@@ -8411,10 +8409,10 @@
8411
8409
  this.material.defines = _extends({}, this.material.defines, enumToObject(VertexAttributeLocation));
8412
8410
  Object.keys(this.material.defines).forEach(function (key) {
8413
8411
  var value = _this4.material.defines[key];
8414
- if (typeof value === 'number') {
8415
- _this4.program.setDefineString(key, "" + value);
8416
- } else {
8412
+ if (typeof value === 'boolean') {
8417
8413
  _this4.program.setDefineBool(key, value);
8414
+ } else {
8415
+ _this4.program.setDefineString(key, "" + value);
8418
8416
  }
8419
8417
  });
8420
8418
  // build shaders
@@ -8837,7 +8835,7 @@
8837
8835
  }]);
8838
8836
  return Instanced;
8839
8837
  }();
8840
- var frag = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nin vec4 v_PickingResult;\nin vec4 v_Color;\nin vec4 v_StrokeColor;\nin vec4 v_StylePacked1;\nin vec4 v_StylePacked2;\n#ifdef USE_UV\n in vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nin vec4 v_Data;\nin vec2 v_Radius;\nin vec4 v_StylePacked3;\n\nout vec4 outputColor;\n\n/**\n * 2D signed distance field functions\n * @see http://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm\n */\n\nfloat sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n\n// @see http://www.iquilezles.org/www/articles/ellipsoids/ellipsoids.htm\nfloat sdEllipsoidApproximated(vec2 p, vec2 r) {\n float k0 = length(p / r);\n float k1 = length(p / (r * r));\n return k0 * (k0 - 1.0) / k1;\n}\n\n// @see https://www.shadertoy.com/view/4llXD7\nfloat sdRoundedBox(vec2 p, vec2 b, vec2 r) {\n vec2 q = abs(p) - b + r;\n return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;\n}\n\nvoid main() {\n int shape = int(floor(v_Data.w + 0.5));\n float epsilon = 0.000001;\n\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\nvec3 u_PickingColor = v_PickingResult.xyz;\n\nif (u_Visible < 0.5) {\n discard;\n}\n #ifdef USE_MAP\n #ifdef USE_PATTERN\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #else\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #endif\n#endif\n\n bool omitStroke = v_StylePacked3.z == 1.0;\n\n float antialiasblur = v_Data.z;\n float antialiased_blur = -max(0.0, antialiasblur);\n vec2 r = (v_Radius - (omitStroke ? 0.0 : u_StrokeWidth)) / v_Radius;\n\n float outer_df;\n float inner_df;\n // 'circle', 'ellipse', 'rect'\n if (shape == 0) {\n outer_df = sdCircle(v_Data.xy, 1.0);\n inner_df = sdCircle(v_Data.xy, r.x);\n } else if (shape == 1) {\n outer_df = sdEllipsoidApproximated(v_Data.xy, vec2(1.0));\n inner_df = sdEllipsoidApproximated(v_Data.xy, r);\n } else if (shape == 2) {\n outer_df = sdRoundedBox(v_Data.xy, vec2(1.0), vec2(0.0));\n inner_df = sdRoundedBox(v_Data.xy, r, vec2(0.0));\n }\n\n float opacity_t = smoothstep(0.0, antialiased_blur, outer_df);\n\n float color_t = u_StrokeWidth < 0.01 ? 0.0 : smoothstep(\n antialiased_blur,\n 0.0,\n inner_df\n );\n\n // vec2 imagecoord = mod(v_Uv, 0.1);\n // vec4 texel = texture(SAMPLER_2D(u_Map), imagecoord);\n // u_Color = texel;\n\n vec4 diffuseColor;\n vec4 strokeColor;\n if (u_IsPicking > 0.5) {\n diffuseColor = vec4(u_PickingColor, 1.0);\n strokeColor = vec4(u_PickingColor, 1.0);\n } else {\n diffuseColor = u_Color;\n strokeColor = (u_StrokeColor == vec4(0) || omitStroke) ? vec4(0.0) : u_StrokeColor;\n }\n\n outputColor = mix(vec4(diffuseColor.rgb, diffuseColor.a * u_FillOpacity), strokeColor * u_StrokeOpacity, color_t);\n outputColor.a = outputColor.a * u_Opacity * opacity_t;\n\n if (outputColor.a < epsilon)\n discard;\n\n if (u_IsPicking > 0.5) {\n if (u_PickingColor.x == 0.0 && u_PickingColor.y == 0.0 && u_PickingColor.z == 0.0) {\n discard;\n }\n }\n}"; // eslint-disable-line
8838
+ var frag = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nin vec4 v_PickingResult;\nin vec4 v_Color;\nin vec4 v_StrokeColor;\nin vec4 v_StylePacked1;\nin vec4 v_StylePacked2;\n#ifdef USE_UV\n in vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nin vec4 v_Data;\nin vec2 v_Radius;\nin vec4 v_StylePacked3;\n\nout vec4 outputColor;\n\n/**\n * 2D signed distance field functions\n * @see http://www.iquilezles.org/www/articles/distfunctions2d/distfunctions2d.htm\n */\n\nfloat sdCircle(vec2 p, float r) {\n return length(p) - r;\n}\n\n// @see http://www.iquilezles.org/www/articles/ellipsoids/ellipsoids.htm\nfloat sdEllipsoidApproximated(vec2 p, vec2 r) {\n float k0 = length(p / r);\n float k1 = length(p / (r * r));\n return k0 * (k0 - 1.0) / k1;\n}\n\n// @see https://www.shadertoy.com/view/4llXD7\nfloat sdRoundedBox(vec2 p, vec2 b, vec2 r) {\n vec2 q = abs(p) - b + r;\n return min(max(q.x, q.y), 0.0) + length(max(q, 0.0)) - r.x;\n}\n\nvoid main() {\n int shape = int(floor(v_Data.w + 0.5));\n float epsilon = 0.000001;\n\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\nvec3 u_PickingColor = v_PickingResult.xyz;\n\nif (u_Visible < 0.5) {\n discard;\n}\n #ifdef USE_MAP\n #ifdef USE_PATTERN\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #else\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #endif\n#endif\n\n bool omitStroke = v_StylePacked3.z == 1.0;\n\n float antialiasblur = v_Data.z;\n float antialiased_blur = -max(0.0, antialiasblur);\n vec2 r = (v_Radius - (omitStroke ? 0.0 : u_StrokeWidth)) / v_Radius;\n\n float outer_df;\n float inner_df;\n // 'circle', 'ellipse', 'rect'\n if (shape == 0) {\n outer_df = sdCircle(v_Data.xy, 1.0);\n inner_df = sdCircle(v_Data.xy, r.x);\n } else if (shape == 1) {\n outer_df = sdEllipsoidApproximated(v_Data.xy, vec2(1.0));\n inner_df = sdEllipsoidApproximated(v_Data.xy, r);\n } else if (shape == 2) {\n outer_df = sdRoundedBox(v_Data.xy, vec2(1.0), vec2(0.0));\n inner_df = sdRoundedBox(v_Data.xy, r, vec2(0.0));\n }\n\n float opacity_t = smoothstep(0.0, antialiased_blur, outer_df);\n\n float color_t = u_StrokeWidth < 0.01 ? 0.0 : smoothstep(\n antialiased_blur,\n 0.0,\n inner_df\n );\n\n vec4 diffuseColor;\n vec4 strokeColor;\n if (u_IsPicking > 0.5) {\n diffuseColor = vec4(u_PickingColor, 1.0);\n strokeColor = vec4(u_PickingColor, 1.0);\n } else {\n diffuseColor = u_Color;\n strokeColor = (u_StrokeColor == vec4(0) || omitStroke) ? vec4(0.0) : u_StrokeColor;\n }\n\n outputColor = mix(vec4(diffuseColor.rgb, diffuseColor.a * u_FillOpacity), strokeColor * u_StrokeOpacity, color_t);\n outputColor.a = outputColor.a * u_Opacity * opacity_t;\n\n if (outputColor.a < epsilon)\n discard;\n\n if (u_IsPicking > 0.5) {\n if (u_PickingColor.x == 0.0 && u_PickingColor.y == 0.0 && u_PickingColor.z == 0.0) {\n discard;\n }\n }\n}"; // eslint-disable-line
8841
8839
 
8842
8840
  var vert = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nlayout(location = MODEL_MATRIX0) in vec4 a_ModelMatrix0;\nlayout(location = MODEL_MATRIX1) in vec4 a_ModelMatrix1;\nlayout(location = MODEL_MATRIX2) in vec4 a_ModelMatrix2;\nlayout(location = MODEL_MATRIX3) in vec4 a_ModelMatrix3;\nlayout(location = COLOR) in vec4 a_Color;\nlayout(location = STROKE_COLOR) in vec4 a_StrokeColor;\nlayout(location = PACKED_STYLE1) in vec4 a_StylePacked1;\nlayout(location = PACKED_STYLE2) in vec4 a_StylePacked2;\nlayout(location = PICKING_COLOR) in vec4 a_PickingColor;\n\nout vec4 v_PickingResult;\nout vec4 v_Color;\nout vec4 v_StrokeColor;\nout vec4 v_StylePacked1;\nout vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = POSITION) in vec2 a_Extrude;\nlayout(location = PACKED_STYLE3) in vec4 a_StylePacked3;\nlayout(location = SIZE) in vec2 a_Size;\n#ifdef USE_UV\n layout(location = UV) in vec2 a_Uv;\n out vec2 v_Uv;\n#endif\n\nout vec4 v_Data;\nout vec2 v_Radius;\nout vec4 v_StylePacked3;\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\nvec2 u_Anchor = a_StylePacked2.yz;\nfloat u_IncreasedLineWidthForHitTesting = a_StylePacked2.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n float strokeWidth;\n if (u_IsPicking > 0.5) {\n strokeWidth = u_IncreasedLineWidthForHitTesting + u_StrokeWidth;\n } else {\n strokeWidth = u_StrokeWidth;\n }\n\n float antialiasblur = 1.0 / (a_Size.x + strokeWidth);\n\n bool omitStroke = a_StylePacked3.z == 1.0;\n vec2 radius = a_Size + vec2(omitStroke ? 0.0 : strokeWidth / 2.0);\n vec2 offset = (a_Extrude + vec2(1.0) - 2.0 * u_Anchor.xy) * radius;\n\n bool isBillboard = a_StylePacked3.w > 0.5;\n if (isBillboard) {\n vec4 mvPosition = u_ViewMatrix * u_ModelMatrix * vec4( 0.0, 0.0, u_ZIndex, 1.0 );\nvec2 scale;\nscale.x = length( vec3( u_ModelMatrix[ 0 ].x, u_ModelMatrix[ 0 ].y, u_ModelMatrix[ 0 ].z ) );\nscale.y = length( vec3( u_ModelMatrix[ 1 ].x, u_ModelMatrix[ 1 ].y, u_ModelMatrix[ 1 ].z ) );\n\n// if (sizeAttenuation < 0.5) {\n// bool isPerspective = isPerspectiveMatrix( u_ProjectionMatrix );\n// if ( isPerspective ) scale *= - mvPosition.z;\n// }\n\nvec2 alignedPosition = offset * scale;\n\nfloat rotation = 0.0;\nvec2 rotatedPosition;\nrotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\nrotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\nmvPosition.xy += rotatedPosition;\n\ngl_Position = u_ProjectionMatrix * mvPosition;\n } else {\n gl_Position = project(vec4(offset, u_ZIndex, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n }\n \n v_Radius = radius;\n v_Data = vec4(a_Extrude, antialiasblur, a_StylePacked3.x);\n v_StylePacked3 = a_StylePacked3;\n}"; // eslint-disable-line
8843
8841
 
@@ -8993,9 +8991,9 @@
8993
8991
  };
8994
8992
  return SDFMesh;
8995
8993
  }(Instanced);
8996
- var frag$1 = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nin vec4 v_PickingResult;\nin vec4 v_Color;\nin vec4 v_StrokeColor;\nin vec4 v_StylePacked1;\nin vec4 v_StylePacked2;\n#ifdef USE_UV\n in vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nin vec4 v_Dash;\n// in vec2 v_Normal;\n\nout vec4 outputColor;\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\nvec3 u_PickingColor = v_PickingResult.xyz;\n\nif (u_Visible < 0.5) {\n discard;\n}\n #ifdef USE_MAP\n #ifdef USE_PATTERN\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #else\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #endif\n#endif\n\n if (u_IsPicking > 0.5) {\n if (u_PickingColor.x == 0.0 && u_PickingColor.y == 0.0 && u_PickingColor.z == 0.0) {\n discard;\n }\n outputColor = vec4(u_PickingColor, 1.0);\n } else {\n outputColor = u_StrokeColor;\n #ifdef USE_MAP\n outputColor = u_Color;\n #endif\n\n // float blur = 1. - smoothstep(0.98, 1., length(v_Normal));\n float u_dash_offset = v_Dash.y;\n float u_dash_array = v_Dash.z;\n float u_dash_ratio = v_Dash.w;\n outputColor.a = outputColor.a\n // * blur\n * u_Opacity * u_StrokeOpacity\n * ceil(mod(v_Dash.x + u_dash_offset, u_dash_array) - (u_dash_array * u_dash_ratio));\n }\n}"; // eslint-disable-line
8994
+ var frag$1 = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nin vec4 v_PickingResult;\nin vec4 v_Color;\nin vec4 v_StrokeColor;\nin vec4 v_StylePacked1;\nin vec4 v_StylePacked2;\n#ifdef USE_UV\n in vec2 v_Uv;\n#endif\n#ifdef USE_MAP\n uniform sampler2D u_Map;\n#endif\n\nin vec4 v_Dash;\nin vec2 v_Distance;\n\nout vec4 outputColor;\n\nvoid main() {\n vec4 u_Color = v_Color;\nvec4 u_StrokeColor = v_StrokeColor;\nfloat u_Opacity = v_StylePacked1.x;\nfloat u_FillOpacity = v_StylePacked1.y;\nfloat u_StrokeOpacity = v_StylePacked1.z;\nfloat u_StrokeWidth = v_StylePacked1.w;\nfloat u_Visible = v_StylePacked2.x;\nvec3 u_PickingColor = v_PickingResult.xyz;\n\nif (u_Visible < 0.5) {\n discard;\n}\n #ifdef USE_MAP\n #ifdef USE_PATTERN\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #else\n vec4 texelColor = texture(SAMPLER_2D(u_Map), v_Uv);\n u_Color = texelColor;\n #endif\n#endif\n\n if (u_IsPicking > 0.5) {\n if (u_PickingColor.x == 0.0 && u_PickingColor.y == 0.0 && u_PickingColor.z == 0.0) {\n discard;\n }\n outputColor = vec4(u_PickingColor, 1.0);\n } else {\n outputColor = u_StrokeColor;\n #ifdef USE_MAP\n outputColor = u_Color;\n #endif\n\n float blur = smoothstep(0.0, v_Distance.y, 1.0 - abs(v_Distance.x));\n float u_dash_offset = v_Dash.y;\n float u_dash_array = v_Dash.z;\n float u_dash_ratio = v_Dash.w;\n\n outputColor.a = outputColor.a\n * blur\n * u_Opacity * u_StrokeOpacity\n * ceil(mod(v_Dash.x + u_dash_offset, u_dash_array) - (u_dash_array * u_dash_ratio));\n }\n}"; // eslint-disable-line
8997
8995
 
8998
- var vert$1 = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nlayout(location = MODEL_MATRIX0) in vec4 a_ModelMatrix0;\nlayout(location = MODEL_MATRIX1) in vec4 a_ModelMatrix1;\nlayout(location = MODEL_MATRIX2) in vec4 a_ModelMatrix2;\nlayout(location = MODEL_MATRIX3) in vec4 a_ModelMatrix3;\nlayout(location = COLOR) in vec4 a_Color;\nlayout(location = STROKE_COLOR) in vec4 a_StrokeColor;\nlayout(location = PACKED_STYLE1) in vec4 a_StylePacked1;\nlayout(location = PACKED_STYLE2) in vec4 a_StylePacked2;\nlayout(location = PICKING_COLOR) in vec4 a_PickingColor;\n\nout vec4 v_PickingResult;\nout vec4 v_Color;\nout vec4 v_StrokeColor;\nout vec4 v_StylePacked1;\nout vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = POSITION) in vec3 a_Position;\nlayout(location = POINTA) in vec3 a_PointA;\nlayout(location = POINTB) in vec3 a_PointB;\nlayout(location = CAP) in float a_Cap;\n#ifdef USE_UV\n layout(location = UV) in vec2 a_Uv;\n out vec2 v_Uv;\n#endif\nlayout(location = DASH) in vec4 a_Dash;\n\nout vec4 v_Dash;\n// out vec2 v_Normal;\n\nbool isPerspectiveMatrix(mat4 m) {\n return m[ 2 ][ 3 ] == - 1.0;\n}\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\nvec2 u_Anchor = a_StylePacked2.yz;\nfloat u_IncreasedLineWidthForHitTesting = a_StylePacked2.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n float strokeWidth;\n if (u_IsPicking > 0.5) {\n strokeWidth = u_IncreasedLineWidthForHitTesting + u_StrokeWidth;\n } else {\n strokeWidth = u_StrokeWidth;\n }\n\n float isBillboard = a_Dash.w;\n bool isPerspective = isPerspectiveMatrix(u_ProjectionMatrix);\n\n if (isBillboard > 0.5 && isPerspective) {\n // clip space\n vec4 clip0 = project(vec4(a_PointA, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n vec4 clip1 = project(vec4(a_PointB, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n // screen space\n vec2 screen0 = u_Viewport * (0.5 * clip0.xy / clip0.w + 0.5);\n vec2 screen1 = u_Viewport * (0.5 * clip1.xy / clip1.w + 0.5);\n vec2 xBasis = normalize(screen1 - screen0);\n vec2 yBasis = vec2(-xBasis.y, xBasis.x);\n vec2 pt0 = screen0 + strokeWidth * (a_Position.x * xBasis + a_Position.y * yBasis);\n vec2 pt1 = screen1 + strokeWidth * (a_Position.x * xBasis + a_Position.y * yBasis);\n vec2 pt = mix(pt0, pt1, a_Position.z);\n vec4 clip = mix(clip0, clip1, a_Position.z);\n gl_Position = vec4(clip.w * (2.0 * pt / u_Viewport - 1.0), clip.z, clip.w);\n } else {\n vec2 xBasis = a_PointB.xy - a_PointA.xy;\n vec2 yBasis = normalize(vec2(-xBasis.y, xBasis.x));\n\n vec2 point = a_PointA.xy + xBasis * a_Position.x + yBasis * strokeWidth * a_Position.y;\n point = point - u_Anchor.xy * abs(xBasis);\n\n // round & square\n if (a_Cap > 1.0) {\n point += sign(a_Position.x - 0.5) * normalize(xBasis) * vec2(strokeWidth / 2.0);\n }\n\n gl_Position = project(vec4(point, u_ZIndex, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n }\n\n v_Dash = vec4(a_Position.x, a_Dash.xyz);\n}"; // eslint-disable-line
8996
+ var vert$1 = "#define GLSLIFY 1\nlayout(std140) uniform ub_SceneParams {\n mat4 u_ProjectionMatrix;\n mat4 u_ViewMatrix;\n vec3 u_CameraPosition;\n float u_DevicePixelRatio;\n vec2 u_Viewport;\n float u_IsOrtho;\n float u_IsPicking;\n};\n\nlayout(location = MODEL_MATRIX0) in vec4 a_ModelMatrix0;\nlayout(location = MODEL_MATRIX1) in vec4 a_ModelMatrix1;\nlayout(location = MODEL_MATRIX2) in vec4 a_ModelMatrix2;\nlayout(location = MODEL_MATRIX3) in vec4 a_ModelMatrix3;\nlayout(location = COLOR) in vec4 a_Color;\nlayout(location = STROKE_COLOR) in vec4 a_StrokeColor;\nlayout(location = PACKED_STYLE1) in vec4 a_StylePacked1;\nlayout(location = PACKED_STYLE2) in vec4 a_StylePacked2;\nlayout(location = PICKING_COLOR) in vec4 a_PickingColor;\n\nout vec4 v_PickingResult;\nout vec4 v_Color;\nout vec4 v_StrokeColor;\nout vec4 v_StylePacked1;\nout vec4 v_StylePacked2;\n\n#define COLOR_SCALE 1. / 255.\nvoid setPickingColor(vec3 pickingColor) {\n v_PickingResult.rgb = pickingColor * COLOR_SCALE;\n}\nvec4 project(vec4 pos, mat4 pm, mat4 vm, mat4 mm) {\n return pm * vm * mm * pos;\n}\n\nlayout(location = POSITION) in vec3 a_Position;\nlayout(location = POINTA) in vec3 a_PointA;\nlayout(location = POINTB) in vec3 a_PointB;\nlayout(location = CAP) in float a_Cap;\n#ifdef USE_UV\n layout(location = UV) in vec2 a_Uv;\n out vec2 v_Uv;\n#endif\nlayout(location = DASH) in vec4 a_Dash;\n\nout vec4 v_Dash;\nout vec2 v_Distance;\n\nbool isPerspectiveMatrix(mat4 m) {\n return m[ 2 ][ 3 ] == - 1.0;\n}\n\nvoid main() {\n mat4 u_ModelMatrix = mat4(a_ModelMatrix0, a_ModelMatrix1, a_ModelMatrix2, a_ModelMatrix3);\nvec4 u_StrokeColor = a_StrokeColor;\nfloat u_Opacity = a_StylePacked1.x;\nfloat u_FillOpacity = a_StylePacked1.y;\nfloat u_StrokeOpacity = a_StylePacked1.z;\nfloat u_StrokeWidth = a_StylePacked1.w;\nfloat u_ZIndex = a_PickingColor.w;\nvec2 u_Anchor = a_StylePacked2.yz;\nfloat u_IncreasedLineWidthForHitTesting = a_StylePacked2.w;\n\nsetPickingColor(a_PickingColor.xyz);\n\nv_Color = a_Color;\nv_StrokeColor = a_StrokeColor;\nv_StylePacked1 = a_StylePacked1;\nv_StylePacked2 = a_StylePacked2;\n\n#ifdef CLIPSPACE_NEAR_ZERO\n gl_Position.z = gl_Position.z * 0.5 + 0.5;\n#endif\n #ifdef USE_UV\n v_Uv = a_Uv;\n #ifdef VIEWPORT_ORIGIN_TL\n v_Uv.y = 1.0 - v_Uv.y;\n #endif\n#endif\n\n float strokeWidth;\n if (u_IsPicking > 0.5) {\n strokeWidth = u_IncreasedLineWidthForHitTesting + u_StrokeWidth;\n } else {\n strokeWidth = u_StrokeWidth;\n }\n\n float isBillboard = a_Dash.w;\n bool isPerspective = isPerspectiveMatrix(u_ProjectionMatrix);\n\n if (isBillboard > 0.5 && isPerspective) {\n // clip space\n vec4 clip0 = project(vec4(a_PointA, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n vec4 clip1 = project(vec4(a_PointB, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n // screen space\n vec2 screen0 = u_Viewport * (0.5 * clip0.xy / clip0.w + 0.5);\n vec2 screen1 = u_Viewport * (0.5 * clip1.xy / clip1.w + 0.5);\n vec2 xBasis = normalize(screen1 - screen0);\n vec2 yBasis = vec2(-xBasis.y, xBasis.x);\n vec2 pt0 = screen0 + strokeWidth * (a_Position.x * xBasis + a_Position.y * yBasis);\n vec2 pt1 = screen1 + strokeWidth * (a_Position.x * xBasis + a_Position.y * yBasis);\n vec2 pt = mix(pt0, pt1, a_Position.z);\n vec4 clip = mix(clip0, clip1, a_Position.z);\n gl_Position = vec4(clip.w * (2.0 * pt / u_Viewport - 1.0), clip.z, clip.w);\n } else {\n vec2 xBasis = a_PointB.xy - a_PointA.xy;\n vec2 yBasis = normalize(vec2(-xBasis.y, xBasis.x));\n\n vec2 point = a_PointA.xy + xBasis * a_Position.x + yBasis * strokeWidth * a_Position.y;\n point = point - u_Anchor.xy * abs(xBasis);\n\n // round & square\n if (a_Cap > 1.0) {\n point += sign(a_Position.x - 0.5) * normalize(xBasis) * vec2(strokeWidth / 2.0);\n }\n gl_Position = project(vec4(point, u_ZIndex, 1.0), u_ProjectionMatrix, u_ViewMatrix, u_ModelMatrix);\n }\n\n float antialiasblur = 1.0 / strokeWidth;\n v_Distance = vec2(a_Position.y * 2.0, antialiasblur);\n v_Dash = vec4(a_Position.x, a_Dash.xyz);\n}"; // eslint-disable-line
8999
8997
 
9000
8998
  var segmentInstanceGeometry = [0, -0.5, 0, 0, 0, 1, -0.5, 1, 1, 0, 1, 0.5, 1, 1, 1, 0, 0.5, 0, 0, 1];
9001
8999
  var InstancedLineVertexAttributeBufferIndex;
@@ -11279,6 +11277,7 @@
11279
11277
  }
11280
11278
  _this = _Instanced.call.apply(_Instanced, [this].concat(args)) || this;
11281
11279
  _this.glyphManager = new GlyphManager();
11280
+ _this.packedBufferObjectMap = new WeakMap();
11282
11281
  return _this;
11283
11282
  }
11284
11283
  var _proto = TextMesh.prototype;
@@ -11359,7 +11358,10 @@
11359
11358
  charUVOffsetBuffer = _this2$buildTextBuffe.charUVOffsetBuffer,
11360
11359
  charPackedBuffer = _this2$buildTextBuffe.charPackedBuffer;
11361
11360
  indicesOff = indicesOffset;
11361
+ var start = packed.length;
11362
11362
  packed.push.apply(packed, charPackedBuffer);
11363
+ var end = packed.length;
11364
+ _this2.packedBufferObjectMap.set(object, [start, end]);
11363
11365
  uvOffsets.push.apply(uvOffsets, charUVOffsetBuffer);
11364
11366
  indices.push.apply(indices, indexBuffer);
11365
11367
  });
@@ -11473,6 +11475,17 @@
11473
11475
  this.material.setUniforms((_this$material$setUni = {}, _this$material$setUni[TextUniform.SDF_MAP] = glyphAtlasTexture, _this$material$setUni[TextUniform.SDF_MAP_SIZE] = [atlasWidth, atlasHeight], _this$material$setUni[TextUniform.FONT_SIZE] = fontSize, _this$material$setUni[TextUniform.GAMMA_SCALE] = 1, _this$material$setUni[TextUniform.STROKE_BLUR] = 0.2, _this$material$setUni[TextUniform.HAS_STROKE] = this.index, _this$material$setUni));
11474
11476
  };
11475
11477
  _proto.changeRenderOrder = function changeRenderOrder(object, renderOrder) {
11478
+ var vertice = this.geometry.vertices[TextVertexAttributeBufferIndex.INSTANCED];
11479
+ var byteStride = this.geometry.inputLayoutDescriptor.vertexBufferDescriptors[TextVertexAttributeBufferIndex.INSTANCED].byteStride;
11480
+ var bytes = byteStride / 4;
11481
+ var _this$packedBufferObj = this.packedBufferObjectMap.get(object),
11482
+ start = _this$packedBufferObj[0],
11483
+ end = _this$packedBufferObj[1];
11484
+ var sliced = vertice.slice(start, end);
11485
+ for (var i = 0; i < end - start; i += bytes) {
11486
+ sliced[i + bytes - 1] = renderOrder * RENDER_ORDER_SCALE;
11487
+ }
11488
+ this.geometry.updateVertexBuffer(TextVertexAttributeBufferIndex.INSTANCED, VertexAttributeLocation.MODEL_MATRIX0, start / byteStride, new Uint8Array(sliced.buffer));
11476
11489
  if (this.material) {
11477
11490
  this.material.programDirty = true;
11478
11491
  this.material.geometryDirty = true;
@@ -11484,7 +11497,7 @@
11484
11497
  this.material.geometryDirty = true;
11485
11498
  // need re-upload SDF texture
11486
11499
  this.material.textureDirty = true;
11487
- } else if (name === 'fill' || name === 'fillOpacity' || name === 'stroke' || name === 'strokeOpacity' || name === 'opacity' || name === 'lineWidth' || name === 'visibility' || name === 'pointerEvents') {
11500
+ } else if (name === 'fill' || name === 'fillOpacity' || name === 'stroke' || name === 'strokeOpacity' || name === 'opacity' || name === 'lineWidth' || name === 'pointerEvents') {
11488
11501
  this.material.geometryDirty = true;
11489
11502
  }
11490
11503
  };
@@ -11937,11 +11950,14 @@
11937
11950
  var existedMesh = _this2.meshes.find(function (mesh) {
11938
11951
  return meshTag === mesh.constructor && mesh.index === i && mesh.shouldMerge(object, i);
11939
11952
  });
11940
- if (!existedMesh) {
11953
+ if (!existedMesh || existedMesh.key !== object.parsedStyle.batchKey) {
11941
11954
  existedMesh = new meshTag(_this2.renderHelper, _this2.texturePool, _this2.lightPool);
11942
11955
  existedMesh.renderer = renderer;
11943
11956
  existedMesh.index = i;
11944
11957
  _this2.meshes.push(existedMesh);
11958
+ if (object.parsedStyle.batchKey) {
11959
+ existedMesh.key = object.parsedStyle.batchKey;
11960
+ }
11945
11961
  }
11946
11962
  if (existedMesh) {
11947
11963
  existedMesh.objects.push(object);
@@ -12395,13 +12411,21 @@
12395
12411
  }
12396
12412
  _this = _AbstractRendererPlug.call.apply(_AbstractRendererPlug, [this].concat(args)) || this;
12397
12413
  _this.name = 'device-renderer';
12414
+ _this.parameters = {
12415
+ /**
12416
+ * ToneMapping is a renderer-level parameter, it will affect all materials.
12417
+ * @see https://threejs.org/docs/#api/en/renderers/WebGLRenderer.toneMapping
12418
+ */
12419
+ toneMapping: ToneMapping.NONE,
12420
+ toneMappingExposure: 1
12421
+ };
12398
12422
  return _this;
12399
12423
  }
12400
12424
  var _proto = Plugin.prototype;
12401
12425
  _proto.init = function init(runtime) {
12402
12426
  var _rendererFactory;
12403
12427
  runtime.geometryUpdaterFactory[gLite.Shape.MESH] = new MeshUpdater();
12404
- var renderHelper = new RenderHelper();
12428
+ var renderHelper = new RenderHelper(this.parameters);
12405
12429
  var lightPool = new LightPool();
12406
12430
  var texturePool = new TexturePool(this.context);
12407
12431
  var pickingIdGenerator = new PickingIdGenerator();
@@ -12428,6 +12452,9 @@
12428
12452
  _proto.toDataURL = function toDataURL(options) {
12429
12453
  return this.getRenderGraphPlugin().toDataURL(options);
12430
12454
  };
12455
+ _proto.setParameters = function setParameters(parameters) {
12456
+ this.parameters = _extends({}, this.parameters, parameters);
12457
+ };
12431
12458
  return Plugin;
12432
12459
  }(gLite.AbstractRendererPlugin);
12433
12460
 
@@ -12505,6 +12532,7 @@
12505
12532
  TexturePool: TexturePool,
12506
12533
  get TextureUsage () { return TextureUsage; },
12507
12534
  TinySDF: TinySDF,
12535
+ get ToneMapping () { return ToneMapping; },
12508
12536
  TransparentBlack: TransparentBlack,
12509
12537
  TransparentWhite: TransparentWhite,
12510
12538
  UNIFORM_SETTERS: UNIFORM_SETTERS,