rerere284

lerp

Apr 12th, 2016
353
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×