Announcement

Collapse
No announcement yet.

Water foam using distance fields

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    Water foam using distance fields

    I'm trying to create water foam using distance fields. I've seen tons of people do it but for some reason I can't replicate the result. What am I doing wrong?

    Here are a few example of people that have done it:
    https://80.lv/articles/working-on-water-shaders-in-ue4/

    https://www.artstation.com/artwork/rnmNe

    When I try it this is the result I get
    https://answers.unrealengine.com/sto...-waterhelp.png

    I made the area bigger so I can see the results more clearly and this is what I got

    https://answers.unrealengine.com/sto...waterhelp2.png

    Messing around with the numbers yield even weirder results

    https://answers.unrealengine.com/sto...waterhelp3.png

    This is what the distance to nearest surface node looks like when plugged directly into base color. Does this look correct to anyone?

    https://answers.unrealengine.com/sto...waterhelp4.png
    Last edited by KrunkFu; 03-02-2018, 04:49 PM.

    #2
    Here's a water shader where I used Distance fields and flow maps for dynamic foam. It's a bit messier than the ones you posted but I always have to play a bit with the numbers depending on how big my uvs/mesh are.

    In your first screenshot the distance to nearest multiplier constant seems to be at 1, have you tried lowering it quite a bit? If I remember correctly I multiply with something like 0.01.

    Comment


      #3
      Thanks for the reply. I originally tried it at .05 and then went up and down by increments of .01 to see if changing the value worked but nothing did. It just got stranger and stranger.

      Could you do me a favor and recreate the basic foam section of any of the materials I posted just to see if I'm the only one having this issue?

      Comment


        #4
        I just got my friend to recreate it and it worked for him. For some reason it wont work for me regardless of what version of the engine I try it in. I'm more confused now than I was before.

        Comment


          #5
          What type of hardware do you have? I've had issues on my older machine (around 8 year old AMD cpu/gpu) where distance fields didn't seem to work properly on any UE version past 4.14

          Comment


            #6
            Originally posted by KrunkFu View Post
            I just got my friend to recreate it and it worked for him. For some reason it wont work for me regardless of what version of the engine I try it in. I'm more confused now than I was before.
            Did you enable Mesh Distant Field Generation in the project settings?
            Nilson Lima
            Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
            Join us at Discord: https://discord.gg/uFFSEXY

            UE4 Marketplace: Cloudscape Seasons
            supporting: Community FREE Ocean plugin

            Comment


              #7
              Originally posted by NilsonLima View Post

              Did you enable Mesh Distant Field Generation in the project settings?
              Of course. The effect im looking for does show up but only in between these weird black and white bands
              https://scontent-mia3-2.xx.fbcdn.net...98&oe=5A9F30B9


              I'm using a GTX 970, some 6 core i7, 32 gigs of ram. I think my friends graphics card is even older than mine but it works for him.

              Comment


                #8
                The node outputs a sign float value in centimeters, so when you plug you should see a gradient representing the outside of an object and the inside. The reason is that you can easily decide how to bias and clamp the values the way you want. If you look in the second link you provided in your 1st post, the step two is the correct way of do it indeed. The code you showed in the 3rd link is not like it.

                As for the hardware, you are all OK, everything works with hardware half the potency you got.
                Nilson Lima
                Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                Join us at Discord: https://discord.gg/uFFSEXY

                UE4 Marketplace: Cloudscape Seasons
                supporting: Community FREE Ocean plugin

                Comment


                  #9
                  The code from the 3rd link was from another foam material which also worked for my friend and not me. There seems to be something wrong with my version of the engine rather than something wrong with the code.

                  Comment


                    #10
                    Just as an example of what I mean here are the results of the "correct" code.
                    https://scontent-mia3-2.xx.fbcdn.net...1d&oe=5AA044F9

                    Regardless of what I do I get these strange bands that move around as I move the camera. You can see that the proper foam effect is there and working, though very sloppy, but these bands also exist. This happens regardless of what version of the material I use.

                    Would it be too much trouble to see the code for your material? I'm curious to see if this will happen with that one too. It might be something wrong with the distance to nearest surface node.

                    Comment


                      #11
                      I have replicated exactly same thing, just it is my map instead, all worked. I have put the project inside google drive, so pick it up and check: https://drive.google.com/file/d/1wy6...ew?usp=sharing

                      Even if you change the dimension for the water plane to 1000, there are no weird bands. Maybe the issue is with the plane mesh you are using, not sure.
                      Nilson Lima
                      Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                      Join us at Discord: https://discord.gg/uFFSEXY

                      UE4 Marketplace: Cloudscape Seasons
                      supporting: Community FREE Ocean plugin

                      Comment


                        #12
                        I'll do a video tutorial on how I did this:

                        https://www.youtube.com/watch?v=KWbT30_PIjw

                        ...tonight.
                        George Rolfe.
                        Technical Coordinator at Orbit Solutions Pty Ltd.

                        Comment


                          #13
                          I just reinstalled the engine and all the versions of it I had. It works in my actual game project but not in the one I use to test stuff in before it gets added to the game. I also tested in other projects I have and have gotten various results from the same banding I currently have to just a solid black or white material. Which project it works in seems to be completely random as 2 projects made in the same version of the engine present 2 different results.

                          NilsonLima The banding happens across mulitple meshes so I don't think thats the issue. I've also tested it using the ue4 primitives and that gives me the same results.

                          This is one of the things that I really hate about game development. Things can just stop working for no reason. It currently works in my actual game project but how long before it randomly doesn't?

                          Comment


                            #14
                            Did the project I posted work at least?
                            Also there is a way to visualize the distant fields in the viewport: click on top of viewport, Show->Visualize->Mesh Distance Field, and the screen will show how the meshes distance field will look like. If this does not work and all are the same, the only thing that remains that I know is that Distance Fields are disabled at Low and Mid scalability settings, it will only work starting on High settings.

                            I would not say that in game developments things just stop working, this is accurate. What we can assure right now, is that there is something different between setups that we didn't catch yet.
                            Nilson Lima
                            Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                            Join us at Discord: https://discord.gg/uFFSEXY

                            UE4 Marketplace: Cloudscape Seasons
                            supporting: Community FREE Ocean plugin

                            Comment


                              #15
                              Here she blows or something:
                              https://www.youtube.com/watch?v=6hKij7UvMlo
                              George Rolfe.
                              Technical Coordinator at Orbit Solutions Pty Ltd.

                              Comment

                              Working...
                              X