css Nightvision

is it possible use the Nightvision from *Counter-Strike Source in gmod?
and if it is possible can somone help me do it?
*

As a matter of facts, yes :

thanks Crazy Quebec



NVON = false
CreateClientConVar("nv_togglespeed", 0.09, true, false)

local Color_Brightness		= 0.8
local Color_Contrast 		= 1.1
local Color_AddGreen		= -0.35
local Color_MultiplyGreen 	= 0.028

local AlphaAdd_Alpha 			= 1
local AlphaAdd_Passes			= 1

local Bloom_Multiply		= 0.3
local Bloom_Darken 			= 0
local Bloom_BlurX			= 0
local Bloom_BlurY			= 22
local Bloom_ColorMul 		= 0.5
local Bloom_Passes			= 1 -- Should be an integer

local matNightVision = Material("effects/nightvision") -- CSS nightvision
matNightVision:SetMaterialFloat( "$alpha", AlphaAdd_Alpha )

local Color_Tab = 
{
	[ "$pp_colour_addr" ] 		= -1,
	[ "$pp_colour_addg" ] 		= Color_AddGreen,
	[ "$pp_colour_addb" ] 		= -1,
	[ "$pp_colour_brightness" ] = Color_Brightness,
	[ "$pp_colour_contrast" ]	= Color_Contrast,
	[ "$pp_colour_colour" ] 	= 0,
	[ "$pp_colour_mulr" ] 		= 0 ,
	[ "$pp_colour_mulg" ] 		= Color_MultiplyGreen,
	[ "$pp_colour_mulb" ] 		= 0
}
local CurScale = 0.2
local sndOn = Sound( "items/nvg_on.wav" )
local sndOff = Sound( "items/nvg_off.wav" )

function NV_FX()
	if LocalPlayer():Alive() and NVON == true then
		if CurScale < 0.995 then 
			CurScale = CurScale + math.Clamp(GetConVarNumber("nv_togglespeed"), 0.01, 1) * (1 - CurScale)
		end
		
		Color_Tab[ "$pp_colour_brightness" ] = CurScale * Color_Brightness
		Color_Tab[ "$pp_colour_contrast" ] = CurScale * Color_Contrast
		DrawColorModify( Color_Tab )
		
		DrawMotionBlur( 0.05, 0.2, 0.023) //0.5, 1.0, 0.003; ( 0.05, 0.2, 0.023)
		for i=1,AlphaAdd_Passes do
			render.UpdateScreenEffectTexture()
			render.SetMaterial( matNightVision )
			render.DrawScreenQuad()
		end
	elseif not LocalPlayer():Alive() then
		surface.PlaySound( sndOff )
		NVON = false
		hook.Remove("RenderScreenspaceEffects", "NV_Render")
		hook.Remove("HUDPaint", "NV_DLight")
	end
end

function NV_DLIGHT()
	if LocalPlayer():Alive() and NVON == true then		
		local dlight = DynamicLight( LocalPlayer():EntIndex() )
		if ( dlight ) then
			local r, g, b, a = 255, 255, 255, 255
			dlight.Pos = LocalPlayer():GetShootPos()
			dlight.r = r
			dlight.g = g
			dlight.b = b
			dlight.Brightness = 1
			dlight.Size = 512
			dlight.Decay = 512
			dlight.DieTime = CurTime() + 0.1
		end
		DrawMaterialOverlay("models/shadertest/shader3.vmt", 0.0001)
	end
end

local function ToggleNightVision()
	if NVON == true then
		NVON = false
		
		surface.PlaySound( sndOff )
		hook.Remove("RenderScreenspaceEffects", "NV_Render")
		hook.Remove("HUDPaint", "NV_DLight")
	else
		NVON = true
		
		CurScale = 0.2
		surface.PlaySound( sndOn )
		hook.Add("RenderScreenspaceEffects", "NV_Render", NV_FX)
		hook.Add("HUDPaint", "NV_DLight", NV_DLIGHT)
	end
end
concommand.Add( "nv_toggle", ToggleNightVision )



You can use mine if you want, create a file called nvscript.lua, then put it into garrysmod/garrysmod/lua/autorun/client (create folders if needed) and write nv_toggle in console.

P.S. I take no credits for putting together 2 scripts and adding the blur-everything-out effect, the turn on blackness decrease/sound effects are by TetaBonita and the actual darkness elimination is by blackops7799

In-game pic (wait for it to load):
[img_thumb]http://filesmelt.com/dl/comparison12.jpg[/img_thumb]

But apparently that blur effect rapes fps, so here’s a non-fps-raping version:



NVON = false
CreateClientConVar("nv_togglespeed", 0.09, true, false)

local Color_Brightness		= 0.8
local Color_Contrast 		= 1.1
local Color_AddGreen		= -0.35
local Color_MultiplyGreen 	= 0.028

local AlphaAdd_Alpha 			= 1
local AlphaAdd_Passes			= 1

local Bloom_Multiply		= 0.3
local Bloom_Darken 			= 0
local Bloom_BlurX			= 0
local Bloom_BlurY			= 22
local Bloom_ColorMul 		= 0.5
local Bloom_Passes			= 1 -- Should be an integer

local matNightVision = Material("effects/nightvision") -- CSS nightvision
matNightVision:SetMaterialFloat( "$alpha", AlphaAdd_Alpha )

local Color_Tab = 
{
	[ "$pp_colour_addr" ] 		= -1,
	[ "$pp_colour_addg" ] 		= Color_AddGreen,
	[ "$pp_colour_addb" ] 		= -1,
	[ "$pp_colour_brightness" ] = Color_Brightness,
	[ "$pp_colour_contrast" ]	= Color_Contrast,
	[ "$pp_colour_colour" ] 	= 0,
	[ "$pp_colour_mulr" ] 		= 0 ,
	[ "$pp_colour_mulg" ] 		= Color_MultiplyGreen,
	[ "$pp_colour_mulb" ] 		= 0
}
local CurScale = 0.2
local sndOn = Sound( "items/nvg_on.wav" )
local sndOff = Sound( "items/nvg_off.wav" )

function NV_FX()
	if LocalPlayer():Alive() and NVON == true then
		if CurScale < 0.995 then 
			CurScale = CurScale + math.Clamp(GetConVarNumber("nv_togglespeed"), 0.01, 1) * (1 - CurScale)
		end
		
		Color_Tab[ "$pp_colour_brightness" ] = CurScale * Color_Brightness
		Color_Tab[ "$pp_colour_contrast" ] = CurScale * Color_Contrast
		DrawColorModify( Color_Tab )
		
		DrawMotionBlur( 0.05, 0.2, 0.023) //0.5, 1.0, 0.003; ( 0.05, 0.2, 0.023)
		for i=1,AlphaAdd_Passes do
			render.UpdateScreenEffectTexture()
			render.SetMaterial( matNightVision )
			render.DrawScreenQuad()
		end
	elseif not LocalPlayer():Alive() then
		surface.PlaySound( sndOff )
		NVON = false
		hook.Remove("RenderScreenspaceEffects", "NV_Render")
		hook.Remove("HUDPaint", "NV_DLight")
	end
end

function NV_DLIGHT()
	if LocalPlayer():Alive() and NVON == true then		
		local dlight = DynamicLight( LocalPlayer():EntIndex() )
		if ( dlight ) then
			local r, g, b, a = 255, 255, 255, 255
			dlight.Pos = LocalPlayer():GetShootPos()
			dlight.r = r
			dlight.g = g
			dlight.b = b
			dlight.Brightness = 1
			dlight.Size = 512
			dlight.Decay = 512
			dlight.DieTime = CurTime() + 0.1
		end
	end
end

local function ToggleNightVision()
	if NVON == true then
		NVON = false
		
		surface.PlaySound( sndOff )
		hook.Remove("RenderScreenspaceEffects", "NV_Render")
		hook.Remove("HUDPaint", "NV_DLight")
	else
		NVON = true
		
		CurScale = 0.2
		surface.PlaySound( sndOn )
		hook.Add("RenderScreenspaceEffects", "NV_Render", NV_FX)
		hook.Add("HUDPaint", "NV_DLight", NV_DLIGHT)
	end
end
concommand.Add( "nv_toggle", ToggleNightVision )