Skip to content

Instantly share code, notes, and snippets.

@unitycoder
Created February 22, 2016 14:23
Show Gist options
  • Save unitycoder/96966397c69c15ad3e2c to your computer and use it in GitHub Desktop.
Save unitycoder/96966397c69c15ad3e2c to your computer and use it in GitHub Desktop.
Draw RenderTexture to Camera with Graphics.DrawTexture
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