In shader, modify texture for use in another shader

Hello,
I am up to an effect with water like this:

For that, i need to get a mask like this one:

but without usage of second camera (water plane is not cheep (flat shaded and modular) so I dont want to render it twice).

I am thinking of this solution:

  1. Create black texture with screen height/width and pass it to the water shader.
  2. When redering the water, for each pixel of the water plane in the screen space, modify texture pixel (and every pixel below) with white color.

Is it a good approach? Is there other, easier (cheaper)?

Is it possible to modify texture in shader? - I dont need to save the texture to CPU, because i would use it in different shader for the underwater as a mask.

Thanks

So, there’s a magic trick in that above image.

The magic trick is they’re just clipping through the water plane with the camera’s near clip, then hiding the edge with a black strip, and nothing else special.

Note the black area is as wide as the maximum variation in the ripple height. All they’re doing is placing a black quad at the near plane with a wavy patterned shader on it, likely rippled by some noise function or just another texture.

That is realy good catch - how do you know?

As i’ve implemented it, it works for some water planes (depending on the wave function), but what if we have different waters with different waves? → Leading back to the original Q.

Is there a way to get the mask from within the water shader pass - eg. can I inject data from transparent shader into some texture?

RWStructuredBuffer was the solution for me, didnt have success with RWTexture2D.