Dayz Explorer 1.28.160049
Loading...
Searching...
No Matches
ppeffects.c
Go to the documentation of this file.
1
3{
4 // COLORIZE IDs
5 static const int COLORIZE_NV = 100;
6
7 //CONSTANTS
8 static const float COLOR_SHOCK = 0.1;//shock color value (relative) //todo
9
10 //-------------------------------------------------------
11 // BLUR START
12 //-------------------------------------------------------
13 static int m_BlurInventory;
14 static int m_BlurDrunk;
15 static int m_BlurFever;
16 static int m_BlurMenu;
17 static int m_BlurOptics;
18 static int m_BlurFlashbang;
19 static int m_BlurShock;
20
21 static int m_BurlapBlindness;
22 static int m_DyingEffect;
23 static int m_ShockEffect;
24
25 static int m_ChromAbbOptic;
26 //static int m_ChromAbbShock;
27
28 static int m_VignetteUnconscious;
29 static int m_VignetteShock;
30 static int m_VignetteTunnel;
31 static int m_VignetteMenu;
32
33 static float m_BloodSaturation;
34
35 static ref array<float> m_BlurValues;
36 static ref array<float> m_ChromAbbValues;
37 static ref array<int> m_VignetteEffects;
38 static ref map<int, ref array<float>> m_VignetteValues;
39 static ref map<int, ref array<float>> m_ColorValues;
40 static ref array<float> m_ColorEffect;
41 static ref map<int, ref array<float>> m_ColorizeEffects;
42
43 //static float m_UnconsciousVignetteColor[4];
44 //static float m_UnconsciousVignetteIntesity;
45
46 static float m_ColorValueTotal[4] = {0,0,0,0};
47 static float m_ColorOverlayTotal;
48
49 static Material m_MatColors;
50 static Material m_RadialBlur;
51
52 static void Init()
53 {
54 //Print("---Init PPEffects---");
55 if ( m_BlurValues )
56 {
57 delete m_BlurValues;
58 }
59 if ( m_ChromAbbValues )
60 {
61 delete m_ChromAbbValues;
62 }
63 if ( m_VignetteEffects )
64 {
65 delete m_VignetteEffects;
66 }
67 if ( m_VignetteValues )
68 {
69 delete m_VignetteValues;
70 }
71 if ( m_ColorEffect )
72 {
73 delete m_ColorEffect;
74 }
75
76 m_MatColors = GetGame().GetWorld().GetMaterial("graphics/materials/postprocess/glow");
77 m_RadialBlur = GetGame().GetWorld().GetMaterial("graphics/materials/postprocess/radialblur");
78 m_BlurValues = new array<float>;
79 m_ChromAbbValues = new array<float>;
80 m_VignetteEffects = new array<int>;
81 m_VignetteValues = new map<int, ref array<float>>;
82
83 // add new blur effects here
84 m_BlurInventory = RegisterBlurEffect();
85 m_BlurDrunk = RegisterBlurEffect();
86 m_BlurFever = RegisterBlurEffect();
87 m_BlurMenu = RegisterBlurEffect();
88 m_BlurOptics = RegisterBlurEffect();
89 m_BlurFlashbang = RegisterBlurEffect();
90
91 // add chromatic abberation effects here
92 m_ChromAbbOptic = RegisterChromAbbEffect();
93 //m_ChromAbbShock = RegisterChromAbbEffect();
94
95 // add vignette effects here
96 m_VignetteUnconscious = RegisterVignetteEffect();
97 m_VignetteShock = RegisterVignetteEffect();
98 m_VignetteTunnel = RegisterVignetteEffect();
99 m_VignetteMenu = RegisterVignetteEffect();
100
101 m_ColorEffect = new array<float>;
102 m_ColorValues = new map<int, ref array<float>>;
103
104 // add new color effects here
105 m_BurlapBlindness = RegisterColorEffect();
106 m_DyingEffect = RegisterColorEffect();
107 m_ShockEffect = RegisterColorEffect();
108
109 // ------------------------NV-related stuff below------------------------
110 array<float> colorizeDefault = {0.0, 0.0, 0.0};
111 m_ColorizeEffects = new map<int, ref array<float>>;
112
113 // colorize: r, g, b
114 // colorize effects registration
115 m_ColorizeEffects.Set(PPEffects.COLORIZE_NV, colorizeDefault);
116 //SetNVParams(1.0, 0.0, 2.35, 2.75); //default values
117 // ------------------------End of NV-related stuff------------------------
118 }
119
120 static void ResetBlurEffects()
121 {
122 if( m_BlurValues )
123 {
124 for ( int i = 0; i < m_BlurValues.Count(); ++i )
125 {
126 m_BlurValues[i] = 0;
127 }
128 UpdateBlur();
129 }
130 }
131
132 static void ResetRadialBlur()
133 {
134 SetRadialBlur(0,0,0,0);
135 }
136
137 static void SetBlurValue(int index, float value)
138 {
139 if ( m_BlurValues && index < m_BlurValues.Count() )
140 {
141 m_BlurValues[index] = value;
142 }
143 else
144 {
145 Print("Error: PPEffects: m_BlurValues with index: "+ index +" is not registered.");
146 }
147 }
148
149 static int RegisterBlurEffect()
150 {
151 return m_BlurValues.Insert(0);
152 }
153
154 //-------------------------------------------------------
156 static void SetRadialBlur(float powerX, float powerY, float offsetX, float offsetY )
157 {
158 if (GetGame())
159 {
160 m_RadialBlur.SetParam("PowerX", powerX);
161 m_RadialBlur.SetParam("PowerY", powerY);
162 m_RadialBlur.SetParam("OffsetX", offsetX);
163 m_RadialBlur.SetParam("OffsetY", offsetY);
164 }
165 }
166 //-------------------------------------------------------
168 static void SetBlur(float value)
169 {
170 if (GetGame())
171 {
172 Material mat_blur = GetGame().GetWorld().GetMaterial("graphics/materials/postprocess/gauss");
173
174 if (mat_blur)
175 {
176 mat_blur.SetParam("Intensity", value);
177 }
178 }
179 }
180 //-------------------------------------------------------
182 static void UpdateBlur()
183 {
184 float blur_value_total = 0;
185 if( m_BlurValues )
186 {
187 for ( int i = 0; i < m_BlurValues.Count(); ++i )
188 {
189 blur_value_total += m_BlurValues[i];
190 }
191 }
192
193 SetBlur( blur_value_total );
194 }
195 //-------------------------------------------------------
197 static void SetBlurInventory(float value)
198 {
199 SetBlurValue(m_BlurInventory, value);
200 UpdateBlur();
201 }
202 //-------------------------------------------------------
204 static void SetBlurDrunk(float value)
205 {
206 SetBlurValue(m_BlurDrunk, value);
207 UpdateBlur();
208 }
209
210 //-------------------------------------------------------
212 static void SetBlurFever(float value)
213 {
214 SetBlurValue(m_BlurFever, value);
215 UpdateBlur();
216 }
217
218 //-------------------------------------------------------
220 static void SetBlurMenu(float value)
221 {
222 SetBlurValue(m_BlurMenu, value);
223 UpdateBlur();
224 }
225
226 //-------------------------------------------------------
228 static void SetBlurOptics(float value)
229 {
230 SetBlurValue(m_BlurOptics, value);
231 UpdateBlur();
232 }
233
234 //-------------------------------------------------------
236 static void SetBlurFlashbang(float value)
237 {
238 SetBlurValue(m_BlurFlashbang, value);
239 UpdateBlur();
240 }
241
242 static void SetBlurShock(float value)
243 {
244 SetBlurValue(m_BlurShock, value);
245 UpdateBlur();
246 }
247
248 //-------------------------------------------------------
249 // BLUR END
250 //-------------------------------------------------------
251
252 //-------------------------------------------------------
253 // CHROMATIC ABBERATION
254 //-------------------------------------------------------
255 static int RegisterChromAbbEffect()
256 {
257 return m_ChromAbbValues.Insert(0);
258 }
259
260 static void ResetChromAbbEffects()
261 {
262 if( m_ChromAbbValues )
263 {
264 for ( int i = 0; i < m_ChromAbbValues.Count(); ++i )
265 {
266 m_ChromAbbValues[i] = 0;
267 }
268 UpdateChromAbb();
269 }
270 }
271
272 static void SetChromAbbValue(int index, float value)
273 {
274 if ( m_ChromAbbValues && index < m_ChromAbbValues.Count() )
275 {
276 m_ChromAbbValues[index] = value;
277 }
278 else
279 {
280 Print("Error: PPEffects: m_ChromAbbValues with index: "+ index +" is not registered.");
281 }
282 }
283
284 static void SetChromAbb(float value)
285 {
286 if (GetGame())
287 {
288 if (m_MatColors)
289 {
290 //Print("SetChromAbb: " + value);
291 m_MatColors.SetParam("MaxChromAbberation", value);
292 //SetVignette(value,0,255,0);
293 }
294 }
295 }
296 //-------------------------------------------------------
298 static void UpdateChromAbb()
299 {
300 float chromabb_value_total = 0;
301 if( m_ChromAbbValues )
302 {
303 for ( int i = 0; i < m_ChromAbbValues.Count(); ++i )
304 {
305 chromabb_value_total += m_ChromAbbValues[i]; //currently additive!
306 }
307 }
308
309 SetChromAbb( chromabb_value_total );
310 }
311
312 static void SetChromAbbOptic(float value)
313 {
314 SetChromAbbValue(m_ChromAbbOptic, value);
315 UpdateChromAbb();
316 }
317
318 /*static void SetChromAbbShock(float value)
319 {
320 SetChromAbbValue(m_ChromAbbShock, value);
321 UpdateChromAbb();
322 }*/
323
324 //-------------------------------------------------------
325 // CHROMATIC ABBERATION END
326 //-------------------------------------------------------
327
328 /*
329 static void SetOverlayColor(float r, float g, float b, float a)
330 {
331 Material matColors = GetGame().GetWorld().GetMaterial("graphics/materials/postprocess/glow");
332
333 m_Color[0] = r;
334 m_Color[1] = g;
335 m_Color[2] = b;
336 m_Color[3] = a;
337
338 matColors.SetParam("OverlayColor", m_Color);
339 matColors.SetParam("OverlayFactor", a);
340
341 }*/
342
343 static void ResetColorEffects()
344 {
345 if( m_ColorEffect )
346 {
347 for ( int i = 0; i < m_ColorEffect.Count(); ++i )
348 {
349 //m_ColorEffect[i] = 0;
350 m_ColorValues.Set(i,{0,0,0,0,0});
351 }
352 UpdateColor();
353 }
354 }
355
356 static void SetColorValue(int index, float r, float g, float b, float a, float overlay)
357 {
358 if ( index < m_ColorEffect.Count() )
359 {
360 array<float> values = {r,g,b,a,overlay};
361
362 m_ColorValues.Set(index, values);
363 }
364 else
365 {
366 Print("Error: PPEffects: m_ColorValues with index: "+ index +" is not registered.");
367 }
368 }
369
370 static int RegisterColorEffect()
371 {
372 return m_ColorEffect.Insert(0);
373 }
374
375 static void UpdateColor()
376 {
377 float color_value_total[4] = {0,0,0,0};
378 float color_overlay;
379 /*
380 m_MatColors.ResetParam("OverlayColor");
381 m_MatColors.ResetParam("OverlayFactor");
382 */
383 if( !GetGame() || !GetGame().GetWorld() )
384 {
385 return;
386 }
387
388 for ( int i = 0; i < m_ColorValues.Count(); ++i )
389 {
390 int key = m_ColorValues.GetKey(i);
391 array<float> value = m_ColorValues.Get(key);
392
393 color_value_total[0] = color_value_total[0] + value[0];
394 color_value_total[1] = color_value_total[1] + value[1];
395 color_value_total[2] = color_value_total[2] + value[2];
396 color_value_total[3] = color_value_total[3] + value[3];
397 color_overlay += value[4];
398 }
399
400 m_ColorValueTotal = color_value_total;
401 m_ColorOverlayTotal = color_overlay;
402 m_MatColors.SetParam("OverlayColor", color_value_total);
403 m_MatColors.SetParam("OverlayFactor", color_overlay);
404 }
405
413 static void SetLensEffect(float lens, float chromAbb, float centerX, float centerY)
414 {
415 PerformSetLensEffect(lens, chromAbb, centerX, centerY);
416 }
417
419 static void PerformSetLensEffect(float lens, float chromAbb, float centerX, float centerY)
420 {
421 m_MatColors.SetParam("LensDistort", lens);
422 SetChromAbbOptic(chromAbb);
423 m_MatColors.SetParam("LensCenterX", centerX);
424 m_MatColors.SetParam("LensCenterY", centerY);
425 }
426
434 static void SetVignette(float intensity, float R, float G, float B, float A)
435 {
436 float color[4];
437 color[0] = R;
438 color[1] = G;
439 color[2] = B;
440 color[3] = A;
441
442 m_MatColors.SetParam("Vignette", intensity);
443 m_MatColors.SetParam("VignetteColor", color);
444 }
445
446 static void SetVignetteEffectValue(int index, float intensity, float r, float g, float b, float a)
447 {
448 if ( index < m_VignetteEffects.Count() )
449 {
450 array<float> values = {intensity,r,g,b,a};
451
452 m_VignetteValues.Set(index, values);
453 }
454 else
455 {
456 Print("Error: PPEffects: m_ColorValues with index: "+ index +" is not registered.");
457 }
458 }
459
460 static int RegisterVignetteEffect()
461 {
462 return m_VignetteEffects.Insert(0);
463 }
464
465 static void SetUnconsciousnessVignette(float value)
466 {
467 SetVignetteEffectValue(m_VignetteUnconscious, value, 0,0,0,0); //todo
468 UpdateVignette();
469 }
470
471 static void SetShockVignette(float value)
472 {
473 SetVignetteEffectValue(m_VignetteShock, value, 0,0,0,0); //todo
474 UpdateVignette();
475 }
476
477 static void SetTunnelVignette(float value)
478 {
479 SetVignetteEffectValue(m_VignetteTunnel, value, 0,0,0,0); //todo
480 UpdateVignette();
481 }
482
483 static void SetMenuVignette(float value)
484 {
485 SetVignetteEffectValue(m_VignetteMenu, value, 0,0,0,0); //todo
486 UpdateVignette();
487 }
488
489 static void ResetVignettes()
490 {
491 if( m_VignetteValues )
492 {
493 for ( int i = 0; i < m_VignetteValues.Count(); ++i )
494 {
495 array<float> values = {0,0,0,0,0};
496
497 m_VignetteValues.Set(i, values);
498 }
499 UpdateVignette();
500 }
501 }
502
503 static void OverrideDOF(bool enable, float focusDistance, float focusLength, float focusLengthNear, float blur, float focusDepthOffset)
504 {
505 GetGame().OverrideDOF(enable, focusDistance, focusLength, focusLengthNear, blur, focusDepthOffset);
506 }
507
508 static void AddPPMask(float ndcX, float ndcY, float ndcRadius, float ndcBlur)
509 {
510 GetGame().AddPPMask(ndcX, ndcY, ndcRadius, ndcBlur);
511 }
512
513 static void ResetPPMask()
514 {
515 if( GetGame() ) GetGame().ResetPPMask();
516 }
517
518 static void ResetDOFOverride()
519 {
520 OverrideDOF(false,0,0,0,0,1);
521 }
522
523 static void ResetLensEffect()
524 {
525 SetLensEffect(0,0,0,0);
526 }
527
528 static void HitEffect(float value)
529 {
530 float m_HitEffectColor[4];
531 m_HitEffectColor[0] = Math.Lerp(Math.Clamp(m_ColorValueTotal[0],0,1), 1, value);
532 m_HitEffectColor[1] = 0;
533 m_HitEffectColor[2] = 0;
534 m_HitEffectColor[3] = Math.Lerp(Math.Clamp(m_ColorValueTotal[0],0,1), 1, value);
535 /*
536 Print("---------------------------");
537 Print("m_ColorValueTotal[0]: " + m_ColorValueTotal[0]);
538 Print("value: " + value);
539 Print("---------------------------");
540 Print("r: " + m_HitEffectColor[0]);
541 Print("g: " + m_HitEffectColor[1]);
542 Print("b: " + m_HitEffectColor[2]);
543 Print("a: " + m_HitEffectColor[3]);
544 */
545 m_MatColors.SetParam("OverlayColor", m_HitEffectColor);
546 m_MatColors.SetParam("OverlayFactor", 0.05);
547 }
548
549 static void SetShockEffectColor(float value)
550 {
551 if (value > 0)
552 SetColorValue(m_ShockEffect, COLOR_SHOCK, COLOR_SHOCK, COLOR_SHOCK, 1, value);
553 else
554 SetColorValue(m_ShockEffect, 0, 0, 0, 1, value);
555 UpdateColor();
556 }
557
558 static void FlashbangEffect(float value)
559 {
560 float hitEffectColor[4];
561 hitEffectColor[0] = 1;
562 hitEffectColor[1] = 1;
563 hitEffectColor[2] = 1;
564 hitEffectColor[3] = Math.Lerp(Math.Clamp(m_ColorValueTotal[0],0,1), 1, value);
565
566 m_MatColors.SetParam("OverlayColor", hitEffectColor);
567 m_MatColors.SetParam("OverlayFactor", 0.75);
568 }
569
570 static void EnableBurlapSackBlindness()
571 {
572 SetColorValue(m_BurlapBlindness, 0, 0, 0, 1, 1.0);
573 UpdateColor();
574 g_Game.SetEVValue(-5);
575 }
576
577 static void DisableBurlapSackBlindness()
578 {
579 SetColorValue(m_BurlapBlindness, 0, 0, 0, 0, 0.0);
580 UpdateColor();
581 g_Game.SetEVValue(0);
582 }
583
584 static void SetDeathDarkening(float value)
585 {
586 value = Math.Clamp(value,0,1);
587 SetColorValue(m_DyingEffect, 0, 0, 0, 1, value);
588 UpdateColor();
589 if (value > 0.99)
590 SetEVValuePP(-5); //additional "darkness" to avoid lens flare
591 else
592 SetEVValuePP(0);
593 }
594
595 static void UpdateSaturation()
596 {
597 m_MatColors.SetParam("Saturation", m_BloodSaturation/*+add_additional_modifiers_here*/);
598 }
599
600 static void UpdateVignette()
601 {
602 float color[4];
603 float intesity;
604
605 float intensity_value_total = 0; //use just the highest?
606 if( m_VignetteEffects )
607 {
608 for ( int i = 0; i < m_VignetteEffects.Count(); ++i )
609 {
610 if (m_VignetteValues.Get(i))
611 {
612 /*color[0] = m_VignetteValues.Get(i)[1]; //red
613 color[1] = m_VignetteValues.Get(i)[2]; //green
614 color[2] = m_VignetteValues.Get(i)[3]; //blue
615 color[3] = m_VignetteValues.Get(i)[4]; //alpha*/
616 color[0] = m_VignetteValues.Get(i).Get(1); //red
617 color[1] = m_VignetteValues.Get(i).Get(2); //green
618 color[2] = m_VignetteValues.Get(i).Get(3); //blue
619 color[3] = m_VignetteValues.Get(i).Get(4); //alpha
620
621 intesity = m_VignetteValues.Get(i).Get(0);
622 intensity_value_total += intesity;
623 }
624 else
625 {
626 //Print("no m_VignetteValues");
627 }
628 }
629 }
630
631 /*color[0] = m_UnconsciousVignetteColor[0];
632 color[1] = m_UnconsciousVignetteColor[1];
633 color[2] = m_UnconsciousVignetteColor[2];
634
635 intesity = m_UnconsciousVignetteIntesity;*/
636
637 SetVignette( intensity_value_total, color[0], color[1], color[2], color[3] );
638 }
639
640 static void SetBloodSaturation(float value)
641 {
642 m_BloodSaturation = value;
643 UpdateSaturation();
644 }
645
646 /*static void SetUnconsciousnessVignette(float value)
647 {
648 m_UnconsciousVignetteIntesity = value;
649 UpdateVignette();
650 }
651
652 static void RemoveUnconsciousnessVignette()
653 {
654 m_UnconsciousVignetteIntesity = 0;
655 UpdateVignette();
656 }*/
657
658 // appropriate parts of the code will call these functions
659 static void SetColorizationNV(float r, float g, float b)
660 {
661 array<float> colorizeArray = {r, g, b};
662 m_ColorizeEffects.Set(PPEffects.COLORIZE_NV, colorizeArray);
663 UpdateColorize();
664 }
665
666 static void UpdateColorize()
667 {
668 bool foundActiveEffect = false;
669 int lowestKey = 1000000;
670 array<float> chosenArray;
671 // search for active effect with highest priority (lower value of key better)
672 for (int i = 0; i < m_ColorizeEffects.Count(); i++)
673 {
674 int currentKey = m_ColorizeEffects.GetKey(i);
675 array<float> colorizeValues = m_ColorizeEffects.Get(currentKey);
676 // check for non-zero active effect
677 for (int j = 0; j < colorizeValues.Count(); j++)
678 {
679 if (colorizeValues[j] != 0.0)
680 {
681 if (currentKey < lowestKey)
682 {
683 chosenArray = colorizeValues;
684 lowestKey = currentKey;
685 foundActiveEffect = true;
686 break;
687 }
688 }
689 }
690 }
691 if (foundActiveEffect)
692 {
693 float color[4];
694 color[0] = chosenArray[0];
695 color[1] = chosenArray[1];
696 color[2] = chosenArray[2];
697 color[3] = 0;
698 m_MatColors.SetParam("ColorizationColor", color);
699 }
700 else
701 {
702 // no active event found, reset colorize effect
703 ResetColorize();
704 }
705 }
706 static void ResetColorize()
707 {
708 float color[4];
709 color[0] = 1.0;
710 color[1] = 1.0;
711 color[2] = 1.0;
712 color[3] = 0;
713 m_MatColors.SetParam("ColorizationColor", color);
714 }
715
716 // EV check for NV optics
717 static void SetEVValuePP(float value)
718 {
719 g_Game.SetEVValue(value);
720 }
721
722 // light multiplier and noise intensity (using filmgrainNV.emat!) for nvg
723 // added other parameters for filmgrainNV.emat, sharpness and grain size
724 static void SetNVParams(float light_mult, float noise_intensity, float sharpness, float grain_size)
725 {
726 Material matHDR = GetGame().GetWorld().GetMaterial("Graphics/Materials/postprocess/filmgrainNV");
727/*#ifdef PLATFORM_CONSOLE
728//worst-case scenario console fix!
729 noise_intensity = 0.0;
730#endif*/
731 g_Game.NightVissionLightParams(light_mult, noise_intensity);
732 matHDR.SetParam("Sharpness", sharpness);
733 matHDR.SetParam("GrainSize", grain_size);
734 }
735
736 // bloom PP, experimental stuff
737 static void SetBloom(float thres, float steep, float inten)
738 {
739 m_MatColors.SetParam("BloomThreshold", thres);
740 m_MatColors.SetParam("BloomSteepness", steep);
741 m_MatColors.SetParam("BloomIntensity", inten);
742 }
743
744 static void ResetAll()
745 {
746 ResetBlurEffects();
747 ResetColorEffects();
748 ResetVignettes();
749 ResetPPMask();
750 ResetDOFOverride();
751 ResetLensEffect();
752 SetBloodSaturation(1);
753 //RemoveUnconsciousnessVignette();
754 ResetColorize();
755 }
756};
@ R
reverse
Definition car.c:71
proto native void ResetPPMask()
proto native void AddPPMask(float ndcX, float ndcY, float ndcRadius, float ndcBlur)
proto native void OverrideDOF(bool enable, float focusDistance, float focusLength, float focusLengthNear, float blur, float focusDepthOffset)
Definition enmath.c:7
Deprecated; 'PPEManager' used instead.
Definition ppeffects.c:3
Result for an object found in CGame.IsBoxCollidingGeometryProxy.
DayZGame g_Game
Definition dayzgame.c:3868
proto native CGame GetGame()
proto void Print(void var)
Prints content of variable to console/log.
@ B
Definition ensystem.c:346
@ A
Definition ensystem.c:345