Please consider this simple scene.

enter image description here

It’s composed of 3 different game objects. 1 background image + 1 static character image + 1 small part (with the pet) that is changed at runtime to perform an animation.

enter image description here

The Background is rendered using a dedicated camera. The character (static + anim) is rendered using another dedicated camera. Both camera are set to Depth Only with a different culling mask (each camera renders only its part). Note that the camera in charge of the character has a greater depth than the one in charge of the background (i.e. Character is rendered after the background).

I need to apply an image effect only on the character camera, but I can’t manage to find a way for this effect to not affect the background.

Example here with a Vortex effect on the character camera.

enter image description here

How would you do such a trick?


1 Answer 1


The problem is that the image effect grab the current screen after render.

Since your camera render directly to backbuffer (they only clear depth), the image effect is apply to everything.

Solution can be :

  • Setup a Camera first that clear to a transparent color, with a setup RenderTarget (you can create it by script so it is the same size as your screen) and the wanted postprocess.
  • Setup a Camera second that render your background, that clear to background color/skybox
  • Setup a Camera third, that render nothing (culling mask set to Nothing), clear nothing and have the AlphaBlit.cs script attached to it. AlphaBlit need two info : a material that use the AlphaBlit.shader and the rendertarget to blend (you'll need to assign it by script if you created it by script in the 1st step)
  • Setup a Camera fourth that render your forward character.

CAREFUL: this is a painter algorithm. Meaning everything the third camera render is rendered on top of what already there, and the fourth camera will render on top that.

I'm not sure there is a way to do better, as it would require to also distort the depth buffer, which is not possible... (not without directly rendering with a vortex effect which is more difficult)...

Of course the more optimised way to do it would be to not apply the postprocess on the 1st camera, but just make it render in a rendertarget and modify the AlphaBlit.shader to do the vortex effect as it blit that RenderTarget. But that's more complexe.

  • \$\begingroup\$ Thanks for your answer. I have some problems with "Render a camera with a script that simply does in the OnRenderImage a Blit of that RenderTarget into the destination render target (i.e. the backbuffer here)". .. because even if the color is transparent black everything is black once blit. \$\endgroup\$
    – lvictorino
    Commented Nov 27, 2015 at 11:03
  • \$\begingroup\$ edited answer with more precision \$\endgroup\$
    – Sirithang
    Commented Nov 27, 2015 at 12:43
  • \$\begingroup\$ The basic solution workflow is fine, but i am facing a unexpected problem with alpha here. Actually i want to blur foreground levels. This solution works, but it looks somehow wired. puu.sh/C6sSB/ca5d5162b0.jpg If i change clear flags color to Magenta with 0 transparency, it has a strange magenta outline at sides (shoud be just transparent). puu.sh/C6sSB/ca5d5162b0.jpg. This makes the entire solution not working for me. I am not really sure, why this happens. Switching clear flags does not help. \$\endgroup\$
    – AvrDragon
    Commented Nov 23, 2018 at 15:03

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .