I am new to unity and have to use unity for a university research I am doing. For this I need to render a scene and use an external tool to modify render image data. This tool needs to read all pixels and generate a separate image based on the original data. So far following https://github.com/Unity-Technologies/NativeRenderingPlugin I was able to change a texture. However passing the render texture to the dll does nothing. Can someone please help.
This works:
tex.filterMode = FilterMode.Point;
tex.Apply();
// Set texture onto our material
GetComponent<Renderer>().material.mainTexture = tex;
SetTextureFromUnity(tex.GetNativeTexturePtr(), tex.width, tex.height);
This does not work:
Camera camera = Camera.main;
var rt = RenderTexture.GetTemporary(Screen.width, Screen.height);
camera.targetTexture = rt;
camera.Render();
var currentRT = RenderTexture.active;
RenderTexture.active = camera.targetTexture;
camera.Render();
Texture2D image = new Texture2D(camera.targetTexture.width, camera.targetTexture.height);
image.ReadPixels(new Rect(0, 0, camera.targetTexture.width, camera.targetTexture.height), 0, 0);
image.Apply();
RenderTexture.active = currentRT;
camera.targetTexture = null;
SetTextureFromUnity(image.GetNativeTexturePtr(), image.width, image.height);
Any help is greatly appreciated. Stuck on this for a long time.