Blur

I got some questions about layering blur under a roundedbox. This is actually the first time im using blur so yeah.
For example i want a layer behind this roundedbox. How would i do this?


draw.RoundedBox( 1500, 1500, 1500, 1500, 1500, Color(255, 255, 255, 255) ) 


surface.DrawBlur = function(x, y, w, h, amount)
	surface.SetDrawColor(color_white)
	surface.SetMaterial(blur)

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

		render.UpdateScreenEffectTexture()

		render.SetScissorRect(x, y, x + w, y + h, true)
			surface.DrawTexturedRect(0, 0, ScrW(), ScrH())
		render.SetScissorRect(0, 0, 0, 0, false)
	end
end



surface.DrawBlur(1500, 1500, 1500, 1500)
draw.RoundedBox(1500, 1500, 1500, 1500, 1500, Color(0, 0, 0, 150))

That would draw a blurred rect with a “circle” inside



local function DrawBlur( p, a, d )
	local x, y = p:LocalToScreen(0, 0)
	surface.SetDrawColor( 255, 255, 255 )
	surface.SetMaterial( blur )
	for i = 1, d do
		blur:SetFloat( "$blur", (i / d ) * ( a ) )
		blur:Recompute()
		render.UpdateScreenEffectTexture()
		surface.DrawTexturedRect( -x, -y, ScrW(), ScrH() )
	end
end




Bleh.Paint = function( self, w, h )
	DrawBlur(self, 1, 2)
	draw.RoundedBox( 1500, 1500, 1500, 1500, 1500, Color(255, 255, 255, 255) )
end


I used this code for my scoreboard which used derma and I think it will work like that (not sure though, might have miss or screwed up something knowing me). There is a link to HUD blur with a Draw.RoundedBoxEx, here is the link: http://forum.facepunch.com/showthread.php?t=1464767

Can’t you do this with the stencil library?

I’m just starting to scratch the surface of GUI so be free to rate boxes :stuck_out_tongue:

EDIT: I’m mainly looking at this line



v:SetModelScale(1.0+math.Rand(0.01,0.013),0) --slightly fuzzy, looks better this way


I want to put this in a other function would this work aswell?


 hook.Add("HUDPaint", "HUD", function()
	local client = LocalPlayer() 
	local curHealth = client:Health() 

	if (health == curHealth) then 
		if (time ~= 0) then
			if (CurTime() > time) then
				return 
			end
		else 
			time = CurTime() + 0
		end
	else 
		health = 100
		time = 0
	end
	
end)  

But the method of creating global function in the surface list will make his addon vulnerable as everyone will be able to call it where the addon is installed. I would go for a local function instead.

It doesn’t appear?


 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(5, 50, 50, 50, 50,Color(0,0,0,205))
   surface.SetDrawColor(0,0,0)
   surface.DrawOutlinedRect(50, 50, 50, 50)
   
end