I'm making a water shader with refraction, but objects above water also get refracted. I've used the depth buffer to stop this before, but I can't get it to work. I already use the depth buffer for coloring:
float depth = texture(DEPTH_TEXTURE, SCREEN_UV).r; depth = depth * 2.0 - 1.0; depth = PROJECTION_MATRIX / (depth + PROJECTION_MATRIX); depth += VERTEX.z; depth = exp(-depth * beer_factor); float colorDepth = clamp(1.0-depth,0.0,1.0);
The variable colorDepth is simply depth inverted and clamped between 0 and 1 to use for alpha.
The refraction in SpatialMaterial also has this problem, so that's no help either.
I thought refracting only if depth is less than zero would work, but that didn't do anything. Does anyone know how to do this?