1+ --[[
2+ GrungeConverter.anm
3+ グランジ素材に変換するアニメーションスクリプト
4+
5+ 使い方:https://scrapbox.io/korarei/GrungeConverter
6+
7+ by Korarei
8+ ]]--
9+
10+ --label:Process
11+ --information:GrungeConverter v1.0.1
12+
13+ --track0:Width,-1,4000,-1,1
14+ --track1:Height,-1,4000,-1,1
15+ --track2:Speed,0,1000,10,1
16+ --track3:Threshold,0.0,1.0,0.5,0.001
17+ --check0:Mix BG,1
18+ --color@_1:Color,0xffffff
19+ --color@_2:BG Color,0x000000
20+ --check@_3:Invert Y,1
21+ --track@_4:Num,1,100,2,1
22+ --track@_5:DX [%],0.0,200.0,100.0,0.001
23+ --track@_6:DY [%],0.0,200.0,100.0,0.001
24+ --value@_7:DZ [px],{-900,-700}
25+ --value@_8:DR [°],{-180,180}
26+ --check@_9:Random Flip,1
27+ --track@_10:Seed,-10000,10000,-1,1
28+ --check@_11:Adjustment,1
29+
30+ --[[pixelshader@thresholding:
31+ Texture2D texture0 : register(t0);
32+ cbuffer constant0 : register(b0) {
33+ float threshold;
34+ float col1;
35+ float col2;
36+ float col2_a;
37+ };
38+ float4 decode_col(float rgb, float a) {
39+ uint col = (uint)rgb;
40+ float r = ((col >> 16) & 0xFF) / 255.0;
41+ float g = ((col >> 8) & 0xFF) / 255.0;
42+ float b = (col & 0xFF) / 255.0;
43+ return float4(r*a, g*a, b*a, a);
44+ };
45+ float4 thresholding(float4 pos : SV_Position) : SV_Target {
46+ float4 col = texture0[int2(pos.xy)];
47+ float mask = step(threshold, col.r);
48+ return lerp(decode_col(col2, col2_a), decode_col(col1, 1.0), mask);
49+ }
50+ ]]
51+
52+ local chk, mes = pcall(function()
53+ local w, h = obj.getpixel()
54+ if w * h == 0 then
55+ return
56+ end
57+ --大きさが0なら以下の処理しない
58+ local floor = math.floor
59+
60+ local width = obj.track0 == -1 and obj.screen_w or obj.track0
61+ local height = obj.track1 == -1 and obj.screen_h or obj.track1
62+ local sp = obj.track2
63+ local threshold = obj.track3
64+ local check_background = obj.check0
65+ local col = _1 _1 = nil
66+ local col2 = _2 _2 = nil
67+ local check_brightness = _3 == 1 _3 = nil
68+ local n = floor(_4) _4 = nil
69+ local dx = {- width * _5 / 200, width * _5 / 200} _5 = nil
70+ local dy = {- height * _6 / 200, height * _6 / 200} _6 = nil
71+ local dz = _7 _7 = nil
72+ local dr = _8 _8 = nil
73+ local check_mirror = _9 == 1 _9 = nil
74+ local seed = _10 _10 = nil
75+ local check_thresholding = _11 == 1 _11 = nil
76+ if dz[3] then
77+ error("The table has too many elements. Please remove the 3rd and subsequent elements.")
78+ elseif dz[2] == nil then
79+ error("The table does not have a 2nd element.")
80+ end
81+ if dr[3] then
82+ error("The table has too many elements. Please remove the 3rd and subsequent elements.")
83+ elseif dr[2] == nil then
84+ error("The table does not have a 2nd element.")
85+ end
86+
87+ if n == 0 then
88+ return
89+ end
90+
91+ --透過
92+ local alpha_type = 0
93+ if check_brightness then
94+ alpha_type = 1
95+ threshold = 1.0 - threshold
96+ end
97+ obj.effect("ルミナンスキー", "基準輝度", floor(4096 * threshold), "ぼかし", 0, "type", alpha_type)
98+ obj.effect("単色化", "強さ", 100, "color", check_thresholding and 0xffffff or col, "輝度を保持する", 0)
99+ obj.copybuffer("cache:processed", "obj")
100+ --乱数生成
101+ local frame = sp == 0 and 0 or floor(obj.frame / sp)
102+
103+ local function rand(st, ed)
104+ seed = seed < 0 and seed - 1 or seed + 1
105+ return obj.rand(st, ed, seed, frame)
106+ end
107+
108+ --仮想バッファに描画
109+ obj.setoption("drawtarget", "tempbuffer", width, height)
110+ if check_background then
111+ obj.load("figure","四角形", check_thresholding and 0x000000 or col2, 1)
112+ obj.drawpoly(- width / 2 , - height / 2, 0, width / 2, - height / 2, 0, width / 2, height / 2, 0, - width / 2, height / 2, 0)
113+ end
114+ for i = 1, n do
115+ local x = rand(dx[1], dx[2])
116+ local y = rand(dy[1], dy[2])
117+ local z = rand(dz[1], dz[2])
118+ local ry = check_mirror and rand(0, 1) == 1 and 180 or 0
119+ local rz = rand(dr[1], dr[2])
120+ obj.copybuffer("obj", "cache:processed")
121+ obj.draw(x, y, z, 1, 1, 0, ry, rz)
122+ end
123+ obj.load("tempbuffer")
124+ --縁ボケを消す2値化(Zを移動させているため)
125+
126+ if check_thresholding then
127+ obj.pixelshader("thresholding", "object", {"object"}, {threshold, col, col2, check_background and 1.0 or 0.0})
128+ end
129+
130+ end)
131+ if not chk then
132+ obj.setfont("游ゴシック", 50)
133+ obj.load("text", "[GrungeConverter.anm]\n"..mes)
134+ obj.draw()
135+ error("[GrungeConverter.anm]"..mes)
136+ end
0 commit comments