Need Help with Water Refraction Shader

Hello, so I created a project here based on @Moka’s amazing water/glass refraction demo here.

I understand since the water refraction is being faked, it’s not going to be perfect, one such case in the project I created, is objects that are not inside the water rectangle will show up inside the water refraction when IRL that wouldn’t happen. Is there any way to tweak the shader to fix this behavior? Screenshot of what I’m talking about is below.

Only thing I can think of is to figure out how to get the water refraction renderer to specifically ignore those objects using layers.

1 Like

@moka ?

1 Like

Usually Oblique Frustum Culling is a technique I’ve used for reflection / refraction clipping - it allows you to align front clipping plane of your camera (by changing projection matrix) to water surface, and so everything that is on the side you don’t want to render (above water part of the world) gets clipped out for free by GPU.

I did search for ‘oblique’ in this project which renders water, and it shows up in scripts, so perhaps you can find a solution here. Used for reflection, but refraction is the same apart from different placement of the camera.

1 Like

As @mvaligursky mentioned, you need a clipping plane, to prevent rendering unnecessary stuff into reflection/refraction buffer.

Here is a Project with Clip Plane shader implementation:
It patches global shader chunk, and has three methods to enable/disable clip plane, as well as set its position and normal. So when you render refraction, set clip plane to position and normal of water plane.