--information:ノイズグラデーション v1.4 by teruyoshi --label:teruyoshi -- Azuriteさんのグラデーション+(https://github.com/azurite581/AviUtl2-GradientPlus)を参考に作成しました --group:ノイズ設定,true --track@str:強さ,0,100,100,0.01 --track@sizeX:ドットサイズX,1,100,1,0.01 --track@sizeY:ドットサイズY,1,100,1,0.01 --track0:中心X,-5000,5000,0,0.01 --track1:中心Y,-5000,5000,0,0.01 --track@angle_deg:角度/内径,-3600,3600,0,0.01 --track@width:幅,0,2000,300,0.01 --select@shape:形状=0,線形=0,円形=1 --select@noiseType:ノイズの種類=0,ホワイトノイズ=0,ブルーノイズ=1,インターリーブグラデーションノイズ(IGN)=2,配列ディザリング(2x2)=3,配列ディザリング(4x4)=4,配列ディザリング(8x8)=5,集中型ディザリング(8x8)=6,網点=7,線=8 --track@period:模様の周期,2,200,8,0.01 --網点・線の間隔(ドットサイズを掛ける前のピクセル数) --hide@period:noiseType<7 --track@patternAngle:模様の角度,-360,360,45,0.01 --hide@patternAngle:noiseType<7 --track3:🕒️グラデ曲線0→100,0,100,0,0.01 --時間制御でグラデーションの遷移を制御する --group:色設定,true --color@rgb1:開始色,0xff0000 --track@a1:開始色透明度,0,100,0,0.01 --color@rgb2:終了色,0x0000ff --track@a2:終了色透明度,0,100,0,0.01 --group:その他の設定,false --select@blendMode:合成モード=0,通常=0,加算=1,減算=2,乗算=3,スクリーン=4,オーバーレイ=5,比較(明)=6,比較(暗)=7,輝度=8,色差=9,陰影=10,明暗=11,差分=12,アルファ加算=13,アルファ最大値=14,アルファ減算=15,アルファ加算2=16 --track@seed:シード,0,10000,0,1 --check@clear:元オブジェクトをクリア,0 local MaxResolution = 255 -- グラデーションカーブの解像度 -- 重い場合はMaxResolutionを下げてください(下のシェーダー側のMaxResolutionも同じ値にしてください) local BM = {"none", "add", "sub", "mul", "screen", "overlay", "light", "dark", "brightness", "chroma", "shadow", "light_dark", "diff", "alpha_add", "alpha_max", "alpha_sub", "alpha_add2"} local num = obj.setanchor("track", 0, "line") for i = 0, num - 1 do cx = obj.getvalue(0) cy = obj.getvalue(1) end --[[pixelshader@noiseGradient: static const uint MaxResolution = 255; // 上のLua側のMaxresolutionと同じ値にすること Texture2D tex : register(t0); cbuffer constant0 : register(b0) { float str; float2 center; float angle; float width; float3 rgb1; float a1; float3 rgb2; float a2; uint shape; float2 size; uint seed; float noiseType; // 選択項目「ノイズの種類」の値(0=ホワイトノイズ) float period; // 網点・線の周期 float patternAngle; // 網点・線の角度(ラジアン) float gCurve[MaxResolution]; }; SamplerState samLinear : register(s0); struct PS_INPUT { float4 pos : SV_Position; float2 uv : TEXCOORD0; }; // 参考: https://andantesoft.hatenablog.com/entry/2024/12/19/193517 float ibukiHash(uint4 u) { // posとseedをもとに、0〜1の疑似乱数を生成 const uint4 mult = uint4(0xae3cc725, 0x9fe72885, 0xae36bfb5, 0x82c1fcad); u = u * mult; u ^= u.wxyz ^ u >> 13; uint r = dot(u, mult); r ^= r >> 11; r = (r * r) ^ r; return r * 2.3283064365386962890625e-10; } static const float PI = 3.14159265; // 配列ディザリング(Bayer行列)の閾値(0〜1)を返す。bitsは行列の一辺のビット数(1=2x2, 2=4x4, 3=8x8) float bayerThreshold(uint2 p, uint bits) { // 8x8のBayer行列の値(0〜63)をビット演算で求める。座標の下位のビットほど上位の桁に入るので、 // 上位の桁だけを取り出すと、そのまま4x4・2x2の行列の値になる uint v = 0; for (uint i = 0; i < 3; i++) { uint x = (p.x >> i) & 1; uint y = (p.y >> i) & 1; v = (v << 2) | ((x ^ y) << 1) | y; } v >>= 6 - bits * 2; return (v + 0.5) / (1u << (bits * 2)); } // 集中型の配列ディザリングの行列(8x8、値は0〜63)。45度に並ぶ2つの点が、中心から順に太っていく static const uint clusterMatrix[64] = { 0, 16, 44, 62, 60, 42, 22, 5, 12, 24, 38, 45, 54, 36, 29, 23, 48, 32, 25, 17, 10, 31, 37, 43, 56, 49, 13, 1, 7, 11, 55, 61, 58, 40, 20, 4, 2, 18, 46, 63, 52, 34, 28, 21, 14, 26, 39, 47, 8, 30, 35, 41, 50, 33, 27, 19, 6, 9, 53, 59, 57, 51, 15, 3 }; // ブルーノイズの行列(32x32、値は0〜1023)。void-and-cluster法で作ったもの static const uint blueNoiseMatrix[1024] = { 1004, 154, 371, 958, 645, 880, 789, 51, 1008, 833, 234, 8, 819, 178, 548, 695, 137, 476, 357, 817, 85, 501, 261, 440, 588, 106, 380, 466, 632, 100, 337, 33, 691, 490, 253, 737, 86, 529, 252, 628, 360, 453, 662, 331, 599, 736, 72, 407, 621, 968, 53, 554, 945, 164, 732, 1003, 314, 829, 746, 980, 175, 930, 739, 560, 861, 52, 804, 564, 188, 395, 946, 116, 744, 890, 158, 940, 426, 244, 802, 917, 303, 757, 226, 677, 411, 320, 857, 27, 653, 531, 248, 2, 572, 441, 221, 398, 312, 646, 438, 995, 305, 843, 705, 473, 287, 40, 545, 707, 104, 1011, 499, 189, 25, 525, 885, 118, 782, 606, 507, 216, 399, 138, 864, 690, 301, 790, 896, 117, 966, 213, 879, 130, 636, 4, 574, 176, 993, 779, 367, 872, 292, 613, 370, 666, 839, 335, 450, 1016, 257, 71, 962, 822, 709, 948, 479, 375, 1010, 67, 664, 539, 773, 87, 516, 368, 750, 429, 913, 345, 510, 624, 207, 462, 30, 826, 132, 977, 562, 730, 163, 595, 382, 669, 445, 93, 324, 600, 47, 193, 622, 497, 169, 346, 423, 607, 825, 265, 971, 198, 795, 64, 852, 121, 951, 745, 530, 689, 233, 413, 83, 262, 866, 5, 806, 916, 202, 552, 776, 259, 909, 727, 846, 271, 939, 702, 238, 1022, 45, 708, 105, 536, 644, 240, 699, 403, 274, 90, 925, 327, 893, 791, 488, 960, 687, 534, 306, 127, 733, 366, 978, 156, 521, 401, 99, 449, 800, 11, 855, 323, 461, 580, 392, 923, 309, 483, 981, 576, 811, 638, 428, 172, 586, 42, 640, 361, 209, 424, 988, 608, 487, 875, 16, 617, 827, 321, 990, 598, 151, 550, 661, 184, 756, 955, 170, 784, 19, 881, 98, 181, 348, 1017, 9, 498, 760, 294, 910, 134, 838, 46, 759, 247, 82, 665, 285, 455, 698, 55, 217, 681, 921, 372, 486, 894, 114, 284, 654, 518, 374, 670, 443, 781, 546, 231, 850, 671, 961, 197, 452, 728, 591, 506, 932, 356, 849, 420, 1018, 133, 931, 535, 762, 431, 293, 69, 703, 567, 386, 812, 65, 860, 203, 755, 277, 908, 66, 712, 406, 115, 351, 555, 74, 1013, 313, 225, 676, 155, 568, 726, 205, 783, 377, 275, 892, 95, 788, 974, 260, 24, 1005, 491, 612, 322, 956, 584, 140, 494, 325, 936, 593, 263, 775, 888, 656, 384, 809, 61, 470, 895, 29, 316, 522, 604, 38, 659, 165, 590, 459, 191, 882, 344, 729, 215, 924, 148, 472, 32, 1001, 660, 820, 160, 457, 987, 59, 480, 251, 147, 614, 954, 722, 393, 787, 965, 110, 920, 824, 493, 983, 359, 853, 630, 523, 799, 447, 77, 686, 390, 832, 714, 355, 219, 561, 22, 751, 648, 192, 847, 710, 915, 519, 112, 295, 214, 611, 477, 256, 397, 199, 701, 297, 14, 734, 119, 929, 159, 298, 597, 887, 241, 541, 126, 805, 434, 922, 300, 858, 365, 435, 575, 1, 333, 418, 835, 583, 1007, 142, 675, 865, 747, 78, 436, 901, 551, 242, 408, 48, 678, 984, 505, 758, 84, 975, 279, 601, 81, 731, 186, 533, 101, 937, 286, 797, 998, 194, 738, 56, 352, 810, 10, 330, 571, 989, 637, 152, 767, 1015, 619, 840, 389, 210, 18, 334, 430, 655, 844, 495, 947, 631, 336, 1021, 696, 157, 623, 502, 97, 658, 467, 919, 540, 427, 943, 180, 465, 268, 821, 373, 76, 475, 291, 557, 748, 871, 626, 938, 785, 153, 363, 7, 235, 404, 813, 49, 464, 898, 741, 230, 387, 891, 290, 166, 700, 232, 764, 627, 900, 41, 524, 229, 862, 715, 179, 89, 258, 460, 113, 517, 228, 587, 1002, 694, 876, 141, 570, 667, 267, 378, 34, 976, 577, 768, 23, 620, 973, 92, 520, 349, 120, 798, 672, 941, 592, 421, 967, 815, 358, 1009, 719, 311, 903, 73, 471, 288, 772, 444, 959, 201, 859, 532, 814, 326, 124, 511, 854, 329, 410, 837, 272, 1023, 721, 409, 299, 167, 6, 328, 641, 528, 43, 650, 174, 842, 412, 752, 663, 131, 558, 36, 317, 718, 107, 616, 177, 697, 905, 433, 220, 716, 547, 57, 652, 469, 212, 581, 969, 503, 740, 914, 145, 706, 873, 405, 579, 28, 537, 204, 918, 385, 985, 823, 508, 886, 394, 1006, 481, 273, 603, 62, 992, 139, 926, 794, 162, 906, 26, 848, 102, 379, 818, 236, 456, 307, 195, 953, 269, 792, 991, 332, 94, 602, 249, 168, 634, 75, 246, 761, 13, 934, 803, 381, 647, 478, 281, 388, 573, 339, 766, 668, 266, 549, 629, 50, 997, 556, 70, 754, 484, 125, 684, 454, 851, 763, 482, 693, 353, 963, 458, 674, 340, 143, 544, 245, 769, 883, 3, 685, 999, 227, 509, 415, 986, 185, 867, 350, 778, 416, 856, 625, 354, 935, 237, 633, 58, 308, 952, 17, 786, 563, 183, 816, 594, 439, 863, 91, 347, 182, 514, 780, 79, 639, 135, 884, 37, 711, 474, 123, 651, 88, 289, 171, 717, 0, 402, 878, 565, 196, 383, 899, 128, 296, 877, 80, 972, 200, 642, 1014, 720, 605, 957, 422, 315, 933, 369, 793, 596, 310, 950, 243, 912, 500, 1020, 582, 897, 504, 801, 161, 1000, 743, 526, 643, 442, 724, 513, 391, 283, 753, 496, 54, 396, 270, 108, 836, 187, 559, 725, 239, 96, 432, 808, 543, 735, 211, 807, 425, 111, 264, 657, 343, 448, 103, 254, 830, 190, 1019, 35, 683, 911, 122, 318, 828, 542, 904, 749, 468, 673, 20, 874, 489, 1012, 682, 173, 12, 364, 679, 68, 338, 771, 982, 553, 39, 845, 618, 942, 60, 362, 585, 841, 222, 610, 417, 949, 688, 218, 31, 589, 250, 979, 302, 400, 150, 569, 342, 834, 615, 964, 463, 907, 538, 223, 704, 146, 927, 723, 304, 414, 770, 680, 276, 109, 492, 777, 15, 566, 149, 451, 996, 376, 144, 796, 512, 649, 774, 44, 944, 224, 419, 136, 278, 609, 831, 21, 437, 319, 485, 208, 578, 129, 527, 970, 446, 902, 341, 994, 255, 869, 742, 282, 635, 868, 692, 63, 928, 206, 889, 280, 713, 515, 870, 765 }; // 網点の濃度関数(0.5-(cos+cos)/4)の値(0〜1を64等分)→その値より小さい部分の面積の割合。 // これで閾値に直すと、不透明になる面積の割合が入力と一致する static const float halftoneArea[65] = { 0.0000, 0.0100, 0.0202, 0.0306, 0.0411, 0.0518, 0.0627, 0.0738, 0.0851, 0.0967, 0.1085, 0.1205, 0.1328, 0.1453, 0.1582, 0.1713, 0.1848, 0.1986, 0.2128, 0.2275, 0.2426, 0.2581, 0.2742, 0.2909, 0.3083, 0.3265, 0.3454, 0.3655, 0.3868, 0.4097, 0.4347, 0.4629, 0.5000, 0.5371, 0.5653, 0.5903, 0.6132, 0.6345, 0.6546, 0.6735, 0.6917, 0.7091, 0.7258, 0.7419, 0.7574, 0.7725, 0.7872, 0.8014, 0.8152, 0.8287, 0.8418, 0.8547, 0.8672, 0.8795, 0.8915, 0.9033, 0.9149, 0.9262, 0.9373, 0.9482, 0.9589, 0.9694, 0.9798, 0.9900, 1.0000 }; // ホワイトノイズ以外の閾値(0〜1)を返す。kindは選択項目「ノイズの種類」の値、sはシード float patternThreshold(float2 pos, uint kind, uint s, float period, float angle) { uint2 p = uint2(pos); if (kind >= 3 && kind <= 5) { // 配列ディザリング(3=2x2, 4=4x4, 5=8x8) return bayerThreshold(p + uint2(s % 8, s / 8 % 8), kind - 2); } if (kind == 6) { // 集中型ディザリング uint2 q = (p + uint2(s % 8, s / 8 % 8)) % 8; return (clusterMatrix[q.y * 8 + q.x] + 0.5) / 64.0; } if (kind == 1) { // ブルーノイズ uint2 q = (p + uint2(s % 32, s / 32 % 32)) % 32; return (blueNoiseMatrix[q.y * 32 + q.x] + 0.5) / 1024.0; } if (kind == 2) { // インターリーブグラデーションノイズ float2 q = pos + s * 5.588238; return frac(52.9829189 * frac(dot(q, float2(0.06711056, 0.00583715)))); } // 網点・線: 模様の角度だけ回した座標を周期で割り、シードの分だけ位相をずらす float sn, cs; sincos(angle, sn, cs); float2 u = float2(pos.x * cs + pos.y * sn, -pos.x * sn + pos.y * cs) / period + frac(s * float2(0.7548777, 0.5698403)); if (kind == 7) { // 網点 float f = saturate(0.5 - (cos(2 * PI * u.x) + cos(2 * PI * u.y)) / 4) * 64; uint i = min((uint)f, 63); return lerp(halftoneArea[i], halftoneArea[i + 1], f - i); } return abs(frac(u.x) * 2 - 1); // 線 } float4 noiseGradient(PS_INPUT input) : SV_Target { float original_a = tex.Sample(samLinear, input.uv).a; // 元オブジェクトの透明度 float4 rgba1 = float4(rgb1 * original_a*a1, a1 * original_a); float4 rgba2 = float4(rgb2 * original_a*a2, a2 * original_a); float rand; if (noiseType < 0.5) { rand = ibukiHash(uint4(input.pos.x, input.pos.y, input.pos.z, input.pos.w + seed)); } else { // 定数はfloatで渡されるので、seedを数値として使う時はfloatに読み替える。シードの分だけ模様の位置をずらす uint s = (uint)asfloat(seed); rand = patternThreshold(input.pos.xy, (uint)noiseType, s, period, patternAngle); } float d; if (shape == 0) { // 線形 d = dot(input.pos.xy - center, float2(cos(angle), sin(angle))) + width/2.0; } else { // 円形 d = length((input.pos.xy - center) * size) - angle; // angleは円形の場合内径として流用 } if (d < 0 ) return rgba1; if (d > width ) return rgba2; float mapped_d = gCurve[floor((d)/width * MaxResolution)]; return (mapped_d > rand) ? rgba2 : rgba1; } ]] --グラデ曲線からグラデーションカーブの配列を作成 local gCurves = {} if obj.getoption("track_mode", "3") == 0 then -- 時間制御が設定されていない場合は直線移動とみなす for i = 0, MaxResolution*4 do gCurves[i] = i/(MaxResolution*4) end else for i = 0, MaxResolution*4 do gCurves[i] = obj.getvalue(3,(obj.totaltime-1/obj.framerate)*i/(MaxResolution*4))/100 end end obj.setoption("drawtarget", "tempbuffer", obj.w, obj.h) if clear == 0 then obj.draw() end -- ドットサイズの逆数倍のりサイズを掛けてピクセルシェーダーへの入力を調整する obj.effect("リサイズ", "拡大率", 100, "X", 100/sizeX, "Y", 100/sizeY, "補間なし", 1, "ピクセル数でサイズ指定", 0) local angle = math.rad(angle_deg) if shape == 0 then -- 線形グラデーション -- リサイズの影響を考慮して角度を補正 angle = math.atan2(sizeX *math.cos(angle), sizeY *math.sin(angle)) + math.pi/2 -- リサイズの影響を考慮して幅を補正 width = width * math.sqrt((math.cos(angle)/sizeX)^2 + (math.sin(angle)/sizeY)^2) else -- 円形グラデーション angle = angle_deg/2 -- 円形の場合は角度を内径として流用 width = width/2 -- 円形の場合はシェーダー側でも補正する end -- 中心座標を補正 cx = cx/sizeX + obj.w / 2 cy = cy/sizeY + obj.h / 2 -- 色をrgbに分解 local r1 , g1, b1 = RGB(rgb1) local r2 , g2, b2 = RGB(rgb2) obj.pixelshader("noiseGradient", "object", "object", { str/100.0, cx, cy, angle, width, r1/255.0, g1/255.0, b1/255.0, 1-a1/100.0, r2/255.0, g2/255.0, b2/255.0, 1-a2/100.0, shape, sizeX, sizeY, math.floor(seed), noiseType, period, math.rad(patternAngle), unpack(gCurves, 4) -- noiseType等を足す前と同じ値がgCurveに入るように、gCurves[4]から渡す }, "copy" ) -- 元のサイズにリサイズ obj.effect("リサイズ", "拡大率", 100, "X", sizeX*100, "Y", sizeY*100, "補間なし", 1, "ピクセル数でサイズ指定", 0) obj.setoption("blend", BM[blendMode+1]) obj.draw(0,0,0,1.0,str/100.0) obj.setoption("blend", "none") obj.copybuffer("obj","tmp")