@swf2es/render 0.1.41 → 0.1.43

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 (59) hide show
  1. package/dist/commands.d.ts +27 -5
  2. package/dist/commands.d.ts.map +1 -1
  3. package/dist/commands.js +43 -5
  4. package/dist/commands.js.map +1 -1
  5. package/dist/index.d.ts +2 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +2 -2
  8. package/dist/index.js.map +1 -1
  9. package/dist/measure.d.ts +7 -2
  10. package/dist/measure.d.ts.map +1 -1
  11. package/dist/measure.js +189 -5
  12. package/dist/measure.js.map +1 -1
  13. package/dist/plan.d.ts.map +1 -1
  14. package/dist/plan.js +8 -4
  15. package/dist/plan.js.map +1 -1
  16. package/dist/scene.d.ts +45 -7
  17. package/dist/scene.d.ts.map +1 -1
  18. package/dist/scene.js +54 -7
  19. package/dist/scene.js.map +1 -1
  20. package/dist/webgl/backdrops.d.ts +60 -0
  21. package/dist/webgl/backdrops.d.ts.map +1 -0
  22. package/dist/webgl/backdrops.js +130 -0
  23. package/dist/webgl/backdrops.js.map +1 -0
  24. package/dist/webgl/backend.d.ts +19 -1
  25. package/dist/webgl/backend.d.ts.map +1 -1
  26. package/dist/webgl/backend.js +88 -28
  27. package/dist/webgl/backend.js.map +1 -1
  28. package/dist/webgl/composite.d.ts +29 -2
  29. package/dist/webgl/composite.d.ts.map +1 -1
  30. package/dist/webgl/composite.js +96 -27
  31. package/dist/webgl/composite.js.map +1 -1
  32. package/dist/webgl/draws.d.ts +6 -3
  33. package/dist/webgl/draws.d.ts.map +1 -1
  34. package/dist/webgl/draws.js +8 -5
  35. package/dist/webgl/draws.js.map +1 -1
  36. package/dist/webgl/holds.d.ts +5 -2
  37. package/dist/webgl/holds.d.ts.map +1 -1
  38. package/dist/webgl/holds.js +9 -4
  39. package/dist/webgl/holds.js.map +1 -1
  40. package/dist/webgl/programs.d.ts +16 -0
  41. package/dist/webgl/programs.d.ts.map +1 -1
  42. package/dist/webgl/programs.js +82 -9
  43. package/dist/webgl/programs.js.map +1 -1
  44. package/dist/webgl/targets.d.ts +6 -0
  45. package/dist/webgl/targets.d.ts.map +1 -1
  46. package/dist/webgl/targets.js.map +1 -1
  47. package/package.json +2 -2
  48. package/src/commands.ts +48 -5
  49. package/src/index.ts +9 -0
  50. package/src/measure.ts +247 -2
  51. package/src/plan.ts +24 -3
  52. package/src/scene.ts +55 -6
  53. package/src/webgl/backdrops.ts +150 -0
  54. package/src/webgl/backend.ts +115 -31
  55. package/src/webgl/composite.ts +121 -48
  56. package/src/webgl/draws.ts +13 -3
  57. package/src/webgl/holds.ts +11 -3
  58. package/src/webgl/programs.ts +87 -8
  59. package/src/webgl/targets.ts +6 -0
@@ -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,
@@ -568,6 +571,25 @@ const layerColor = (row: string) => ` if (${row} >= 0 && front.a > 0.0) {
568
571
  }
569
572
  `;
570
573
 
574
+ /**
575
+ * Added to a blend program's uMode where its target is a layer drawn for
576
+ * its blend mode alone (SceneList.fresh), which BLEND_FRONT takes apart.
577
+ */
578
+ export const FRESH = 64;
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
+
571
593
  /** A composited layer's pixel, `front`, coloured by its row's colour transform where it has one (uRow not -1). */
572
594
  export const LAYER_COLOR = layerColor("uRow");
573
595
 
@@ -576,35 +598,86 @@ export const LAYER_COLOR = layerColor("uRow");
576
598
  * (uBack, a copy of it, whose texel at the fragment is uBackOffset short of
577
599
  * it) into finalColor: normal, layer, add and screen as `front` alone, GL's
578
600
  * blending computing them; the separable modes blend straight colours and
579
- * composite source over, the others have formulas of their own.
601
+ * composite source over, the others have formulas of their own: invert
602
+ * ignores the source's colour, inverting the clear part of what is below
603
+ * to white, and subtract adds alphas, as BitmapData.draw's do.
604
+ *
605
+ * In a layer drawn for its blend mode alone (FRESH added to uMode,
606
+ * SceneList.fresh), adl draws `front` as it is, in any mode, over a pixel
607
+ * nothing in the layer has drawn, where subtract, invert, alpha and erase
608
+ * would leave black or nothing: an inverted shape in an inverted clip
609
+ * shows. A pixel drawn and then cleared, by erase or alpha, blends by the
610
+ * formulas, so they mark it DRAWN_CLEAR, clear but for a red no
611
+ * premultiplied colour has, which the formulas read as clear and
612
+ * compositeFragment drops, as Flash's premultiplied pixels of no alpha
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.
580
622
  */
581
- const BLEND_FRONT = ` if (uMode == ${NORMAL} || uMode == ${LAYER} || uMode == ${SCREEN} || uMode == ${ADD}) {
623
+ const BLEND_FRONT = ` int mode = uMode & ${FRESH - 1};
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})) {
582
628
  finalColor = front;
583
629
  return;
584
630
  }
585
631
 
586
632
  vec4 back = texelFetch(uBack, ivec2(gl_FragCoord.xy) - uBackOffset, 0);
633
+ if (fresh && back == vec4(0.0)) {
634
+ finalColor = front;
635
+ return;
636
+ }
637
+
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}) {
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);
649
+ }
650
+
587
651
  vec3 cb = straight(back);
588
652
  vec3 cf = straight(front);
589
653
  vec3 b;
590
- switch (uMode) {
654
+ switch (mode) {
591
655
  case ${MULTIPLY}: b = cb * cf; break;
592
656
  case ${LIGHTEN}: b = max(cb, cf); break;
593
657
  case ${DARKEN}: b = min(cb, cf); break;
594
658
  case ${DIFFERENCE}: b = abs(cb - cf); break;
595
659
  case ${OVERLAY}: b = hardlight(cf, cb); break;
596
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;
597
667
  case ${SUBTRACT}:
598
- finalColor = vec4(max(back.rgb - front.rgb, 0.0), front.a + back.a * (1.0 - front.a));
668
+ finalColor = vec4(max(back.rgb - front.rgb, 0.0), min(front.a + back.a, 1.0));
599
669
  return;
600
670
  case ${INVERT}:
601
- finalColor = vec4((back.a - back.rgb) * front.a + back.rgb * (1.0 - front.a), back.a);
671
+ finalColor = vec4(
672
+ (1.0 - back.rgb) * front.a + back.rgb * (1.0 - front.a),
673
+ front.a + back.a * (1.0 - front.a)
674
+ );
602
675
  return;
603
676
  case ${ALPHA}:
604
- finalColor = front.a > 0.0 ? back * front.a : back;
677
+ finalColor = drawn(front.a > 0.0 || solid ? back * front.a : back, fresh);
605
678
  return;
606
679
  case ${ERASE}:
607
- finalColor = back * (1.0 - front.a);
680
+ finalColor = drawn(back * (1.0 - front.a), fresh);
608
681
  return;
609
682
  default:
610
683
  finalColor = front + back * (1.0 - front.a);
@@ -616,7 +689,9 @@ const BLEND_FRONT = ` if (uMode == ${NORMAL} || uMode == ${LAYER} || uMode == $
616
689
  `;
617
690
 
618
691
  /** BLEND_FRONT's helpers. */
619
- const BLEND_HELPERS = `vec3 straight(vec4 c) { return c.a > 0.0 ? c.rgb / c.a : vec3(0.0); }
692
+ const BLEND_HELPERS = `const vec4 DRAWN_CLEAR = vec4(1.0 / 255.0, 0.0, 0.0, 0.0);
693
+ vec3 straight(vec4 c) { return c.a > 0.0 ? c.rgb / c.a : vec3(0.0); }
694
+ vec4 drawn(vec4 c, bool fresh) { return fresh && c.a < 0.5 / 255.0 ? DRAWN_CLEAR : c; }
620
695
  vec3 hardlight(vec3 cb, vec3 cf) {
621
696
  vec3 multiply = 2.0 * cb * cf;
622
697
  vec3 screen = 1.0 - 2.0 * (1.0 - cb) * (1.0 - cf);
@@ -649,6 +724,10 @@ void main(void) {
649
724
  ivec2 frag = ivec2(gl_FragCoord.xy);
650
725
  ivec2 at = ivec2(frag.x - uOffset.x, uFlip ? uOffset.y - frag.y : frag.y - uOffset.y);
651
726
  vec4 front = texelFetch(uLayer, at, 0);
727
+ if (front.a == 0.0) {
728
+ front = vec4(0.0);
729
+ }
730
+
652
731
  ${LAYER_COLOR}
653
732
  ${BLEND_FRONT}}
654
733
  `;
@@ -143,6 +143,12 @@ export interface Open {
143
143
  object?: KernelObject | null;
144
144
  /** Whether it is opaque throughout, as the stage is (Commands.opaqueStage). */
145
145
  opaque?: boolean;
146
+ /** Whether it is a layer drawn for its blend mode alone (SceneList.fresh). */
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;
146
152
  }
147
153
 
148
154
  /** A whole layer's object from params `p` from `at` (plan.ts, layerParams): null for none. */