28 private Color currentColor =
new Color(0, 0, 0, 0);
29 private Color targetColor =
new Color(0, 0, 0, 0);
30 private Color deltaColor =
new Color(0, 0, 0, 0);
31 private bool fadeOverlay =
false;
33 static public void Start(Color newColor,
float duration,
bool fadeOverlay =
false)
35 SteamVR_Events.Fade.Send(newColor, duration, fadeOverlay);
38 static public void View(Color newColor,
float duration)
40 var compositor = OpenVR.Compositor;
41 if (compositor != null)
42 compositor.FadeToColor(duration, newColor.r, newColor.g, newColor.b, newColor.a,
false);
48 if (Input.GetKeyDown(KeyCode.Space))
50 SteamVR_Fade.View(Color.black, 0);
51 SteamVR_Fade.View(Color.clear, 1);
56 public void OnStartFade(Color newColor,
float duration,
bool fadeOverlay)
60 targetColor = newColor;
61 deltaColor = (targetColor - currentColor) / duration;
65 currentColor = newColor;
69 static Material fadeMaterial = null;
70 static int fadeMaterialColorID = -1;
74 if (fadeMaterial == null)
76 fadeMaterial =
new Material(Shader.Find(
"Custom/SteamVR_Fade"));
77 fadeMaterialColorID = Shader.PropertyToID(
"fadeColor");
80 SteamVR_Events.Fade.Listen(OnStartFade);
81 SteamVR_Events.FadeReady.Send();
86 SteamVR_Events.Fade.Remove(OnStartFade);
91 if (currentColor != targetColor)
94 if (Mathf.Abs(currentColor.a - targetColor.a) < Mathf.Abs(deltaColor.a) * Time.deltaTime)
96 currentColor = targetColor;
97 deltaColor =
new Color(0, 0, 0, 0);
101 currentColor += deltaColor * Time.deltaTime;
106 var overlay = SteamVR_Overlay.instance;
109 overlay.alpha = 1.0f - currentColor.a;
114 if (currentColor.a > 0 && fadeMaterial)
116 fadeMaterial.SetColor(fadeMaterialColorID, currentColor);
117 fadeMaterial.SetPass(0);
120 GL.Vertex3(-1, -1, 0);
121 GL.Vertex3( 1, -1, 0);
123 GL.Vertex3(-1, 1, 0);