12 protected const int FOCUSDISTANCE_MULTIPIER = 30;
13 protected const int FOCALLENGTH_MAX = 5000;
14 [
Attribute( defvalue:
"225", uiwidget: UIWidgets.EditBox,
desc:
"Intensity of the nearby DOF" )]
15 protected int m_iFocalLengthNearIntensity;
18 protected const float FOCALDISTANCE_INTENSITY = 0.3;
19 protected const float STANDARD_FOCALCHANGE_NEAR = 0.25;
20 protected const int SIMPLEDOF_FOCALCHANGE_MAX = 10000;
21 protected const int SIMPLEDOF_EFFECT_MAX = 1500;
23 protected const float DOF_START_OPACITY = 0.7;
24 protected const float DOF_FADEIN_OPACITY_TARGET = 1;
27 static const int DEPTH_OF_FIELD_PRIORITY = 8;
30 protected const float DOFOUT_OPACITY_FADEOUT_DURATION = 2;
31 protected const float DOFOUT_PROGRESSION_FADEOUT_DURATION = 1;
34 private static float s_fFocalChange = 10000;
35 private static float s_fFocalDistance;
36 private static float s_fFocalChangeNear;
37 protected static bool s_bSkipFar;
38 protected const string DOF_NORMAL_EMAT =
"{403795B9349EA61C}UI/Materials/ScreenEffects_DepthOfFieldPP.emat";
41 private static float s_fFocalLength = 0.1;
42 private static float s_fFocusDistance;
43 protected int m_iCustomFocusDistanceScale;
44 protected bool m_bForceSimpleToggle;
45 private static float s_fFocalLengthNear;
46 protected const string DOF_BOKEH_EMAT =
"{5CFBB3297D669D9C}UI/Materials/ScreenEffects_DepthOfFieldBokehPP.emat";
48 private int m_iDesiredDofType;
49 private int m_iNeededDofType;
52 private ImageWidget m_wDOFOut;
53 private ImageWidget m_wDeath;
56 private static bool s_bNearDofEffect;
57 private static bool s_bEnableDOFBokeh;
58 private static bool s_bEnableDOF;
59 private bool m_bDisplaySuspended;
62 protected ChimeraCharacter m_pCharacterEntity;
63 protected SightsComponent m_SightsComponent;
66 override void DisplayStartDraw(IEntity owner)
68 m_wDOFOut = ImageWidget.Cast(
m_wRoot.FindAnyWidget(
"DOFOut"));
69 m_wDeath = ImageWidget.Cast(
m_wRoot.FindAnyWidget(
"DeathOverlay"));
73 override void SettingsChanged()
78 BaseContainer m_VideoSettings =
GetGame().GetGameUserSettings().GetModule(
"SCR_VideoSettings");
81 m_VideoSettings.Get(
"m_iDofType", m_iDesiredDofType);
82 m_VideoSettings.Get(
"m_bNearDofEffect", s_bNearDofEffect);
85 if (!m_pCharacterEntity)
89 m_iNeededDofType = GetDOFType(addNear,
true);
93 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfFieldBokeh,
"");
94 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfField, DOF_NORMAL_EMAT);
95 m_iNeededDofType = m_iDesiredDofType;
99 m_bForceSimpleToggle = 0;
100 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfField,
"");
101 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfFieldBokeh, DOF_BOKEH_EMAT);
102 m_iNeededDofType = m_iDesiredDofType;
107 override void DisplayControlledEntityChanged(IEntity from, IEntity to)
109 m_pCharacterEntity = ChimeraCharacter.Cast(to);
114 protected override void DisplayOnSuspended()
116 m_bDisplaySuspended =
true;
121 protected override void DisplayOnResumed()
123 m_bDisplaySuspended =
false;
127 override void UpdateEffect(
float timeSlice)
129 if (m_bDisplaySuspended)
139 m_iNeededDofType = GetDOFType(addNear,
true);
142 AddDOFEffect(timeSlice, addNear);
144 AddDOFBokehEffect(addNear);
150 bool IsNearDOFAllowed(out
bool forceSimpleDOF)
152 if (!s_bNearDofEffect || !m_pCharacterEntity)
155 CharacterControllerComponent controller = m_pCharacterEntity.GetCharacterController();
156 if (!controller.IsWeaponRaised() || controller.IsGadgetInHands() || controller.GetInspect())
159 if (!controller.IsWeaponADS())
162 if (m_iCustomFocusDistanceScale != -1 && m_iDesiredDofType ==
DepthOfFieldTypes.BOKEH)
163 ToggleForcedSimpleDOF(
false);
165 m_iCustomFocusDistanceScale = -1;
171 BaseWeaponManagerComponent weaponManager = m_pCharacterEntity.GetCharacterController().GetWeaponManagerComponent();
174 SightsComponent sights = weaponManager.GetCurrentSights();
178 SCR_2DPIPSightsComponent pipSightsComp = SCR_2DPIPSightsComponent.Cast(sights);
179 if (pipSightsComp && pipSightsComp.IsPIPEnabled())
183 if (m_SightsComponent != sights)
185 sights.GetDOFRelatedPrefabData(m_iCustomFocusDistanceScale, forceSimpleDOF);
188 if (!m_bForceSimpleToggle && forceSimpleDOF)
189 ToggleForcedSimpleDOF(
true);
191 m_SightsComponent = sights;
201 DepthOfFieldTypes GetDOFType(out
bool isNearDOFAllowed,
bool settingsChanged =
false)
203 if (!s_bNearDofEffect || !m_pCharacterEntity)
205 isNearDOFAllowed =
false;
206 return m_iDesiredDofType;
209 CharacterControllerComponent controller = m_pCharacterEntity.GetCharacterController();
210 if (!controller.IsWeaponRaised() || controller.IsGadgetInHands() || controller.GetInspect())
212 isNearDOFAllowed =
false;
213 m_iNeededDofType = m_iDesiredDofType;
214 return m_iDesiredDofType;
217 if (!controller.IsWeaponADS())
220 if (m_iCustomFocusDistanceScale != -1 && m_iDesiredDofType ==
DepthOfFieldTypes.BOKEH)
221 ToggleForcedSimpleDOF(
false);
223 m_iCustomFocusDistanceScale = -1;
225 isNearDOFAllowed =
true;
226 return m_iDesiredDofType;
230 BaseWeaponManagerComponent weaponManager = m_pCharacterEntity.GetCharacterController().GetWeaponManagerComponent();
233 SightsComponent sights = weaponManager.GetCurrentSights();
236 isNearDOFAllowed =
false;
237 m_iNeededDofType = m_iDesiredDofType;
238 return m_iDesiredDofType;
241 SCR_2DPIPSightsComponent pipSightsComp = SCR_2DPIPSightsComponent.Cast(sights);
242 if (pipSightsComp && pipSightsComp.IsPIPEnabled())
244 isNearDOFAllowed =
false;
245 m_iNeededDofType = m_iDesiredDofType;
246 return m_iDesiredDofType;
250 if (m_SightsComponent != sights || settingsChanged)
253 sights.GetDOFRelatedPrefabData(m_iCustomFocusDistanceScale, forceSimpleDOF);
255 m_SightsComponent = sights;
260 ToggleForcedSimpleDOF(
true);
262 m_iCustomFocusDistanceScale = 1;
266 m_iNeededDofType = m_iDesiredDofType;
271 isNearDOFAllowed =
true;
272 return m_iNeededDofType;
276 void ToggleForcedSimpleDOF(
bool forceSimpleDOF)
280 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfFieldBokeh,
"");
281 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfField, DOF_NORMAL_EMAT);
282 m_bForceSimpleToggle =
true;
286 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfField,
"");
287 m_pCharacterEntity.GetWorld().SetCameraPostProcessEffect(m_pCharacterEntity.GetWorld().GetCurrentCameraId(),DEPTH_OF_FIELD_PRIORITY,PostProcessEffectType.DepthOfFieldBokeh, DOF_BOKEH_EMAT);
288 m_bForceSimpleToggle =
false;
289 m_SightsComponent =
null;
290 m_iNeededDofType = m_iDesiredDofType;
295 void AddDOFBokehEffect(
bool nearDofAllowed)
297 if (!m_pCharacterEntity)
300 if (m_wDeath.GetOpacity() > 0.1 && !m_bDisplaySuspended)
301 s_fFocalLength = s_fFocalLengthNear + (FOCALLENGTH_MAX * (m_wDeath.GetOpacity() - DOF_START_OPACITY) / (DOF_FADEIN_OPACITY_TARGET - DOF_START_OPACITY));
303 s_fFocalLength = 0.1;
305 if (m_iCustomFocusDistanceScale > -1)
306 s_fFocusDistance = m_iCustomFocusDistanceScale;
308 s_fFocusDistance = FOCUSDISTANCE_MULTIPIER;
311 if (s_fFocalLength > 0.2 || nearDofAllowed)
313 s_bEnableDOFBokeh =
true;
314 s_fFocalLengthNear = m_iFocalLengthNearIntensity;
317 s_bEnableDOFBokeh =
false;
321 void AddDOFEffect(
float timeslice,
bool nearDofAllowed)
323 if (!m_pCharacterEntity)
326 s_fFocalDistance = FOCALDISTANCE_INTENSITY;
329 if (s_fFocalChange < SIMPLEDOF_FOCALCHANGE_MAX)
333 s_fFocalChangeNear = SIMPLEDOF_FOCALCHANGE_MAX;
335 else if (nearDofAllowed)
337 s_fFocalChangeNear = STANDARD_FOCALCHANGE_NEAR;
342 s_bEnableDOF =
false;
345 if (damageMan && damageMan.GetState() ==
EDamageState.DESTROYED && !m_bDisplaySuspended)
346 s_fFocalChange = 100 - 100 * (m_wDeath.GetOpacity() - DOF_START_OPACITY) / (DOF_FADEIN_OPACITY_TARGET - DOF_START_OPACITY);
348 s_fFocalChange = SIMPLEDOF_FOCALCHANGE_MAX;
352 protected override void ClearEffects()
354 s_fFocalLength = 0.1;
355 s_bEnableDOF =
false;
356 s_bEnableDOFBokeh =
false;