Announcement

Collapse
No announcement yet.

Technique for Automatic Lava Flow?

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

    Technique for Automatic Lava Flow?

    I'm searching for a good technique that makes lava flow down automatically no matter which way a mesh is positioned, and it speeds up based on the angle of the mesh facing downwards. UVs seem to be the biggest problem with an automated technique.

    I know flow maps will work beautifully for a static object, but not a rotated or tilted one. So the object would have to be repeated.

    One of the methods I tried is driving the Z value through world aligned textures. Unfortunately, while the results are more than acceptable around the object, the surfaces facing on top will always have UV issues as the texture is either static (like a planar mapped texture from the top), or if it moves, it will overlap the mess underneath and move totally in the wrong direction. And if I make the transition sharper, the textures on the side start stretching.

    I also recreated UDK's wet material example in UE4, but that method mapped the distortion to the screen position, so the lava flows very oddly with the screen when you walk around it or change the camera.

    It seems the only way to make lava flow down no matter what requires bad UVs in the finished product, or a completely procedural method that would undoubtedly be far more expensive than what I am doing. But if anyone has figured out how to make an automated lava flow material, please let me know.

    #2
    When I had similar task I've also ran into issues with UVs. My main problem was obvious discontinuity of flow at UV seam, and in my case, there was no way to hide the seam, due to procedural placement of the mesh. Eventually, I ended up doing 3-way projection, exactly as in UDK rain example, but adding a height lerp between projections based on a mask. Height lerp allowed side projections to reach further towards top, while still keeping the blend sharp enough.

    Additionally, it is possible to approximate flow vector in tangent space somewhat like this:


    It gives pretty good flow out of the box, but is prone to being affected by UVs, and seams in particular.

    There is a method to cure seam issues with this one. You would do two texture projections. One regular texture,distorted by flow, as you would do it usually, and the second one, using another UV channel. This UV channel should be laid out in such way, that its UV shells completely overlap seams of your UV0. Then you would lerp between two projections based on vertex color, or mask, bringing out second texture over original seams.
    The complication in this method lies in the fact, that second flow map and second normal map transforms need to be calculated for custom tangent basis. Theoretically it is doable, but might end up being quite unpractical.

    3-way projection looks much more usable to me. Also, in triplannar setup, you do not really need to have top projections being stationary. You could expand UDK rain example to calculate flow in each projection, rather than having flat top and scrolling sides. However that would end up being more performance intensive.
    Last edited by Deathrey; 07-29-2016, 08:51 AM.

    Comment


      #3
      This already works way better than the world projection methods I tried! Thank you!

      The problem with world projection is not what happens around UV seams, but how the texture is mapped at the top and around the sides. You can get a decent cylinder by blending two different sides, but the top surface will not flow downwards because it is inherently locked by planar map from the top down. I used world position to make a mountainous landscape and fixed this issue by using a horizontally-emphasized texture for wrapping around and a neutral base texture for the top while lerping the normals from the side so the top is always plain (to make sure the top normals don't interfere with the side ones). Obviously this solution makes rocky surfaces look smooth, but given a certain style it actually looks quite lovely. And this method has its own issues with seams popping up for seemingly no reason in certain places, most likely a flaw with the way world aligned normals are calculated because the textures have no glaring seams at all whatsoever.

      This method is the ONLY one I know of where lava will always flow down. And it only looks wrong on UV seams. I'll try this on a mesh without any UVs set up.

      Just so you know, the UDK rain example does calculate flow in all directions, it just doesn't shift the top too much. But my biggest problem with that is the flow is calculated in screen space, so when you make the effect larger and more deliberate and move around the screen, it looks very weird.

      Comment


        #4
        Originally posted by mariomguy View Post
        This already works way better than the world projection methods I tried! Thank you!

        The problem with world projection is not what happens around UV seams, but how the texture is mapped at the top and around the sides. You can get a decent cylinder by blending two different sides, but the top surface will not flow downwards because it is inherently locked by planar map from the top down. I used world position to make a mountainous landscape and fixed this issue by using a horizontally-emphasized texture for wrapping around and a neutral base texture for the top while lerping the normals from the side so the top is always plain (to make sure the top normals don't interfere with the side ones). Obviously this solution makes rocky surfaces look smooth, but given a certain style it actually looks quite lovely. And this method has its own issues with seams popping up for seemingly no reason in certain places, most likely a flaw with the way world aligned normals are calculated because the textures have no glaring seams at all whatsoever.

        This method is the ONLY one I know of where lava will always flow down. And it only looks wrong on UV seams. I'll try this on a mesh without any UVs set up.

        Just so you know, the UDK rain example does calculate flow in all directions, it just doesn't shift the top too much. But my biggest problem with that is the flow is calculated in screen space, so when you make the effect larger and more deliberate and move around the screen, it looks very weird.
        I assume we are speaking about this UDK mat:
         
        Spoiler


        If that is the case, there is no flow calculation. For RB and GB projections, B is being incremented by 0.25*RainSpeed, while R and G are shifted by 0.01*RaindSpeed. So thats... not really down. It is close to vertical, but only in projection space. RG projection is simply being panned by 0.01*RainSpeed, just so that it does not appear being still.
        This way it is relatively cheap, and it is hard to note the actual direction of the water. Fake, but cheap and efficient. That will be not as cool for lava.

        That is why I imply on possibility of calculating actual flow direction, based on relation of vertex normal or explicit normal to world down vector. You would follow the same logic, as calculating it in tangent space, but do it for projection space instead. I will try to sketch a quick MF example, if I have some time later today or tomorrow.

        Comment


          #5
          [MENTION=641]mariomguy[/MENTION]
          Here is hastily assembled example for you, just copy-paste it into a new material function:
           
          Spoiler


          This approach is universal,but far from being performance-effective.

          Comment


            #6
            Wow! It is a tad bit expensive, but that material function does fix a lot of the distortions with the simple method, and works great! Unfortunately, seams are still a problem, sometimes even causing the lava to flow in opposite directions.

            What I'm hoping for is to find a method that works for both landscape and static meshes that can then be combined for interesting designs without requiring specific assets to each mesh while allowing meshes to be scaled and rotated. I'll see if I can build something nice with this setup.

            Comment


              #7
              It works on landscapes and static meshes, scaled non-uniformly and rotated in any way. As optimization, you could use single RG projection instead of 3.

              There should not be any visible seams or discontinuities at all with this approach btw.

              Comment


                #8
                Originally posted by Deathrey View Post
                [MENTION=641]mariomguy[/MENTION]
                Here is hastily assembled example for you, just copy-paste it into a new material function:
                 
                Spoiler


                This approach is universal,but far from being performance-effective.
                got a version of this that works in 4.25?
                Matt Walton: Programmer and owner of WireLiteSoft Games.

                [Streaming Terrains][WireLiteSoft.us]

                Comment

                Working...
                X