-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path@Path_S.anm2
More file actions
857 lines (789 loc) · 27.9 KB
/
@Path_S.anm2
File metadata and controls
857 lines (789 loc) · 27.9 KB
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
--[[
MIT License
Copyright (c) 2025-2026 sigma-axis
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
https://mit-license.org/
]]
@パスマスクσ
--information:パスマスクσ@Path_S v1.20 (for beta43) by σ軸
--label:Path_S\クリッピング
--filter
--require:2004001
--track@intensity:強さ,0,100,100,0.01
--check@invert:反転,false
--group:パス設定,true
--value@num_points:頂点数,4
--select@path_type:線タイプ=3,折れ線=0,補間移動=1,2次ベジェ曲線=2,3次ベジェ曲線=3
--value@points:点リスト,{0,-100,55.23,-100,100,-55.23,100,0,100,55.23,55.23,100,0,100,-55.23,100,-100,55.23,-100,0,-100,-55.23,-55.23,-100}
--track@precision:曲線精度,1,128,8,1,,0.25
--group:塗り設定,false
--track@inflation:追加幅,0,1000,0,0.01,,0.2
--select@mode_fill:範囲=0,内側=0,奇偶=1,内側反転=2,奇偶反転=3
--group:配置,false
--track@X:移動X,-4000,4000,0,0.01,,0.25
--track@Y:移動Y,-4000,4000,0,0.01,,0.25
--trackgroup@X,Y:Position
--track@zoom:拡大率,0,5000,100,0.001,,0.16
--track@rotate:回転,-3600,3600,0,0.01,,0.1
--check@toggle_gui:アンカー切り替え,false
--group:その他,false
--track@antialias:ぼかし幅,0,1000,1,0.01,,0.2
--value@PI:PI,{}
--[[pixelshader@const_alpha:
cbuffer constant0 : register(b0) {
float alpha;
};
float4 const_alpha(float4 pos : SV_Position) : SV_Target
{
return float4(0, 0, 0, alpha);
}
]]
--[[pixelshader@carve:
Texture2D<half4> coords : register(t0);
cbuffer constant0 : register(b0) {
float2 alpha_map;
float N_f, mode_fill_f,
padding, aa_thick;
};
float decode_float(half3 c)
{
const uint3 c_i = floor(255 * c + 0.5);
const int i = (c_i.r << 8) | (c_i.g << 16) | (c_i.b << 24);
return i / float(1 << 16);
}
float2 get_point(uint i)
{
static const uint log2_span_x = 12, span_x = 1 << log2_span_x;
const uint x = (i << 1) & (span_x - 1), y = i >> (log2_span_x - 1);
return float2(
decode_float(coords.Load(int3(x | 0, y, 0)).rgb),
decode_float(coords.Load(int3(x | 1, y, 0)).rgb));
}
uint quadrant(float2 v)
{
return (v.x >= 0 ? 0 : 1) ^ (v.y >= 0 ? 0 : 3);
}
bool is_inner(int cycles)
{
static const uint mode_fill = uint(mode_fill_f);
switch(mode_fill) {
case 0: default: return cycles != 0;
case 1: return (cycles & 1) != 0;
case 2: return cycles == 0;
case 3: return (cycles & 1) == 0;
}
}
float4 carve(float4 pos : SV_Position) : SV_Target
{
int cycles = 0;
float sq_dist = (aa_thick + padding + 1) * (aa_thick + padding + 1);
static const uint N = uint(N_f);
float2 pt0 = get_point(0) - pos.xy;
uint q0 = quadrant(pt0);
for (uint i = 1; i < N; i++) {
const float2 pt1 = get_point(i) - pos.xy,
d = pt1 - pt0;
const float side = d.y * pt1.x - d.x * pt1.y;
const uint q1 = quadrant(pt1);
if (side < 0) { if (q1 > q0) cycles--; }
else { if (q1 < q0) cycles++; }
sq_dist = min(sq_dist,
dot(d, pt0) >= 0 || dot(d, pt1) <= 0 ?
dot(pt0, pt0) : side * side / dot(d, d));
pt0 = pt1; q0 = q1;
}
const float a = 1 - smoothstep(0, aa_thick, is_inner(cycles) ? 0 : sqrt(sq_dist) - padding);
return float4(0, 0, 0, dot(alpha_map, float2(a, 1)));
}
]]
local path_s = require "Path_S";
local obj, math, tonumber, type = obj, math, tonumber, type;
-- see if the points are already buffered.
local pt_buff = type(PI.pt_buff) == "string" and PI.pt_buff or nil;
if pt_buff and pt_buff ~= "tempbuffer" and not pt_buff:match("^cache:.+$") then pt_buff = nil end
-- set anchors.
if obj.getoption("gui") and not pt_buff then
if toggle_gui then obj.setanchor("X,Y", 0, "line") else
num_points = math.max(math.floor(0.5 + (tonumber(num_points) or 4)), 3);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
local _, pts = path_s.anchor("points", path_type, points, num_points, true);
points = pts;
end
end
-- take parameters.
--[==[
PI = {
intensity: number?,
num_points: number?,
path_type: string?,
points: table?,
precision: number?,
antialias: number?,
inflation: number?,
mode_fill: string?,
invert: boolean|number|nil,
X: number?,
Y: number?,
zoom: number?,
rotate: number?,
pt_buff: string?,
}
]==]
local function as_bool(t, v)
if type(t) == "boolean" then return t;
elseif type(t) == "number" then return t ~= 0;
else return v end
end
intensity = tonumber(PI.intensity) or intensity;
num_points = tonumber(PI.num_points) or num_points;
if type(PI.path_type) == "string" then
local name2num = {
["折れ線"] = 0, ["補間移動"] = 1, ["2次ベジェ曲線"] = 2, ["3次ベジェ曲線"] = 3,
};
path_type = name2num[PI.path_type] or path_type;
end
if type(PI.points) == "table" then points = PI.points end
precision = tonumber(PI.precision) or precision;
antialias = tonumber(PI.antialias) or antialias;
inflation = tonumber(PI.inflation) or inflation;
if type(PI.mode_fill) == "string" then
local name2num = {
["内側"] = 0, ["奇偶"] = 1, ["内側反転"] = 2, ["奇偶反転"] = 3,
};
mode_fill = name2num[PI.mode_fill] or mode_fill;
end
invert = as_bool(PI.invert, invert);
X = tonumber(PI.X) or X;
Y = tonumber(PI.Y) or Y;
zoom = tonumber(PI.zoom) or zoom;
rotate = tonumber(PI.rotate) or rotate;
-- normalize parameters.
intensity = math.min(math.max(intensity / 100, 0), 1);
num_points = math.max(math.floor(0.5 + num_points), 3);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
precision = math.max(precision, 1);
antialias = math.max(antialias, 1 / 1024);
inflation = math.max(inflation, 0);
mode_fill = math.min(math.max(math.floor(0.5 + mode_fill), 0), 3);
zoom = math.min(math.max(zoom / 100, 0), 50);
rotate = math.pi / 180 * (rotate % 360);
if intensity <= 0 then return end
-- further calculations.
local alpha_outer, alpha_inner = 1 - intensity, 1;
if invert then alpha_outer, alpha_inner = alpha_inner, alpha_outer end
if pt_buff then
path_s.path_mask_area_buffered(
alpha_outer, alpha_inner, mode_fill,
inflation, antialias,
pt_buff, num_points);
else
path_s.path_mask_area(
alpha_outer, alpha_inner, mode_fill,
inflation, antialias,
path_type, points, num_points, precision,
zoom, rotate, X, Y);
end
@パスマスク(ライン)σ
--information:パスマスク(ライン)σ@Path_S v1.20 (for beta43) by σ軸
--label:Path_S\クリッピング
--filter
--require:2004001
--track@intensity:強さ,0,100,100,0.01
--check@invert:反転,false
--track@line:ライン幅,0,1000,5,0.01,,0.2
--group:パス設定,true
--value@num_points:頂点数,4
--select@path_type:線タイプ=3,折れ線=0,補間移動=1,2次ベジェ曲線=2,3次ベジェ曲線=3
--value@points:点リスト,{-100.00,50.00,-75.00,0.00,-50.00,-50.00,-25.00,-50.00,0.00,-50.00,0.00,50.00,25.00,50.00,50.00,50.00,75.00,0.00,100.00,-50.00}
--check@loop:ループ,false
--track@precision:曲線精度,1,128,8,1,,0.25
--group:ライン設定,false
--track@start_pos:開始位置,-400,400,0,0.001,,0.25
--track@end_pos:終了位置,-400,400,100,0.001,,0.25
--select@end_shape:端の形状=0,円=0,四角=1
--value@dash_pat:破線パターン,{100,0}
--check@dash_adj:破線周期補正,true
--track@dash_pos:破線位置,-4000,4000,0,0.01,,0.25
--group:配置,false
--track@X:移動X,-4000,4000,0,0.01,,0.25
--track@Y:移動Y,-4000,4000,0,0.01,,0.25
--trackgroup@X,Y:Position
--track@zoom:拡大率,0,5000,100,0.001,,0.16
--track@rotate:回転,-3600,3600,0,0.01,,0.1
--check@toggle_gui:アンカー切り替え,false
--group:その他,false
--track@antialias:ぼかし幅,0,1000,1,0.01,,0.2
--value@PI:PI,{}
--[[pixelshader@carve:
Texture2D<half4> coords : register(t0);
cbuffer constant0 : register(b0) {
float2 alpha_map;
float N_f, padding, aa_thick;
float4 end_points[2];
};
float decode_float(half3 c)
{
const uint3 c_i = floor(255 * c + 0.5);
const int i = (c_i.r << 8) | (c_i.g << 16) | (c_i.b << 24);
return i / float(1 << 16);
}
float2 get_point(uint i)
{
static const uint log2_span_x = 12, span_x = 1 << log2_span_x;
const uint x = (i << 1) & (span_x - 1), y = i >> (log2_span_x - 1);
return float2(
decode_float(coords.Load(int3(x | 0, y, 0)).rgb),
decode_float(coords.Load(int3(x | 1, y, 0)).rgb));
}
float4 carve(float4 pos : SV_Position) : SV_Target
{
float sq_dist = (aa_thick + padding + 1) * (aa_thick + padding + 1);
static const uint N = uint(N_f);
float2 pt0 = get_point(0) - pos.xy;
for (uint i = 1; i < N; i++) {
const float2 pt1 = get_point(i) - pos.xy,
d = pt1 - pt0;
const float L = dot(d, d), l = sqrt(L),
side = d.y * pt1.x - d.x * pt1.y;
sq_dist = min(sq_dist,
dot(d, pt0) >= 0 ? dot(pt0, pt0) :
dot(d, pt1) <= 0 ? dot(pt1, pt1) :
side * side / L);
pt0 = pt1;
}
float end_dist = sqrt(sq_dist);
for (i = 0; i < 2; i++) {
const float2 pt = end_points[i].xy - pos.xy,
d = end_points[i].zw, nd = float2(-d.y, d.x);
end_dist = min(end_dist, max(abs(dot(d, pt) - padding / 2) + padding / 2, abs(dot(nd, pt))));
}
const float a = 1 - smoothstep(0, aa_thick, end_dist - padding);
return float4(0, 0, 0, dot(alpha_map, float2(a, 1)));
}
]]
--[[pixelshader@carve_dash:
Texture2D<half4> coords : register(t0);
cbuffer constant0 : register(b0) {
float2 alpha_map;
float N_f, padding, aa_thick,
M_f, len_period0, idx_period0;
float4 end_points[2];
float4 phase_whole;
float4 phase_period[64];
};
float decode_float(half3 c)
{
const uint3 c_i = floor(255 * c + 0.5);
const int i = (c_i.r << 8) | (c_i.g << 16) | (c_i.b << 24);
return i / float(1 << 16);
}
float2 get_point(uint i)
{
static const uint log2_span_x = 12, span_x = 1 << log2_span_x;
const uint x = (i << 1) & (span_x - 1), y = i >> (log2_span_x - 1);
return float2(
decode_float(coords.Load(int3(x | 0, y, 0)).rgb),
decode_float(coords.Load(int3(x | 1, y, 0)).rgb));
}
float4 carve_dash(float4 pos : SV_Position) : SV_Target
{
float sq_dist = (aa_thick + padding + 1) * (aa_thick + padding + 1),
len_whole = phase_whole[0], len_period = len_period0;
uint idx_whole = 0, idx_period = idx_period0;
static const uint N = uint(N_f), M = uint(M_f);
float2 pt0 = get_point(0) - pos.xy;
for (uint i = 1; i < N; i++) {
const float2 pt1 = get_point(i) - pos.xy,
d = pt1 - pt0;
const float L = dot(d, d), l = sqrt(L),
side = d.y * pt1.x - d.x * pt1.y,
L_side = side * side / L;
for (float rest = l; rest > 0 && idx_whole < 4; ) {
if (len_whole <= 0) len_whole += phase_whole[(++idx_whole) & 3];
if (len_period <= 0) {
++idx_period;
idx_period %= M;
len_period += phase_period[idx_period >> 2][idx_period & 3];
}
const float consume = min(rest, min(len_whole, len_period));
rest -= consume; len_whole -= consume; len_period -= consume;
const float2 ptm = pt1 - (rest / l) * d;
if ((idx_whole & idx_period & 1) != 0) {
sq_dist = min(sq_dist,
dot(d, pt0) >= 0 ? dot(pt0, pt0) :
dot(d, ptm) <= 0 ? dot(ptm, ptm) :
L_side);
}
pt0 = ptm;
}
}
float end_dist = sqrt(sq_dist);
for (i = 0; i < 2; i++) {
const float2 pt = end_points[i].xy - pos.xy,
d = end_points[i].zw, nd = float2(-d.y, d.x);
end_dist = min(end_dist, max(abs(dot(d, pt) - padding / 2) + padding / 2, abs(dot(nd, pt))));
}
const float a = 1 - smoothstep(0, aa_thick, end_dist - padding);
return float4(0, 0, 0, dot(alpha_map, float2(a, 1)));
}
]]
local path_s = require "Path_S";
local obj, math, tonumber, type = obj, math, tonumber, type;
-- see if the points are already buffered.
local pt_buff, len_buff, endpt_buff =
type(PI.pt_buff) == "string" and PI.pt_buff or nil,
tonumber(PI.len_buff),
type(PI.endpt_buff) == "table" and PI.endpt_buff or nil;
if (pt_buff and pt_buff ~= "tempbuffer" and not pt_buff:match("^cache:.+$")) or not (len_buff and len_buff > 0) then pt_buff = nil end
-- set anchors.
if obj.getoption("gui") and not pt_buff then
if toggle_gui then obj.setanchor("X,Y", 0, "line") else
num_points = math.max(math.floor(0.5 + (tonumber(num_points) or 4)), 2);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
local _, pts = path_s.anchor("points", path_type, points, num_points - (loop and 0 or 1), loop);
points = pts;
end
end
-- take parameters.
--[==[
PI = {
line: number?,
intensity: number?,
num_points: number?,
path_type: string?,
points: table?,
precision: number?,
antialias: number?,
loop: boolean|number|nil,
start_pos: number?,
end_pos: number?,
end_shape: string?,
dash_pat: table?,
dash_adj: boolean|number|nil,
dash_pos: number?,
invert: boolean|number|nil,
X: number?,
Y: number?,
zoom: number?,
rotate: number?,
pt_buff: string?,
len_buff: number?,
endpt_buff: table?,
}
]==]
local function as_bool(t, v)
if type(t) == "boolean" then return t;
elseif type(t) == "number" then return t ~= 0;
else return v end
end
line = tonumber(PI.line) or line;
intensity = tonumber(PI.intensity) or intensity;
num_points = tonumber(PI.num_points) or num_points;
if type(PI.path_type) == "string" then
local name2num = {
["折れ線"] = 0, ["補間移動"] = 1, ["2次ベジェ曲線"] = 2, ["3次ベジェ曲線"] = 3,
};
path_type = name2num[PI.path_type] or path_type;
end
if type(PI.points) == "table" then points = PI.points end
precision = tonumber(PI.precision) or precision;
antialias = tonumber(PI.antialias) or antialias;
loop = as_bool(PI.loop, loop);
start_pos = tonumber(PI.start_pos) or start_pos;
end_pos = tonumber(PI.end_pos) or end_pos;
if type(PI.end_shape) == "string" then
local name2num = {
["円"] = 0, ["四角"] = 1,
};
end_shape = name2num[PI.end_shape] or end_shape;
end
if type(PI.dash_pat) == "table" then dash_pat = PI.dash_pat end
dash_adj = as_bool(PI.dash_adj, dash_adj);
dash_pos = tonumber(PI.dash_pos) or dash_pos;
invert = as_bool(PI.invert, invert);
X = tonumber(PI.X) or X;
Y = tonumber(PI.Y) or Y;
zoom = tonumber(PI.zoom) or zoom;
rotate = tonumber(PI.rotate) or rotate;
-- normalize parameters.
line = math.max(line, 0);
intensity = math.min(math.max(intensity / 100, 0), 1);
num_points = math.max(math.floor(0.5 + num_points), 2);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
precision = math.max(precision, 1);
antialias = math.max(antialias, 1 / 1024);
start_pos = start_pos / 100;
end_pos = end_pos / 100;
end_shape = math.min(math.max(math.floor(0.5 + end_shape), 0), 1);
zoom = math.min(math.max(zoom / 100, 0), 50);
rotate = math.pi / 180 * (rotate % 360);
if intensity <= 0 then return end
local alpha_outer, alpha_inner = 1 - intensity, 1;
if invert then alpha_outer, alpha_inner = alpha_inner, alpha_outer end
if pt_buff then
path_s.path_mask_line_buffered(
alpha_outer, alpha_inner, line, antialias,
pt_buff, num_points, len_buff, loop,
start_pos, end_pos, end_shape, endpt_buff,
dash_pat, dash_pos, dash_adj);
else
path_s.path_mask_line(
alpha_outer, alpha_inner, line, antialias,
path_type, points, num_points - (loop and 0 or 1), loop, precision,
start_pos, end_pos, end_shape,
dash_pat, dash_pos, dash_adj,
zoom, rotate, X, Y);
end
@パス部分フィルタσ
--information:パス部分フィルタσ@Path_S v1.20 (for beta43) by σ軸
--label:Path_S\加工
--require:2004001
--check@invert:反転,false
--group:パス設定,true
--value@num_points:頂点数,4
--select@path_type:線タイプ=3,折れ線=0,補間移動=1,2次ベジェ曲線=2,3次ベジェ曲線=3
--value@points:点リスト,{0,-100,55.23,-100,100,-55.23,100,0,100,55.23,55.23,100,0,100,-55.23,100,-100,55.23,-100,0,-100,-55.23,-55.23,-100}
--track@precision:曲線精度,1,128,8,1,,0.25
--group:塗り設定,false
--track@inflation:追加幅,0,1000,0,0.01,,0.2
--select@mode_fill:範囲=0,内側=0,奇偶=1,内側反転=2,奇偶反転=3
--group:配置,false
--track@X:移動X,-4000,4000,0,0.01,,0.25
--track@Y:移動Y,-4000,4000,0,0.01,,0.25
--trackgroup@X,Y:Position
--track@zoom:拡大率,0,5000,100,0.001,,0.16
--track@rotate:回転,-3600,3600,0,0.01,,0.1
--check@toggle_gui:アンカー切り替え,false
--group:フィルタ設定,false
--select@extra_filter:追加のフィルタ効果=0,後続フィルタ=0,スクリプト実行=1
--text@extra_script:追加スクリプト,obj.effect("グラデーション",\n "形状","凸形",\n "角度",30,\n "開始色",0x00ff00) -- グラデーション適用\nobj.cx=obj.cx+100 -- 位置もずらせる\n
--group:その他,false
--track@antialias:ぼかし幅,0,1000,1,0.01,,0.2
--value@PI:PI,{}
--[[pixelshader@interpolate:
Texture2D ori : register(t0);
Texture2D eff : register(t1);
Texture2D rate : register(t2);
cbuffer constant0 : register(b0) {
float2 ofs_ori, ofs_eff;
};
float4 interpolate(float4 pos : SV_Position) : SV_Target
{
return lerp(
ori.Load(int3(pos.xy + ofs_ori, 0)),
eff.Load(int3(pos.xy + ofs_eff, 0)),
rate.Load(int3(pos.xy, 0)).a);
}
]]
local path_s = require "Path_S";
local obj, math, tonumber, type, tostring = obj, math, tonumber, type, tostring;
-- set anchors.
if obj.getoption("gui") then
if toggle_gui then obj.setanchor("X,Y", 0, "line") else
num_points = math.max(math.floor(0.5 + (tonumber(num_points) or 4)), 3);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
local _, pts = path_s.anchor("points", path_type, points, num_points, true);
points = pts;
end
end
-- take parameters.
--[==[
PI = {
num_points: number?,
path_type: string?,
points: table?,
precision: number?,
antialias: number?,
inflation: number?,
mode_fill: string?,
invert: boolean|number|nil,
X: number?,
Y: number?,
zoom: number?,
rotate: number?,
extra_filter: string?,
}
]==]
local function as_bool(t, v)
if type(t) == "boolean" then return t;
elseif type(t) == "number" then return t ~= 0;
else return v end
end
num_points = tonumber(PI.num_points) or num_points;
if type(PI.path_type) == "string" then
local name2num = {
["折れ線"] = 0, ["補間移動"] = 1, ["2次ベジェ曲線"] = 2, ["3次ベジェ曲線"] = 3,
};
path_type = name2num[PI.path_type] or path_type;
end
if type(PI.points) == "table" then points = PI.points end
precision = tonumber(PI.precision) or precision;
antialias = tonumber(PI.antialias) or antialias;
inflation = tonumber(PI.inflation) or inflation;
if type(PI.mode_fill) == "string" then
local name2num = {
["内側"] = 0, ["奇偶"] = 1, ["内側反転"] = 2, ["奇偶反転"] = 3,
};
mode_fill = name2num[PI.mode_fill] or mode_fill;
end
invert = as_bool(PI.invert, invert);
X = tonumber(PI.X) or X;
Y = tonumber(PI.Y) or Y;
zoom = tonumber(PI.zoom) or zoom;
rotate = tonumber(PI.rotate) or rotate;
if type(PI.extra_filter) == "string" then
local name2num = {
["後続フィルタ"] = 0, ["スクリプト実行"] = 1,
};
extra_filter = name2num[PI.extra_filter] or extra_filter;
end
-- normalize parameters.
num_points = math.max(math.floor(0.5 + num_points), 3);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
precision = math.max(precision, 1);
antialias = math.max(antialias, 1 / 1024);
inflation = math.max(inflation, 0);
mode_fill = math.min(math.max(math.floor(0.5 + mode_fill), 0), 3);
zoom = math.min(math.max(zoom / 100, 0), 50);
rotate = math.pi / 180 * (rotate % 360);
extra_filter = math.min(math.max(math.floor(0.5 + extra_filter), 0), 1);
if extra_filter == 1 and extra_script:match("^%s*(.-)%s*$") == "" then return end
-- backup the current image.
local cache_name_ori, cache_name_eff = "cache:path_s/part/ori#"..obj.effect_id, "cache:path_s/part/eff";
obj.copybuffer(cache_name_ori, "object");
-- apply following filters.
local w0, h0, cx0, cy0 = obj.w, obj.h, obj.cx, obj.cy;
if extra_filter == 0 then obj.effect();
else
local f, c, e;
f, e = loadstring(extra_script);
if f then c, e = pcall(f) end
if not (f and c) then
path_s.print_script_error(tostring(e), extra_script);
obj.setoption("draw_state", true);
return;
end
end
if obj.w <= 0 or obj.h <= 0 then return end -- subsequent filter already drew.
obj.copybuffer(cache_name_eff, "object");
-- adjust the size and center.
local w1, h1, cx1, cy1 = obj.w, obj.h, obj.cx, obj.cy;
local w, h, cx, cy do
local L, R, T, B =
math.min(-w0 / 2 - cx0, -w1 / 2 - cx1),
math.max(w0 / 2 - cx0, w1 / 2 - cx1),
math.min(-h0 / 2 - cy0, -h1 / 2 - cy1),
math.max(h0 / 2 - cy0, h1 / 2 - cy1);
w, h = math.ceil(R - L), math.ceil(B - T);
cx, cy = -(2 * L + w) / 2, -(2 * T + h) / 2;
end
-- create the shape of the path.
obj.clearbuffer("tempbuffer", w, h, 0x000000);
obj.cx, obj.cy = cx, cy;
path_s.path_mask_area(
invert and 1 or 0, invert and 0 or 1, mode_fill, inflation, antialias,
path_type, points, num_points, precision,
zoom, rotate, X + (cx - cx0), Y + (cy - cy0),
{ name = "tempbuffer", w = w, h = h }, "object");
-- interpolate the original and effected buffers by that shape.
obj.clearbuffer("object", w, h);
obj.pixelshader("interpolate", "object", { cache_name_ori, cache_name_eff, "tempbuffer" }, {
-(w - w0) / 2 - (cx - cx0), -(h - h0) / 2 - (cy - cy0);
-(w - w1) / 2 - (cx - cx1), -(h - h1) / 2 - (cy - cy1);
});
if extra_filter == 0 then
-- draw to the framebuffer.
obj.setoption("drawtarget", "framebuffer");
obj.draw();
end
@パスに沿って配置σ
--information:パスに沿って配置σ@Path_S v1.20 (for beta43) by σ軸
--label:Path_S\配置
--require:2004001
--track@position:位置,-400,400,0,0.001,,0.25
--track@rotate:回転,-3600,3600,0,0.01,,0.1
--check@rot_tangent:パスに沿って回転,true
--track@ofs_indiv:個別位置ズレ,-200,200,-5,0.001,,0.5
--select@out_of_range:範囲外=0,非表示=0,始点のみ表示=1,終点のみ表示=2,表示=3
--group:パス設定,true
--value@num_points:頂点数,4
--select@path_type:線タイプ=3,折れ線=0,補間移動=1,2次ベジェ曲線=2,3次ベジェ曲線=3
--value@points:点リスト,{0,-100,55.23,-100,100,-55.23,100,0,100,55.23,55.23,100,0,100,-55.23,100,-100,55.23,-100,0,-100,-55.23,-55.23,-100}
--check@loop:ループ,true
--track@precision:曲線精度,1,128,8,1,,0.25
--check@toggle_gui:パスの表示,false
--group:その他,false
--value@PI:PI,{}
local path_s = require "Path_S";
local obj, math, tonumber, type = obj, math, tonumber, type;
-- set anchors.
if obj.getoption("gui") then
num_points = math.max(math.floor(0.5 + (tonumber(num_points) or 4)), 2);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
local _, pts = path_s.anchor("points", path_type, points, num_points - (loop and 0 or 1), loop);
points = pts;
end
-- take parameters.
--[==[
PI = {
position: number?,
rotate: number?,
rot_tangent: boolean|number|nil,
ofs_indiv: number?,
out_of_range: string?,
num_points: number?,
path_type: string?,
points: table?,
precision: number?,
loop: boolean|number|nil,
}
]==]
local function as_bool(t, v)
if type(t) == "boolean" then return t;
elseif type(t) == "number" then return t ~= 0;
else return v end
end
position = tonumber(PI.position) or position;
rotate = tonumber(PI.rotate) or rotate;
rot_tangent = as_bool(PI.rot_tangent, rot_tangent);
ofs_indiv = tonumber(PI.ofs_indiv) or ofs_indiv;
if type(PI.out_of_range) == "string" then
local name2num = {
["非表示"] = 0, ["始点のみ表示"] = 1, ["終点のみ表示"] = 2, ["表示"] = 3,
};
out_of_range = name2num[PI.out_of_range] or out_of_range;
end
num_points = tonumber(PI.num_points) or num_points;
if type(PI.path_type) == "string" then
local name2num = {
["折れ線"] = 0, ["補間移動"] = 1, ["2次ベジェ曲線"] = 2, ["3次ベジェ曲線"] = 3,
};
path_type = name2num[PI.path_type] or path_type;
end
if type(PI.points) == "table" then points = PI.points end
precision = tonumber(PI.precision) or precision;
loop = as_bool(PI.loop, loop);
-- normalize parameters.
position = position / 100;
rotate = rotate % 360;
ofs_indiv = ofs_indiv / 100;
out_of_range = math.min(math.max(math.floor(0.5 + out_of_range), 0), 3);
local is_mult_obj = obj.getoption("multi_object");
num_points = math.max(math.floor(0.5 + num_points), 2);
path_type = math.min(math.max(math.floor(0.5 + path_type), 0), 3);
precision = math.max(precision, 1);
toggle_gui = toggle_gui and
obj.getoption("gui") and (not is_mult_obj or obj.index == 0);
-- further calculations.
points, num_points = path_s.poll(path_type, points, num_points - (loop and 0 or 1), loop, precision);
if toggle_gui then
-- backup the original object.
local cache_name = "cache:path_s/place/obj";
obj.copybuffer(cache_name, "object");
-- find the bounding box.
local L, R, T, B, len = path_s.measure(points, num_points);
local pts, rate = points, 1;
if (R - L) + (B - T) > obj.screen_w + obj.screen_w then
-- shrink the points so the canvas will not be too large.
pts, rate = {}, (obj.screen_w + obj.screen_w) / ((R - L) + (B - T));
for i = 1, 2 * num_points do
pts[i] = rate * points[i];
end
L, R, T, B, len = rate * L, rate * R, rate * T, rate * B, rate * len;
end
L, R = math.floor(L) - 1, math.ceil(R) + 1;
T, B = math.floor(T) - 1, math.ceil(B) + 1;
-- prepare the canvas.
obj.clearbuffer("object", R - L, B - T, 0xffffff);
-- carve by the path.
path_s.path_mask_line(
0, 1, 2, 1,
0, points, num_points - (loop and 0 or 1), loop, 1,
0, 1, 0, { 6, 10 }, 0, true,
1, 0, -(L + R) / 2, -(T + B) / 2);
-- adjust the position.
local cx, cy = obj.getvalue("center");
cx, cy, obj.cx, obj.cy = obj.cx, obj.cy,
rate * obj.cx + (rate - 1) * cx - (R + L) / 2,
rate * obj.cy + (rate - 1) * cy - (B + T) / 2;
-- then draw to the framebuffer.
obj.setoption("blend", "diff");
obj.draw(0, 0, 0, 1 / rate);
obj.setoption("blend");
obj.setoption("draw_state", false);
-- rewind the states.
obj.copybuffer("object", cache_name);
obj.cx, obj.cy = cx, cy;
end
local ofs = position + ofs_indiv * (is_mult_obj and obj.index or 0);
if loop then ofs = ofs % 1;
elseif (ofs < 0 and out_of_range % 2 == 0) or (ofs > 1 and out_of_range < 2) then
-- hide the object.
obj.setoption("draw_state", true);
return;
else ofs = math.min(math.max(ofs, 0), 1) end
-- find the position and the angle.
local X, Y, A do
local i, j = path_s.find_index(-ofs, points, num_points);
-- -- calculate the position and the angle.
X, Y =
(1 - j) * points[2 * i - 1] + j * points[2 * i + 1],
(1 - j) * points[2 * i - 0] + j * points[2 * i + 2];
if rot_tangent then
A = math.atan2(
points[2 * i + 2] - points[2 * i - 0],
points[2 * i + 1] - points[2 * i - 1]);
-- as to the angle, interpolate with the neighbor secant.
if j < 0.5 then i = i - 1;
else i, j = i + 1, 1 - j end
if loop then
if i < 1 then i = i + (num_points - 1);
elseif i >= num_points then i = i - (num_points - 1) end
end
local dA = 0;
if 0 < i and i < num_points then
dA = math.atan2(
points[2 * i + 2] - points[2 * i - 0],
points[2 * i + 1] - points[2 * i - 1]);
dA = (dA - A) / (2 * math.pi);
dA = ((dA + 0.5) % 1) - 0.5;
dA = 360 * (0.5 - j) * dA;
end
A = 180 / math.pi * A + dA;
else A = 0 end
end
-- convert anchor coordinates to screen coordinates.
local Z = 0 do
local x, y, z = obj.getvalue("center");
X, Y, Z = X - obj.cx - x, Y - obj.cy - y, Z - obj.cz - z;
x, y, z = obj.getvalue("scale");
X, Y, Z = obj.sx * x * X, obj.sy * y * Y, obj.sz * z * Z;
x, y, z = obj.getvalue("angle");
x, y, z =
math.pi / 180 * (obj.rx + x),
math.pi / 180 * (obj.ry + y),
math.pi / 180 * (obj.rz + z);
local c, s = math.cos(x), math.sin(x);
X, Y = c * X - s * Y, s * X + c * Y;
c, s = math.cos(y), math.sin(y);
Z, X = c * Z - s * X, s * Z + c * X;
c, s = math.cos(z), math.sin(z);
Y, Z = c * Y - s * Z, s * Y + c * Z;
end
-- apply the position and the angle.
obj.ox, obj.oy, obj.oz = obj.ox + X, obj.oy + Y, obj.oz + Z;
obj.rz = obj.rz + rotate + A;