wave-harmonic / crest

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

Foam / wake vibration when approaching whirlpools #1123

Open Revmatek opened 1 year ago

Revmatek commented 1 year ago

Is there an existing issue for this?

Have you checked the documentation to resolve your problem?

Current Behavior

If a boat or other object approaches a whirlpool (in various configurations) as the foam or wake begins to touch the spiral / flow the rendering of the foam will beginning shake and / or vibrate from its current position as it is sucked into the flow of the whirlpool

Expected Behavior

As the boat wake approaches the whirlpool and is sucked it, the foam should appear to move smoothly with the flow of the whirlpool as it is sucked in.

Steps To Reproduce

  1. Open the "BoatWakes" dev scene
  2. Add an empty gameobject to the scene (ensure that it is in the path of the sphere wakes)
  3. Add the "Crest Whirlpool" script to the empty gameobject (increasing the radius may better display the issue)
  4. Hit the play button
  5. Move the camera to observe the foam being generated as it enters the flow of the whirlpool from various angles
  6. Observe jitter / shaking in some cases Note: The shakiness may not always be immediately apparent but it can be much much worse at times. Given this image below (obviously not shaking because it is a still frame) the vibration in the render occurs at the forward most edge of the foam on the right. Depending on how things are configured the entire foam cap inside the flow will vibrate image

Unity Version

2021.3.26f1

Crest Version

4.17.3

Render Pipeline

Built-In

Editor or Standalone

Editor (Edit Mode), Editor (Play Mode), Standalone

Environment

- OS: Windows

Anything else?

I am fairly certain this used to work in an older version (4.15.2 maybe), I recently updated my version and resolved many of the other issues I had mentioned previously. I was unable to mitigate this behavior by tweaking the settings of the whirlpool other than setting the eye radius to 0 which is not really a solution.

daleeidd commented 1 year ago

Flow does cause pulsing artefacts. Is that what you are seeing? I will need a video to understand if it is not too much trouble.

Revmatek commented 1 year ago

Flow does cause pulsing artefacts. Is that what you are seeing? I will need a video to understand if it is not too much trouble.

I will get some video.

Revmatek commented 1 year ago

Flow does cause pulsing artefacts. Is that what you are seeing? I will need a video to understand if it is not too much trouble.

Videos are low res and broken up to support upload.

This first one is the scene more or less following the repro steps:

https://github.com/wave-harmonic/crest/assets/114962753/c5df8383-90fb-4f7e-ac70-3c1015e725f7

https://github.com/wave-harmonic/crest/assets/114962753/9341f332-1041-4625-bb1b-e6f464746ea5

This one is with an actual physics objects / boat stuff happening.

https://github.com/wave-harmonic/crest/assets/114962753/7245c05a-9a1a-42c4-9377-01c01d05ac77

This is something new I am pretty sure, it did not used to do this.

daleeidd commented 1 year ago

Thanks. I wasn't able to reproduce it myself. Not sure what it could be.

Have you changed any of the simulation settings files (Foam or Dynamic Waves)? There is a simulation frequency setting for both that may help.

What is your frame rate?

Revmatek commented 1 year ago

The framerate for these in game is ~60FPS. I believe the framerate in the example scene is unbound so it was probably ~300fps. The only settings I changed in the boatwakes scene was zeroing out the spectrum for the waves to make it easier to see and adding whirlpools on empty game objects where I moved around and changed the radius.

I was able to verify this is some sort of regression, I ran the same test with the BoatWakes scene in crest version 4.15 (same unity version) and everything is nice and smooth as it gets sucked down into the whirlpools. It seems reproducible on multiple computers with 4.17.

Here is some more video comparing the 2 versions. As far as I can tell both of these have the same settings and are unaltered from the branch, with the exception of the spectrum and addition of whirlpools. The only difference I noticed is that the whirlpools do not appear until playback has started in 4.15

4.15 (smooth):

https://github.com/wave-harmonic/crest/assets/114962753/a57bbc12-426a-4da2-8cf3-2804e62ec036

4.17.3 (shaky):

image

https://github.com/wave-harmonic/crest/assets/114962753/48199652-ca1d-48cf-bfbd-f795c063a57e

Revmatek commented 1 year ago

There is a simulation frequency setting for both that may help.

For both 4.15 and 4.17 BoatWake scenes the simulation frequency is:

image

Increasing this value in 4.17 has no effect (probably undesirable performance impacts). Decreasing the value seems to make the problem much much worse. Maybe that can help reproduce it. Decreasing this value on 4.15 does degrade visuals but the overall movement is still smooth.

The foam simulation rate is 30 on both and has similar effects as described above.

Revmatek commented 1 year ago

I'm looking at this more to see if I can help pinpoint the cause and provide as much info as I can.

It does not seem to be caused by changes to the following:

It may be related to changes to (the 2 versions are pretty incompatible so its hard to tell):

Problems do not occur if "Create Flow Sim" is off Problems do not occur if "Create Flow" is off on Whirlpool Problems do not occur when passing through a CrestRegisterFlowInput Problems still occur when "Flow" is disabled on the shader (which is interesting) Problems still occur when zoomed out (and LOD still visible)

It does not seem related to foam (just easier to see). It still happens when Foam is off on the shader: The image below is just a visual reference, shaking is hard to see even on video.

image

If I manually disable foam vs sphere interaction behavior the problems still occur if only one is enabled which tells me its definitely related to flow, not foam or sphere interactions.

I am seeing a fundamental difference in wake foam between versions as well, while not really a concern it may indicate the cause.

4.15

image image

4.17

image image
daleeidd commented 1 year ago

Thanks. I was able to reproduce it only intermittently. Some machines were harder than others. I was able to reproduce a more subtle jitter reliably 4.17 and 4.15. Not sure if that means 4.15 will reproduce the less subtle case or not.

Are you able to reproduce the more noticeable jitter case (like the red plane video) reliably?

I agree that it may have something to do with SWI and flow together. Since SWI queries flow I think it has to do with queries. I will see if I can get a reliably reproducible together at some point.

Revmatek commented 1 year ago

Thanks. I was able to reproduce it only intermittently. Some machines were harder than others. I was able to reproduce a more subtle jitter reliably 4.17 and 4.15. Not sure if that means 4.15 will reproduce the less subtle case or not.

That is good news, thanks. I'm not concerned with 4.15 except as a comparison. 4.17 fixed a lot of other issues so I'm probably going to stick with it and continue updating as needed. I think there is subtle jitter in 4.15 in general, but not as extreme (that I noticed.) and it did not appear in any game builds.

Are you able to reproduce the more noticeable jitter case (like the red plane video) reliably?

Yes. Its 100% of the time in the current build with 4.17. The BoatWake scenes is about 90% of the time. I am happy to try out any available fixes / branches in the future and / or get it thoroughly tested.

I agree that it may have something to do with SWI and flow together. Since SWI queries flow I think it has to do with queries. I will see if I can get a reliably reproducible together at some point. 👍

daleeidd commented 1 year ago

I'm not concerned with 4.15 except as a comparison

Yeah, it is more about getting a more reproducible case. I am not having much luck and starting to doubt previous findings.

For both 4.15 and 4.17 BoatWake scenes the simulation frequency is:

Is that Dynamic Waves? Foam also has a simulation frequency. Have you tried increasing it to 120 too? Everything seems related to simulation frequency so far for me. This will be especially the case at high speeds.

Revmatek commented 1 year ago

Is that Dynamic Waves? Foam also has a simulation frequency. Have you tried increasing it to 120 too? Everything seems related to simulation frequency so far for me. This will be especially the case at high speeds.

I attempted to adjust both of the sliders related to simulation frequency. They seemed to have little affect on the jitter. The only time the jitter ever stopped was when flow was turned off in some form.

Revmatek commented 1 year ago

I looked at this some more and I noticed something odd and something else useful.

What was odd was that after closing the crest project and opening it later (today), it was much harder to see any jitter. I had to play around with a bit to even see a hint of what I saw before.

I noticed when I was trying to figure out where there jitter went that by removing the camera from the wake rig, the jitter seemed less, so I used a free moving camera and placed some spheres around a new whirlpool and everything seemed mostly fine. So I checked in game and it does seem related to movement in some way. It does not occur when boats are kinematic. Could be related to velocity.

I was able to narrow this down a bit more specific. I created a sphere with a foam override that also has a CrestSimpleFloatingObject on it. I placed it in the BoatWake scene and it seems fine spinning around the flow of the whirlpool. I placed an identical object in game and it freaks out like the boat does. So now I can only assume there is something different. A settings somewhere... something that changed from 4.15 -> 4.17

I copied the entire ocean from BoatWake into the problem scene and the issue still occurs. I am going to have to start picking things apart to see when the problem stops I guess.

The more I examine this the less it seems to make sense. I added a sphere with foam override at the same time the boat was having issues and it seemed to make things smoother. Removing the sphere seemed to make it worse, seems to indicate a timing issue to me or some sort of rendering out of order. The camera in the demo scene is using Update to move the camera around, my camera is using LateUpdate. Changing camera to use Update (which is not really an option) does not make it smooth however copying the Demo camera into the scene seems to be slightly smoother for some reason. It feels like I am chasing the symptoms of a different timing issue upstream related to changes from 4.15 -> 4.17 as I cannot pinpoint any one thing causing the problem and it seems unrelated to any configuration of the Ocean given that the example one has the same issues. To confuse matters even more I am no longer able to reproduce jitter in the boat wakes scene even though I was able to this morning and previously.

Revmatek commented 1 year ago

If you add a sphere to the demo scene and hardcode the framerate to not be unbound it seems like it is a lot more reproducible and looks very close to what I am seeing in game. In game I have vsync on and get around 60fps so its not exactly the same.

QualitySettings.vSyncCount = 0; Application.targetFrameRate = 50

image

Setting the framerate somewhere between 30-60 seems to display the issue. It does not always show though... which is strange. Sometimes I had to change the framerate from 30 to 50 then let it compile then hit play and it happens, other times I set it to 30 and hit play and it seems smooth, but it is definitely easier to happen. It may also help to follow the sphere with the camera as it moves. Hardcoding this behavior in 4.15 does not seem to cause this problem.

Visual reference:

image

Whirlpool settings:

image

Sphere settings:

image image

Hope this helps!

Revmatek commented 1 year ago

@daleeidd Were you able to reproduce this?

Revmatek commented 1 year ago

Here is a repro scene modifying the BoatWakes scene. Move the camera around and follow the cube. Its a bit goofy setup, but it took a while to repro in latest.

repro.zip

daleeidd commented 1 year ago

I don't believe I was able to reliably reproduce it before, but I could with your scene.

Just to confirm the issue, is it only related to physics objects? Applying interpolation to the rigid body to the repro seems to be a pretty good workaround.

Revmatek commented 1 year ago

I don't believe I was able to reliably reproduce it before, but I could with your scene.

Just to confirm the issue, is it only related to physics objects? Applying interpolation to the rigid body to the repro seems to be a pretty good workaround.

Excellent, glad you are able to see the issue now.

It does seem directly related to being tied to a physics object and flow/foam. PhysX Interpolation is not an option and does not resolve the problems at runtime or in my project. Override foam on "static" objects or transform based movement seems to have less issue.

One bizarre note about this I have been seeing off an on is that solutions can be inconsistent, for example interpolation may momentarily appear to solve the issue the same way that reducing the flow speed or changing some other setting will, but it quickly goes back to vibration foam. Similar things happen when adding new foam to the scene or removing them while attempting to troubleshoot, almost seems like it changes the timing for the better momentarily, couldn't say for sure.

I would say its some sort of timing / update issue that is revealed by FixedUpdate behavior of some sort. Something in the execution order is moving the foam/flow back to where it was or predicting its location erroneously.

Revmatek commented 7 months ago

Any updates on this?

daleeidd commented 7 months ago

No. I noticed Follow Horizontal Motion is disabled for the foam input. Does enabling change anything?

Revmatek commented 7 months ago

No. I noticed Follow Horizontal Motion is disabled for the foam input. Does enabling change anything?

It does not appear to have an affect.