Guest User

HSV node

a guest
May 9th, 2020
76
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function init()
  2.     setName("HSV")
  3.     setDesc("Adjust HSV values")
  4.     setSize(120,18+18+18+24+64+8+8+7+4)
  5.     addOutput(24+32)
  6.     addInput("Texture",24+64+8+8)
  7.     addInputParameter("H","Hue",18+24+64+8+8,0,0,255)
  8.     addInputParameter("S","Saturation",18+18+24+64+8+8,127,0,255)
  9.     addInputParameter("V","Value",18+18+18+24+64+8+8,127,0,255)
  10. end
  11. -- Ugly way to use channels
  12. function getChroma(R, G, B)
  13.     m = math.min(math.min(R, G), B)
  14.     M = math.max(math.max(R, G), B)
  15.     return (M-m)
  16. end
  17. function rgbM(n, H, S, V)
  18.     k = math.fmod((n + (H*6)), 6)
  19.     out = V - (V*S*math.max(math.min(k,4-k,1),0))
  20.     return out
  21. end
  22. function getHue(R, G, B)
  23.     m = math.min(math.min(R, G), B)
  24.     M = math.max(math.max(R, G), B)
  25.    
  26.     if (m == M) then
  27.         return 0
  28.     end
  29.     if (M == R) then
  30.         hue = (G-B)/(M-m)
  31.     end
  32.     if (M == G) then
  33.         hue = 2+(B-R)/(M-m)
  34.     end
  35.     if (M == B) then
  36.         hue = 4+(R-G)/(M-m)
  37.     end
  38.    
  39.     hue = hue / 6
  40.    
  41.     if (hue < 0) then
  42.         hue = hue + 1
  43.     end
  44.     if (hue > 1) then
  45.         hue = hue - 1
  46.     end
  47.    
  48.     return hue
  49. end
  50. function apply()
  51.     x = 0
  52.     y = 0
  53.     tileSize = getTileSize()
  54.     for i=0, tileSize*tileSize-1 do
  55.         x = i%tileSize
  56.         y = math.floor(i/tileSize)
  57.         R, G, B = getValue(0,x,y,1) -- Scan Texture
  58.        
  59.         hmod = getValue(1,x,y,255)
  60.         hnew = getHue(R, G, B) + hmod
  61.         if (hnew > 1) then
  62.             hnew = hnew - 1
  63.         end
  64.         if (hnew < 0) then
  65.             hnew = hnew + 1
  66.         end
  67.        
  68.         vmod = (getValue(3,x,y,255)*2) - 1
  69.         vnew = math.min((math.max((math.max( (math.max(R, G)) , B) + vmod), 0)), 1)
  70.        
  71.         smod = (getValue(2,x,y,255)*2) - 1
  72.         if(vnew == 0) then
  73.             snew = (getChroma(R, G, B)) + smod
  74.         else
  75.             snew = (getChroma(R, G, B) / vnew) + smod
  76.         end
  77.        
  78.         --convert to rgb
  79.         outr = rgbM(5, hnew, snew, vnew)
  80.         outg = rgbM(3, hnew, snew, vnew)
  81.         outb = rgbM(1, hnew, snew, vnew)
  82.        
  83.         setPixel(0,x,y,outr,outg,outb)
  84.        
  85.     end
  86. 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.

×