HKI Core
AntiAliasingController.cs
Go to the documentation of this file.
1 using UnityEngine;
2 using UnityEngine.Rendering.PostProcessing;
3 
4 namespace HKI.Core.Settings
5 {
9  [RequireComponent(typeof(PostProcessLayer))]
10  public class AntiAliasingController : MonoBehaviour
11  {
12  // Public variables
13  [SerializeField] AntiAliasingMode AntiAliasingMode = null;
14 
15  // Private variables
16  PostProcessLayer PPL = null;
17 
18  // Awake function
19  void Awake()
20  {
21  if(AntiAliasingMode != null)
22  {
23  PPL = GetComponent<PostProcessLayer>();
24  ChangeAAMode();
25  AntiAliasingMode.OnValueChanged += ChangeAAMode;
26  }
27  else
28  Debug.LogError("There is no linked >AntiAliasingMode< variable of type >AntiAliasingMode< in this AntiAliasingController!");
29  }
30 
31  // OnDestory function
32  void OnDestroy()
33  {
34  if(AntiAliasingMode != null)
35  AntiAliasingMode.OnValueChanged -= ChangeAAMode;
36  }
37 
38  // Helper function
39  void ChangeAAMode()
40  {
41  switch(AntiAliasingMode.Value)
42  {
43  case AntiAliasingModes.Off: PPL.antialiasingMode = PostProcessLayer.Antialiasing.None; break;
44 
45  case AntiAliasingModes.FXAA: PPL.antialiasingMode = PostProcessLayer.Antialiasing.FastApproximateAntialiasing; break;
46 
47  case AntiAliasingModes.TAA: PPL.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing; break;
48 
49  case AntiAliasingModes.SMAA_Low: PPL.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing; PPL.subpixelMorphologicalAntialiasing.quality = SubpixelMorphologicalAntialiasing.Quality.Low; break;
50 
51  case AntiAliasingModes.SMAA_Medium: PPL.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing; PPL.subpixelMorphologicalAntialiasing.quality = SubpixelMorphologicalAntialiasing.Quality.Medium; break;
52 
53  case AntiAliasingModes.SMAA_High: PPL.antialiasingMode = PostProcessLayer.Antialiasing.SubpixelMorphologicalAntialiasing; PPL.subpixelMorphologicalAntialiasing.quality = SubpixelMorphologicalAntialiasing.Quality.High; break;
54 
55  default: PPL.antialiasingMode = PostProcessLayer.Antialiasing.TemporalAntialiasing; break;
56  }
57  }
58  }
59 }
Special Variable enables the use of the AntiAliasingModes data type as a variable of the settings sys...
AntiAliasingModes
All possible settings for anti aliasing.
This MonoBehaviour sets anti aliasing values on the PostProcessLayer that is attached to the same Gam...