# Bend

a guest
May 9th, 2020
68
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. function init()
2.     setName("Bend")
3.     setDesc("Bend texture into a shape")
4.     setSize(100, 18+18+18+24+64+8+8+18+18+7+4)
7.     addInputParameter("Deform", "The Z Generic Distance", 24+64+8+8+18, 1, 0, 10)
8.     addInputParameter("Depth", "Image Depth", 24+64+8+8+18+18, 100, 1, 200, true)
9.     addParameter("Translate","Translates the image in Z",18+18+18+24+64+8+8,100,1,200)
10.     addParameter("DepthClamp","Clamps the image after a certain Z",18+18+18+18+24+64+8+8,50,0,100)
12. end
13.
14. function normalize(x, y, z)
15.     l = math.sqrt(x*x+y*y+z*z)
16.     return x/l, y/l, z/l
17. end
18.
19. function apply()
20.     tileSize = getTileSize()
21.     for i=0, tileSize*tileSize-1 do
22.         x = i%tileSize
23.         y = math.floor(i/tileSize)
24.
25.         Dist = getValue(3,x,y,100)-((getValue(2,x,y,100)-1)*getValue(1, x, y, 1))
26.         if (Dist == 0) then
27.             Dist = 1;
28.         end
29.
30.         Tx = (tileSize/2)-(tileSize/(2*Dist))
31.         Ty = (tileSize/2)-(tileSize/(2*Dist))
32.
33.         xnew = (x/Dist) + Tx
34.         ynew = (y/Dist) + Ty
35.
36.         outr,outg,outb = getValue(0,xnew,ynew,1)
37.
38.         if (Dist > getValue(4, x, y, 100)+getValue(5,x,y,100)) then
39.             setPixel(0, x, y, outr, outg, outb)
40.         end
41.     end
42. end
RAW Paste Data