Advertisement
Guest User

Untitled

a guest
Jul 21st, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.87 KB | None | 0 0
  1.  
  2. Visualizer = {
  3. AudioChannel = nil,
  4. Data = {},
  5. SmoothData = {},
  6. BlurMat = Material("blur3.png", "smooth noclamp"),
  7. MovingMat = Material("blurbackground.png", "smooth noclamp"),
  8. NoteMat = Material("musicnote.png", "smooth noclamp"),
  9. Intensity = 50,
  10. }
  11.  
  12.  
  13.  
  14. local function DrawCircle( x, y, radius, seg )
  15. local cir = {}
  16.  
  17. table.insert( cir, { x = x, y = y, u = 0.5, v = 0.5 } )
  18. for i = 0, seg do
  19. local a = math.rad( ( i / seg ) * -360 )
  20. table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
  21. end
  22.  
  23. local a = math.rad( 0 ) -- This is needed for non absolute segment counts
  24. table.insert( cir, { x = x + math.sin( a ) * radius, y = y + math.cos( a ) * radius, u = math.sin( a ) / 2 + 0.5, v = math.cos( a ) / 2 + 0.5 } )
  25.  
  26. surface.DrawPoly( cir )
  27. end
  28. local i = 1
  29. function DrawBackgroundD(mat, clr, x, y, w, h, limitW, limitH)
  30.  
  31. render.ClearStencil();
  32. render.SetStencilEnable( true );
  33. render.SetStencilCompareFunction( STENCIL_ALWAYS );
  34. render.SetStencilPassOperation( STENCIL_REPLACE );
  35. render.SetStencilFailOperation( STENCIL_KEEP );
  36. render.SetStencilZFailOperation( STENCIL_KEEP );
  37. render.SetStencilWriteMask( 255 );
  38. render.SetStencilTestMask( 255 );
  39. render.SetStencilReferenceValue( 1 );
  40.  
  41. surface.SetDrawColor( clr )
  42. surface.DrawRect( x, y, limitW, limitH )
  43.  
  44. render.SetStencilCompareFunction( STENCIL_EQUAL );
  45.  
  46. -- clear the inside of our mask so we have a nice clean slate to draw in.
  47. render.ClearBuffersObeyStencil( 0, 0, 0, 0, true );
  48. surface.SetDrawColor( clr )
  49. surface.SetMaterial( Visualizer.BlurMat )
  50. local texW = 3840
  51. local texH = 2400
  52. local limitW2, limitH2 = limitW, limitH
  53. surface.DrawTexturedRect( x, y, w, h )
  54. surface.SetMaterial( Visualizer.MovingMat )
  55. surface.DrawTexturedRect( x - Visualizer.Intensity or 50/2, y - Visualizer.Intensity/2 or 50/2, w, h )
  56. render.SetStencilEnable( false );
  57. end
  58.  
  59.  
  60. function Visualizer.PlayURL(url, flags, callback)
  61. sound.PlayURL(url, flags, function(channel, err, errtxt)
  62. if IsValid(channel) then
  63. for i = 1, 1024 do
  64. Visualizer.SmoothData[i] = 0
  65. end
  66. callback(channel, err, errtxt)
  67. Visualizer.AudioChannel = channel
  68. else
  69. return
  70. end
  71. end)
  72. end
  73.  
  74. function Visualizer.PlayFile(path, flags, callback)
  75. sound.PlayFile(path, flags, function(channel, err, errtxt)
  76. if IsValid(channel) then
  77. callback(channel, err, errtxt)
  78. Visualizer.AudioChannel = channel
  79. else
  80. return
  81. end
  82. end)
  83. end
  84.  
  85. local blur = Material("pp/blurscreen")
  86. local function DrawCircleBlur(x, y, radius, seg, amount)
  87. surface.SetDrawColor(20, 20, 20, 200)
  88. draw.NoTexture()
  89. DrawCircle(x, y, radius, seg)
  90. end
  91.  
  92. hook.Add( "PostDrawOpaqueRenderables", "example", function()
  93. local pos = Vector(-11100, -1550, -8050)
  94. local angle = Angle(0, 90, 90)
  95. cam.Start3D2D( pos, angle, 1 )
  96. DrawBackgroundD( Visualizer.BlurMat, Color(255, 255, 255, 255), 0, 0, 1280/6 + Visualizer.Intensity, 720/6 + Visualizer.Intensity, 1280/6, 720/6)
  97. if IsValid(Visualizer.AudioChannel) and Visualizer.AudioChannel:GetState() == 1 then
  98. Visualizer.Data = { }
  99. Visualizer.AudioChannel:FFT(Visualizer.Data, FFT_2048)
  100. for i = 1, 1024 do
  101. Visualizer.SmoothData[i] = Lerp(5 * FrameTime(), Visualizer.SmoothData[i], Visualizer.Data[i])
  102. end
  103. Visualizer.Intensity = Visualizer.SmoothData[5] * 1000
  104. surface.SetDrawColor( 0, 0, 0, 200 )
  105. DrawCircleBlur(1280/6/2, 720/6/2, math.Clamp(Visualizer.Intensity or 50, 50, 100), 30 )
  106. surface.SetDrawColor( 255, 255, 255, 255 )
  107. surface.SetMaterial(Visualizer.NoteMat)
  108. DrawCircle(1280/6/2, 720/6/2, math.Clamp(Visualizer.Intensity - 15 or 35, 35, 85) , 30)
  109. end
  110. cam.End3D2D()
  111. end )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement