

OutColor = texture(image, fSource + vec2(0.1, 0)) Again, pixels are showing up on the water surfaces, seemingly ignoring the stencil buffer. I confirmed the problem by instead sampling with shifted UV coordinates (rather than outputting solid yellow).

The water surfaces happen to sit at Y value 7.85. Vec3 position = texture(positions, fSource).xyz These pixels should be rejected via stenciling (appearing black, just like before), but for some reason, they're visible. #version 440 coreĪs an additional test, I tried rendering only pixels under the water surfaces with a solid color. Instead, everything is purple, including the water surface. What I'd expect here is non-submerged pixels to be purple, but the water surface pixels (previously black) to remain black (since they should still be rejected through stenciling). When I change this fragment shader to output a solid color, those underwater pixels are suddenly visible (the stencil buffer and stencil settings have not changed). With stenciling enabled, only pixels not covered by a water surface are rendered.

As you can see, it simply samples from a previously-used frame buffer and outputs the pixel directly to the screen. Here's the fragment shader I'm using (where fSource is fullscreen UV coordinates). Here's the same scene, but with water surfaces stenciled out (the black portions of the screen): For context, here's a screenshot of the scene without water surfaces: To achieve water surface transparency, I'm using a stencil buffer to render water surfaces separately from other geometry. The scene consists of a grassy environment and a small lake (visible as two surfaces).
