Flowing water layer working through terrain client/server

The terrain textures with glsl. I thought I could do the same with the water layer, but apparently glsl doesn’t have access to the frame buffer so can’t do transparency. My water layer uses the transparency in the texture image, based on water depth, so water gets more opaque when deeper. The two look pretty good together. The server calculates the water texture position based on depth and other things and includes that data with the vertexes.

Indeed.

To be clear:

  • The fragment shader in GLSL outputs the RGBA color, and it can set alpha < 1. Later “blending operation” can use this (or any other value) to do the transparency.

  • So you can have transparency with GLSL (everything is rendered using GLSL in the end, on modern hardware :slight_smile: ). But you indeed do not have access to the framebuffer in the simple “forward rendering” approach so you cannot implement your own equation “how to do blending”. You just tell the model to use blending (MyAppearanceNode.AlphaMode := amBlend in Pascal, Appearance { mode "BLEND" .. } in X3D) and optionally adjust the blending equation (see 2.28.1. Blending factors (node BlendMode and field Appearance.blendMode).

I thought I had tried all the permutations when testing glsl on my water, I definitely had blending set to true… it would always display opaque even if I returned alpha 0.5 on the color. Or I could make it all transparent out side of the glsl but then lose the ability to have per pixel transparency. I think the way that it is working now using vertex tex coords is acceptable and fast, the client does almost no work. The server has access to more data (like flora layer) for selecting the tex pos in the image that would take more work to get to the client and into a glsl. But this approach does have more jagginess near water boundary. I will have to experiment more. I did want to use the gl to get the ripple effect like the terrain demo water … but it was unclear how to make that work with mine… the demo is a water plane in a x3dv file it I am not sure how to apply it to my water castlescene. That just randomizes the normals?

I’m not sure what you mean by “lose the ability to have per pixel transparency” :slight_smile: I would need to see the testcase to tell more in details.

But in general: Once you activate blending, by MyAppearanceNode.AlphaMode := amBlend, then OpenGL (after fragment shader runs) will mix the RGBA color produced by the fragment shader with the RGBA color in the framebuffer. This is done independently to what the rest of the GLSL shader does, and you could even use discard in the shader (e.g. rejecting some pixels based on any condition). If only the fragment shader doesn’t do discard then it’s RGBA output will be mixed the framebuffer’s RGBA following the blending equation, which you can control by Appearance.BlendMode.

1 Like