Rendering one Render Texture on top of the other one - Depth problems

Hi,

I have a base camera that renders to a texture, with the clearing flag set to skybox and a depth of 0, then I have another camera with the exact same settings but the depth set to 100. This second camera is rendering the main character to another texture.

No matter what the clear flags I set on the second camera, it seems to always clear the depth buffer of the first one, so character is always drawn on top, even if behind a wall.

I’m using the built-in pipeline. Any idea what I’m doing wrong?

Thanks!

If both Cameras are rendering to render textures than how are you compositing them? If you rendering both textures before combining them, keep in mind that render textures are simply 2d images and don’t have any depth-buffer information.

hey kggalla, many thanks for the reply!

I thought render textures could store depth information too.

I have tried to set the depthbuffer of the first RT on the second RT by calling SetTargetBuffers on OnPreRender, but that just displays really funky results :S

Any idea how they could be combined properly?

Actually, it looks like I may have been wrong about render textures. There is such a thing as RenderTexture.depthBuffer in the API, so it must be possible to store depth info after all.

I don’t know what you are trying to do exactly by rendering your character separately. Are you trying to do an old PS1 Final Fantasy 7 sort-of look?

hey, thanks again for the reply.

Yeah, something like that. Originaly I had everything (background and characters) rendered to a low resolution texture. That looks ok, but to be closer to the original look I wanted to apply some antialiasing to the background and that’s why I need two cameras, one will render the backgrounds with some antialiasing and then the other one will render the characters on top.