Guest User

Bend

a guest
May 9th, 2020
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  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)
  5.     addOutput(24+32)
  6.     addInput("Texture", 24+64+8+8)
  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)
  11.     addParameter("ClampDisl","Dislocates the clamping",18+18+18+18+18+24+64+8+8,0,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
Add Comment
Please, Sign In to add comment