



/*---------------------------------------------------------
   Register the convars that will control this effect
---------------------------------------------------------*/   
CreateClientConVar( "pp_mat_overlay", "0", false, false )
CreateClientConVar( "pp_mat_overlay_texture", "models/shadertest/shader4", false, false )
CreateClientConVar( "pp_mat_overlay_refractamount", "0.3", false, false )

local lastTexture = nil
local mat_Overlay = nil

function DrawMaterialOverlay( texture, refractamount )

	if (texture ~= lastTexture or mat_Overlay == nil) then
		mat_Overlay = Material( texture )
		lastTexture = texture
	end
	
	if (mat_Overlay == nil) then return end

	render.UpdateScreenEffectTexture()

	mat_Overlay:SetMaterialFloat("$envmap",			0)
	mat_Overlay:SetMaterialFloat("$envmaptint",		0)
	mat_Overlay:SetMaterialFloat("$refractamount",	refractamount)
	mat_Overlay:SetMaterialInt("$ignorez",		1)

	render.SetMaterial( mat_Overlay )
	render.DrawScreenQuad()
	
end

local function DrawInternal()

	if ( GetConVarNumber( "pp_mat_overlay" ) == 0 ) then return end
	if ( !GAMEMODE:PostProcessPermitted( "material overlay" ) ) then return end

	DrawMaterialOverlay( 
			GetConVarString( "pp_mat_overlay_texture" ), 
			GetConVarNumber( "pp_mat_overlay_refractamount" )
		);

end

hook.Add( "RenderScreenspaceEffects", "RenderMaterialOverlay", DrawInternal )