12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- using System;
- using UnityEngine;
- using UnityEngine.VR;
- public class OVRRTOverlayConnector : MonoBehaviour
- {
- private void ConstructRenderTextureChain()
- {
- for (int i = 0; i < 3; i++)
- {
- this.overlayRTChain[i] = new RenderTexture(this.srcRT.width, this.srcRT.height, 1, this.srcRT.format, RenderTextureReadWrite.sRGB);
- this.overlayRTChain[i].antiAliasing = 1;
- this.overlayRTChain[i].depth = 0;
- this.overlayRTChain[i].wrapMode = TextureWrapMode.Clamp;
- this.overlayRTChain[i].hideFlags = HideFlags.HideAndDontSave;
- this.overlayRTChain[i].Create();
- this.overlayTexturePtrs[i] = this.overlayRTChain[i].GetNativeTexturePtr();
- }
- }
- private void Start()
- {
- this.ownerCamera = base.GetComponent<Camera>();
- this.srcRT = this.ownerCamera.targetTexture;
- this.ConstructRenderTextureChain();
- }
- private void OnPostRender()
- {
- if (this.srcRT)
- {
- Graphics.Blit(this.srcRT, this.overlayRTChain[this.overlayRTIndex]);
- OVROverlay component = this.ovrOverlayObj.GetComponent<OVROverlay>();
- component.OverrideOverlayTextureInfo(this.overlayRTChain[this.overlayRTIndex], this.overlayTexturePtrs[this.overlayRTIndex], VRNode.LeftEye);
- this.overlayRTIndex++;
- this.overlayRTIndex %= 3;
- }
- }
- public int alphaBorderSizePixels = 3;
- private const int overlayRTChainSize = 3;
- private int overlayRTIndex;
- private IntPtr[] overlayTexturePtrs = new IntPtr[3];
- private RenderTexture[] overlayRTChain = new RenderTexture[3];
- public GameObject ovrOverlayObj;
- private RenderTexture srcRT;
- private Camera ownerCamera;
- }
|