In 2017.1, Camera.targetTexture was not updated between OnPreRender and OnPostRender

Before updating to 2017, we used an alternative way of doing post effects:

  1. in OnPreRender, assign a render texture to camera.
  2. in OnPostRender, set camera.targetTexture to null, and do post effects on the updated render texture, eventually Blit to screen(null as RenderTexture).

For a mobile project, this is much better than using Unity’s OnRenderImage:

  1. We can use the appropriate format for camera.targetTexture and every intermediate RT’s used for post effects. In our case, it is R11G11B10, which has the same memory as RGBA8 while having basic ability to do HDR render. If we use OnRenderImage, the source and destination RT will be forced to RGBAHalf format, which use 2x memory than our solution.
  2. We can limit the number of intermediate RT’s to a minimum amount.

Now in Unity 2017 these are not possible anymore. If we are forced to do all post processing in OnRenderImage, memory consumption will be greatly increased especially on device with high resolution. Basically, it means that we are losing the market share of iPhone 6 and 6 plus, and other device that have 1G ram.

This is submitted as a bug, case 937031. I hope this is not the design choice of unity.

I am upgrading to 2017 recently and it seems that “the alternative way” you metioned is still working.

Sometimes it works, but in this simple example it always doesn’t work, and it works on 5.6.0f3. Open the testScene in the project and you can see the cube in game view is not spinning in 2017, which means the target texture was not updated between OnPreRender and OnPostRender.

3167154–241169–PostProcess.zip (23.8 KB)

Do you have to set the render target in pre-render each frame? What I do is to set the render target once when initializing and switch them when necessary.