wave-harmonic / crest

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

ICollProvider queries excluding DynWaves #700

Open emaber opened 3 years ago

emaber commented 3 years ago

we are trying to use DynWaves as a cosmetic feature only, but we don't want the dynamic waves to impact my simulation which is based on Ocean queries using OceanRenderer.Instance.CollisionProvider.

Unfortunately there seems to be no way to exclude DynWaves from the query.

Things we already explored:

Is this something that can be achieved already, or planned in any way, or what would be the best approach to look into this?

Thank you

huwb commented 3 years ago

Hi there, yeah its an issue with our stuff.

The CPU option excludes too many Ocean features

Which features out of interest? The CPU should be a valid option, but is rarely used and probably way out of date

The trouble is that the dynamic waves are simulated at multiple resolutions/cascades, and these are copied into the displacement textures, and then a 'combine' pass integrates the data from all the cascades together. It's all mixed up together. See our siggraph talk from last year for more info about the combine pass.

I think an approach to this might be:

  1. Add a texture array for the combined dynamic waves to LodDataDynWaves. See CreateCombineBuffer() function and code around it.
  2. After dynamic wave simulation, run the combine pass, similar to the CombinePassCompute() function to combine all the dynamic wave cascades
  3. Remove the code in ShapeCombine.compute that copies in the dynamic waves
  4. Add code to Ocean.shader to sample the combined dynamic waves (this would need to be added as a new sampler)

This separates the dynamic waves from the displacement textures. They would be combined separately, and sampled from the ocean shader. This means that the dynamic wave data wont be in the displacement textures that the queries sample.

emaber commented 3 years ago

The CPU option excludes too many Ocean features

Which features out of interest? The CPU should be a valid option, but is rarely used and probably way out of date

Multiple Gerstner Inputs and attenuation.

[...]

Lot of information that we need to work on before we can provide a proper feedback on the rest!

Our understanding was that the _LD_TexArray_AnimatedWaves contains both the AnimWaves and DynWaves, while _LD_TexArray_DynamicWaves contains only the DynWaves.

So we just tried to do the following in "QueryDisplacements.compute":

return (wt_0 * _LD_TexArray_AnimatedWaves.SampleLevel(LODData_linear_clamp_sampler, uv0, 0).xyz + wt_1 * _LD_TexArray_AnimatedWaves.SampleLevel(LODData_linear_clamp_sampler, uv1, 0).xyz) - (wt_0 * _LD_TexArray_DynamicWaves.SampleLevel(LODData_linear_clamp_sampler, uv0, 0).xyz + wt_1 * _LD_TexArray_DynamicWaves.SampleLevel(LODData_linear_clamp_sampler, uv1, 0).xyz);

But it does not seem to work.

Thanks a lot for the quick answer for now. I'll update here once we work more on your proposed approach.

huwb commented 3 years ago

Two problems with naively subtrating dynamic waves from animated waves:

But i thought of an alternative approach that may work and be better:

  1. Leave animated waves the way they are now
  2. Perform a combine pass on the dynamic waves as described in my last post, probably into a new texture array
  3. In the query shader, subtract the dynamic waves, kind of like what you have, but used the combined dynamic waves, and generate a displacement to get the xyz you need

This is probably better as it avoids messing with the animated waves (which are used for foam and stuff), and avoids messing with the ocean shader.