wave-harmonic / crest

A class-leading water system implemented in Unity
MIT License
3.47k stars 478 forks source link

Toggleable automatic ocean clipping under Terrain with DepthCache #567

Closed StarChick971 closed 2 years ago

StarChick971 commented 4 years ago

I managed to get the first seafloor depth slice as texture2d but it is not the full texture from OceanDepthCache, i displayed it on a quad in my scene: image

Now I can use this texture as input for clip surface shader to remove water under the terrain (in case your terrain or scene goes below sea level). Would it be possible to simply add such feature as a new depth-clip shader? The idea is to clip water under any meshfiltered by layer (i.e terrain) registering into the depth cache:

I would advise to pre-bake the ocean depth in editor to clip the ocean surface with the filtered layers.

daleeidd commented 4 years ago

I tried this idea myself a while ago. I was just using the ocean depth value directly in the shader. It only worked for me well when the Attenuation In Shallows value on SimSettingsAnimatedWaves is set to 1. Otherwise, water will rise at the shoreline and be clipped above the terrain. But with enough padding it might work.

StarChick971 commented 4 years ago

I tried this idea myself a while ago. I was just using the ocean depth value directly in the shader. It only worked for me well when the Attenuation In Shallows value on SimSettingsAnimatedWaves is set to 1. Otherwise, water will rise at the shoreline and be clipped above the terrain. But with enough padding it might work.

Yes I know, especially in stormy conditions waves are just cut brutally when reaching the clip surface above the terrain. It might need to clip only vertices below terrain to fix that behaviour, thus we could even have shorelines wave that way like this: image source: Las-Islas-Seamless-Shorelines-Curves

huwb commented 4 years ago

Hello all,

It's not clear to me that clipping under terrain helps. Is this intended to help performance?

The gpu depth test will fail if the water is behind terrain, so any surface under the terrain will not even begin drawing.

StarChick971 commented 4 years ago

Hello all,

It's not clear to me that clipping under terrain helps. Is this intended to help performance?

The gpu depth test will fail if the water is behind terrain, so any surface under the terrain will not even begin drawing.

No, it isn't about performance as we already talk about very few improvement concerning it on Discord. The topic here is to clip automatically the surface below terrain without the need to create a clipping texture with quads ourselves to remove water locally. Just imagine a volcano island, you simply don't want water to be visible inside like in this course: MR Sharing 250: HoloLens and immersive headset (I tried this course at work both AR & VR for demonstration purposes). image The problem is I have to update the clip texture each time I modify the terrain. It is ok when working alone on the same scene but not within team (one dev in charge of land terrain, other for water related stuff, etc.)

huwb commented 4 years ago

Ahh ok.

Some times it's enough to just slap in a quad to give the rough shape of the hole is it's a simple shape.

Another thing we've added is a WaterBody script which defines where water should be located. There are some words about it in the user guide here on GitHub (not in urp/hdrp until next release).

But to actually answer the question, yeah I guess this could be added. Could clip if depth is less than -2m or something like that to avoid clipping being visible. I think this could just be an option directly on the ocean material, rather than needing the clipping system active. I could try this in a bit.

huwb commented 4 years ago

Seems to work, and does not require the clipping system to be enabled (Create Clip Surface Data toggle on ocean component), so is more efficient as well.

https://github.com/crest-ocean/crest/pull/582

Feedback welcome

daleeidd commented 2 years ago

Released in 4.5. HDRP missed this feature but will add it.