VignetteEffectManager.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. namespace COM3D2.MeidoPhotoStudio.Plugin
  2. {
  3. public class VignetteEffectManager : IEffectManager
  4. {
  5. public const string header = "EFFECT_VIGNETTE";
  6. private Vignetting Vignette { get; set; }
  7. private float initialIntensity;
  8. private float initialBlur;
  9. private float initialBlurSpread;
  10. private float initialChromaticAberration;
  11. public bool Ready { get; private set; }
  12. public bool Active { get; private set; }
  13. private float intensity;
  14. public float Intensity
  15. {
  16. get => intensity;
  17. set => intensity = Vignette.intensity = value;
  18. }
  19. private float blur;
  20. public float Blur
  21. {
  22. get => blur;
  23. set => blur = Vignette.blur = value;
  24. }
  25. private float blurSpread;
  26. public float BlurSpread
  27. {
  28. get => blurSpread;
  29. set => blurSpread = Vignette.blurSpread = value;
  30. }
  31. private float chromaticAberration;
  32. public float ChromaticAberration
  33. {
  34. get => chromaticAberration;
  35. set => chromaticAberration = Vignette.chromaticAberration = value;
  36. }
  37. public void Activate()
  38. {
  39. if (Vignette == null)
  40. {
  41. Ready = true;
  42. Vignette = GameMain.Instance.MainCamera.GetOrAddComponent<Vignetting>();
  43. Vignette.mode = Vignetting.AberrationMode.Simple;
  44. initialIntensity = Vignette.intensity;
  45. initialBlur = Vignette.blur;
  46. initialBlurSpread = Vignette.blurSpread;
  47. initialChromaticAberration = Vignette.chromaticAberration;
  48. }
  49. SetEffectActive(false);
  50. }
  51. public void Deactivate()
  52. {
  53. Intensity = initialIntensity;
  54. Blur = initialBlur;
  55. BlurSpread = initialBlurSpread;
  56. ChromaticAberration = initialChromaticAberration;
  57. Vignette.enabled = false;
  58. Active = false;
  59. }
  60. public void Reset()
  61. {
  62. Vignette.intensity = initialIntensity;
  63. Vignette.blur = initialBlur;
  64. Vignette.blurSpread = initialBlurSpread;
  65. Vignette.chromaticAberration = initialChromaticAberration;
  66. }
  67. public void SetEffectActive(bool active)
  68. {
  69. Vignette.enabled = active;
  70. if (Active = active)
  71. {
  72. Vignette.intensity = Intensity;
  73. Vignette.blur = Blur;
  74. Vignette.blurSpread = BlurSpread;
  75. Vignette.chromaticAberration = ChromaticAberration;
  76. }
  77. else Reset();
  78. }
  79. public void Update() { }
  80. }
  81. }