void CASWNightVisionSelfIllumProxy::OnBind( void *pC_BaseEntity )
{
	Assert( m_pResult );
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer || !pC_BaseEntity )
	{
		SetFloatResult( 0.0f );
		return;
	}

	C_ASW_Marine *pMarine = pPlayer->GetMarine();
	if ( !pMarine )
	{
		SetFloatResult( 0.0f );
		return;
	}

	if ( C_JaS_Alien_Controller::AutoList().Count() )
	{
		C_JaS_Alien_Controller *pAlienController = dynamic_cast<C_JaS_Alien_Controller *>( C_JaS_Alien_Controller::AutoList().Head()->GetEntity() );
		if ( pAlienController->m_hBuzzerOverride )
		{
			SetFloatResult( 255.0f );
			return;
		}
	}

	C_BaseCombatWeapon*	pExtraItem = pMarine->GetWeapon( 2 );
	if ( pExtraItem && pExtraItem->Classify() == CLASS_ASW_NIGHT_VISION )
	{
		C_ASW_Weapon_Night_Vision *pVision = assert_cast<CASW_Weapon_Night_Vision*>( pExtraItem );
		float flVisionAlpha = pVision->m_flVisionAlpha;
		if ( flVisionAlpha != 0.0f )
		{
			SetFloatResult( flVisionAlpha / 255.0f * asw_night_vision_self_illum_multiplier.GetFloat() );
			return;
		}
	}

	if ( pPlayer->IsSniperScopeActive() && g_bRenderingGlows )
	{
		SetFloatResult( asw_sniper_scope_self_illum_multiplier.GetFloat() );
		return;
	}

	SetFloatResult( 0.0f );
}
void CASWViewRender::PerformNightVisionEffect( const CViewSetup &view )
{
	C_ASW_Player *pPlayer = C_ASW_Player::GetLocalASWPlayer();
	if ( !pPlayer )
		return;

	C_ASW_Marine *pMarine = pPlayer->GetMarine();
	if ( !pMarine )
		return;

	float flVisionAlpha = 0.0f;
	float flFlashAlpha = 0.0f;
	C_BaseCombatWeapon*	pExtraItem = pMarine->GetWeapon( 2 );
	if ( pExtraItem && pExtraItem->Classify() == CLASS_ASW_NIGHT_VISION )
	{
		C_ASW_Weapon_Night_Vision *pVision = assert_cast<CASW_Weapon_Night_Vision*>( pExtraItem );
		flVisionAlpha = pVision->UpdateVisionAlpha();
		flFlashAlpha = pVision->UpdateFlashAlpha();
	}

	if ( flVisionAlpha > 0 )
	{
		IMaterial *pMaterial = materials->FindMaterial( "effects/nightvision", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( pMaterial )
		{
			byte overlaycolor[4] = { 0, 255, 0, 255 };

			UpdateScreenEffectTexture( 0, view.x, view.y, view.width, view.height );

			overlaycolor[3] = flVisionAlpha;

			render->ViewDrawFade( overlaycolor, pMaterial );

			CMatRenderContextPtr pRenderContext( materials );
			pRenderContext->DrawScreenSpaceQuad( pMaterial );
			render->ViewDrawFade( overlaycolor, pMaterial );
			pRenderContext->DrawScreenSpaceQuad( pMaterial );
		}
		IMaterial *pNoiseMaterial = materials->FindMaterial( "effects/nightvision_noise", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( pNoiseMaterial )
		{
			byte overlaycolor[4] = { 255, 255, 255, 255 };
			overlaycolor[3] = MAX( flFlashAlpha, 16.0f );
			CMatRenderContextPtr pRenderContext( materials );
			render->ViewDrawFade( overlaycolor, pNoiseMaterial );
		}
	}
	if ( flFlashAlpha > 0 )
	{
		IMaterial *pMaterial = materials->FindMaterial( "effects/nightvision_flash", TEXTURE_GROUP_CLIENT_EFFECTS, true );

		if ( pMaterial )
		{
			byte overlaycolor[4] = { 255, 255, 255, 255 };
			overlaycolor[3] = flFlashAlpha;
			CMatRenderContextPtr pRenderContext( materials );
			render->ViewDrawFade( overlaycolor, pMaterial );
		}		
	}
}