Created
February 22, 2016 14:23
-
-
Save unitycoder/96966397c69c15ad3e2c to your computer and use it in GitHub Desktop.
Draw RenderTexture to Camera with Graphics.DrawTexture
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
// attach this scrip to the camera you want to draw your rt from elsewhere | |
public class DrawRT : MonoBehaviour | |
{ | |
public RenderTexture rt; // render to this rt from another camera | |
Camera cam; | |
Rect cameraViewRect; | |
void Start() | |
{ | |
cam = GetComponent<Camera>(); | |
cameraViewRect = new Rect(cam.rect.xMin * Screen.width, Screen.height - cam.rect.yMax * Screen.height, cam.pixelWidth, cam.pixelHeight); | |
} | |
// works | |
void OnGUI() | |
{ | |
//if (Event.current.type.Equals(EventType.Repaint)) | |
// { | |
//Graphics.DrawTexture(rect, rt); | |
// } | |
} | |
// works, if have ongui method included | |
IEnumerator OnPostRender() | |
{ | |
yield return new WaitForEndOfFrame(); | |
Graphics.DrawTexture(cameraViewRect, rt); | |
} | |
// doesnt work | |
/* | |
void PostRender() | |
{ | |
Graphics.DrawTexture(rect, rt); | |
}*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment