Method to mask/identify distant material (Cycles)

Humm, I’ve got a boat mesh sat on a ‘water’ plane, this plane intersects the internal area of the boat so I need to be able to set the section of the water inside the boat to transparent/invisible;

I am currently just using a footprint mask [image], it works for now but its not robust… As I’m going to need to animate waves into the water it’s not going to work for long, the footprint mask simply can’t account for the narrowing/widening of the boat at different heights, meaning that the water will be visible inside the boat at the peeks of the waves and the hole will be visible outside, under the boat in the troughs of the waves.

So, What I’m thinking is to maybe put a mesh over the top of the boat (closing the hole) and somehow setting the materials to identify that rays have passed through this new mesh before they hit the water, and set the transparency on the water that way.

Can this be done, if so, how?

And/or: Any other methods for achieving this that I’m simply not thinking of?

Thanks.

Perhaps it’s better to do it with the boolean modifier… here’s an example

The problem of doing it at shader level, is because each time the shader is going to be called, you really don’t know nothing about the origin of the ray that hits the shader (except the info from the ‘Light Path’ node). And that alone is insufficient for determining if the shader should behave as water or to be transparent.
Even with OSL, where you can throw rays to the scene to get nearby information (or even trace back the incoming ray to get normals, materialID, etc), it woun’t be an easy task, and it will slow down the rendering.

Even worse, since the Water object may occupy a large area of your image, where each pixel will be sampled N times… the slow down will be huge.

You can do it this way:


this way you can do any object transparent when it is seen through objects with transparent materials on them.

Thanks and thanks.
Bools might work, but I’ve used them enough to know they can be a bit flakey, in several hundred frames of animation there’s bound to be a few glitchy frames in there.

Ray depth however… woohoo, it’s always so simple once someone else explains how to do it, eh, that’ll work perfectly :slight_smile: