How to access the rendered frame in unity3d
Hello,
I'm using unity3d for VR development and need to access the rendered frame for some computations unrelated to the display. There is one thing i couldn't find in the documentation: how can you access the rendered frame or is it possible to access the rendered frame in unity3d?
Best, Krissy
Answer by Hellium · Oct 19, 2017 at 01:32 PM
You may be interested in OnRenderImage
OnRenderImage is called after all rendering is complete to render image.
It allows you to modify final image by processing it with shader based filters. The incoming image is source render texture. The result should end up in destination render texture. You must always issue a Graphics.Blit() or render a fullscreen quad if you override this method.
When there are multiple image filters attached to the camera, they process image sequentially, by passing first filter's destination as the source to the next filter.
This message is sent to all scripts attached to the camera.
using UnityEngine;
using System.Collections;
public class ExampleClass : MonoBehaviour {
public Material mat;
void OnRenderImage(RenderTexture src, RenderTexture dest) {
Graphics.Blit(src, dest, mat);
}
}
Just so I don't misunderstand: this method is called after each rendering cycle correct?
This is probably not exactly what I'm looking for since it is thought for postprocessing, but it might work for me. Thanks :)
Is it possible to access the frame after postprocesssing?
This method can be used to apply post processing effects. But src
contains the rendered image, as you requested.
That's why this should work for me. But since I want to create a library, it would be nice if i didn't have to use this, so that the user of my library can still override OnRenderImage (maybe I should have metoined that). But that was very helpful thank you.
Your answer
![](https://koobas.hobune.stream/wayback/20220612141402im_/https://answers.unity.com/themes/thub/images/avi.jpg)