Arma Reforger Explorer
1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Toggle main menu visibility
Loading...
Searching...
No Matches
SCR_DepthOfFieldEffect.c
Go to the documentation of this file.
1
enum
DepthOfFieldTypes
2
{
3
NONE
,
4
SIMPLE
,
5
BOKEH
,
6
}
7
8
class
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"
)]
15
protected
int
m_iFocalLengthNearIntensity
;
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;
43
protected
int
m_iCustomFocusDistanceScale
;
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
62
protected
ChimeraCharacter
m_pCharacterEntity
;
63
protected
SightsComponent
m_SightsComponent
;
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
{
75
ClearEffects
();
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
85
if
(!
m_pCharacterEntity
)
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
{
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;
103
}
104
}
105
106
//------------------------------------------------------------------------------------------------
107
override
void
DisplayControlledEntityChanged
(
IEntity
from,
IEntity
to)
108
{
109
m_pCharacterEntity
=
ChimeraCharacter
.Cast(to);
110
SettingsChanged
();
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)
163
ToggleForcedSimpleDOF
(
false
);
164
165
m_iCustomFocusDistanceScale
= -1;
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)
189
ToggleForcedSimpleDOF
(
true
);
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)
221
ToggleForcedSimpleDOF
(
false
);
222
223
m_iCustomFocusDistanceScale
= -1;
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
{
260
ToggleForcedSimpleDOF
(
true
);
261
m_iNeededDofType =
DepthOfFieldTypes
.SIMPLE;
262
m_iCustomFocusDistanceScale
= 1;
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
);
282
m_bForceSimpleToggle
=
true
;
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
{
297
if
(!
m_pCharacterEntity
)
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
305
if
(
m_iCustomFocusDistanceScale
> -1)
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
{
323
if
(!
m_pCharacterEntity
)
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
344
SCR_CharacterDamageManagerComponent
damageMan =
SCR_CharacterDamageManagerComponent
.Cast(
m_pCharacterEntity
.GetDamageManager());
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
}
GetGame
ArmaReforgerScripted GetGame()
Definition
game.c:1398
DisplayStartDraw
override event void DisplayStartDraw(IEntity owner)
Definition
SCR_AvailableActionsDisplay.c:589
DOF_FADEIN_OPACITY_TARGET
const float DOF_FADEIN_OPACITY_TARGET
Definition
SCR_DepthOfFieldEffect.c:24
m_pCharacterEntity
ChimeraCharacter m_pCharacterEntity
Definition
SCR_DepthOfFieldEffect.c:62
SIMPLEDOF_EFFECT_MAX
const int SIMPLEDOF_EFFECT_MAX
Definition
SCR_DepthOfFieldEffect.c:21
ToggleForcedSimpleDOF
void ToggleForcedSimpleDOF(bool forceSimpleDOF)
Definition
SCR_DepthOfFieldEffect.c:276
DOF_BOKEH_EMAT
const string DOF_BOKEH_EMAT
Definition
SCR_DepthOfFieldEffect.c:46
IsNearDOFAllowed
bool IsNearDOFAllowed(out bool forceSimpleDOF)
Definition
SCR_DepthOfFieldEffect.c:150
FOCALDISTANCE_INTENSITY
const float FOCALDISTANCE_INTENSITY
Definition
SCR_DepthOfFieldEffect.c:18
STANDARD_FOCALCHANGE_NEAR
const float STANDARD_FOCALCHANGE_NEAR
Definition
SCR_DepthOfFieldEffect.c:19
FOCALLENGTH_MAX
const int FOCALLENGTH_MAX
Definition
SCR_DepthOfFieldEffect.c:13
SettingsChanged
override void SettingsChanged()
Definition
SCR_DepthOfFieldEffect.c:73
AddDOFEffect
void AddDOFEffect(float timeslice, bool nearDofAllowed)
Definition
SCR_DepthOfFieldEffect.c:321
m_bForceSimpleToggle
bool m_bForceSimpleToggle
Definition
SCR_DepthOfFieldEffect.c:44
UpdateEffect
override void UpdateEffect(float timeSlice)
Definition
SCR_DepthOfFieldEffect.c:127
DOF_START_OPACITY
const float DOF_START_OPACITY
Definition
SCR_DepthOfFieldEffect.c:23
DOFOUT_PROGRESSION_FADEOUT_DURATION
const float DOFOUT_PROGRESSION_FADEOUT_DURATION
Definition
SCR_DepthOfFieldEffect.c:31
DOFOUT_OPACITY_FADEOUT_DURATION
const float DOFOUT_OPACITY_FADEOUT_DURATION
Definition
SCR_DepthOfFieldEffect.c:30
AddDOFBokehEffect
void AddDOFBokehEffect(bool nearDofAllowed)
Definition
SCR_DepthOfFieldEffect.c:295
m_SightsComponent
SightsComponent m_SightsComponent
Definition
SCR_DepthOfFieldEffect.c:63
ClearEffects
override void ClearEffects()
Definition
SCR_DepthOfFieldEffect.c:352
m_iCustomFocusDistanceScale
int m_iCustomFocusDistanceScale
Definition
SCR_DepthOfFieldEffect.c:43
SIMPLEDOF_FOCALCHANGE_MAX
const int SIMPLEDOF_FOCALCHANGE_MAX
Definition
SCR_DepthOfFieldEffect.c:20
FOCUSDISTANCE_MULTIPIER
enum DepthOfFieldTypes FOCUSDISTANCE_MULTIPIER
GetDOFType
DepthOfFieldTypes GetDOFType(out bool isNearDOFAllowed, bool settingsChanged=false)
Definition
SCR_DepthOfFieldEffect.c:201
DepthOfFieldTypes
DepthOfFieldTypes
Definition
SCR_DepthOfFieldEffect.c:2
BOKEH
@ BOKEH
Definition
SCR_DepthOfFieldEffect.c:5
DOF_NORMAL_EMAT
const string DOF_NORMAL_EMAT
Definition
SCR_DepthOfFieldEffect.c:38
m_iFocalLengthNearIntensity
int m_iFocalLengthNearIntensity
Definition
SCR_DepthOfFieldEffect.c:15
m_wRoot
Widget m_wRoot
Definition
SCR_GameModeCleanSweep.c:25
DisplayControlledEntityChanged
void DisplayControlledEntityChanged(IEntity from, IEntity to)
Definition
SCR_VonDisplay.c:859
DisplayOnSuspended
void DisplayOnSuspended()
Called when GUI is temporarily suspended due to visibility flags; e.g. GM entered and GUI marked as n...
Definition
SCR_InfoDisplayExtended.c:93
DisplayOnResumed
void DisplayOnResumed()
Definition
SCR_InfoDisplayExtended.c:103
SIMPLE
SIMPLE
Definition
SCR_MapMarkerConfig.c:22
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition
SCR_RespawnBriefingComponent.c:17
BaseContainer
Definition
BaseContainer.c:13
ChimeraCharacter
Definition
ChimeraCharacter.c:13
IEntity
Definition
IEntity.c:13
ImageWidget
Definition
ImageWidget.c:13
SCR_BaseScreenEffect
Definition
SCR_BaseScreenEffect.c:2
SCR_CharacterDamageManagerComponent
Definition
SCR_CharacterDamageManagerComponent.c:19
SightsComponent
Definition
SightsComponent.c:18
UIWidgets
Definition
attributes.c:40
NONE
@ NONE
When Shape is created and not initialized yet.
Definition
ShapeType.c:15
Attribute
SCR_FieldOfViewSettings Attribute
Definition
SendGoalMessage.c:170
EDamageState
EDamageState
Definition
EDamageState.c:13
PostProcessEffectType
PostProcessEffectType
Definition
EnWorld.c:20
scripts
Game
UI
ScreenEffects
SCR_DepthOfFieldEffect.c
Generated by
1.17.0