multiple-pass compositing problem

Hello,

I’m working on a project where we will have a number of boats on an ocean. At the moment i’m trying to find a way to have the boats sit in the ocean but not have the ocean be visible as it is coming through the bottom of the boats.

I’ve implemented a way to do this by multiple pass rendering to different textures and composite them for the final render image.
This is the approach:
Create 3 cameras in identical locations, a Main, a Non-Ocean, and a Mask. Depending on the camera that is being used, swap materials on the objects during OnWillRenderObject, with the following logic:

Non-Ocean camera renders the scene without the ocean, to capture the bottom of the boats that may be covered by water.

Mask renders a white circle around the area that includes the inside of the boat, and the ocean and background as black everywhere else, creating a black and white image mask. This mask can be covered by waves in front of the boat, but will cover any waves poking through the bottom of the boat.

in the final OnRenderImage for the main camera, a shader is used to consider the mask as alpha channel to lerp pixels from the non-ocean view overlaying them with the full scene view, effectively “revealing” the bottoms of the boats that were covered by waves.

See the screenshots for an example of what I’m talking about. The first is a shot of the problem, the second of the solution with the render textures (mask, No-Ocen) shown at the top left

The problem is when using RenderTextures is that they don’t support Anti Aliasing, so the inside of the boat is alias when everything else in the scene is not. My question is if there is a different approach to take, or if it’s possible to render the scene twice and composite together them without using RenderTextures?

Or am I missing a different approach to the problem entirely?

Thanks!


It’s a bit dated, but this is probably what you want:
http://www.unifycommunity.com/wiki/index.php?title=DepthMask

wow, thanks Daniel for pointing me in the right direction. I totally missed the boat on that one.

I get the concept, it’s a much more elegant approach than what I was doing. Unfortunately the example project doesn’t seem to work in Unity3, as you can still see the water in the hull. I’m picking apart the shader now but don’t quite know what could potentially be going wrong, or exactly how to debug it.

Is there something simple that could be an obvious reason that it doesn’t work from upgrading to Unity 3?

thanks so much,

http://forum.unity3d.com/threads/55234-depht-mask-shader-from-wiki-not-working-in-unity-3?

Isn’t their an easy way to use two cameras where one renders things on a different layer? If only I could figure out how to composite two cameras.

You don’t need to figure it out; the FM already tells you how to do it. You should RThat. :slight_smile:

Look for Depth Only.

Yes, I had read that already. I but I miss read soemthing and got confused. Works now. Thanks for the help.