PostProcessing specific GameObjects


In my project i want to make some custom postprocessing for specific game objects.
For example, i have 10 cubes in the scene, but need to re-render (for a postprocess step) only specific 5 of them. Currently, the postprocess consists of rendering to a texture with a simple shader, which outputs white color.
While searching for ways to do this in Unity (i’m new to Unity) i found 2 methods:

  1. add a second camera, set it up same as main camera, set it’s render target and set specific layers to render. At the same time set these layers for objects, which i need to render.
  2. draw objects with Graphics.DrawMeshNow.

Method (1) looks a kind of hacky to me. The “problem” is that objects that i need to re-render are changing constantly. It’s just something like a selected list of objects in RTS. A user is able to pick some of them and not the others. And i need to re-render those, which are picked and not the others. For this i will need to:

  1. before redering, save previous object’s layer (used for physics raycastings and stuff)
  2. set the one which is needed for second camera rendering
  3. render objects
  4. set the layer back

Looks a bit messy.

So i took method (2). It needs only one main camera and all the steps are kind of straightforward (during OnRenderImage()):

  1. set my shader pass as current
  2. set render target
  3. iterate through needed objects and through their renderers
  4. draw each of them with Graphics.DrawMeshNow(mesh, renderer.transform.localToWorldMatrix)
  5. put everything back

This looks much better and cleaner, but has one little-bit problem.
DrawMeshNow() doesn’t render statically batched meshes. Don’t know why, but seems that when i simply remove the appropriate flag, they begin to render as they should. But when flag is set, all i get is a blank screen. No matter what has been drawn previously.

So my question is, what should i do with this? Take the “hacky” method (1) with the camera, or there is something that could be done for method (2) to work with statically batched meshes?

Btw, this was tested in Unity 5.0.1f1 Personal.

A little late but here’s how I did this:

on the camera that doesn’t have post processing:

in inspector set “clear flags” to “depth only”, “culling mask” to be a layer which you want to ignore post processing, named “PrePostProcess” or something, and finally on “depth” change that to a value higher than all other camera’s “depth”

on the camera that has post processing:

set “cull mask” to all the layers you want to apply the post processing to, and again the “depth” should be lower than the other camera


set all objects that you want to ignore post processing on to have the layer “PrePostProcess” or whatever you named it