Using depth buffer to make water edge soft
Asked Answered
L

1

7

I want to make soft edged water. so i make a render target to hold the depth of the scene, and then i render water geometry.

And let water alpha = ( SceneDepth - WaterDepth ) * Scale

looking at the results of the following chart, the edge of water is softed, but it seem strange, like a ladder.

so how to deal with?

Thanks very much!

water alpha

Locution answered 21/3, 2013 at 6:7 Comment(4)
Which is it, OpenGL or Direct3D?Quintus
It could be a lack of resolution in the z-buffer. Have you tried pushing out the near plane a bit more?Crocker
I think your rendertarget has a too low precision to hold the z-data. Which format did you use?Adenoid
Could you post how SceneDepth, WaterDepth and Scale are determined? I'm guessing that WaterDepth and Scale are passed in via constant buffer?Duffy
A
1

I've been working on a similar issue recently.

I use transparency to soften the edges of the water.

In order to utilize the water's depth to determine the alpha value, I use the HLSL smoothstep and clamp functions to return an opacity value between 0.75f and 1.0f:

// colour can be whatever your lighting equations compute
float3 colour = (r, g, b); 

if ( SeaDepth <= 0.2f )
    discard;

float opacity = clamp( 
    smoothstep( 0.f, 12.f, SeaDepth  ), 
    .75f, 1.f
);

return float4(colour.xyz, opacity);
Alkyl answered 24/8, 2013 at 3:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.