Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DepthOfFieldEffect.c
Go to the documentation of this file.
7
8class SCR_DepthOfFieldEffect : SCR_BaseScreenEffect
9{
10 // PP constants
11 //DOFBokeh AddDOFBokehEffect()
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")]
16
17 //DOFNormal AddDOFEffect()
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;
22 // Variables synced with DeathEffect
23 protected const float DOF_START_OPACITY = 0.7;
24 protected const float DOF_FADEIN_OPACITY_TARGET = 1;
25
26 // Variables connected to a material, need to be static
27 static const int DEPTH_OF_FIELD_PRIORITY = 8;
28
29 // Play Animation of ClearDOFOutEffect()
30 protected const float DOFOUT_OPACITY_FADEOUT_DURATION = 2;
31 protected const float DOFOUT_PROGRESSION_FADEOUT_DURATION = 1;
32
33 //DepthOfField
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";
39
40 //DepthOfFieldBOKEH
41 private static float s_fFocalLength = 0.1; // Blur originates from horizon, higher is closer to camera
42 private static float s_fFocusDistance;
44 protected bool m_bForceSimpleToggle;
45 private static float s_fFocalLengthNear; // Blur originates from camera, higher is further
46 protected const string DOF_BOKEH_EMAT = "{5CFBB3297D669D9C}UI/Materials/ScreenEffects_DepthOfFieldBokehPP.emat";
47
48 private int m_iDesiredDofType;
49 private int m_iNeededDofType;
50
51 // Widgets
52 private ImageWidget m_wDOFOut;
53 private ImageWidget m_wDeath;
54
55 // Enabling/Disabling of PP fx
56 private static bool s_bNearDofEffect;
57 private static bool s_bEnableDOFBokeh;
58 private static bool s_bEnableDOF;
59 private bool m_bDisplaySuspended;
60
61 //Character
64
65 //------------------------------------------------------------------------------------------------
66 override void DisplayStartDraw(IEntity owner)
67 {
68 m_wDOFOut = ImageWidget.Cast(m_wRoot.FindAnyWidget("DOFOut"));
69 m_wDeath = ImageWidget.Cast(m_wRoot.FindAnyWidget("DOFOverlay"));
70 }
71
72 //------------------------------------------------------------------------------------------------
73 override void SettingsChanged()
74 {
76
77 // Get desired type of DOF
78 BaseContainer m_VideoSettings = GetGame().GetGameUserSettings().GetModule("SCR_VideoSettings");
79 if (m_VideoSettings)
80 {
81 m_VideoSettings.Get("m_iDofType", m_iDesiredDofType);
82 m_VideoSettings.Get("m_bNearDofEffect", s_bNearDofEffect);
83 }
84
86 return;
87
88 bool addNear;
89 m_iNeededDofType = GetDOFType(addNear, true);
90
91 if (m_iDesiredDofType == DepthOfFieldTypes.SIMPLE || m_iNeededDofType == DepthOfFieldTypes.SIMPLE)
92 {
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;
96 }
97 else if (m_iDesiredDofType == DepthOfFieldTypes.BOKEH)
98 {
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;
103 }
104 }
105
106 //------------------------------------------------------------------------------------------------
108 {
111 }
112
113 //------------------------------------------------------------------------------------------------
114 protected override void DisplayOnSuspended()
115 {
116 m_bDisplaySuspended = true;
117 ClearEffects();
118 }
119
120 //------------------------------------------------------------------------------------------------
121 protected override void DisplayOnResumed()
122 {
123 m_bDisplaySuspended = false;
124 }
125
126 //------------------------------------------------------------------------------------------------
127 override void UpdateEffect(float timeSlice)
128 {
129 if (m_bDisplaySuspended)
130 return;
131
132 if (!m_wDeath)
133 return;
134
135 if (m_iDesiredDofType == DepthOfFieldTypes.NONE)
136 return;
137
138 bool addNear;
139 m_iNeededDofType = GetDOFType(addNear, true);
140
141 if (m_iNeededDofType == DepthOfFieldTypes.SIMPLE)
142 AddDOFEffect(timeSlice, addNear);
143 else if (m_iNeededDofType == DepthOfFieldTypes.BOKEH)
144 AddDOFBokehEffect(addNear);
145 }
146
147 //------------------------------------------------------------------------------------------------
150 protected bool IsNearDOFAllowed(out bool forceSimpleDOF)
151 {
152 if (!s_bNearDofEffect || !m_pCharacterEntity)
153 return false;
154
155 CharacterControllerComponent controller = m_pCharacterEntity.GetCharacterController();
156 if (!controller.IsWeaponRaised() || controller.IsGadgetInHands() || controller.GetInspect())
157 return false;
158
159 if (!controller.IsWeaponADS())
160 {
161 // when un-ADS'ing while Bokeh is desired, toggle off forced simple DOF once
162 if (m_iCustomFocusDistanceScale != -1 && m_iDesiredDofType == DepthOfFieldTypes.BOKEH)
164
166
167 return true;
168 }
169
170 //When ADS'sing and current sights are using PIP, disable nearDOF
171 BaseWeaponManagerComponent weaponManager = m_pCharacterEntity.GetCharacterController().GetWeaponManagerComponent();
172 if (weaponManager)
173 {
174 SightsComponent sights = weaponManager.GetCurrentSights();
175 if (!sights)
176 return true;
177
178 SCR_2DPIPSightsComponent pipSightsComp = SCR_2DPIPSightsComponent.Cast(sights);
179 if (pipSightsComp && pipSightsComp.IsPIPEnabled())
180 return false;
181
182 // to prevent unnecessary calls for prefabData, only call when the held weapon has changed
183 if (m_SightsComponent != sights)
184 {
185 sights.GetDOFRelatedPrefabData(m_iCustomFocusDistanceScale, forceSimpleDOF);
186
187 // If desired DOF type is Bokeh, but this sight forces simple DOF, toggle to simple DOF or vice versa
188 if (!m_bForceSimpleToggle && forceSimpleDOF)
190
191 m_SightsComponent = sights;
192 }
193 }
194
195 return true;
196 }
197
198 //------------------------------------------------------------------------------------------------
201 protected DepthOfFieldTypes GetDOFType(out bool isNearDOFAllowed, bool settingsChanged = false)
202 {
203 if (!s_bNearDofEffect || !m_pCharacterEntity)
204 {
205 isNearDOFAllowed = false;
206 return m_iDesiredDofType;
207 }
208
209 CharacterControllerComponent controller = m_pCharacterEntity.GetCharacterController();
210 if (!controller.IsWeaponRaised() || controller.IsGadgetInHands() || controller.GetInspect())
211 {
212 isNearDOFAllowed = false;
213 m_iNeededDofType = m_iDesiredDofType;
214 return m_iDesiredDofType;
215 }
216
217 if (!controller.IsWeaponADS())
218 {
219 // when un-ADS'ing while Bokeh is desired, toggle off forced simple DOF once
220 if (m_iCustomFocusDistanceScale != -1 && m_iDesiredDofType == DepthOfFieldTypes.BOKEH)
222
224
225 isNearDOFAllowed = true;
226 return m_iDesiredDofType;
227 }
228
229 //When ADS'sing and current sights are using PIP, disable nearDOF
230 BaseWeaponManagerComponent weaponManager = m_pCharacterEntity.GetCharacterController().GetWeaponManagerComponent();
231 if (weaponManager)
232 {
233 SightsComponent sights = weaponManager.GetCurrentSights();
234 if (!sights)
235 {
236 isNearDOFAllowed = false;
237 m_iNeededDofType = m_iDesiredDofType;
238 return m_iDesiredDofType;
239 }
240
241 SCR_2DPIPSightsComponent pipSightsComp = SCR_2DPIPSightsComponent.Cast(sights);
242 if (pipSightsComp && pipSightsComp.IsPIPEnabled())
243 {
244 isNearDOFAllowed = false;
245 m_iNeededDofType = m_iDesiredDofType;
246 return m_iDesiredDofType;
247 }
248
249 // to prevent unnecessary calls for prefabData, only call when the held weapon has changed
250 if (m_SightsComponent != sights || settingsChanged)
251 {
252 bool forceSimpleDOF;
253 sights.GetDOFRelatedPrefabData(m_iCustomFocusDistanceScale, forceSimpleDOF);
254
255 m_SightsComponent = sights;
256
257 // If desired DOF type is Bokeh, but this sight forces simple DOF, toggle to simple DOF or vice versa
258 if (forceSimpleDOF)
259 {
261 m_iNeededDofType = DepthOfFieldTypes.SIMPLE;
263 }
264 else
265 {
266 m_iNeededDofType = m_iDesiredDofType;
267 }
268 }
269 }
270
271 isNearDOFAllowed = true;
272 return m_iNeededDofType;
273 }
274
275 //------------------------------------------------------------------------------------------------
276 protected void ToggleForcedSimpleDOF(bool forceSimpleDOF)
277 {
278 if (forceSimpleDOF)
279 {
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);
283 }
284 else
285 {
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;
291 }
292 }
293
294 //------------------------------------------------------------------------------------------------
295 protected void AddDOFBokehEffect(bool nearDofAllowed)
296 {
298 return;
299
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));
302 else
303 s_fFocalLength = 0.1; //If no death/unconsciousness blur is desired, set focallength to defaultvalue
304
306 s_fFocusDistance = m_iCustomFocusDistanceScale;
307 else
308 s_fFocusDistance = FOCUSDISTANCE_MULTIPIER;
309
310 //s_fFocalLength cannot be 0, so it is disabled when it is within a 0.1 margin of the lowest permitted value
311 if (s_fFocalLength > 0.2 || nearDofAllowed)
312 {
313 s_bEnableDOFBokeh = true;
314 s_fFocalLengthNear = m_iFocalLengthNearIntensity;
315 }
316 else
317 s_bEnableDOFBokeh = false;
318 }
319
320 //------------------------------------------------------------------------------------------------
321 protected void AddDOFEffect(float timeslice, bool nearDofAllowed)
322 {
324 return;
325
326 s_fFocalDistance = FOCALDISTANCE_INTENSITY;
327
328 // if s_bNearDofEffect is allowed, simpleDOF always must be enabled. If not, it must be disabled when inactive (i.e. focalchange > max)
329 if (s_fFocalChange < SIMPLEDOF_FOCALCHANGE_MAX)
330 {
331 s_bEnableDOF = true;
332 s_bSkipFar = false;
333 s_fFocalChangeNear = SIMPLEDOF_FOCALCHANGE_MAX;
334 }
335 else if (nearDofAllowed)
336 {
337 s_fFocalChangeNear = STANDARD_FOCALCHANGE_NEAR;
338 s_bEnableDOF = true;
339 s_bSkipFar = true;
340 }
341 else
342 s_bEnableDOF = false;
343
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);
347 else
348 s_fFocalChange = SIMPLEDOF_FOCALCHANGE_MAX;
349 }
350
351 //------------------------------------------------------------------------------------------------
352 protected override void ClearEffects()
353 {
354 s_fFocalLength = 0.1;
355 s_bEnableDOF = false;
356 s_bEnableDOFBokeh = false;
357 }
358}
ArmaReforgerScripted GetGame()
Definition game.c:1398
override event void DisplayStartDraw(IEntity owner)
const float DOF_FADEIN_OPACITY_TARGET
ChimeraCharacter m_pCharacterEntity
const int SIMPLEDOF_EFFECT_MAX
void ToggleForcedSimpleDOF(bool forceSimpleDOF)
const string DOF_BOKEH_EMAT
bool IsNearDOFAllowed(out bool forceSimpleDOF)
const float FOCALDISTANCE_INTENSITY
const float STANDARD_FOCALCHANGE_NEAR
const int FOCALLENGTH_MAX
override void SettingsChanged()
void AddDOFEffect(float timeslice, bool nearDofAllowed)
bool m_bForceSimpleToggle
override void UpdateEffect(float timeSlice)
const float DOF_START_OPACITY
const float DOFOUT_PROGRESSION_FADEOUT_DURATION
const float DOFOUT_OPACITY_FADEOUT_DURATION
void AddDOFBokehEffect(bool nearDofAllowed)
SightsComponent m_SightsComponent
override void ClearEffects()
int m_iCustomFocusDistanceScale
const int SIMPLEDOF_FOCALCHANGE_MAX
enum DepthOfFieldTypes FOCUSDISTANCE_MULTIPIER
DepthOfFieldTypes GetDOFType(out bool isNearDOFAllowed, bool settingsChanged=false)
const string DOF_NORMAL_EMAT
int m_iFocalLengthNearIntensity
Widget m_wRoot
void DisplayControlledEntityChanged(IEntity from, IEntity to)
void DisplayOnSuspended()
Called when GUI is temporarily suspended due to visibility flags; e.g. GM entered and GUI marked as n...
void DisplayOnResumed()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
@ NONE
When Shape is created and not initialized yet.
Definition ShapeType.c:15
SCR_FieldOfViewSettings Attribute
EDamageState
PostProcessEffectType
Definition EnWorld.c:20