aviutl2スクリプトの切れ端集
10行程度のやつ
モザイク(シャープ)
code:モザイク(シャープ).anm2
--label:加工
--track@size:Size,1,4000,0,1
--track@sizeX:sizeX,0.001,1,1,0.001
--track@sizeY:sizeY,0.001,1,1,0.001
--[[pixelshader@psmain:
Texture2D tex0 : register(t0);
SamplerState smp0 : register(s0);
cbuffer constant0 : register(b0) {float2 resolution;
float2 size;};
float4 psmain(float4 pos : SV_Position,float2 UV : TEXCOORD0) : SV_Target {
float2 samplepos=clamp(floor((pos.xy-resolution.xy/2)/size)*size+resolution.xy/2+size/2,size/2,resolution-size/2);
return tex0.Sample(smp0,samplepos.xy/resolution.xy);
}
]]
local w,h=obj.getpixel()
obj.pixelshader("psmain","object","object",{w,h,size*sizeX,size*sizeY})
モーションブラーもどき(ざこ)
code:モーションブラーもどき.obj
--track0:Time,-100,100,-0.1,0.01
--track1:Num,0,100,2,1
--track2:Alpha,0,1,0.5,0.01
--track3:Decay,0,1,0,1.01
--file:
local time_tra=obj.track0
local num=obj.track1
local alpha=obj.track2
local decay=obj.track3
obj.setoption("drawtarget","tempbuffer")
obj.load("movie",file,math.max(obj.time ,0))
obj.draw(0,0,0,1,1)
for i=1,num do --手前から描画
if (obj.time + time_tra*(i/num)>=0) then
obj.load("movie",file,math.max(obj.time + time_tra*(i/num) ,0))
end
obj.draw(0,0,0,1,(1-i/num*decay)*alpha)
end
obj.load("tempbuffer")
動画を時間差で読んで重ねるだけ モーションブラーですらない
なんと無印aviutlでも使える
code:角縁取り
--label:装飾
--track@size:Size,0,1000,5,1
--color@col:Color,0xffffff
--[[pixelshader@psmain:
Texture2D tex0 : register(t0);
cbuffer constant0 : register(b0) {
float l;float3 outlinecol;
float2 dir;
}
float4 psmain(float4 pos : SV_Position) : SV_Target {
float4 col=float4(0,0,0,0);
if (maxA==1) {
} else {
for (int i = -l; i<=l; i++) {
if (refA > maxA) {
col=float4(outlinecol,1);
break;
}
}
}
return col;
}
]]
obj.effect("領域拡張","右",size,"左",size,"上",size,"下",size)
local r,g,b=RGB(col)
r,g,b=r/255,g/255,b/255
--縦横l^2ピクセルを一気に調べるよりlピクセル調べるのを2回回したほうが速い
obj.pixelshader("psmain","object","object",{size,r,g,b,1,0})
obj.pixelshader("psmain","object","object",{size,r,g,b,0,1})
ドット絵を縁取りするときに使える可能性がなくもない
ヒストグラム
code:Histgram.obj2
--label:色調整
--track@layerRel:Layer(rel),-100,100,-1,1
--track@histW:Width,1,5000,512,1
--track@histH:Height,1,5000,512,1
--check@gray:Gray,0
--check@r:R,0
--check@g:G,0
--check@b:B,0
--check@normalize:Normalize,0
local ffi=require("ffi")
local function calc_histRGB(p, size)
local histR,histG,histB,histGray = ffi.new("uint32_t256"),ffi.new("uint32_t256"),ffi.new("uint32_t256"),ffi.new("uint32_t256") local maxR,maxG,maxB,maxGray=0,0,0,0
for i = 0, size - 1 do
local gray = math.floor((r*299 + g*587 + b*114 + 500)/1000)
histRr,histGg,histBb,histGraygray=histRr+1,histGg+1,histBb+1,histGraygray+1 maxR,maxG,maxB,maxGray=math.max(maxR,histRr),math.max(maxG,histGg),math.max(maxB,histBb),math.max(maxGray,histGraygray) end
return histGray,histR,histG,histB,maxGray,maxR,maxG,maxB
end
local function draw_hist(hist,max,col)
obj.load("figure","四角形",col,2)
for i=0,255 do
local dx=histW/256
local px=i*dx-histW/2
local py=histH/2
local height=histi/math.max(max,1)*histH --念の為max obj.drawpoly(
px,py,0,
px+dx,py,0,
px+dx,py-height,0,
px,py-height,0)
end
end
obj.load("layer",obj.layer+layerRel,true) --指定したレイヤーの画像を読む
local data,w,h=obj.getpixeldata("object")
local p=ffi.cast("uint8_t*",data)
local histGray,histR,histG,histB,maxGray,maxR,maxG,maxB=calc_histRGB(p,w*h)
obj.setoption("drawtarget","tempbuffer",histW,histH)
if (normalize==0) then maxR,maxG,maxB,maxGray=math.max(maxR,maxG,maxB,maxGray),math.max(maxR,maxG,maxB,maxGray),math.max(maxR,maxG,maxB,maxGray),math.max(maxR,maxG,maxB,maxGray) end --オフのときは全体の最大値を使用、オンのときは個別の最大値を採用
if (r==1) then draw_hist(histR,maxR,0xff0000) end
if (g==1) then draw_hist(histG,maxG,0x00ff00) end
if (b==1) then draw_hist(histB,maxB,0x0000ff) end
if (gray==1) then draw_hist(histGray,maxGray,0x000000) end
obj.copybuffer("object","tempbuffer")
beta13でgetpixeldata使えるようになったがdllなど書けるわけないので結果できたもの