Advertisement
rerere284

lerp

Apr 12th, 2016
550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. --made by rerere284
  2. function init()
  3.     setName("Lerp")
  4.     setDesc("Linear interpolation. Combine two textures.")
  5.     setSize(100, 24+64+8+8+18+18+7+4)
  6.     addOutput(24+32)
  7.     addInputParameter("Texture", "The first value", 24+64+8+8, 0, 0, 100, true) --should probably be input parameters
  8.     addInputParameter("Texture", "The second value", 24+64+8+8+18, 100, 0, 100, true)
  9.     addInputParameter("t", "How much it is one texture or the other", 24+64+8+8+18+18, 50, 0, 100, true)
  10. end
  11.  
  12. function lerp(a,b,t)
  13.     return ((1-t)*a) + (t*b)
  14. end
  15.  
  16. function apply()
  17.     tileSize = getTileSize()
  18.     for i=0, tileSize*tileSize-1 do
  19.         x = i%tileSize
  20.         y = math.floor(i/tileSize)
  21.         ar, ag, ab = getValue(0, x, y, 100) --get pixels at that location for both
  22.         br, bg, bb = getValue(1, x, y, 100)
  23.         ttr, ttb, ttg = getValue(2, x, y, 100)
  24.         tt = (ttr+ttb+ttg)/3
  25.         fr = lerp(ar,br,tt)
  26.         fg = lerp(ag,bg,tt)
  27.         fb = lerp(ab,bb,tt)
  28.         setPixel(0, x, y, fr, fg, fb)
  29.     end
  30. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement