Drawing a material to the screen (with a specific alpha)

Ok, i’ve tried two different ways, to no avail:

Render:



render.SetBlend(mat_alpha)
render.SetMaterial(Pain)
render.DrawScreenQuad()
render.SetBlend(1)


Draw:



local QuadTable = {} 
 
QuadTable.texture 	= surface.GetTextureID( "effects/screenpain" )
QuadTable.color		= Color( 255, 255, 255, mat_alpha*255 ) 
 
QuadTable.x = 0 
QuadTable.y = 0 
QuadTable.w = ScrW()
QuadTable.h = ScrH()
draw.TexturedQuad( QuadTable )


Both draw the texture on the screen, only it’s at full alpha, which isn’t what I want. I’ve checked mat_alpha, and that seems to be fine.
VMT of the texture looks like this, in case i’ve bodged it…



"UnlitGeneric"
{
	"$basetexture" "effects/screenpain"
	"$additive" 1
	"$nolod" 1
	"$translucent" 1
	"$vertexalpha" 1
}


Any ideas?

Try this.

I think this will work for what your doing.
[lua] RunConsoleCommand(“pp_mat_overlay”, “effects/screenpain”); [/lua]
Hopefully that helped.

As he said, try this:

[lua]surface.SetDrawColor(255, 255, 255, mat_alpha)
surface.SetMaterial(Pain)
surface.DrawTexturedRect(0, 0, ScrW(), ScrH())[/lua]

No.

More complete example:
[lua]
local Pain = surface.GetTextureID( “effects/screenpain” );
hook.Add(“HUDPaint”,“PainDraw”,function()
if (PAIN_SHOULD_DRAW) then
surface.SetDrawColor(255, 255, 255, mat_alpha*255);
surface.SetMaterial(Pain);
surface.DrawTexturedRect(0, 0, ScrW(), ScrH());
end
end);[/lua]

Tried it. Didn’t seem to work. I’m going to go ahead and see if it works in HUDPaint instead of RenderScreenSpaceEffects, but that can’t be the problem since it still renders, just at full alpha all the time

are you sure mat_alpha isn’t 1?
And surface is supposed to be used in 2d rendering, ie HUDPaint.

Set render.SetBlend to less than 1?

mat_alpha is usually between 0.3 and 0.8, constantly changing. I’ve definitely debugged that one.
Putting it in HUDPaint failed as well.

Yes but…

You’re setting it to mat_alpha but then a few lines down are setting it to 1.

He sets it back to 1 after he draws the screenquad.

Of course, I’m blind.