RoundedBox Blur

-snip everything-

I have it fixed. It was easy as hell, not sure why I didn’t get it earlier.


local blur = Material("pp/blurscreen")

local function DrawBlurPanel(panel, amount, heavyness)
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(blur)

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

		render.UpdateScreenEffectTexture()
		surface.DrawTexturedRect(x * -1, y * -1, ScrW(), ScrH())
	end
end

local function DrawBlurRect(x, y, w, h, amount, heavyness)
	surface.SetDrawColor(255, 255, 255, 255)
	surface.SetMaterial(blur)

	for i = 1, heavyness 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 * -1, 0 * -1, ScrW(), ScrH())
		render.SetScissorRect(0, 0, 0, 0, false)
	end
end

DrawBlurRect(0, 0, ScrW(), 25, 5, 2)

However, I get the following:

As you can see, it’s just blurred. How can I make it darker?

RoundedBox uses images to get the rounded effect, so my suggestion would be to create a stencil using a poly drawn from DrawPoly that matches the rounded box, and use the stencil to draw the blur.

-snip all-

added to op

Well, the way gmod makes the blur darker is simply by drawing a transparent black rectangle over the blur, as you can see here. Pretty simple, but that took me ages to figure out, mainly because I’m an idiot

Would that not make performance go up a bit?

Well yeah, but hardly by anything - much less than recomputing blur or drawing multiple textured rects would (both of which you are already doing)

Also, I think it’s the only option if you wanted to darken the blur

[editline]24th April 2016[/editline]

It’s not like drawing boxes using that function is something nobody ever does, in fact, the RoundedBox function uses it internally multiple times, such as here. I usually use it for all kinds of stuff since I think it’s the fastest way

I see, thanks mate! :slight_smile: