VignetteEffectManager.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. namespace COM3D2.MeidoPhotoStudio.Plugin
  2. {
  3. internal 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 Serialize(System.IO.BinaryWriter binaryWriter)
  38. {
  39. binaryWriter.Write(header);
  40. binaryWriter.Write(Intensity);
  41. binaryWriter.Write(Blur);
  42. binaryWriter.Write(BlurSpread);
  43. binaryWriter.Write(ChromaticAberration);
  44. binaryWriter.Write(Active);
  45. }
  46. public void Deserialize(System.IO.BinaryReader binaryReader)
  47. {
  48. Intensity = binaryReader.ReadSingle();
  49. Blur = binaryReader.ReadSingle();
  50. BlurSpread = binaryReader.ReadSingle();
  51. ChromaticAberration = binaryReader.ReadSingle();
  52. SetEffectActive(binaryReader.ReadBoolean());
  53. }
  54. public void Activate()
  55. {
  56. if (Vignette == null)
  57. {
  58. Ready = true;
  59. Vignette = GameMain.Instance.MainCamera.GetOrAddComponent<Vignetting>();
  60. Vignette.mode = Vignetting.AberrationMode.Simple;
  61. initialIntensity = Vignette.intensity;
  62. initialBlur = Vignette.blur;
  63. initialBlurSpread = Vignette.blurSpread;
  64. initialChromaticAberration = Vignette.chromaticAberration;
  65. }
  66. }
  67. public void Deactivate()
  68. {
  69. Intensity = initialIntensity;
  70. Blur = initialBlur;
  71. BlurSpread = initialBlurSpread;
  72. ChromaticAberration = initialChromaticAberration;
  73. Vignette.enabled = false;
  74. Active = false;
  75. }
  76. public void Reset()
  77. {
  78. Vignette.intensity = initialIntensity;
  79. Vignette.blur = initialBlur;
  80. Vignette.blurSpread = initialBlurSpread;
  81. Vignette.chromaticAberration = initialChromaticAberration;
  82. }
  83. public void SetEffectActive(bool active)
  84. {
  85. Vignette.enabled = active;
  86. Active = active;
  87. if (this.Active)
  88. {
  89. Vignette.intensity = Intensity;
  90. Vignette.blur = Blur;
  91. Vignette.blurSpread = BlurSpread;
  92. Vignette.chromaticAberration = ChromaticAberration;
  93. }
  94. else Reset();
  95. }
  96. public void Update() { }
  97. }
  98. }