@swf2es/render 0.1.42 → 0.1.44

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 (69) hide show
  1. package/dist/commands.d.ts +26 -5
  2. package/dist/commands.d.ts.map +1 -1
  3. package/dist/commands.js +42 -5
  4. package/dist/commands.js.map +1 -1
  5. package/dist/filter-shaders.d.ts +2 -2
  6. package/dist/filter-shaders.d.ts.map +1 -1
  7. package/dist/filter-shaders.js +7 -4
  8. package/dist/filter-shaders.js.map +1 -1
  9. package/dist/index.d.ts +2 -2
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +2 -2
  12. package/dist/index.js.map +1 -1
  13. package/dist/measure.d.ts +7 -2
  14. package/dist/measure.d.ts.map +1 -1
  15. package/dist/measure.js +189 -5
  16. package/dist/measure.js.map +1 -1
  17. package/dist/plan.d.ts.map +1 -1
  18. package/dist/plan.js +8 -4
  19. package/dist/plan.js.map +1 -1
  20. package/dist/registry.d.ts +12 -0
  21. package/dist/registry.d.ts.map +1 -1
  22. package/dist/registry.js +19 -0
  23. package/dist/registry.js.map +1 -1
  24. package/dist/scene.d.ts +35 -4
  25. package/dist/scene.d.ts.map +1 -1
  26. package/dist/scene.js +41 -4
  27. package/dist/scene.js.map +1 -1
  28. package/dist/webgl/backdrops.d.ts +60 -0
  29. package/dist/webgl/backdrops.d.ts.map +1 -0
  30. package/dist/webgl/backdrops.js +130 -0
  31. package/dist/webgl/backdrops.js.map +1 -0
  32. package/dist/webgl/backend.d.ts +31 -1
  33. package/dist/webgl/backend.d.ts.map +1 -1
  34. package/dist/webgl/backend.js +140 -31
  35. package/dist/webgl/backend.js.map +1 -1
  36. package/dist/webgl/composite.d.ts +29 -2
  37. package/dist/webgl/composite.d.ts.map +1 -1
  38. package/dist/webgl/composite.js +96 -27
  39. package/dist/webgl/composite.js.map +1 -1
  40. package/dist/webgl/draws.d.ts +5 -3
  41. package/dist/webgl/draws.d.ts.map +1 -1
  42. package/dist/webgl/draws.js +7 -5
  43. package/dist/webgl/draws.js.map +1 -1
  44. package/dist/webgl/holds.d.ts +5 -2
  45. package/dist/webgl/holds.d.ts.map +1 -1
  46. package/dist/webgl/holds.js +9 -4
  47. package/dist/webgl/holds.js.map +1 -1
  48. package/dist/webgl/programs.d.ts +11 -0
  49. package/dist/webgl/programs.d.ts.map +1 -1
  50. package/dist/webgl/programs.js +42 -6
  51. package/dist/webgl/programs.js.map +1 -1
  52. package/dist/webgl/targets.d.ts +4 -0
  53. package/dist/webgl/targets.d.ts.map +1 -1
  54. package/dist/webgl/targets.js.map +1 -1
  55. package/package.json +2 -2
  56. package/src/commands.ts +47 -5
  57. package/src/filter-shaders.ts +7 -4
  58. package/src/index.ts +9 -0
  59. package/src/measure.ts +247 -2
  60. package/src/plan.ts +24 -4
  61. package/src/registry.ts +21 -0
  62. package/src/scene.ts +42 -3
  63. package/src/webgl/backdrops.ts +150 -0
  64. package/src/webgl/backend.ts +175 -34
  65. package/src/webgl/composite.ts +120 -48
  66. package/src/webgl/draws.ts +10 -3
  67. package/src/webgl/holds.ts +11 -3
  68. package/src/webgl/programs.ts +46 -5
  69. package/src/webgl/targets.ts +4 -0
@@ -22,6 +22,7 @@ import type { GpuTextures } from "./gpu-textures.js";
22
22
  import type { KernelHost, KernelPrograms } from "./kernels.js";
23
23
  import {
24
24
  BACK_UNIT,
25
+ BELOW_STEP,
25
26
  blendFillFragment,
26
27
  FILL_SLOT,
27
28
  FILL_TEXTURES,
@@ -556,11 +557,13 @@ export class Draws {
556
557
  /**
557
558
  * Entry `i`, blendable, drawn onto the target bound in blend mode `mode`,
558
559
  * a layer drawn for its blend mode alone where `fresh` (SceneList.fresh),
560
+ * what is below read as `below` says there (SceneList.below),
559
561
  * coloured by its layer's row `layerRow` (or -1), where the masks pushed
560
562
  * pass: GL's blending computing add, screen and, where it does not
561
563
  * `reads` below, multiply, the program the rest from the copy of what is
562
- * below (Compositor.copyBelow), whose texel at a fragment is (`backX`,
563
- * `backY`) short of it.
564
+ * below (Compositor.copyBoxes, made for it or shared with the blends
565
+ * drawn direct before it: Backdrops), whose texel at a fragment is
566
+ * (`backX`, `backY`) short of it.
564
567
  */
565
568
  drawBlended(
566
569
  scene: SceneList,
@@ -568,6 +571,7 @@ export class Draws {
568
571
  mode: number,
569
572
  reads: boolean,
570
573
  fresh: boolean | undefined,
574
+ below: number,
571
575
  layerRow: number,
572
576
  backX: number,
573
577
  backY: number,
@@ -579,7 +583,10 @@ export class Draws {
579
583
  gl.uniform4fv(this.blendViewLocation, this.view);
580
584
  gl.uniform1f(this.blendUnitLocation, this.unit);
581
585
  // Its pixel alone where GL's blending computes the mode (readsBelow).
582
- gl.uniform1i(this.blendModeLocation, (reads ? mode : NORMAL) + (fresh ? FRESH : 0));
586
+ gl.uniform1i(
587
+ this.blendModeLocation,
588
+ (reads ? mode : NORMAL) + (fresh ? FRESH : 0) + below * BELOW_STEP,
589
+ );
583
590
  gl.uniform1i(this.blendLayerRowLocation, layerRow);
584
591
  gl.uniform2i(this.blendBackLocation, backX, backY);
585
592
  this.gatherRun(scene, i, i + 1, false);
@@ -4,6 +4,9 @@ import {
4
4
  HELD,
5
5
  HOLD_POP,
6
6
  HOLD_PUSH,
7
+ operandBelow,
8
+ operandMode,
9
+ operandSolid,
7
10
  RUN,
8
11
  STENCIL_POP,
9
12
  STENCIL_PUSH,
@@ -545,8 +548,11 @@ export class HeldLayers {
545
548
  state.stencil(null);
546
549
  }
547
550
 
548
- /** Held output `held` composited onto `under`, bound, in blend mode `mode`, coloured by `row`. */
549
- compositeHeld(held: number, under: Open, mode: number, row: number): void {
551
+ /**
552
+ * Held output `held` composited onto `under`, bound, in blend mode and
553
+ * below `operand` (modeWithBelow), coloured by `row`.
554
+ */
555
+ compositeHeld(held: number, under: Open, operand: number, row: number): void {
550
556
  const hold = this.holds[held];
551
557
  const result = hold.result;
552
558
  if (!result) {
@@ -561,7 +567,9 @@ export class HeldLayers {
561
567
  open.height = hold.height;
562
568
  open.ox = result.x;
563
569
  open.oy = result.y;
564
- this.compositor.compositeLayer(open, under, mode, row);
570
+ open.below = operandBelow(operand);
571
+ open.solid = operandSolid(operand);
572
+ this.compositor.compositeLayer(open, under, operandMode(operand), row);
565
573
  }
566
574
 
567
575
  /**
@@ -3,6 +3,9 @@ import { ROWS_A_LINE } from "../rows.js";
3
3
  import {
4
4
  ADD,
5
5
  ALPHA,
6
+ BELOW_CLEARED,
7
+ BELOW_INVERTED,
8
+ BELOW_SUBTRACTED,
6
9
  DARKEN,
7
10
  DIFFERENCE,
8
11
  ERASE,
@@ -574,6 +577,19 @@ const layerColor = (row: string) => ` if (${row} >= 0 && front.a > 0.0) {
574
577
  */
575
578
  export const FRESH = 64;
576
579
 
580
+ /**
581
+ * Added to a composite's uMode where the layer is the bitmap of its
582
+ * filters (SceneList.solids), whose clear pixels BLEND_FRONT draws as it
583
+ * draws the rest.
584
+ */
585
+ export const SOLID_FRONT = 128;
586
+
587
+ /**
588
+ * What a blend program's uMode has, times this, for how it reads what is
589
+ * below it in a layer drawn for its blend mode alone (SceneList.below).
590
+ */
591
+ export const BELOW_STEP = 256;
592
+
577
593
  /** A composited layer's pixel, `front`, coloured by its row's colour transform where it has one (uRow not -1). */
578
594
  export const LAYER_COLOR = layerColor("uRow");
579
595
 
@@ -594,11 +610,21 @@ export const LAYER_COLOR = layerColor("uRow");
594
610
  * formulas, so they mark it DRAWN_CLEAR, clear but for a red no
595
611
  * premultiplied colour has, which the formulas read as clear and
596
612
  * compositeFragment drops, as Flash's premultiplied pixels of no alpha
597
- * have no colour.
613
+ * have no colour. What is drawn over a pixel so drawn as it is reads it as
614
+ * the mode would have left it over nothing, which the planner works out
615
+ * where it can (uMode / BELOW_STEP, SceneList.below): an invert's as white,
616
+ * a subtract's as black, an erase's or alpha's as clear, at its alpha, in
617
+ * any mode, normal too, for which GL's blending cannot read it. Where
618
+ * `front` is clear the pixel keeps what it holds, and alpha leaves it be,
619
+ * as Flash draws a shape, but not where `front` is the bitmap of a display
620
+ * object's filters (SOLID_FRONT added to uMode): adl draws that bitmap's
621
+ * clear pixels as it does the rest.
598
622
  */
599
623
  const BLEND_FRONT = ` int mode = uMode & ${FRESH - 1};
600
- bool fresh = uMode >= ${FRESH};
601
- if (mode == ${NORMAL} || mode == ${LAYER} || mode == ${SCREEN} || mode == ${ADD}) {
624
+ bool fresh = (uMode & ${FRESH}) != 0;
625
+ bool solid = (uMode & ${SOLID_FRONT}) != 0;
626
+ int below = uMode / ${BELOW_STEP};
627
+ if (below == 0 && (mode == ${NORMAL} || mode == ${LAYER} || mode == ${SCREEN} || mode == ${ADD})) {
602
628
  finalColor = front;
603
629
  return;
604
630
  }
@@ -609,8 +635,17 @@ const BLEND_FRONT = ` int mode = uMode & ${FRESH - 1};
609
635
  return;
610
636
  }
611
637
 
612
- if (back.a == 0.0) {
638
+ if (below != 0 && front.a == 0.0 && !solid) {
639
+ finalColor = back;
640
+ return;
641
+ }
642
+
643
+ if (back.a == 0.0 || below == ${BELOW_CLEARED}) {
613
644
  back = vec4(0.0);
645
+ } else if (below == ${BELOW_INVERTED}) {
646
+ back = vec4(back.a);
647
+ } else if (below == ${BELOW_SUBTRACTED}) {
648
+ back = vec4(0.0, 0.0, 0.0, back.a);
614
649
  }
615
650
 
616
651
  vec3 cb = straight(back);
@@ -623,6 +658,12 @@ const BLEND_FRONT = ` int mode = uMode & ${FRESH - 1};
623
658
  case ${DIFFERENCE}: b = abs(cb - cf); break;
624
659
  case ${OVERLAY}: b = hardlight(cf, cb); break;
625
660
  case ${HARDLIGHT}: b = hardlight(cb, cf); break;
661
+ case ${ADD}:
662
+ finalColor = min(front + back, 1.0);
663
+ return;
664
+ case ${SCREEN}:
665
+ finalColor = front + back * (1.0 - front);
666
+ return;
626
667
  case ${SUBTRACT}:
627
668
  finalColor = vec4(max(back.rgb - front.rgb, 0.0), min(front.a + back.a, 1.0));
628
669
  return;
@@ -633,7 +674,7 @@ const BLEND_FRONT = ` int mode = uMode & ${FRESH - 1};
633
674
  );
634
675
  return;
635
676
  case ${ALPHA}:
636
- finalColor = drawn(front.a > 0.0 ? back * front.a : back, fresh);
677
+ finalColor = drawn(front.a > 0.0 || solid ? back * front.a : back, fresh);
637
678
  return;
638
679
  case ${ERASE}:
639
680
  finalColor = drawn(back * (1.0 - front.a), fresh);
@@ -145,6 +145,10 @@ export interface Open {
145
145
  opaque?: boolean;
146
146
  /** Whether it is a layer drawn for its blend mode alone (SceneList.fresh). */
147
147
  fresh?: boolean;
148
+ /** How it reads what is below it in a layer drawn for its blend mode alone (SceneList.below). */
149
+ below?: number;
150
+ /** Whether it is the bitmap of its filters, its clear pixels drawn (SceneList.solids). */
151
+ solid?: boolean;
148
152
  }
149
153
 
150
154
  /** A whole layer's object from params `p` from `at` (plan.ts, layerParams): null for none. */