-
Notifications
You must be signed in to change notification settings - Fork 1
/
post5.js
4279 lines (4160 loc) · 168 KB
/
post5.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* post5 0.1.0 | (c) 2020, Cole Granof | MIT License */
// @ts-nocheck
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.blurandtrace = exports.BlurAndTrace = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class BlurAndTrace extends merge_pass_1.EffectLoop {
constructor(brightness, blurSize, reps, taps, samplerNum, useDepth) {
const brightnessFloat = merge_pass_1.float(brightness);
const blurSizeFloat = merge_pass_1.float(blurSize);
super([
...(!useDepth ? [merge_pass_1.loop([merge_pass_1.channel(samplerNum)]).target(samplerNum)] : []),
merge_pass_1.blur2d(blurSizeFloat, blurSizeFloat, reps, taps),
merge_pass_1.edge(brightnessFloat, samplerNum),
], { num: 1 });
this.brightnessFloat = brightnessFloat;
this.blurSizeFloat = blurSizeFloat;
this.brightness = brightness;
this.blurSize = blurSize;
}
setBrightness(brightness) {
this.brightnessFloat.setVal(merge_pass_1.wrapInValue(brightness));
this.brightness = merge_pass_1.wrapInValue(brightness);
}
setBlurSize(blurSize) {
this.blurSizeFloat.setVal(merge_pass_1.wrapInValue(blurSize));
this.blurSize = merge_pass_1.wrapInValue(blurSize);
}
}
exports.BlurAndTrace = BlurAndTrace;
function blurandtrace(brightness = merge_pass_1.mut(1), blurSize = merge_pass_1.mut(1), reps = 4, taps = 9, samplerNum = 0, useDepth = false) {
return new BlurAndTrace(merge_pass_1.wrapInValue(brightness), merge_pass_1.wrapInValue(blurSize), reps, taps, samplerNum, useDepth);
}
exports.blurandtrace = blurandtrace;
},{"@bandaloo/merge-pass":62}],2:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.celshade = exports.CelShade = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class CelShade extends merge_pass_1.WrappedExpr {
constructor(mult, bump, center, edge) {
const multFloat = merge_pass_1.float(mult);
const bumpFloat = merge_pass_1.float(bump);
const centerFloat = merge_pass_1.float(center);
const edgeFloat = merge_pass_1.float(edge);
const smooth = merge_pass_1.cfloat(merge_pass_1.tag `(smoothstep(-${edgeFloat} + ${centerFloat}, ${edgeFloat} + ${centerFloat}, ${merge_pass_1.rgb2hsv(merge_pass_1.fcolor())}.z) * ${multFloat} + ${bumpFloat})`);
const expr = merge_pass_1.hsv2rgb(merge_pass_1.changecomp(merge_pass_1.rgb2hsv(merge_pass_1.fcolor()), smooth, "z"));
super(expr);
this.multFloat = multFloat;
this.bumpFloat = bumpFloat;
this.centerFloat = centerFloat;
this.edgeFloat = edgeFloat;
this.mult = mult;
this.bump = bump;
this.center = center;
this.edge = edge;
}
setMult(mult) {
this.multFloat.setVal(merge_pass_1.wrapInValue(mult));
this.mult = merge_pass_1.wrapInValue(mult);
}
setBump(bump) {
this.bumpFloat.setVal(merge_pass_1.wrapInValue(bump));
this.bump = merge_pass_1.wrapInValue(bump);
}
setCenter(center) {
this.centerFloat.setVal(merge_pass_1.wrapInValue(center));
this.center = merge_pass_1.wrapInValue(center);
}
setEdge(edge) {
this.edgeFloat.setVal(merge_pass_1.wrapInValue(edge));
this.edge = merge_pass_1.wrapInValue(edge);
}
}
exports.CelShade = CelShade;
function celshade(mult = merge_pass_1.mut(0.8), bump = merge_pass_1.mut(0.3), center = merge_pass_1.mut(0.3), edge = merge_pass_1.mut(0.03)) {
return new CelShade(merge_pass_1.wrapInValue(mult), merge_pass_1.wrapInValue(bump), merge_pass_1.wrapInValue(center), merge_pass_1.wrapInValue(edge));
}
exports.celshade = celshade;
},{"@bandaloo/merge-pass":62}],3:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.foggyrays = exports.FoggyRaysExpr = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class FoggyRaysExpr extends merge_pass_1.WrappedExpr {
constructor(period, speed, throwDistance, numSamples, samplerNum, convertDepthColor) {
const periodFloat = merge_pass_1.float(period);
const speedFloat = merge_pass_1.float(speed);
const throwDistanceFloat = merge_pass_1.float(throwDistance);
const fog = merge_pass_1.op(merge_pass_1.op(merge_pass_1.simplex(merge_pass_1.op(merge_pass_1.op(merge_pass_1.pos(), "+", merge_pass_1.op(merge_pass_1.op(merge_pass_1.time(), "*", speedFloat), "/", periodFloat)), "*", merge_pass_1.op(merge_pass_1.resolution(), "/", merge_pass_1.op(periodFloat, "*", 2)))), "*", merge_pass_1.simplex(merge_pass_1.op(merge_pass_1.op(merge_pass_1.pos(), "+", merge_pass_1.op(merge_pass_1.op(merge_pass_1.time(), "*", speedFloat), "/", merge_pass_1.op(periodFloat, "*", -2))), "*", merge_pass_1.op(merge_pass_1.resolution(), "/", merge_pass_1.op(periodFloat, "*", 4))))), "*", 0.5);
const expr = merge_pass_1.godrays({
weight: 0.009,
density: merge_pass_1.op(throwDistanceFloat, "+", merge_pass_1.op(fog, "*", 0.5)),
convertDepth: convertDepthColor !== undefined
? { threshold: 0.01, newColor: convertDepthColor }
: undefined,
samplerNum: samplerNum,
numSamples: numSamples,
});
super(expr);
this.periodFloat = periodFloat;
this.speedFloat = speedFloat;
this.throwDistanceFloat = throwDistanceFloat;
this.godraysExpr = expr;
this.convertsDepth = convertDepthColor !== undefined;
this.period = period;
this.speed = speed;
this.throwDistance = throwDistance;
}
setPeriod(period) {
this.periodFloat.setVal(merge_pass_1.wrapInValue(period));
this.period = merge_pass_1.wrapInValue(period);
}
setSpeed(speed) {
this.speedFloat.setVal(merge_pass_1.wrapInValue(speed));
this.speed = merge_pass_1.wrapInValue(speed);
}
setThrowDistance(throwDistance) {
this.throwDistanceFloat.setVal(merge_pass_1.wrapInValue(throwDistance));
this.throwDistance = merge_pass_1.wrapInValue(throwDistance);
}
setNewColor(newColor) {
if (this.convertsDepth === undefined) {
throw new Error("can only set new color if you are converting from a depth buffer");
}
this.godraysExpr.setNewColor(newColor);
}
}
exports.FoggyRaysExpr = FoggyRaysExpr;
function foggyrays(period = merge_pass_1.mut(100), speed = merge_pass_1.mut(1), throwDistance = merge_pass_1.mut(0.3), numSamples = 100, samplerNum, convertDepthColor) {
return new FoggyRaysExpr(merge_pass_1.wrapInValue(period), merge_pass_1.wrapInValue(speed), merge_pass_1.wrapInValue(throwDistance), numSamples, samplerNum, convertDepthColor);
}
exports.foggyrays = foggyrays;
},{"@bandaloo/merge-pass":62}],4:[function(require,module,exports){
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
};
Object.defineProperty(exports, "__esModule", { value: true });
__exportStar(require("./foggyrays"), exports);
__exportStar(require("./vignette"), exports);
__exportStar(require("./blurandtrace"), exports);
__exportStar(require("./lightbands"), exports);
__exportStar(require("./noisedisplacement"), exports);
__exportStar(require("./oldfilm"), exports);
__exportStar(require("./kaleidoscope"), exports);
__exportStar(require("./celshade"), exports);
},{"./blurandtrace":1,"./celshade":2,"./foggyrays":3,"./kaleidoscope":5,"./lightbands":6,"./noisedisplacement":7,"./oldfilm":8,"./vignette":10}],5:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.kaleidoscope = exports.Kaleidoscope = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class Kaleidoscope extends merge_pass_1.WrappedExpr {
constructor(sides, scale) {
const sidesFloat = merge_pass_1.float(sides);
const scaleFloat = merge_pass_1.float(scale);
const tpos = merge_pass_1.op(merge_pass_1.translate(merge_pass_1.pos(), merge_pass_1.vec2(-0.5, -0.5)), "/", scaleFloat);
const angle = merge_pass_1.a2("atan", merge_pass_1.getcomp(tpos, "y"), merge_pass_1.getcomp(tpos, "x"));
const b = merge_pass_1.op(2 * Math.PI, "*", merge_pass_1.op(1, "/", sidesFloat));
const mangle = merge_pass_1.op(merge_pass_1.a1("floor", merge_pass_1.op(angle, "/", b)), "*", b);
const a = merge_pass_1.op(angle, "-", mangle);
const flip = merge_pass_1.op(b, "-", merge_pass_1.op(2, "*", a));
const sign = merge_pass_1.a1("floor", merge_pass_1.op(merge_pass_1.a2("mod", merge_pass_1.op(mangle, "+", 0.1), merge_pass_1.op(b, "*", 2)), "/", b));
const spos = merge_pass_1.translate(merge_pass_1.rotate(tpos, merge_pass_1.op(mangle, "-", merge_pass_1.op(flip, "*", sign))), merge_pass_1.vec2(0.5, 0.5));
super(merge_pass_1.channel(-1, spos));
this.sidesFloat = sidesFloat;
this.scaleFloat = scaleFloat;
this.sides = sides;
this.scale = scale;
}
setSides(sides) {
this.sidesFloat.setVal(merge_pass_1.wrapInValue(sides));
this.sides = merge_pass_1.wrapInValue(sides);
}
setScale(scale) {
this.scaleFloat.setVal(merge_pass_1.wrapInValue(scale));
this.scale = merge_pass_1.wrapInValue(scale);
}
}
exports.Kaleidoscope = Kaleidoscope;
function kaleidoscope(sides = merge_pass_1.mut(8), scale = merge_pass_1.mut(1)) {
return new Kaleidoscope(merge_pass_1.wrapInValue(sides), merge_pass_1.wrapInValue(scale));
}
exports.kaleidoscope = kaleidoscope;
},{"@bandaloo/merge-pass":62}],6:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.lightbands = exports.LightBands = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class LightBands extends merge_pass_1.WrappedExpr {
constructor(speed, intensity, threshold, samplerNum) {
const speedFloat = merge_pass_1.float(speed);
const intensityFloat = merge_pass_1.float(intensity);
const thresholdFloat = merge_pass_1.float(threshold);
const expr = merge_pass_1.brightness(merge_pass_1.ternary(merge_pass_1.op(merge_pass_1.getcomp(merge_pass_1.channel(0), "r"), "-", thresholdFloat), merge_pass_1.op(merge_pass_1.a1("sin", merge_pass_1.op(merge_pass_1.op(merge_pass_1.time(), "*", speedFloat), "+", merge_pass_1.truedepth(merge_pass_1.getcomp(merge_pass_1.channel(samplerNum), "r")))), "*", intensityFloat), 0));
super(expr);
this.speedFloat = speedFloat;
this.intensityFloat = intensityFloat;
this.thresholdFloat = thresholdFloat;
this.speed = speed;
this.intensity = intensity;
this.threshold = threshold;
}
setSpeed(speed) {
this.speedFloat.setVal(merge_pass_1.wrapInValue(speed));
this.speed = merge_pass_1.wrapInValue(speed);
}
setIntensity(intensity) {
this.intensityFloat.setVal(merge_pass_1.wrapInValue(intensity));
this.intensity = merge_pass_1.wrapInValue(intensity);
}
setThreshold(threshold) {
this.thresholdFloat.setVal(merge_pass_1.wrapInValue(threshold));
this.threshold = merge_pass_1.wrapInValue(threshold);
}
}
exports.LightBands = LightBands;
function lightbands(speed = merge_pass_1.mut(4), intensity = merge_pass_1.mut(0.3), threshold = merge_pass_1.mut(0.01), samplerNum = 0) {
return new LightBands(merge_pass_1.wrapInValue(speed), merge_pass_1.wrapInValue(intensity), merge_pass_1.wrapInValue(threshold), samplerNum);
}
exports.lightbands = lightbands;
},{"@bandaloo/merge-pass":62}],7:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.noisedisplacement = exports.NoiseDisplacement = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
const X_OFF = 1234;
const Y_OFF = 5678;
class NoiseDisplacement extends merge_pass_1.WrappedExpr {
constructor(period, speed, intensity) {
const periodFloat = merge_pass_1.float(period);
const speedFloat = merge_pass_1.float(speed);
const intensityFloat = merge_pass_1.float(intensity);
const noise = (comp) => merge_pass_1.simplex(merge_pass_1.op(merge_pass_1.op(merge_pass_1.changecomp(merge_pass_1.op(merge_pass_1.pos(), "/", periodFloat), merge_pass_1.op(merge_pass_1.time(), "*", speedFloat), comp, "+"), "*", merge_pass_1.op(merge_pass_1.resolution(), "/", merge_pass_1.getcomp(merge_pass_1.resolution(), "y"))), "+", comp === "x" ? X_OFF : Y_OFF));
super(merge_pass_1.channel(-1, merge_pass_1.op(merge_pass_1.op(merge_pass_1.op(merge_pass_1.vec2(noise("x"), noise("y")), "*", intensityFloat), "*", merge_pass_1.op(merge_pass_1.get2comp(merge_pass_1.resolution(), "yx"), "/", merge_pass_1.getcomp(merge_pass_1.resolution(), "y"))), "+", merge_pass_1.pos())));
this.periodFloat = periodFloat;
this.speedFloat = speedFloat;
this.intensityFloat = intensityFloat;
this.period = period;
this.speed = speed;
this.intensity = intensity;
}
setPeriod(period) {
this.periodFloat.setVal(merge_pass_1.wrapInValue(period));
this.period = merge_pass_1.wrapInValue(period);
}
setSpeed(speed) {
this.speedFloat.setVal(merge_pass_1.wrapInValue(speed));
this.speed = merge_pass_1.wrapInValue(speed);
}
setIntensity(intensity) {
this.intensityFloat.setVal(merge_pass_1.wrapInValue(intensity));
this.speed = merge_pass_1.wrapInValue(intensity);
}
}
exports.NoiseDisplacement = NoiseDisplacement;
function noisedisplacement(period = merge_pass_1.mut(0.1), speed = merge_pass_1.mut(1), intensity = merge_pass_1.mut(0.005)) {
return new NoiseDisplacement(merge_pass_1.wrapInValue(period), merge_pass_1.wrapInValue(speed), merge_pass_1.wrapInValue(intensity));
}
exports.noisedisplacement = noisedisplacement;
},{"@bandaloo/merge-pass":62}],8:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.oldfilm = exports.OldFilm = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class OldFilm extends merge_pass_1.WrappedExpr {
constructor(speckIntensity, lineIntensity, grainIntensity) {
const speckIntensityFloat = merge_pass_1.float(speckIntensity);
const lineIntensityFloat = merge_pass_1.float(lineIntensity);
const grainIntensityFloat = merge_pass_1.float(grainIntensity);
const ftime = merge_pass_1.a1("floor", merge_pass_1.op(merge_pass_1.time(), "*", 24));
const grainy = merge_pass_1.op(merge_pass_1.random(merge_pass_1.op(merge_pass_1.pixel(), "+", merge_pass_1.a2("mod", merge_pass_1.op(ftime, "*", 99), 3000))), "*", grainIntensityFloat);
const rate = 10;
const triangles = merge_pass_1.op(merge_pass_1.op(merge_pass_1.op(merge_pass_1.a1("abs", merge_pass_1.op(merge_pass_1.op(2, "*", merge_pass_1.a1("fract", merge_pass_1.op(rate, "*", merge_pass_1.getcomp(merge_pass_1.pos(), "x")))), "-", 1)), "-", 0.5), "*", 2), "*", lineIntensityFloat);
const stepping = merge_pass_1.a2("step", merge_pass_1.op(1, "-", merge_pass_1.op(1, "/", rate * 12)), merge_pass_1.a2("mod", merge_pass_1.op(merge_pass_1.getcomp(merge_pass_1.pos(), "x"), "+", merge_pass_1.random(merge_pass_1.op(merge_pass_1.vec2(50, 50), "*", merge_pass_1.time()))), 1));
const lines = merge_pass_1.op(triangles, "*", stepping);
const spos = merge_pass_1.a2("mod", merge_pass_1.op(merge_pass_1.op(merge_pass_1.pos(), "*", merge_pass_1.op(merge_pass_1.resolution(), "/", merge_pass_1.getcomp(merge_pass_1.resolution(), "y"))), "+", ftime), merge_pass_1.vec2(100, 100));
const fsimplex = merge_pass_1.op(merge_pass_1.op(merge_pass_1.simplex(merge_pass_1.op(spos, "*", 7)), "*", 0.44), "+", 0.5);
const spots = merge_pass_1.op(merge_pass_1.a2("step", fsimplex, 0.08), "*", speckIntensityFloat);
super(merge_pass_1.monochrome(merge_pass_1.brightness(spots, merge_pass_1.brightness(lines, merge_pass_1.brightness(grainy)))));
this.speckIntensityFloat = speckIntensityFloat;
this.lineIntensityFloat = lineIntensityFloat;
this.grainIntensityFloat = grainIntensityFloat;
this.speckIntensity = speckIntensity;
this.lineIntensity = lineIntensity;
this.grainIntensity = grainIntensity;
}
setSpeckIntensity(speckIntensity) {
this.speckIntensityFloat.setVal(merge_pass_1.wrapInValue(speckIntensity));
this.speckIntensity = merge_pass_1.wrapInValue(speckIntensity);
}
setLineIntensity(lineIntensity) {
this.lineIntensityFloat.setVal(merge_pass_1.wrapInValue(lineIntensity));
this.lineIntensity = merge_pass_1.wrapInValue(lineIntensity);
}
setGrainIntensity(grainIntensity) {
this.grainIntensityFloat.setVal(merge_pass_1.wrapInValue(grainIntensity));
this.grainIntensity = merge_pass_1.wrapInValue(grainIntensity);
}
}
exports.OldFilm = OldFilm;
function oldfilm(speckIntensity = merge_pass_1.mut(0.4), lineIntensity = merge_pass_1.mut(0.12), grainIntensity = merge_pass_1.mut(0.11)) {
return new OldFilm(merge_pass_1.wrapInValue(speckIntensity), merge_pass_1.wrapInValue(lineIntensity), merge_pass_1.wrapInValue(grainIntensity));
}
exports.oldfilm = oldfilm;
},{"@bandaloo/merge-pass":62}],9:[function(require,module,exports){
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// @ts-nocheck
const postpre = __importStar(require("./index"));
const mergepass = __importStar(require("@bandaloo/merge-pass"));
window.MP = Object.assign({}, postpre, mergepass);
},{"./index":4,"@bandaloo/merge-pass":62}],10:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.vignette = exports.Vignette = void 0;
const merge_pass_1 = require("@bandaloo/merge-pass");
class Vignette extends merge_pass_1.EffectLoop {
constructor(blurScalar, brightnessScalar, brightnessExponent) {
const blurScalarFloat = merge_pass_1.float(blurScalar);
const brightnessScalarFloat = merge_pass_1.float(brightnessScalar);
const brightnessExponentFloat = merge_pass_1.float(brightnessExponent);
const blurLen = merge_pass_1.op(merge_pass_1.len(merge_pass_1.center()), "*", blurScalarFloat);
const blurExpr = merge_pass_1.blur2d(blurLen, blurLen);
const brightLen = merge_pass_1.a2("pow", merge_pass_1.len(merge_pass_1.center()), brightnessExponentFloat);
const brightExpr = merge_pass_1.brightness(merge_pass_1.op(brightLen, "*", merge_pass_1.op(brightnessScalarFloat, "*", -1)));
super([blurExpr, brightExpr], { num: 1 });
this.blurScalarFloat = blurScalarFloat;
this.brightnessScalarFloat = brightnessScalarFloat;
this.brightnessExponentFloat = brightnessExponentFloat;
this.blurScalar = blurScalar;
this.brightnessScalar = brightnessScalar;
this.brightnessExponent = brightnessExponent;
}
setBlurScalar(blurScalar) {
this.blurScalarFloat.setVal(merge_pass_1.wrapInValue(blurScalar));
this.blurScalar = merge_pass_1.wrapInValue(blurScalar);
}
setBrightnessScalar(brightnessScalar) {
this.brightnessScalarFloat.setVal(merge_pass_1.wrapInValue(brightnessScalar));
this.brightnessScalar = merge_pass_1.wrapInValue(brightnessScalar);
}
setBrightnessExponent(brightnessExponent) {
this.brightnessExponentFloat.setVal(merge_pass_1.wrapInValue(brightnessExponent));
this.brightnessExponent = merge_pass_1.wrapInValue(brightnessExponent);
}
}
exports.Vignette = Vignette;
function vignette(blurScalar = merge_pass_1.mut(3), brightnessScalar = merge_pass_1.mut(1.8), brightnessExponent = merge_pass_1.mut(1.8)) {
return new Vignette(merge_pass_1.wrapInValue(blurScalar), merge_pass_1.wrapInValue(brightnessScalar), merge_pass_1.wrapInValue(brightnessExponent));
}
exports.vignette = vignette;
},{"@bandaloo/merge-pass":62}],11:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CodeBuilder = exports.channelSamplerName = void 0;
const expr_1 = require("./exprs/expr");
const webglprogramloop_1 = require("./webglprogramloop");
const settings_1 = require("./settings");
/** @ignore */
const FRAG_SET = ` gl_FragColor = texture2D(uSampler, gl_FragCoord.xy / uResolution);\n`;
/** @ignore */
const SCENE_SET = `uniform sampler2D uSceneSampler;\n`;
/** @ignore */
const TIME_SET = `uniform mediump float uTime;\n`;
/** @ignore */
const MOUSE_SET = `uniform mediump vec2 uMouse;\n`;
/** @ignore */
const COUNT_SET = `uniform int uCount;\n`;
/** @ignore */
const BOILERPLATE = `#ifdef GL_ES
precision mediump float;
#endif
uniform sampler2D uSampler;
uniform mediump vec2 uResolution;\n`;
/**
* returns the string name of the sampler uniform for code generation purposes
* @param num channel number to sample from
*/
function channelSamplerName(num) {
// texture 2 sampler has number 0 (0 and 1 are used for back buffer and scene)
return num === -1 ? "uSampler" : `uBufferSampler${num}`;
}
exports.channelSamplerName = channelSamplerName;
/**
* returns the string of the declaration of the sampler for code generation
* purposes
* @param num channel number to sample from
*/
function channelSamplerDeclaration(num) {
return `uniform sampler2D ${channelSamplerName(num)};`;
}
/** class that manages generation and compilation of GLSL code */
class CodeBuilder {
constructor(effectLoop) {
this.calls = [];
this.externalFuncs = new Set();
this.uniformDeclarations = new Set();
this.counter = 0;
this.baseLoop = effectLoop;
const buildInfo = {
uniformTypes: {},
externalFuncs: new Set(),
exprs: [],
// update me on change to needs
needs: {
centerSample: false,
neighborSample: false,
sceneBuffer: false,
timeUniform: false,
mouseUniform: false,
passCount: false,
extraBuffers: new Set(),
},
};
this.addEffectLoop(effectLoop, 1, buildInfo);
// add all the types to uniform declarations from the `BuildInfo` instance
for (const name in buildInfo.uniformTypes) {
const typeName = buildInfo.uniformTypes[name];
this.uniformDeclarations.add(`uniform mediump ${typeName} ${name};`);
}
// add all external functions from the `BuildInfo` instance
buildInfo.externalFuncs.forEach((func) => this.externalFuncs.add(func));
this.totalNeeds = buildInfo.needs;
this.exprs = buildInfo.exprs;
}
addEffectLoop(effectLoop, indentLevel, buildInfo, topLevel = true) {
const needsLoop = !topLevel && effectLoop.loopInfo.num > 1;
if (needsLoop) {
const iName = "i" + this.counter;
indentLevel++;
const forStart = " ".repeat(indentLevel - 1) +
`for (int ${iName} = 0; ${iName} < ${effectLoop.loopInfo.num}; ${iName}++) {`;
this.calls.push(forStart);
}
for (const e of effectLoop.effects) {
if (e instanceof expr_1.Expr) {
e.parse(buildInfo);
this.calls.push(" ".repeat(indentLevel) + "gl_FragColor = " + e.sourceCode + ";");
this.counter++;
}
else {
this.addEffectLoop(e, indentLevel, buildInfo, false);
}
}
if (needsLoop) {
this.calls.push(" ".repeat(indentLevel - 1) + "}");
}
}
/** generate the code and compile the program into a loop */
compileProgram(gl, vShader, uniformLocs, shaders = []) {
// set up the fragment shader
const fShader = gl.createShader(gl.FRAGMENT_SHADER);
if (fShader === null) {
throw new Error("problem creating fragment shader");
}
const fullCode = BOILERPLATE +
(this.totalNeeds.sceneBuffer ? SCENE_SET : "") +
(this.totalNeeds.timeUniform ? TIME_SET : "") +
(this.totalNeeds.mouseUniform ? MOUSE_SET : "") +
(this.totalNeeds.passCount ? COUNT_SET : "") +
Array.from(this.totalNeeds.extraBuffers)
.map((n) => channelSamplerDeclaration(n))
.join("\n") +
"\n" +
[...this.uniformDeclarations].join("\n") +
"\n" +
[...this.externalFuncs].join("\n") +
"\n" +
"void main() {\n" +
(this.totalNeeds.centerSample ? FRAG_SET : "") +
this.calls.join("\n") +
"\n}";
if (settings_1.settings.verbosity > 0)
console.log(fullCode);
gl.shaderSource(fShader, fullCode);
gl.compileShader(fShader);
// set up the program
const program = gl.createProgram();
if (program === null) {
throw new Error("problem creating program");
}
gl.attachShader(program, vShader);
gl.attachShader(program, fShader);
shaders.push(fShader);
const shaderLog = (name, shader) => {
const output = gl.getShaderInfoLog(shader);
if (output)
console.log(`${name} shader info log\n${output}`);
};
shaderLog("vertex", vShader);
shaderLog("fragment", fShader);
gl.linkProgram(program);
// we need to use the program here so we can get uniform locations
gl.useProgram(program);
// find all uniform locations and add them to the dictionary
for (const expr of this.exprs) {
for (const name in expr.uniformValChangeMap) {
const location = gl.getUniformLocation(program, name);
if (location === null) {
throw new Error("couldn't find uniform " + name);
}
// TODO enforce unique names in the same program
if (uniformLocs[name] === undefined) {
uniformLocs[name] = { locs: [], counter: 0 };
}
// assign the name to the location
uniformLocs[name].locs.push(location);
}
}
// set the uniform resolution (every program has this uniform)
const uResolution = gl.getUniformLocation(program, "uResolution");
gl.uniform2f(uResolution, gl.drawingBufferWidth, gl.drawingBufferHeight);
if (this.totalNeeds.sceneBuffer) {
// TODO allow for texture options for scene texture
const location = gl.getUniformLocation(program, "uSceneSampler");
// put the scene buffer in texture 1 (0 is used for the backbuffer)
gl.uniform1i(location, 1 + settings_1.settings.offset);
}
// set all sampler uniforms
for (const b of this.totalNeeds.extraBuffers) {
const location = gl.getUniformLocation(program, channelSamplerName(b));
// offset the texture location by 2 (0 and 1 are used for scene and original)
gl.uniform1i(location, b + 2 + settings_1.settings.offset);
}
// set the default sampler if there is an offset
if (settings_1.settings.offset !== 0) {
const location = gl.getUniformLocation(program, "uSampler");
gl.uniform1i(location, settings_1.settings.offset);
}
// TODO do we need to do this every time?
// get attribute
const position = gl.getAttribLocation(program, "aPosition");
// enable the attribute
gl.enableVertexAttribArray(position);
// points to the vertices in the last bound array buffer
gl.vertexAttribPointer(position, 2, gl.FLOAT, false, 0, 0);
return new webglprogramloop_1.WebGLProgramLoop(new webglprogramloop_1.WebGLProgramLeaf(program, this.totalNeeds, this.exprs), this.baseLoop.loopInfo, gl);
}
}
exports.CodeBuilder = CodeBuilder;
},{"./exprs/expr":25,"./settings":64,"./webglprogramloop":66}],12:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a1 = exports.Arity1HomogenousExpr = void 0;
const expr_1 = require("./expr");
/** @ignore */
function genArity1SourceList(name, val) {
return {
sections: [name + "(", ")"],
values: [val],
};
}
/** arity 1 homogenous function expression */
class Arity1HomogenousExpr extends expr_1.Operator {
constructor(val, operation) {
super(val, genArity1SourceList(operation, val), ["uVal"]);
this.val = val;
}
/** set the value being passed into the arity 1 homogenous function */
setVal(val) {
this.setUniform("uVal" + this.id, val);
this.val = expr_1.wrapInValue(val);
}
}
exports.Arity1HomogenousExpr = Arity1HomogenousExpr;
/**
* built-in functions that take in one `genType x` and return a `genType x`
* @param name function name (see [[Arity1HomogenousName]] for valid function names)
* @param val the `genType x` argument
*/
function a1(name, val) {
return new Arity1HomogenousExpr(expr_1.wrapInValue(val), name);
}
exports.a1 = a1;
},{"./expr":25}],13:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.a2 = exports.Arity2HomogenousExpr = void 0;
const expr_1 = require("./expr");
// note: glsl has atan(y/x) as well as atan(y, x)
/** @ignore */
function genArity1SourceList(name, val1, val2) {
return {
sections: [name + "(", ",", ")"],
values: [val1, val2],
};
}
/** arity 2 homogenous function expression */
class Arity2HomogenousExpr extends expr_1.Operator {
constructor(name, val1, val2) {
super(val1, genArity1SourceList(name, val1, val2), ["uVal1", "uVal2"]);
this.val1 = val1;
this.val2 = val2;
}
/** set the first value being passed into the arity 2 homogenous function */
setFirstVal(val1) {
this.setUniform("uVal1" + this.id, val1);
this.val1 = expr_1.wrapInValue(val1);
}
/** set the second value being passed into the arity 2 homogenous function */
setSecondVal(val2) {
this.setUniform("uVal2" + this.id, val2);
this.val2 = expr_1.wrapInValue(val2);
}
}
exports.Arity2HomogenousExpr = Arity2HomogenousExpr;
// implementation
/**
* built-in functions that take in two `genType x` arguments and return a `genType x`
* @param name function name (see [[Arity2HomogenousName]] for valid function names)
* @param val1 the first `genType x` argument
* @param val2 the second `genType x` argument
*/
function a2(name, val1, val2) {
return new Arity2HomogenousExpr(name, expr_1.wrapInValue(val1), expr_1.wrapInValue(val2));
}
exports.a2 = a2;
},{"./expr":25}],14:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.bloom = exports.BloomLoop = void 0;
const mergepass_1 = require("../mergepass");
const arity2_1 = require("./arity2");
const blurexpr_1 = require("./blurexpr");
const brightnessexpr_1 = require("./brightnessexpr");
const channelsampleexpr_1 = require("./channelsampleexpr");
const contrastexpr_1 = require("./contrastexpr");
const expr_1 = require("./expr");
const fragcolorexpr_1 = require("./fragcolorexpr");
const opexpr_1 = require("./opexpr");
const vecexprs_1 = require("./vecexprs");
// TODO bloom uses `input` so it has to be the first
// TODO maybe a way to update the scene buffer?
/** bloom loop */
class BloomLoop extends mergepass_1.EffectLoop {
constructor(threshold = expr_1.float(expr_1.mut(0.4)), horizontal = expr_1.float(expr_1.mut(1)), vertical = expr_1.float(expr_1.mut(1)), boost = expr_1.float(expr_1.mut(1.3)), samplerNum = 1, taps = 9, reps = 3) {
const bright = expr_1.cfloat(expr_1.tag `((${channelsampleexpr_1.channel(samplerNum)}.r + ${channelsampleexpr_1.channel(samplerNum)}.g + ${channelsampleexpr_1.channel(samplerNum)}.b) / 3.)`);
const step = arity2_1.a2("step", bright, threshold);
const col = expr_1.cvec4(expr_1.tag `vec4(${channelsampleexpr_1.channel(samplerNum)}.rgb * (1. - ${step}), 1.)`);
const list = [
mergepass_1.loop([col]).target(samplerNum),
mergepass_1.loop([
blurexpr_1.gauss(vecexprs_1.vec2(horizontal, 0), taps),
blurexpr_1.gauss(vecexprs_1.vec2(0, vertical), taps),
brightnessexpr_1.brightness(0.1),
contrastexpr_1.contrast(boost),
], reps).target(samplerNum),
opexpr_1.op(fragcolorexpr_1.fcolor(), "+", channelsampleexpr_1.channel(samplerNum)),
];
super(list, { num: 1 });
this.threshold = threshold;
this.horizontal = horizontal;
this.vertical = vertical;
this.boost = boost;
}
/**
* set the horizontal stretch of the blur effect (no greater than 1 for best
* effect)
*/
setHorizontal(num) {
if (!(this.horizontal instanceof expr_1.BasicFloat))
throw new Error("horizontal expression not basic float");
this.horizontal.setVal(num);
}
/**
* set the vertical stretch of the blur effect (no greater than 1 for best
* effect)
*/
setVertical(num) {
if (!(this.vertical instanceof expr_1.BasicFloat))
throw new Error("vertical expression not basic float");
this.vertical.setVal(num);
}
/** set the treshold */
setThreshold(num) {
if (!(this.threshold instanceof expr_1.BasicFloat))
throw new Error("threshold expression not basic float");
this.threshold.setVal(num);
}
/** set the contrast boost */
setBoost(num) {
if (!(this.boost instanceof expr_1.BasicFloat))
throw new Error("boost expression not basic float");
this.boost.setVal(num);
}
}
exports.BloomLoop = BloomLoop;
/**
* creates a bloom loop
* @param threshold values below this brightness don't get blurred (0.4 is
* about reasonable, which is also the default)
* @param horizontal how much to blur vertically (defaults to 1 pixel)
* @param vertical how much to blur horizontally (defaults to 1 pixel)
* @param taps how many taps for the blur (defaults to 9)
* @param reps how many times to loop the blur (defaults to 3)
*/
function bloom(threshold, horizontal, vertical, boost, samplerNum, taps, reps) {
return new BloomLoop(expr_1.wrapInValue(threshold), expr_1.wrapInValue(horizontal), expr_1.wrapInValue(vertical), expr_1.wrapInValue(boost), samplerNum, taps, reps);
}
exports.bloom = bloom;
},{"../mergepass":63,"./arity2":13,"./blurexpr":16,"./brightnessexpr":17,"./channelsampleexpr":19,"./contrastexpr":20,"./expr":25,"./fragcolorexpr":26,"./opexpr":43,"./vecexprs":59}],15:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.blur2d = exports.Blur2dLoop = void 0;
const mergepass_1 = require("../mergepass");
const blurexpr_1 = require("./blurexpr");
const expr_1 = require("./expr");
const vecexprs_1 = require("./vecexprs");
/** 2D blur loop */
class Blur2dLoop extends mergepass_1.EffectLoop {
constructor(horizontal = expr_1.float(expr_1.mut(1)), vertical = expr_1.float(expr_1.mut(1)), reps = 2, taps, samplerNum) {
const side = blurexpr_1.gauss(vecexprs_1.vec2(horizontal, 0), taps, samplerNum);
const up = blurexpr_1.gauss(vecexprs_1.vec2(0, vertical), taps, samplerNum);
super([side, up], { num: reps });
this.horizontal = horizontal;
this.vertical = vertical;
}
/**
* set the horizontal stretch of the blur effect (no greater than 1 for best
* effect)
*/
setHorizontal(num) {
if (!(this.horizontal instanceof expr_1.BasicFloat))
throw new Error("horizontal expression not basic float");
this.horizontal.setVal(num);
}
/**
* set the vertical stretch of the blur effect (no greater than 1 for best
* effect)
*/
setVertical(num) {
if (!(this.vertical instanceof expr_1.BasicFloat))
throw new Error("vertical expression not basic float");
this.vertical.setVal(num);
}
}
exports.Blur2dLoop = Blur2dLoop;
/**
* creates a loop that runs a horizontal, then vertical gaussian blur (anything
* more than 1 pixel in the horizontal or vertical direction will create a
* ghosting effect, which is usually not desirable)
* @param horizontalExpr float for the horizontal blur (1 pixel default)
* @param verticalExpr float for the vertical blur (1 pixel default)
* @param reps how many passes (defaults to 2)
* @param taps how many taps (defaults to 5)
* @param samplerNum change if you want to sample from a different channel and
* the outer loop has a different target
*/
function blur2d(horizontalExpr, verticalExpr, reps, taps, samplerNum) {
return new Blur2dLoop(expr_1.wrapInValue(horizontalExpr), expr_1.wrapInValue(verticalExpr), reps, taps, samplerNum);
}
exports.blur2d = blur2d;
},{"../mergepass":63,"./blurexpr":16,"./expr":25,"./vecexprs":59}],16:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.gauss = exports.BlurExpr = void 0;
const glslfunctions_1 = require("../glslfunctions");
const expr_1 = require("./expr");
/** @ignore */
function genBlurSource(direction, taps) {
return {
sections: [`gauss${taps}(`, ")"],
values: [direction],
};
}
/** @ignore */
function tapsToFuncSource(taps) {
switch (taps) {
case 5:
return glslfunctions_1.glslFuncs.gauss5;
case 9:
return glslfunctions_1.glslFuncs.gauss9;
case 13:
return glslfunctions_1.glslFuncs.gauss13;
}
}
/** gaussian blur expression */
class BlurExpr extends expr_1.ExprVec4 {
constructor(direction, taps = 5, samplerNum) {
// this is already guaranteed by typescript, but creates helpful error for
// use in gibber or anyone just using javascript
if (![5, 9, 13].includes(taps)) {
throw new Error("taps for gauss blur can only be 5, 9 or 13");
}
super(genBlurSource(direction, taps), ["uDirection"]);
this.direction = direction;
this.externalFuncs = [tapsToFuncSource(taps)];
this.brandExprWithChannel(0, samplerNum);
}
/** set the blur direction (keep magnitude no greater than 1 for best effect) */
setDirection(direction) {
this.setUniform("uDirection" + this.id, direction);
this.direction = direction;
}
}
exports.BlurExpr = BlurExpr;
/**
* creates expression that performs one pass of a gaussian blur
* @param direction direction to blur (keep magnitude less than or equal to 1
* for best effect)
* @param taps number of taps (defaults to 5)
* @param samplerNum which channel to sample from (default 0)
*/
function gauss(direction, taps = 5, samplerNum) {
return new BlurExpr(direction, taps, samplerNum);
}
exports.gauss = gauss;
},{"../glslfunctions":61,"./expr":25}],17:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.brightness = exports.Brightness = void 0;
const glslfunctions_1 = require("../glslfunctions");
const expr_1 = require("./expr");
const fragcolorexpr_1 = require("./fragcolorexpr");
/** brightness expression */
class Brightness extends expr_1.ExprVec4 {
constructor(brightness, col = fragcolorexpr_1.fcolor()) {
super(expr_1.tag `brightness(${brightness}, ${col})`, ["uBrightness", "uColor"]);
this.brightness = brightness;
this.externalFuncs = [glslfunctions_1.glslFuncs.brightness];
}
/** set the brightness (should probably be between -1 and 1) */
setBrightness(brightness) {
this.setUniform("uBrightness" + this.id, brightness);
this.brightness = expr_1.wrapInValue(brightness);
}
}
exports.Brightness = Brightness;
/**
* changes the brightness of a color
* @param val float for how much to change the brightness by (should probably be
* between -1 and 1)
* @param col the color to increase the brightness of (defaults to current
* fragment color)
*/
function brightness(val, col) {
return new Brightness(expr_1.wrapInValue(val), col);
}
exports.brightness = brightness;
},{"../glslfunctions":61,"./expr":25,"./fragcolorexpr":26}],18:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.changecomp = exports.ChangeCompExpr = void 0;
const expr_1 = require("./expr");
const getcompexpr_1 = require("./getcompexpr");
/** @ignore */
function getChangeFunc(typ, id, setter, comps, op = "") {
return `${typ} changecomp_${id}(${typ} col, ${setter.typeString()} setter) {
col.${comps} ${op}= setter;
return col;
}`;
}
/**
* throws a runtime error if component access is not valid, and disallows
* duplicate components because duplicate components can not be in a left
* expression. (for example `v.xyx = vec3(1., 2., 3.)` is illegal, but `v1.xyz
* = v2.xyx` is legal.) also checks for type errors such as `v1.xy = vec3(1.,
* 2., 3.)`; the right hand side can only be a `vec2` if only two components
* are supplied
* @param comps component string
* @param setter how the components are being changed
* @param vec the vector where components are being accessed
*/
function checkChangeComponents(comps, setter, vec) {
// setter has different length than components
if (comps.length !== getcompexpr_1.typeStringToLength(setter.typeString())) {
throw new Error("components length must be equal to the target float/vec");
}
// duplicate components
if (duplicateComponents(comps)) {
throw new Error("duplicate components not allowed on left side");
}
// legal components
getcompexpr_1.checkLegalComponents(comps, vec);
}
/** @ignore */
function duplicateComponents(comps) {
return new Set(comps.split("")).size !== comps.length;
}
/** change component expression */
class ChangeCompExpr extends expr_1.Operator {
constructor(vec, setter, comps, op) {
checkChangeComponents(comps, setter, vec);
// part of name of custom function
const operation = op === "+"
? "plus"
: op === "-"
? "minus"
: op === "*"
? "mult"
: op === "/"
? "div"
: "assign";
const suffix = `${vec.typeString()}_${setter.typeString()}_${comps}_${operation}`;
super(vec, { sections: [`changecomp_${suffix}(`, ", ", ")"], values: [vec, setter] }, ["uOriginal", "uNew"]);
this.originalVec = vec;
this.newVal = setter;
this.externalFuncs = [
getChangeFunc(vec.typeString(), suffix, setter, comps, op),
];
}
/** set the original vector */
setOriginal(originalVec) {
this.setUniform("uOriginal" + this.id, originalVec);
this.originalVec = originalVec;
}
/** set the neww vector */
setNew(newVal) {
this.setUniform("uNew" + this.id, newVal);
this.newVal = expr_1.wrapInValue(newVal);
}
}
exports.ChangeCompExpr = ChangeCompExpr;
/**
* change the components of a vector
* @param vec the vector to augment components of
* @param setter the vector (or float, if only one component is changed) for
* how to change the components
* @param comps string representing the components to change (e.g. `"xy"` or
* `"r"` or `"stpq"`.)
* @param op optionally perform an operation on the original component
* (defaults to no operation, just assigning that component to a new value)
*/
function changecomp(vec, setter, comps, op) {
return new ChangeCompExpr(vec, expr_1.wrapInValue(setter), comps, op);
}
exports.changecomp = changecomp;
},{"./expr":25,"./getcompexpr":30}],19:[function(require,module,exports){
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.channel = exports.ChannelSampleExpr = void 0;
const codebuilder_1 = require("../codebuilder");
const expr_1 = require("./expr");
const normfragcoordexpr_1 = require("./normfragcoordexpr");
const glslfunctions_1 = require("../glslfunctions");
/** @ignore */
function genChannelSampleSource(buf, coord) {
return {
sections: ["channel(", `, ${codebuilder_1.channelSamplerName(buf)})`],
values: [coord],
};
}
// TODO create a way to sample but not clamp by region
/** channel sample expression */
class ChannelSampleExpr extends expr_1.ExprVec4 {
constructor(buf, coord = normfragcoordexpr_1.pos()) {
super(genChannelSampleSource(buf, coord), ["uVec"]);
this.coord = coord;
this.externalFuncs = [glslfunctions_1.glslFuncs.channel];
if (buf !== -1)
this.needs.extraBuffers = new Set([buf]);
else
this.needs.neighborSample = true;