HUD Blur Background

So i’m making a new HUD and I want to add a blur
to the background of the main background. If anyone
could help me with this that would be great. Thanks.





local blur = Material("pp/blurscreen")
local function DrawBlurRect(x, y, w, h)
	local X, Y = 0,0

	surface.SetDrawColor(255,255,255)
	surface.SetMaterial(blur)

	for i = 1, 5 do
		blur:SetFloat("$blur", (i / 3) * (5))
		blur:Recompute()

		render.UpdateScreenEffectTexture()

		render.SetScissorRect(x, y, x+w, y+h, true)
			surface.DrawTexturedRect(X * -1, Y * -1, scrW, scrH)
		render.SetScissorRect(0, 0, 0, 0, false)
	end
   
   draw.RoundedBox(0,x,y,w,h,Color(0,0,0,205))
   surface.SetDrawColor(0,0,0)
   surface.DrawOutlinedRect(x,y,w,h)
   
end




Credit to Chessnut.

Gave me this error:

[ERROR] addons/blurryvision/lua/autorun/client/cl_main.lua:34: attempt to perform arithmetic on local ‘x’ (a nil value)

  1. DrawBlurRect - addons/blurryvision/lua/autorun/client/cl_main.lua:34
  2. fn - addons/blurryvision/lua/autorun/client/cl_main.lua:46
    3. unknown - addons/ulib/lua/ulib/shared/hook.lua:179

Can you post the code you wrote?

You can’t expect us to magically figure something out…

Well, your the one who gave me the code… But here



local blur = Material("pp/blurscreen")
local function DrawBlurRect(x, y, w, h)
	local X, Y = 0,0

	surface.SetDrawColor(255,255,255)
	surface.SetMaterial(blur)

	for i = 1, 5 do
		blur:SetFloat("$blur", (i / 3) * (5))
		blur:Recompute()

		render.UpdateScreenEffectTexture()

		render.SetScissorRect(x, y, x+w, y+h, true)
			surface.DrawTexturedRect(X * -1, Y * -1, scrW, scrH)
		render.SetScissorRect(0, 0, 0, 0, false)
	end
   
   draw.RoundedBox(0,x,y,w,h,Color(0,0,0,205))
   surface.SetDrawColor(0,0,0)
   surface.DrawOutlinedRect(x,y,w,h)
   
end


You’re supposed to use it like this after pasting the code somewhere in the file:





hook.Add( "HUDPaint", "longdick", function()


    DrawBlurRect( 0, 0, 200, 200 )


end)




Isn’t that going to be a bit FPS heavy? Considering its drawing the material 5 times in a HUDPaint hook?

Still gives me this error even with that code

[ERROR] addons/blurryvision/lua/autorun/client/cl_main.lua:39: bad argument #4 to ‘DrawTexturedRect’ (number expected, got nil)

  1. DrawTexturedRect - [C]:-1
  2. DrawBlurRect - addons/blurryvision/lua/autorun/client/cl_main.lua:39
    3. fn - addons/blurryvision/lua/autorun/client/cl_main.lua:52
    4. unknown - addons/ulib/lua/ulib/shared/hook.lua:179

surface.DrawTexturedRect(X * -1, Y * -1, scrW, scrH)

Shouldn’t scrW and scrH be ScrW() and ScrH() ?

THAT WORKS! THANKS SO MUCH!

Ooh you’re right. I was kind of in a rush when I gave that example.

You’re*

Sorry… had to.

What’s wrong with you?