//=============================================================================== //=============================================================================== bool CBaseFlashlightEffect::UpdateDefaultFlashlightState( FlashlightState_t& state, const Vector &vecPos, const Vector &vecForward, const Vector &vecRight, const Vector &vecUp ) { VPROF_BUDGET( __FUNCTION__, VPROF_BUDGETGROUP_SHADOW_DEPTH_TEXTURING ); // No esta encendida if ( !IsOn() ) return false; if ( ComputeLightPosAndOrientation( vecPos, vecForward, vecRight, vecUp, state.m_vecLightOrigin, state.m_quatOrientation ) == false ) return false; state.m_fQuadraticAtten = m_flQuadratic; state.m_fConstantAtten = m_flConstant; // Color de la luz state.m_Color[0] = 1.0f; state.m_Color[1] = 1.0f; state.m_Color[2] = 1.0f; state.m_Color[3] = m_flAlpha; // Distancia y FOV state.m_NearZ = m_flNear + r_flashlightnearoffsetscale.GetFloat() * m_flCurrentPullBackDist; state.m_FarZ = state.m_FarZAtten = m_flFar; state.m_fHorizontalFOVDegrees = state.m_fVerticalFOVDegrees = m_flFOV; // Es el efecto de un "MuzzleFlash" if ( m_bMuzzleFlashEnabled ) { state.m_pSpotlightTexture = m_nMuzzleFlashTexture; state.m_fLinearAtten = m_flMuzzleFlashBrightness; state.m_bShadowHighRes = false; state.m_nShadowQuality = 0; state.m_flShadowFilterSize = 2.0f; } // Es una linterna normal else { state.m_pSpotlightTexture = m_nFlashlightTexture; state.m_fLinearAtten = m_flBrightness; state.m_bShadowHighRes = true; state.m_nShadowQuality = 1; state.m_flShadowFilterSize = r_projectedtexture_filter.GetFloat(); } state.m_pProjectedMaterial = NULL; state.m_nSpotlightTextureFrame = 0; // Propiedades de las sombras generadas state.m_bEnableShadows = m_bCastsShadows; state.m_flShadowAtten = r_flashlightshadowatten.GetFloat(); state.m_flShadowSlopeScaleDepthBias = g_pMaterialSystemHardwareConfig->GetShadowSlopeScaleDepthBias(); state.m_flShadowDepthBias = g_pMaterialSystemHardwareConfig->GetShadowDepthBias(); return true; }
bool CFlashlightEffect::UpdateDefaultFlashlightState( FlashlightState_t& state, const Vector &vecPos, const Vector &vecForward, const Vector &vecRight, const Vector &vecUp, bool castsShadows, bool bTracePlayers ) { VPROF_BUDGET( __FUNCTION__, VPROF_BUDGETGROUP_SHADOW_DEPTH_TEXTURING ); if ( !m_bIsOn ) { // return; } if ( ComputeLightPosAndOrientation( vecPos, vecForward, vecRight, vecUp, state.m_vecLightOrigin, state.m_quatOrientation, bTracePlayers ) == false ) { return false; } state.m_fQuadraticAtten = r_flashlightquadratic.GetFloat(); bool bFlicker = false; #ifdef HL2_EPISODIC C_BaseHLPlayer *pPlayer = (C_BaseHLPlayer *)C_BasePlayer::GetLocalPlayer(); if ( pPlayer ) { float flBatteryPower = ( pPlayer->m_HL2Local.m_flFlashBattery >= 0.0f ) ? ( pPlayer->m_HL2Local.m_flFlashBattery ) : pPlayer->m_HL2Local.m_flSuitPower; if ( flBatteryPower <= 10.0f ) { float flScale; if ( flBatteryPower >= 0.0f ) { flScale = ( flBatteryPower <= 4.5f ) ? SimpleSplineRemapVal( flBatteryPower, 4.5f, 0.0f, 1.0f, 0.0f ) : 1.0f; } else { flScale = SimpleSplineRemapVal( flBatteryPower, 10.0f, 4.8f, 1.0f, 0.0f ); } flScale = clamp( flScale, 0.0f, 1.0f ); if ( flScale < 0.35f ) { float flFlicker = cosf( gpGlobals->curtime * 6.0f ) * sinf( gpGlobals->curtime * 15.0f ); if ( flFlicker > 0.25f && flFlicker < 0.75f ) { // On state.m_fLinearAtten = r_flashlightlinear.GetFloat() * flScale; } else { // Off state.m_fLinearAtten = 0.0f; } } else { float flNoise = cosf( gpGlobals->curtime * 7.0f ) * sinf( gpGlobals->curtime * 25.0f ); state.m_fLinearAtten = r_flashlightlinear.GetFloat() * flScale + 1.5f * flNoise; } state.m_fHorizontalFOVDegrees = r_flashlightfov.GetFloat() - ( 16.0f * (1.0f-flScale) ); state.m_fVerticalFOVDegrees = r_flashlightfov.GetFloat() - ( 16.0f * (1.0f-flScale) ); bFlicker = true; } } #endif // HL2_EPISODIC if ( bFlicker == false ) { if ( m_flLinearAtten > 0.0f ) { state.m_fLinearAtten = m_flLinearAtten; } else { state.m_fLinearAtten = r_flashlightlinear.GetFloat(); } if ( m_flFov > 0.0f ) { state.m_fHorizontalFOVDegrees = m_flFov; state.m_fVerticalFOVDegrees = m_flFov; } else { state.m_fHorizontalFOVDegrees = r_flashlightfov.GetFloat(); state.m_fVerticalFOVDegrees = r_flashlightfov.GetFloat(); } if ( m_bMuzzleFlashEnabled ) { state.m_fHorizontalFOVDegrees = state.m_fVerticalFOVDegrees = r_flashlightmuzzleflashfov.GetFloat(); } } state.m_fConstantAtten = r_flashlightconstant.GetFloat(); state.m_Color[0] = 1.0f; state.m_Color[1] = 1.0f; state.m_Color[2] = 1.0f; state.m_Color[3] = r_flashlightambient.GetFloat(); state.m_NearZ = r_flashlightnear.GetFloat() + r_flashlightnearoffsetscale.GetFloat() * m_flCurrentPullBackDist; // Optionally push near plane out so that we don't clip the world when the flashlight pulls back if ( m_flFarZ > 0.0f ) { state.m_FarZ = state.m_FarZAtten = m_flFarZ; // Strictly speaking, these are different, but the game can treat them the same } else { state.m_FarZ = state.m_FarZAtten = r_flashlightfar.GetFloat(); // Strictly speaking, these are different, but the game can treat them the same } state.m_bEnableShadows = castsShadows && r_flashlightdepthtexture.GetBool(); state.m_flShadowMapResolution = r_flashlightdepthres.GetInt(); state.m_flShadowFilterSize = 3.0f; // uberlight state.m_bUberlight = r_flashlightuberlight.GetBool(); state.m_uberlightState.m_fRoundness = 1.0f; if ( m_bMuzzleFlashEnabled ) { state.m_pSpotlightTexture = m_MuzzleFlashTexture; state.m_pProjectedMaterial = NULL; state.m_Color[0] = m_flMuzzleFlashBrightness; state.m_Color[1] = m_flMuzzleFlashBrightness; state.m_Color[2] = m_flMuzzleFlashBrightness; } else { state.m_pSpotlightTexture = m_FlashlightTexture; state.m_pProjectedMaterial = NULL; } state.m_nSpotlightTextureFrame = 0; state.m_flShadowAtten = r_flashlightshadowatten.GetFloat(); state.m_flShadowSlopeScaleDepthBias = g_pMaterialSystemHardwareConfig->GetShadowSlopeScaleDepthBias(); state.m_flShadowDepthBias = g_pMaterialSystemHardwareConfig->GetShadowDepthBias(); state.m_bVolumetric = r_flashlightvolumetrics.GetBool(); state.m_flAmbientOcclusion = r_flashlightAO.GetFloat(); return true; }
//=============================================================================== // Actualiza el estado (la configuración) de la proyección //=============================================================================== bool CInternalLight::UpdateState( FlashlightState_t& state, const Vector &vecPos, const Vector &vecForward, const Vector &vecRight, const Vector &vecUp ) { VPROF_BUDGET( __FUNCTION__, VPROF_BUDGETGROUP_SHADOW_DEPTH_TEXTURING ); // No esta encendida if ( !IsOn() ) return false; // Calculamos la posición y la orientación if ( !m_nState.m_bGlobalLight ) { if ( !ComputeLightPosAndOrientation( vecPos, vecForward, vecRight, vecUp, state.m_vecLightOrigin, state.m_quatOrientation ) ) return false; } // state.m_fQuadraticAtten = m_nState.m_fQuadraticAtten; state.m_fConstantAtten = m_nState.m_fConstantAtten; state.m_fLinearAtten = m_nState.m_fLinearAtten; // Color de la luz state.m_Color[0] = m_nState.m_Color[0]; state.m_Color[1] = m_nState.m_Color[1]; state.m_Color[2] = m_nState.m_Color[2]; state.m_Color[3] = m_nState.m_Color[3]; state.m_fBrightnessScale = m_nState.m_fBrightnessScale; // Distancia y FOV state.m_NearZ = m_nState.m_NearZ + r_projectedtexture_nearoffsetscale.GetFloat() * m_flCurrentPullBackDist; state.m_FarZ = m_nState.m_FarZ; state.m_FarZAtten = m_nState.m_FarZAtten; state.m_fHorizontalFOVDegrees = m_nState.m_fHorizontalFOVDegrees; state.m_fVerticalFOVDegrees = m_nState.m_fVerticalFOVDegrees; // Textura proyectada state.m_pSpotlightTexture = m_nLightTexture; state.m_pProjectedMaterial = NULL; state.m_nSpotlightTextureFrame = 0; // Luz Global state.m_bGlobalLight = m_nState.m_bGlobalLight; if ( state.m_bGlobalLight ) { state.m_vecLightOrigin = vecPos; state.m_quatOrientation = m_nState.m_quatOrientation; } // Ortho state.m_bOrtho = m_nState.m_bOrtho; if ( state.m_bOrtho ) { state.m_fOrthoLeft = m_nState.m_fOrthoLeft; state.m_fOrthoTop = m_nState.m_fOrthoTop; state.m_fOrthoRight = m_nState.m_fOrthoRight; state.m_fOrthoBottom = m_nState.m_fOrthoBottom; } // Propiedades de las sombras generadas state.m_bEnableShadows = m_nState.m_bEnableShadows; state.m_flShadowSlopeScaleDepthBias = g_pMaterialSystemHardwareConfig->GetShadowSlopeScaleDepthBias(); state.m_flShadowDepthBias = g_pMaterialSystemHardwareConfig->GetShadowDepthBias(); // Calidad de las sombras if ( state.m_bEnableShadows ) { state.m_flShadowAtten = r_projectedtexture_shadowatten.GetFloat(); state.m_bShadowHighRes = m_nState.m_bShadowHighRes; state.m_nShadowQuality = m_nState.m_nShadowQuality; state.m_flShadowFilterSize = (m_nState.m_flShadowFilterSize > 0) ? m_nState.m_flShadowFilterSize : r_projectedtexture_filter.GetFloat(); ConVarRef r_flashlightdepthreshigh( "r_flashlightdepthreshigh" ); ConVarRef r_flashlightdepthres( "r_flashlightdepthres" ); if ( state.m_bShadowHighRes ) { state.m_flShadowMapResolution = r_flashlightdepthreshigh.GetFloat(); } else { state.m_flShadowMapResolution = r_flashlightdepthres.GetFloat(); } } /*state.m_flNoiseStrength = 0.8f; state.m_nNumPlanes = 64; state.m_flPlaneOffset = 0.0f; state.m_bVolumetric = true; state.m_flVolumetricIntensity = 1.0f;*/ return true; }