Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using depth buffer to make water edge soft

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

like image 363
xfxsworld Avatar asked Mar 21 '13 06:03

xfxsworld


1 Answers

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);
like image 54
fishfood Avatar answered Oct 21 '22 03:10

fishfood