

/*---------------------------------------------------------
   Initializes the effect. The data is a table of data 
   which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )
	
	local ent = data:GetEntity()
	if ( ent == NULL ) then return end
	
	self.Entity:SetModel( ent:GetModel() )
	self.Entity:SetPos( ent:GetPos() )
	self.Entity:SetAngles( ent:GetAngles() )
	self.Entity:SetParent( ent )
	
	self.Time = 0.5
	self.LifeTime = CurTime() + self.Time
	
end


/*---------------------------------------------------------
   THINK
   Returning false makes the entity die
---------------------------------------------------------*/
function EFFECT:Think( )

	return ( self.LifeTime > CurTime() ) 
	
end

local matOverlay = Material( "models/spawn_effect" )

/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render()
	
	// Todo, some kind of non refraction crappy additive blended crap crap
	if ( render.GetDXLevel() < 8 ) then return end
	
	local Fraction = (self.LifeTime - CurTime()) / self.Time
	//Fraction = math.Clamp( Fraction * 2, 0, 1 )
	//self.Entity:SetColor( 255, 255, 255, Fraction * 255 )

	Fraction = Fraction ^ 3
	
	matOverlay:SetMaterialFloat( "$refractamount", Fraction )
	
	render.UpdateScreenEffectTexture()
	
	// Place the camera a tiny bit closer to the entity - so it draw a tiny bit bigger
	local EyeNormal = self.Entity:GetPos() - EyePos()
	local Distance = EyeNormal:Length()
	EyeNormal:Normalize()
	
	local Pos = EyePos() + EyeNormal * Distance * 0.01
	cam.Start3D( Pos, EyeAngles() )
	
	// White Outline (big)
	SetMaterialOverride( matOverlay )
		self.Entity:DrawModel()
	SetMaterialOverride( 0 )
	
	cam.End3D()

end



