How can i change the texture a camera captures so that my changes are reflected on the UI in real time?
Hey guys, i implemented a native plugin for modifying textures. For this i used the sample from Unity. In the sample there, the scenario is that the c# script is attached to a plane object, there is a mesh-renderer, a 2d texture is created and set as renderer.material.mainTexture. Now the pointer is passed to the plugin using the GetNativeTexturePtr. Everything works fine, i'm able to change the texture from inside the plugin and the changes are reflected in the scene on the plane object frame by frame.
Now what i wanted to do is to change the targetTexture of a camera from the plugin. But now the changes i'm doing inside the plugin are not reflected on the targetTexture. My final scope here was to have the capturing of a camera changed by using a native plugin and the changes to be reflected and shown by the camera in real time.
The way i imagined it would work is to use 2 cameras, a main camera and a second camera in the exact same position. So, what i did is:
attach the script to the main camera, just to have access to OnPostRender callback
create programmatically a RenderTexture and pass it as targetTexture for the second camera
pass the secondCamera.targetTexture.GetNativeTexturePtr to the plugin
alter the texture inside the plugin
in the OnPostRender call Graphics.Blit(secondCamera.targetTexture, null ) to have the altered texture shown by the main camera
Well this doesn't work. In the plugin i have the correct texture and i change it and dump it to a bitmap file and all looks good. But for example if i save the secondCamera.targetTexture as a png in the OnPostRender callback (using ReadPixels) my changes in the texture are not there.
Could someone help me?
Thank you kindly.
Your answer
Follow this Question
Related Questions
Render Texture from Cameras targetTexture produces seams. 1 Answer
Problem with Samsung Galaxy Note 8 1 Answer
Why does everything render in the scene editor, but not after I build it? 0 Answers
ScreenCapture.CaptureScreenshotAsTexture() is making a milky white tinted screenshot. 1 Answer
Unity Camera areas 0 Answers