OVRRTOverlayConnector.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.VR;
  4. public class OVRRTOverlayConnector : MonoBehaviour
  5. {
  6. private void ConstructRenderTextureChain()
  7. {
  8. for (int i = 0; i < 3; i++)
  9. {
  10. this.overlayRTChain[i] = new RenderTexture(this.srcRT.width, this.srcRT.height, 1, this.srcRT.format, RenderTextureReadWrite.sRGB);
  11. this.overlayRTChain[i].antiAliasing = 1;
  12. this.overlayRTChain[i].depth = 0;
  13. this.overlayRTChain[i].wrapMode = TextureWrapMode.Clamp;
  14. this.overlayRTChain[i].hideFlags = HideFlags.HideAndDontSave;
  15. this.overlayRTChain[i].Create();
  16. this.overlayTexturePtrs[i] = this.overlayRTChain[i].GetNativeTexturePtr();
  17. }
  18. }
  19. private void Start()
  20. {
  21. this.ownerCamera = base.GetComponent<Camera>();
  22. this.srcRT = this.ownerCamera.targetTexture;
  23. this.ConstructRenderTextureChain();
  24. }
  25. private void OnPostRender()
  26. {
  27. if (this.srcRT)
  28. {
  29. Graphics.Blit(this.srcRT, this.overlayRTChain[this.overlayRTIndex]);
  30. OVROverlay component = this.ovrOverlayObj.GetComponent<OVROverlay>();
  31. component.OverrideOverlayTextureInfo(this.overlayRTChain[this.overlayRTIndex], this.overlayTexturePtrs[this.overlayRTIndex], VRNode.LeftEye);
  32. this.overlayRTIndex++;
  33. this.overlayRTIndex %= 3;
  34. }
  35. }
  36. public int alphaBorderSizePixels = 3;
  37. private const int overlayRTChainSize = 3;
  38. private int overlayRTIndex;
  39. private IntPtr[] overlayTexturePtrs = new IntPtr[3];
  40. private RenderTexture[] overlayRTChain = new RenderTexture[3];
  41. public GameObject ovrOverlayObj;
  42. private RenderTexture srcRT;
  43. private Camera ownerCamera;
  44. }