Unity Screen Texture ID

How do I find the texture of the screen at any given point in Unity? I.E. in the OnGUI function, it would be nice to be able to grab the screen’s texture, like it is passed in for OnRenderImage( ).

Would capturing a a screenshot every LateUpdate () via Texture2D.ReadPixels () work for you?

That’s the idea. Except Texture2D.ReadPixels( ) is way too slow. I’m trying to use a plugin called Syphon ( http://syphon.v002.info/ ) which has a great function where you provide it a NativeTextureID and it allows you to share that texture with another program.

The trouble with the current implementation of Syphon’s Unity plugin is that it uses OnRenderImage, which provides a RenderTexture (source) to pass, but if I have other post-processing effects going on in the scene it misses those (grabs too early), also it has a resolution issue on a couple of the cameras.

My other option may be to create a new Texture2D, then use glCopyTexSubImage2D to copy the FBO to the Texture2D hardware accelerated, then pass that Texture2D to syphon for sharing, then release the created Texture2D.

I was hoping instead that there would be an easy NativeTextureID that represented the current image before the GUI did it’s work. Or perhaps some way to grab a NativeTextureID after the last post processing effect has completed.

Maybe, there is a trick using multiple cameras or a render texture or a second render pass… something that will pass everything currently drawn back through a camera for a change at a second OnRenderImage pass.

there is no such id as there is no image. Render buffers / swap chains don’t have hard IDs nor are their memory locations even stable, the driver and gpu swap them through as they see need and fit to operate optimally.

If you don’t grab it into a persistent buffer (texture2d or render texture), there is nothing to access…

The “at which point it grabs” is a thing to tackle through multiple cameras, yes.

Hi guys,

I have the same problem as AIResearcher. I want to send my Unity output through the Syphon Server (Unity Syphon plugin) to some VJ software. Besides this Syphon Server I am using several cameras that render to a RenderTexture. This combination does not work because of the reason that AIResearcher describes: The Syphon Server grabs the RenderTexture too early.

However this topic has been dead for a while, I hope someone can help me (us) with this problem.