 local MatSurfacePropTranslate = {
  [MAT_ANTLION]        = util.GetSurfaceIndex("antlion"),
            [MAT_BLOODYFLESH]    = util.GetSurfaceIndex("bloodyflesh"),
            [MAT_CONCRETE]        = util.GetSurfaceIndex("concrete"),
            [MAT_DIRT]            = util.GetSurfaceIndex("dirt"),
            [MAT_FLESH]            = util.GetSurfaceIndex("flesh"),
            [MAT_GRATE]            = util.GetSurfaceIndex("metalgrate"),
            [MAT_ALIENFLESH]    = util.GetSurfaceIndex("alienflesh"),
            [MAT_CLIP]            = util.GetSurfaceIndex("player_control_clip"),
            [MAT_PLASTIC]        = util.GetSurfaceIndex("plastic"),
            [MAT_METAL]            = util.GetSurfaceIndex("metal"),
            [MAT_SAND]            = util.GetSurfaceIndex("sand"),
            [MAT_FOLIAGE]        = util.GetSurfaceIndex("foliage"),
            [MAT_COMPUTER]        = util.GetSurfaceIndex("computer"),
            [MAT_SLOSH]            = util.GetSurfaceIndex("water"),
            [MAT_TILE]            = util.GetSurfaceIndex("tile"),
            [MAT_VENT]            = util.GetSurfaceIndex("metalvent"),
            [MAT_WOOD]            = util.GetSurfaceIndex("wood"),
            [MAT_GLASS]            = util.GetSurfaceIndex("glass")}
			
function EFFECT:Init( data )
	local MatType = data:GetSurfaceProp()
	if MatType == MAT_DIRT then
		self:Dirt(data)
	end	
	if MatType == MAT_CONCRETE then
		self:Concrete(data)
	end	
	if MatType == MAT_METAL then	
		self:Metal(data)
	end
end

function EFFECT:Concrete(data)
	local Norm = data:GetNormal()
	local vOffset = data:GetOrigin()
	local Scale = data:GetScale()

	local emitter = ParticleEmitter( vOffset )
    local SurfaceColor = render.GetSurfaceColor( vOffset + Norm, vOffset - Norm * 60 ) * 255

	SurfaceColor.r = math.Clamp( SurfaceColor.r + 40, 0, 255 )
	SurfaceColor.g = math.Clamp( SurfaceColor.g + 40, 0, 255 )
	SurfaceColor.b = math.Clamp( SurfaceColor.b + 40, 0, 255 )
	
	local fx 	= EffectData()
	fx:SetStart(vOffset)
	fx:SetOrigin(vOffset)
	fx:SetNormal(Norm)
	fx:SetScale(Scale)
	util.Effect("ground_hit_concretedebris",fx)	
	
	for i=0, math.random(Scale,Scale + 10) do
		local Debris = emitter:Add( "effects/fleck_cement"..math.random(1,2), vOffset )
		Debris:SetVelocity( data:GetNormal() * math.random( 0, 90 * Scale) + VectorRand() * math.Clamp(100 * Scale,120, 220) )
		Debris:SetDieTime( math.random( 0.6, 1) )
		Debris:SetStartAlpha( 255 )
		Debris:SetEndAlpha( 0 )
		Debris:SetStartSize( math.random(1,2.5*Scale) )
		Debris:SetRoll( math.Rand(0, 360) )
		Debris:SetRollDelta( math.Rand(-5, 5) )			
		Debris:SetAirResistance( 50 ) 			 			
		Debris:SetColor(SurfaceColor.r,SurfaceColor.g,SurfaceColor.b)
		Debris:SetGravity( Vector( 0, 0, -600) ) 
		Debris:SetCollide( true )
		Debris:SetBounce( 1 )			
	end
	
	for i=0, math.random(Scale,Scale + 10) do
		local Smoke = emitter:Add( "particle/particle_composite", vOffset )
		Smoke:SetVelocity( data:GetNormal() * math.random( 0, 30 * Scale) + VectorRand() * 15 * Scale )
		Smoke:SetDieTime( math.Rand( 0.15 , 0.5 ) * Scale )
		Smoke:SetStartAlpha( 150 )
		Smoke:SetEndAlpha( 0 )
		Smoke:SetStartSize( 1 )
		Smoke:SetEndSize( math.Clamp(30*Scale,0,100) )
		Smoke:SetRoll( math.Rand(150, 360) )
		Smoke:SetRollDelta( math.Rand(-2, 2) )			
		Smoke:SetAirResistance( 120 ) 			 
		Smoke:SetGravity( Vector( math.Rand(-50, 50) * Scale, math.Rand(-50, 50) * Scale, math.Rand(0, -100) ) ) 			
		Smoke:SetColor(SurfaceColor.r,SurfaceColor.g,SurfaceColor.b)
	end
	
	if math.random(1, 1 + 5 - Scale) == 1 then
		local Flash = emitter:Add( "effects/muzzleflash"..math.random(1,4).."", vOffset )
		Flash:SetVelocity( data:GetNormal() * 100 )
		Flash:SetAirResistance( 200 )
		Flash:SetDieTime( 0.1 )
		Flash:SetStartAlpha( 255 )
		Flash:SetEndAlpha( 0 )
		Flash:SetStartSize( 0 )
		Flash:SetEndSize( math.Rand( 5, 10 ) * Scale )
		Flash:SetRoll( math.Rand(180,480) )
		Flash:SetRollDelta( math.Rand(-1,1) )
		Flash:SetColor(255,255,255)	
	end
	
	emitter:Finish()
end	

function EFFECT:Metal(data)
	local Norm = data:GetNormal()
	local vOffset = data:GetOrigin()
	local Scale = data:GetScale()

	local emitter = ParticleEmitter( vOffset )
    local SurfaceColor = render.GetSurfaceColor( vOffset + Norm, vOffset - Norm * 60 ) * 255
	
	for i=0, math.random(Scale + 5,Scale + 20) do
		local particle = emitter:Add("effects/yellowflare", vOffset)
		particle:SetVelocity( data:GetNormal() * math.random( 0, 90 * Scale) + VectorRand() * math.Clamp(100 * Scale,120, 220) )
		particle:SetDieTime( math.Rand(0.1, 0.25) * Scale )
		particle:SetStartAlpha( 255 )
		particle:SetEndAlpha( 0 )
		particle:SetStartSize( math.random(1,5 * Scale) )
		particle:SetRoll( math.Rand(0, 360) )
		particle:SetRollDelta( math.Rand(-5, 5) )			
		particle:SetAirResistance( 550 ) 			 			
		particle:SetGravity( Vector( 0, 0, -100) ) 
		particle:SetCollide( true )
		particle:SetStartLength(0)
		particle:SetEndLength(math.Rand(0.31, 0.55) * Scale)
		particle:SetVelocityScale(true)
		particle:SetBounce( 1 )			
	end
	
	if math.random(1, 1 + 5 - Scale) == 1 then
		local Flash = emitter:Add( "effects/muzzleflash"..math.random(1,4).."", vOffset )
		Flash:SetVelocity( data:GetNormal() * 100 )
		Flash:SetAirResistance( 200 )
		Flash:SetDieTime( 0.1 )
		Flash:SetStartAlpha( 255 )
		Flash:SetEndAlpha( 0 )
		Flash:SetStartSize( 0 )
		Flash:SetEndSize( math.Rand( 5, 10 ) * Scale )
		Flash:SetRoll( math.Rand(180,480) )
		Flash:SetRollDelta( math.Rand(-1,1) )
		Flash:SetColor(255,255,255)	
	end
	
	for i = 1,math.random(Scale,Scale + 10) do
		local particle = emitter:Add( "particle/particle_smokegrenade", vOffset )
		particle:SetVelocity( math.Clamp(math.Rand( Scale * 5, Scale * 25 ),0,60) * i * data:GetNormal() + 8 * VectorRand() )
		particle:SetAirResistance(400)
		particle:SetGravity( Vector(0, 0, -math.Rand( 10, 100 )) )
		particle:SetDieTime( math.Rand( 1.5, 3 ) )
		particle:SetStartAlpha( math.Rand( 150, 255 ) )
		particle:SetEndAlpha( 0 )
		particle:SetStartSize( i * math.Rand( 1, 3 ) + Scale * 2 )
		particle:SetEndSize( i * math.Rand( 3, 8 ) + Scale * 2 )
		particle:SetRoll( math.Rand( -25, 25 ) )
		particle:SetRollDelta( math.Rand( -0.05, 0.05 ) )
		particle:SetColor(SurfaceColor.r,SurfaceColor.g,SurfaceColor.b)
		particle:SetCollide(true)
		particle:SetLighting(true)
	end
	
	emitter:Finish()
end	

function EFFECT:Dirt(data)
	local Norm = data:GetNormal()
	local vOffset = data:GetOrigin()
	local Scale = data:GetScale()

	local emitter = ParticleEmitter( vOffset )
    local SurfaceColor = render.GetSurfaceColor( vOffset + Norm, vOffset - Norm * 60 ) * 255

	SurfaceColor.r = math.Clamp( SurfaceColor.r + 40, 0, 255 )
	SurfaceColor.g = math.Clamp( SurfaceColor.g + 40, 0, 255 )
	SurfaceColor.b = math.Clamp( SurfaceColor.b + 40, 0, 255 )
	
	for i = 1,math.random(Scale,Scale + 10) do
		local particle = emitter:Add( "particle/particle_smokegrenade", vOffset )
		particle:SetVelocity( math.Clamp(math.Rand( Scale * 25, Scale * 55 ),0,60) * i * data:GetNormal() + 8 * VectorRand() )
		particle:SetAirResistance(400)
		particle:SetGravity( Vector(0, 0, -math.Rand( 10, 100 )) )
		particle:SetDieTime( math.Rand( 1.5, 3 ) )
		particle:SetStartAlpha( math.Rand( 150, 255 ) )
		particle:SetEndAlpha( 0 )
		particle:SetStartSize( i * math.Rand( 1, 3 ) + Scale * 2 )
		particle:SetEndSize( i * math.Rand( 3, 8 ) + Scale * 2 )
		particle:SetRoll( math.Rand( -25, 25 ) )
		particle:SetRollDelta( math.Rand( -0.05, 0.05 ) )
		particle:SetColor(SurfaceColor.r,SurfaceColor.g,SurfaceColor.b)
		particle:SetCollide(true)
		particle:SetLighting(true)
	end
	
	for i=0, math.random(Scale,Scale + 10) do
		local Smoke = emitter:Add( "particle/particle_composite", vOffset )
		Smoke:SetVelocity( data:GetNormal() * math.random( 0, 30 * Scale) + VectorRand() * 15 * Scale )
		Smoke:SetDieTime( math.Rand( 0.15 , 0.5 ) * Scale )
		Smoke:SetStartAlpha( 150 )
		Smoke:SetEndAlpha( 0 )
		Smoke:SetStartSize( 1 )
		Smoke:SetEndSize( math.Clamp(30*Scale,0,100) )
		Smoke:SetRoll( math.Rand(150, 360) )
		Smoke:SetRollDelta( math.Rand(-2, 2) )			
		Smoke:SetAirResistance( 120 ) 			 
		Smoke:SetGravity( Vector( math.Rand(-50, 50) * Scale, math.Rand(-50, 50) * Scale, math.Rand(0, -100) ) ) 			
		Smoke:SetColor(105,100,90)
	end

	for i=0, math.random(Scale,Scale + 10) do
		local Debris = emitter:Add( "effects/fleck_cement"..math.random(1,2), vOffset )
		Debris:SetVelocity( data:GetNormal() * math.random( 0, 90 * Scale) + VectorRand() * math.Clamp(100 * Scale,120, 220) )
		Debris:SetDieTime( math.random( 0.6, 1) )
		Debris:SetStartAlpha( 255 )
		Debris:SetEndAlpha( 0 )
		Debris:SetStartSize( math.random(1,2.5*Scale) )
		Debris:SetRoll( math.Rand(0, 360) )
		Debris:SetRollDelta( math.Rand(-5, 5) )			
		Debris:SetAirResistance( 50 ) 			 			
		Debris:SetColor(SurfaceColor.r,SurfaceColor.g,SurfaceColor.b)
		Debris:SetGravity( Vector( 0, 0, -600) ) 
		Debris:SetCollide( true )
		Debris:SetBounce( 1 )			
	end
	
	emitter:Finish()
end

function EFFECT:Think()
	return false
end


function EFFECT:Render()
end