Hi, I’m trying to render a set of special objects after the entire scene has been rendered. For this, I’m using a secondary camera (with clear flags set to “do not clear”, and also turned off), and the following code:
public Shader glow_pass;
public Camera post_processing_camera;
void OnRenderImage (RenderTexture source, RenderTexture destination){
RenderTexture test = RenderTexture.GetTemporary(Screen.width,Screen.height, 0, RenderTextureFormat.ARGB32);
post_processing_camera.SetTargetBuffers(test.colorBuffer, source.depthBuffer);
post_processing_camera.RenderWithShader(glow_pass,"RenderType");
Graphics.Blit(test,destination);
test.Release();
}
My scene setup is as follows:
I’ve a cube, which should be rendered in the glow_pass, and that cube is behind a wall. After the scene is rendered, I take it’s depth buffer (source.depthBuffer) and set it as the depthBuffer of the secondary camera, with a temprary render texture for the color buffer (test.colorBuffer).
So if everything is correct, what SHOULD happen is that the cube should not be rendered, because its using the depth buffer of the scene which has a wall in front of the cube, so the depth test should fail. The problem is that not only the cube is being rendered as if the wall/depth was not there, but also the cube is showing artifacts ( pic below)

Am I doing something wrong?