Code Monkey home page Code Monkey logo

Comments (20)

huwb avatar huwb commented on May 31, 2024

Thanks for posting! Wow thats quite a bug!

I upgraded to 2018.2 and I followed the same steps. (I noticed the errors that appear in the log - I updated the setup steps to pre-empt them). I assume you also got to 0 errors.

I did not get any flicker so far, so I'll think about repro steps and post back. I will try in standalone builds.

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

So double checked and no errors at all. It appears to somehow fully cover a tile in foam for some reason every once in awhile. I caught a shot of this in the editor and you can see its a full tile flickering. Not sure if this is helpful but maybe a clue. Going through the code and the shader right now.

image

from crest.

huwb avatar huwb commented on May 31, 2024

Interesting, thanks.

A couple of thoughts occurred to me. In #34 we are discussing an issue where the delta times can be 0 in the sim which can lead to badness.

i pushed a hacky fix in 001887b . this covers _SimDeltaTimePrev, but we're not doing the same for _SimDeltaTime (and foam is generated by computing accel which divides by delta time, so this could be bad news if this is 0). could you try adding this at the top of ShapeSimWave:

_SimDeltaTime = max(_SimDeltaTime, 0.001f);

The other thing that comes to mind is that there are three ways that foam gets added, via the following lines in shaders:

ShapeSimFoam.shader - From gerstner waves: foam += 5. * _SimDeltaTime * _WaveFoamStrength * saturate(_WaveFoamCoverage - det);

ShapeSimFoam.shader - From shallow water: _ShorelineFoamStrength * _SimDeltaTime * saturate(1. - signedOceanDepth / _ShorelineFoamMaxDepth);

ShapeSimWaveGenerateFoam.shader - added into the foam buffer from the dynamic wave sim

It could be interesting to knock out the contributions of each of these in turn to see if any one of them is causing the badness (my bet would be the last one - coming from the dynamic wave sim).

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

Ok I think I know what is going on. It appears to be the LOD system. So changing foam via your suggestions did not fix it. But this lead me to playing with the LOD because I also notice as I move my camera in and out on the Y (using a fly camera) caused the foam to resize. I then switched to 2 LODs on the ocean and the problem went away. Basically because I am guessing it does not do a LOD switch with so few at that level.

Here is a video of that happening, Ignore the big foam flicker and you see some foam resizing. https://drive.google.com/open?id=1oC3ibTqeOP_37Jx0h4M9R0VXvr7jhero

image

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

Ok so it is not really the LOD system on the ocean. Set that back to 7. Its the Simulation Layers. So if I drop the resolutions to only one element or 6 elements all the same size then the problem goes away.
I still get an issue with the foam shrinking and going away as I move the camera up and down.

So the issue has something to do with the camera distance to the waves that are generating foam AND having different sim foam resolutions. It is constantly trying to adjust those resolutions and causes not just the flicker but the weird scaling of the foam. Will shoot up another video in a sec.

same link as above
https://drive.google.com/open?id=1oC3ibTqeOP_37Jx0h4M9R0VXvr7jhero

another maybe better example

https://drive.google.com/open?id=1h8z6JDg2CmbVE7nXQAnw4QwbB-eXHdFc

from crest.

huwb avatar huwb commented on May 31, 2024

It seems like sometimes the wrong textures are bound. Thanks for your tests.

I'm guessing if you knock out the foam inputs i described above, the foam will just disappear and the flickering wont be visible (but is probably still occurring).

I just tried on a different PC (setting up a new project from scratch) and I didn't see the issue. What sort of framerates are you getting (roughly - are you getting 60fps+, or does it feel 30fps or lower)? Looks like a good framerate in the videos.

I'm not sure if it will help, but could you perhaps upload the new unity project you created (just Assets and ProjectSettings folders should be enough), just in case we set something up differently?

I'm still yet to spend a lot of time repro'ing, I hope to get some time this evening. Sorry you're running into this and thanks for bearing with me and helping to track it down!

EDIT: Oh just had the thought - a renderdoc capture of the bug in action (one of the frames with too much foam) would probably shed light, if you're familiar with that end of things and feeling lucky you could try to capture one of the glitchy frames. However ideally i can find a way to repro it and then i can work through it myself (and verify any potential fix!).

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

BTW framerate is around 60+

No problem and I am just glad you are doing this project so thanks for looking into this. We have tried every other water solution (including rolling our own) and have not been happy with anything until finding Crest.

So tracked it down to something in the changes to the ocean.shader

new one which causes the flicker.
//ComputeFoam(i.foam_screenPos.x, i.lodAlpha_worldXZUndisplaced.yz, i.worldPos.xz, n_pixel, pixelZ, sceneZ, view, lightDir, bubbleCol, whiteFoamCol);

old one

				ComputeFoam(1. - i.invDeterminant_lodAlpha_worldXZUndisplaced.x, i.invDeterminant_lodAlpha_worldXZUndisplaced.zw, i.worldPos.xz, n_pixel, i.shorelineFoam_screenPos.x, pixelZ, sceneZ, view, lightDir, bubbleCol, whiteFoamCol);

old one hacked to try it which gets rid of the flicker. Does not also really work well ie foam is not correct and still get the weird changes to foam as I zoom in and zoom out. So the changes from invDeterminant_lodAlpha_worldXZUndisplaced and shoreline set from the old shader is creating the problem for me. Not sure why you would not see it perhaps because I am running this on an older card ie Radeon HD 5800 (did update to latest drivers). Still have not had any issues with that card so far any place else. This also appears to be related to the camera and LOD so something with Depth. The difference between the shaders definitely changed how foam screen position was calculated so has to be someplace in those changes. Just weird that you dont see the texture sizes changing etc as you move the camera around on the Y.

ComputeFoam(1. - i.lodAlpha_worldXZUndisplaced.x, i.lodAlpha_worldXZUndisplaced.yz, i.worldPos.xz,n_pixel, pixelZ, sceneZ, view, lightDir, bubbleCol, whiteFoamCol);

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

So tried it on some other boxes here that have newer cards and works fine (NVIDIA this time). Has to be something with this old card but would be a bit nervous to ignore the issue without understanding why since it might come up again on other cards/consoles etc and create support nightmares. So wonder what changes that would cause an issue with an older card.

from crest.

huwb avatar huwb commented on May 31, 2024

It could be a precision problem or some other hardware fun like differences in error/nan handling. I'd guess its a legit issue (that more modern cards are perhaps masking) and I'd also like to see it fixed!

Do you have a changelist for version you have that does not exhibit the problem? How did you track it down - did you bisect to get to a certain changelist, or a range of changelists? If we could determine exactly which changelist introduced the problem that would be ideal..

Renderdoc may help a lot for an issue in the shader and may be an alternative next step.. If you have the time, could you please:

  • Turn on "Compile shader with debug info" on the ocean material - this will give symbols/source etc when debugging. Does the problem still occur? I hope it does! If it does not, all is not lost, its just a bit trickier to debug.
  • Turn off irrelevant features of the ocean material - Add Directional Light, Sub-Surface Scattering, Foam 3D Lighting, Transparency. Does the problem still occur with all these turned off?
  • Try to get a renderdoc capture on a frame where the issue occurs. If you have renderdoc installed, you should be able to load it into unity using the dropdown menu at the top right of the game view (before playing) and there'll be a little renderdoc icon at the top of the game view when in play mode which will grab a capture.
  • Renderdoc will open after grabbing a capture. Double click the capture and click some of the last events in the Texture Viewer tab. Do you see the issue in the current output /render target view? If not then its not occurring when renderdoc emulates the render, and its a dead end i think. If it is visible, could you send me the capture and I'll pray that i can also see the same issue on my side?

Hmmm that's a long chain of ifs!! But if all of that does work out it will enable me to zero in on the problem pretty fast..

In the meantime, I just spent some time out on the open ocean trying to repro it, still no luck. I did however find and fix another NaN issue, just pushed to master. I doubt its related though..

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

The build that I know works was download on July 26 from Master. The zip file says it was mod on the 22nd. I have been comparing that (ie the ocean.shader) to the current one in the latest build from master to get my info for the last post. Not sure which changelist that was. I could try and start pulling in new changesets one by one and seeing when the problem pops up. Guessing its whenever you bumped to 2.0.

I will play with RenderDoc as soon as possible and let you know.

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

Ok so the changeset that starts the issue is c1527d5: Wave sim generates foams based on accel and writes into foam sim. This one shows the ocean as all black and flickers white.

The ocean does not reappear until 275867d but has a massive NAN prop where the ocean is eaten up by black ink. BTW was seeing that in the checkins before your latest btw slowly over time at certain camera angles but it appears your most recent checkin fixed that.

275867d: Use foam value to lerp to white. Looking pretty good!

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

Ok more info. So using the c1527d5 build and setting Ocean.shader and OceanLODData.cginc back to version "e9b77e48: Fix for boat sinking under water - use ocean coll providers" fixes the problem.

It also wanted OceanSurfaceAlpha.shader updated so I did that as well but worked without it.

from crest.

huwb avatar huwb commented on May 31, 2024

Thanks this, that is gold!! This should give me plenty! I hope to focus on this this evening and hope to have some good news for you soon.

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

Turn on "Compile shader with debug info" on the ocean material - this will give symbols/source etc when debugging. Does the problem still occur? I hope it does! If it does not, all is not lost, its just a bit trickier to debug.

Yes the problem still occurs.

Turn off irrelevant features of the ocean material - Add Directional Light, Sub-Surface Scattering, Foam 3D Lighting, Transparency. Does the problem still occur with all these turned off?

Yes still happening with everything turned off and settings to 0 where I can. Only leaving foam and the foam texture on.

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

Ok here are the render docs showing the issue.

In the file CrestRenderDocCap.rdc I think I see the problem going from 1479-1980 to 1480-1502, you see the foam correctly then going to 1480 (UpdateDepthTexture) the screen fills up with "foam". Its blue like that because I turned off everything in the shader. Gray area is the water and the blue the foam.

You see it again going from 1510 to 1512-1891. The weird thing is at the end of the frame it shows the foam correctly but when I grabbed this it was not showing it in the editor or the little image shot in Render Doc. ie you can see what it looked like by looking at the icon image of the file (weird).

Capture of the issue as it happened ie during a flicker.
https://drive.google.com/open?id=1VNfu2jSW8EapuFKpVgUq_bg8x4rzZM56
https://drive.google.com/open?id=18SaMNTDPiZwbtOiYJUVWTIZX9WRiuMXa

Capture during the non flicker part.
https://drive.google.com/open?id=1_DfYIdZ92OGCml--sK8_3ZDxj5W2EXAo

from crest.

huwb avatar huwb commented on May 31, 2024

Nice one!

At first RenderDoc showed a bunch of warnings about NaNs in texture coordinates for sampling the foam texture, which i got excited about until i found that many of the shader params are 0 which causes an NaN party, for both the flicker and non flicker captures :(

image

I doubt that _Time is 0 (that is set by unity engine) so I'm guessing the capture is incorrect.

This did however bring my attention to some dangerously unbound material params, which could be set to 0 which would cause NaNs, I've updated the UI ranges now. The two params were Foam Scale and Shoreline Foam Min Depth. You dont have these set to 0 on the ocean material do you? I doubt it, but worth asking i guess.

I think i'll move on from the captures and focus on the code changes next.

from crest.

huwb avatar huwb commented on May 31, 2024

I reread the above - I see you did set some things to 0 and may have run into the bad range issue that i just fixed above (although I have no idea why _Time would be 0... maybe because I'm not using it in the shader but that would be a surprising optimisation, to me at least).

You mention 1480 - what do you see exactly? I think it might be a red herring - its just showing some random stuff because there is no render target bound for colours, it only renders to the depth buffer. If you go in the other direction then I can make this even show something completely different - screenshot below. I'm not sure if you're seeing the same - both captures look pretty much identical to me so I'm probably seeing different results to you (as im on a different GPU).

On c1527d, the foam sim is not even running in the main scene! It was only in very recent versions that I enabled the foam sim in all scenes. So it doesnt appear to have anything to do with the sim. This makes c1527d a simpler place to focus.

In c1527d, the foam is just sampled directly from the alpha channel of the displacement textures, and not processed in any way. There is no foam sim running. The cameras that have the WaveDataCam scripts attached clear the displacement textures with (0,0,0,0). So the only thing that affects foam is the camera clear, and then the gerstner render. Ohhhhhhh and while writing that i think i figured out what the problem is. I'm outputting a 3-vector from the gerstner shader, but its writing to a 4-channel displacement texture, and it might be dropping random stuff into the last channel, the foam...

In ShapeGerstnerBatch.shader, could you set the return type to half4 instead of half3, and then make the return statement at the end:

return half4(i.worldPos_wt.z * result, 0.);

If that does not make a difference, I'd like to see what is happening with the alpha channel of your displacement textures. This should not require renderdoc actually - could you enable showing the alpha channel of hte disp textures on the debug overlay (this will enable alpha blending). Do you see them flickering with this enabled?

image

Finally the screenshot of the unbound RT at event 1480:

image
(btw this the only time i see the all-blue image - i think this is a ghost of a previous frame - it probably captured the previous frame buffer from your video memory and shows it here. on every other event i dont see it all blue like this, on my GPU)

from crest.

holdingjason avatar holdingjason commented on May 31, 2024

That did it! Switching to half4 worked. Great job finding this one. I know from experience how hard it is to catch stuff that you cannot repro yourself. Thanks a ton for working on this.

from crest.

huwb avatar huwb commented on May 31, 2024

Man, thats awesome news :). Would not have tracked it down without your help, so thanks to you!!!

I'll get this pushed today or tomorrow. I'll also browse around for other cases that might be lurking around...!

from crest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.