Guest User

Untitled

a guest
Jun 20th, 2018
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.25 KB | None | 0 0
  1. if SERVER then return end
  2.  
  3. flomp = flomp or {} local f = flomp
  4.  
  5. flomp.emitter = ParticleEmitter(EyePos(), false)
  6.  
  7. f.FFT = {}
  8. f.FFT_Size = 256
  9.  
  10. f.FFT_Bass_1 = 0
  11. f.FFT_Bass_2 = 0
  12.  
  13. f.max_volume = 0
  14. f.scale = 1
  15. f.eye_angles = Angle(0)
  16. f.eye_origin = vector_origin
  17. f.vol_multplier = 1
  18.  
  19. f.fft_detail = 10
  20. f.mul_fft = f.FFT_Size/f.fft_detail
  21.  
  22. for i = 1, f.FFT_Size do
  23.     f.FFT[i] = 0
  24. end
  25.  
  26. function flomp.SetSource(var)
  27.     var = type(var) == "number" and Entity(var) or var
  28.     if type(var) == "Vector" or (IsEntity(var) and var:IsValid()) then
  29.         f.source = var
  30.     end
  31. end
  32.  
  33. function flomp.SetScale(n)
  34.     f.scale = n
  35. end
  36.  
  37. function flomp.SetVolumeInputScale(n)
  38.     f.vol_multplier = n
  39. end
  40.  
  41. function flomp.GetSourcePos()
  42.     return type(f.source) == "Vector" and f.source or IsEntity(f.source) and f.source:IsValid() and f.source:GetPos() or vector_origin
  43. end
  44.  
  45. function flomp.GetAverage(istart, iend)
  46.     istart = math.Round(math.Clamp(istart, 1, f.FFT_Size))
  47.     iend = math.Round(math.Clamp(iend, 1, f.FFT_Size))
  48.     local n = 0
  49.     for i=istart, iend do
  50.     --  if f.FFT[i] then
  51.             n = n + f.FFT[i]
  52. --      end
  53.     end
  54.  
  55.     local div = (iend - istart)
  56.  
  57.     return div == 0 and 0 or (n / div)
  58. end
  59.  
  60. function flomp.IsAround(number, min, max)
  61.     return number > min and number < max and true or false
  62. end
  63.  
  64. flomp.powscale = 0.5
  65.  
  66. function flomp.ScaleVolume(volume)
  67.     return (volume ^ flomp.powscale) * f.vol_multplier * 7
  68. end
  69.  
  70. function flomp.Spectrum2D()
  71.     do return end
  72.     --if bawss and bawss.channel then bawss.channel:stop() bawss = nil end -- declan interuption protection
  73.  
  74.     local h = ScrH() + -400
  75.     local w = ScrW()
  76.     local volume = 0
  77.  
  78.     for fr = 1, f.FFT_Size do
  79.         volume = f.ScaleVolume(f.FFT[fr])
  80.  
  81.         surface.SetDrawColor(volume,volume,255*volume,255)
  82.         surface.DrawLine(
  83.             (w+fr)-ScrW(), h,
  84.             (w+fr)-ScrW(), h-(volume*50)
  85.         )
  86.     end
  87. end
  88.  
  89. function flomp.ParticleThink(data)
  90.     f.FFT = data
  91.  
  92.     f.FFT_Bass_1 = flomp.GetAverage(1, 6)
  93.  
  94.     for i = 1, 4 do
  95.  
  96.         local fr = (i * 256)
  97.  
  98.         local volume = f.ScaleVolume(f.FFT[math.Clamp(math.Round(i*f.mul_fft), 1, f.FFT_Size)])
  99.  
  100.         if volume < 0.01 then continue end
  101.  
  102.         local n_fr = -(fr-30) + f.FFT_Size -- negative fr, f.FFT_Size to 0
  103.  
  104.         local f_fr = (fr-30)/f.FFT_Size -- fraction fr, 0, 1
  105.         local nf_fr = n_fr/f.FFT_Size -- negative fraction, 1, 0
  106.  
  107.         for i = 1, math.Clamp(math.Round(volume*4),0,15) do
  108.  
  109.             local size = (f.FFT_Bass_1 * 20 ^ 1.5)
  110.             local color = HSVToColor(((CurTime()*10)+(f_fr*40))%360, 0.3, 1)
  111.             local velocity = ((f.eye_origin - f.GetSourcePos() ):Normalize() * 2 + VectorRand()):GetNormal()* volume ^ 1.3
  112.  
  113.             local particle = f.emitter:Add("particle/Particle_Glow_04_Additive", f:GetSourcePos() + (velocity*5*f.scale))
  114.  
  115.             particle:SetVelocity(velocity*500*f.scale)
  116.  
  117.             particle:SetLifeTime(0)
  118.             particle:SetDieTime(math.Clamp(volume*0.2, 0.1, 0.8))
  119.  
  120.             particle:SetStartLength(size*7*f.scale)
  121.             particle:SetEndLength(size*2*f.scale)
  122.             particle:SetStartSize(size*f.scale)
  123.             particle:SetEndSize(0)
  124.  
  125.             particle:SetStartAlpha(255)
  126.             particle:SetEndAlpha(0)
  127.  
  128.             particle:SetAirResistance(math.Clamp((-size+800), 10, 1200)*f.scale)
  129.             --particle:SetGravity((VectorRand()*50)*f.scale)
  130.  
  131.             particle:SetColor(color.r, color.g, color.b)
  132.             particle:SetCollide(true)
  133.             particle:SetBounce(0.1)
  134.         end
  135.     end
  136. end
  137.  
  138. f.smooth_pp = 0
  139. f.look_at_mult = 1
  140.  
  141. function flomp.DrawPostProcess()
  142.     local w = ScrW()
  143.     local h = ScrH()
  144.  
  145.     local vec2 = f.GetSourcePos():ToScreen()
  146.  
  147.     local m = math.max(f.eye_angles:Forward():DotProduct((f.GetSourcePos()-f.eye_origin):Normalize()), 0) ^ 3
  148.     f.look_at_mult = m
  149.     m = m * (f.sound_vol * 2) ^ 2
  150.  
  151.     --m = m * math.Clamp((-f.eye_origin:Distance(f.GetSourcePos()) / 15000) + 1, 0, 1)
  152.  
  153.     if m < 0.001 then return end
  154.  
  155.     m = math.Clamp(m, 0, 1)
  156.  
  157.     local vol = f.FFT_Bass_1
  158.     local darkness = (-m+1)
  159.  
  160.     local avr = math.Clamp(vol * 2  - 0.1,0,1) * m
  161.     local blur = math.Clamp((vol*-0.5)+1, 0.2, 1)
  162.     local invert = (vol*-10+1)
  163.  
  164.     local angle = VectorRand() * f.GetAverage(3, 7) ^ 1.5 * m
  165.     angle.x = math.Clamp(angle.x, -0.2, 0.2)
  166.     angle.y = math.Clamp(angle.y, -0.2, 0.2)
  167.     angle.z = 0
  168.     LocalPlayer():SetEyeAngles(LocalPlayer():EyeAngles() + angle)
  169.  
  170.     f.smooth_pp = f.smooth_pp + ((avr - f.smooth_pp)*FrameTime()*10)
  171.  
  172.     local mscale = m * f.vol_multplier
  173.  
  174.     local tbl= {}
  175.     tbl[ "$pp_colour_addr" ] = 3/255*m
  176.     tbl[ "$pp_colour_addg" ] = 0
  177.     tbl[ "$pp_colour_addb" ] = 4/255*m
  178.     tbl[ "$pp_colour_brightness" ] = -0.05*m
  179.     tbl[ "$pp_colour_contrast" ] = Lerp(m, 1, 2)
  180.     tbl[ "$pp_colour_colour" ] = 1+(0.6*m)
  181.     tbl[ "$pp_colour_mulr" ] = 0
  182.     tbl[ "$pp_colour_mulg" ] = 0
  183.     tbl[ "$pp_colour_mulb" ] = 0
  184.  
  185.  
  186.     --DrawMotionBlur(blur, 1, 0)
  187.     DrawBloom(darkness, invert*(m/20), math.max(invert*20+2, 5), math.max(invert*20+10, 5), 4, 3, 1, 1, 1 )
  188.     DrawSunbeams(darkness+0.2, math.max(vol*0.5, 0.1), 0.05 * (vol * 20) ^ 1.5, vec2.x / ScrW(), vec2.y / ScrH())
  189.     DrawColorModify(tbl)
  190.     DrawToyTown(Lerp(avr, 0, 10), ScrH()*0.55)
  191.  
  192.     materials.SetSkyColor(Vector()*(darkness ^ 2))
  193.     --print(blur)
  194. end
  195.  
  196. hook.Add("HUDPaint", "flomp_Helper", flomp.Spectrum2D)
  197. hook.Add("SpotifySpectrum", "flomp_Think", flomp.ParticleThink)
  198. hook.Add("RenderScreenspaceEffects", "flomp_RenderScreenspaceEffects", flomp.DrawPostProcess)
  199.  
  200.  
  201. hook.Add("RenderScene", "flomp_CalcView", function(pos, ang)
  202.     f.eye_origin = pos
  203.     f.eye_angles = ang
  204. end)
  205.  
  206. local voldata = Vector(1,1,1) -- V, L, R
  207.  
  208. local function calcsource(eye, rgt, src, dist, fwd, vel)
  209.     local vol = math.Clamp(-((eye - src):Length() / dist) + 1, 0, 1)
  210.     local dot = rgt:Dot((src - eye):Normalize())
  211.  
  212.     local left = math.Clamp(-dot, 0, 1) + 0.5
  213.     local right = math.Clamp(dot, 0, 1) + 0.5
  214.  
  215.     if vol ~= 0 then
  216.     return vol, -left + right
  217.     end
  218. end
  219.  
  220. function GetVolumeData(source, falloff)
  221.     local ply = LocalPlayer()
  222.     return calcsource(ply:EyePos(),f.eye_angles:Right(), source, falloff, f.eye_angles:Forward(), ply:GetVelocity())
  223. end
  224.  
  225. f.sound_vol = 1
  226.  
  227. hook.Add("Think","flomp_volume",function()
  228.     local vol, panning = GetVolumeData(flomp.GetSourcePos(), 4000)
  229.  
  230.     if vol then
  231.         f.sound_vol = vol
  232.         vol = vol * f.look_at_mult
  233.  
  234.         BlahSetVolume(vol^1.5)
  235.         BlahSetPanning(panning)
  236.     end
  237. end)
  238.  
  239. flomp.SetSource(Entity(187))
  240. flomp.SetVolumeInputScale(1)
  241.  
  242. hook.Add("HUDPaintBackground", "itsaparty")
  243. hook.Add("CalcView", "itsaparty")
Add Comment
Please, Sign In to add comment