CreateClientConVar( "pp_dof_initlength", "256", false, false )
CreateClientConVar( "pp_dof_spacing", "512", false, false )

// Global table to hold the DoF effect
DOF_Ents 		= {}
DOF_SPACING 	= 0
DOF_OFFSET 		= 0

local NUM_DOF_NODES = 16

function DOF_Kill( )

	for k, v in pairs(DOF_Ents) do
	
		if (v:IsValid()) then
			v:Remove()
		end
	
	end

	DOFModeHack( false )
	
end


function DOF_Start()

	DOF_Kill()
	
	for i=0, NUM_DOF_NODES do
		
		local effectdata = EffectData()
			effectdata:SetScale( i )
		util.Effect( "dof_node", effectdata )
	
	end
	
	DOFModeHack( true )

end


function DOF_Think( )

	local ply = LocalPlayer()
	if (ply == NULL) then return end
	DOF_SPACING = tonumber( ply:GetInfo("pp_dof_spacing") )
	DOF_OFFSET = tonumber( ply:GetInfo("pp_dof_initlength") )

end

hook.Add( "Think", "DOFThink", DOF_Think )


local function pp_dof( player, command, arguments )

	if ( !GAMEMODE:PostProcessPermitted( "dof" ) ) then	return end

	if ( tonumber(arguments[1]) > 0 ) then
		DOF_Start()
	else
		DOF_Kill()
	end

end


concommand.Add( "pp_dof", pp_dof )