wave-harmonic / crest

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

ShapeGerstner not working with floating origin #834

Closed huwb closed 2 years ago

huwb commented 3 years ago

Describe the bug ShapeGerstner not working with floating origin. This was not heavily tested IIRC so is likely broken. Reported by discord user Junsu.

Screenshots / video These are very helpful to understand and diagnose issues.

Versions Which render pipeline (built-in/LWRP/HDRP)? Which version of LWRP/HDRP? Which version of unity (including minor, i.e. 2019.1.0f2)?

To Reproduce How can the developers reproduce this bug? Are you able to reproduce the issue in the example content/scenes? Please include steps to reproduce the behaviour, with the example content ideally so we can follow the steps on our side.

Platform

daleeidd commented 2 years ago

Came across this while looking at adding FO to FFTs. It was not hooked up so I added with fix/shape-gerstner-floating-origin. Turns out the SetOrigin method wasn't correct either. I used the update spectrum path to get it working quickly but got stuck on wind direction.

I had a look at FFTs but not sure where to begin there. Will have to deep dive into the system.

huwb commented 2 years ago

I guess when the origin moves, we need to apply an opposite offset to compensate when writing the wave buffer data into loddataanimwaves.

The fft is performed in a canonical frame. The lower left corner of every fft slice is always the origin as far as the fft is concerned. This shouldn't change. What should change is the shader that writes the data to the final displacements. I think this needs to keep track of all origin shifts and subtract these shifts from the world position before sampling the wave data. Maybe.