-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdirectional_blur.lua
40 lines (38 loc) · 1.19 KB
/
directional_blur.lua
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
function init()
setName("Directional Blur")
setDesc("Blurs texture in a direction")
setSize(140, 24+64+8+8+18+18+7+4)
addOutput(24+32)
addInput("Texture", 24+64+8+8)
addInputParameter("Direction", "Blur direction", 24+64+8+8+18, 0, -1, -1)
addInputParameter("Intensity", "Blur intensity", 24+64+8+8+18+18, 10, 0, 100, true)
end
function normalize(x, y, z)
l = math.sqrt(x*x+y*y+z*z)
return x/l, y/l, z/l
end
function apply()
tileSize = getTileSize()
for i=0, tileSize*tileSize-1 do
x = i%tileSize
y = math.floor(i/tileSize)
intensity = getValue(2, x, y, 100.0)
dist = tileSize*intensity
samples = math.max(1.0, math.floor(dist))
direction = getValue(1, x, y, 360.0)*360.0*math.pi/180.0
dx, dy = normalize(math.sin(direction), -math.cos(direction), 0.0)
fr = 0
fg = 0
fb = 0
for b=0, samples-1 do
cr, cg, cb = getValue(0, x+dx*dist*b/samples, y+dy*dist*b/samples, 1.0)
fr = fr+cr
fg = fg+cg
fb = fb+cb
end
fr = fr/samples
fg = fg/samples
fb = fb/samples
setPixel(0, x, y, fr, fg, fb)
end
end