I am trying to use a post processing shader to create bodies of water. The water level will be at y = 0 and anything underneath that boundary will be affected by the shader. I will cast rays out from the camera position in the shader and retrieve the distance from the ground of each ray. I will then use that information to calculate how much water you are seeing through in order to calculate the color of the surface.The problem is I have no idea how to detect and calculate the distance travelled by the ray before intersecting with y = 0. Is there any way for me to achieve this effect.
Failed Code
float rayGroundIntersect(float3 rayOrigin, float3 rayDir) {
if (rayDir.y <= 0) {
return maxFloat;
}
float a = rayOrigin.y / rayDir.y;
float l = length(rayDir.xz * a);
return l;
}
A similar successful project but on a sphere.