Announcement

Collapse
No announcement yet.

[Community Project] WIP Weather & Ocean Water Shader

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Originally posted by Out0f1deas View Post
    I finally got it working in 4.19, and feel that maybe the wiki may need to clarify something for stupid people like me who didn't figure it out right off the bat, but the reason only one blueprint copied over and not the rest was because I hadn't created all of the blueprints I needed in my own project. For each blueprint you want to copy from the Ocean Project editor, you have to drag in the same blueprint from Contents in your own project, in my case, I hadn't dragged in the BP_Sun_Vector_Updater or BP_Underwater blueprints, resulting in those being left out when copying them. The whole time, all I did was drag in only the two BPs that the wiki told me to dump in. Also, if you are making a C++ project, (correct me if I'm wrong) you may have to have the Visual Studio solution saved once (if you just started a new project) in order for this to work as well. That may have been why my first attempt failed. Another really important thing I want to address is what I found out the hard way: If you are working with terrains in your project after importing and implementing the Ocean Project contents, do not have BP_Skydome selected when you click the "Terrain" tab, it will make your editor crash! While modifying terrains in the terrain editor, do not toggle the visibility of BP_Skydome, it will also make your editor crash! Aside from that, I am really looking forward to using this in my project. As of 4.18, UpdateSunPosition with Unreal's default procedural sky doesn't work (no matter what, the sun stays on the horizon), and seeing that this actually works and looks way better than Unreal's sky makes me look forward to seeing what I can do with it for my worlds. Thanks for sharing this project and keep up the good work!
    As this project has about 4 years now and it is a community effort to keep it up, mostly we are focusing on making the Ocean component work as intended, even if there is a sky and fish component integrated, they are usually replaced by other solutions people feel more compeling. Having several systems into one might be troublesome, performance wise not desirable, thats why people choose something different. People must realize that projects like this given for free are a huge opportunity for knowledge, chance to experiment and understand complex systems, chance to maintain the code while engine evolves, and this is something game development is all about, at least for my point of view, learn as much as you can experimenting by yourselves.

    I can point directions when I have time, make a video or two, but I can't put concepts inside peoples mind, this is something that only experimentation can provide and I think a project like this offers that in a level that prooves Im right.

    Out0f1deas comment makes me happy since it comes to the same conclusion: when something goes wrong we start to look at the problematic parts, isolate them and understand what works and what doesn't and this is the growth in game development I mentioned above. Once someone tackles the challenge to figure things out by themselves the process ends with a much more understanding on how things work in the asset, and also inside the engine.

    Exploration is the key! Worked in the past, now and in the future!
    Nilson Lima
    Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
    Join us at Discord: https://discord.gg/FUwTvzr

    UE4 Marketplace: Cloudscape Seasons
    supporting: Community FREE Ocean plugin

    Comment



      Originally posted by NilsonLima View Post

      Thanks.. Worked finally...
      So how does the sun work? Is there a tutorial on this?
      Or weather conditions available?

      how can i change size bp_ocean.
      Last edited by ShaNexxx; 04-25-2018, 07:44 PM.

      Comment


        Originally posted by ShaNexxx View Post



        Thanks.. Worked finally...
        So how does the sun work? Is there a tutorial on this?
        Or weather conditions available?

        how can i change size bp_ocean.
        The project is more oriented towards the Ocean part, thou there were several systems developed in parallel over time (the project is 4 years old), it includes a day and night cycle including Moon and during night you have the stars in a texture showing Milkway. There is an experimental snow. One fellow called EvoPulseGaming is working on a separate weather project which will in the end integrate with this one in the future, you can ask him.

        For now, from what you get in this project:

        - if you have in the level a BP_Skydome (you will need to remove any BP_Sky_Sphere if you add one), you need to set the light source (the one which will be your Sun). You can set at the Time section the hour which the level will start once you hit Play and Time Scale which represent how much realtime will pass for each minute in game, try 360 to speedup time by 360x. In this blueprint you can activate snow, but it will only show up when you hit Play.

        - BP_SunVector_Updater is important to read the current Sun position and feed it to the ocean material so the SSS effect is done properly and the reflections too.

        I don't understand what do you mean by change the size of bp_ocean... Which size are you talking about?
        Nilson Lima
        Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
        Join us at Discord: https://discord.gg/FUwTvzr

        UE4 Marketplace: Cloudscape Seasons
        supporting: Community FREE Ocean plugin

        Comment


          Originally posted by NilsonLima View Post

          This is the piece of code which handles the modulation. The function is supposed to return the WaveHeight for buoyancy purposes, which is in fact the real wave height at position x,y,z:

          //Landscape height modulation
          float LandscapeModulation = 1.f;
          if (bEnableLandscapeModulation && IsValid(Landscape)) // Nilson-> Modulation only if you provide the actor asset and checkbox enabled
          {
          const FVector LandLoc = Landscape->GetActorLocation();
          const FVector2D LandXY = FVector2D(LandLoc.X, LandLoc.Y);
          const FVector2D LocXY = FVector2D(location.X, location.Y);
          const FVector LandScale = Landscape->GetActorScale3D();
          const FVector2D ScaleXY = FVector2D(LandScale.X * HeightmapWidth, LandScale.Y * HeightmapHeight);

          if (LocXY > LandXY && LocXY < LandXY + ScaleXY) //optimization: don't calculate modulation if outside of landscape bounds
          {
          FVector2D UV = LocXY - (LandXY + ScaleXY / 2.f);
          UV = UV / ScaleXY + 0.5f;

          float height = GetHeightmapPixel(UV.X, UV.Y).R - 0.5f; // Nilson-> this is the function call where the heightmap texture are read for the given coordinates. The -0.5 is to correctly sign the height
          height = height * 512 * LandScale.Z + LandLoc.Z;

          LandscapeModulation = height - SeaLevel - ModulationStartHeight; // Nilson-> SeaLevel is the Z axis for the ocean actor plane
          LandscapeModulation /= FMath::Abs(ModulationStartHeight - ModulationMaxHeight);
          LandscapeModulation = 1 - FMath::Clamp(LandscapeModulation, 0.f, 1.f);
          LandscapeModulation = FMath::Pow(LandscapeModulation, ModulationPower);
          // Calculate the Gerstner Wave Sets
          if (TwoIterations)
          {
          const FVector xy = CalculateGerstnerWaveSetVector(location, time * GlobalWaveSpeed, true, false);
          const float z = CalculateGerstnerWaveSetVector(location - xy, time * GlobalWaveSpeed, false, true).Z;
          return FVector(xy.X * LandscapeModulation, xy.Y * LandscapeModulation, z * LandscapeModulation + SeaLevel);
          }
          return CalculateGerstnerWaveSetVector(location, time * GlobalWaveSpeed, !HeightOnly, true) * LandscapeModulation + FVector(0, 0, SeaLevel);
          }

          The modulation value is a value between 0 and 1 (see the clamp above) and since it is calculated earlier based on terrain height - SeaLevel - ModulationStart, for me means the modulation is actuating at landscape level as reference. So in the OceanProject Map, the value for StartHeight = -500 (at least in my project it is) and MaxHeight = 200, I deduce it wants to start modulate 500 cm bellow ocean level to the max 200 cm above ocean level.

          So, the return value in the end has the following components: The waveset height from Gerstner formula multiplied by the modulation and added to SeaLevel.


          Tell me if you understand anything different, the discussion is good and very interesting for others which might follow it up in the future.
          Thanks, I think I got it to work. It seems that sometimes it doesn't update but that might be a memory issue on my side. Not sure yet.

          As for memory, when you insert the heightmap into the modulation, that'll eat a lot of memory I imagine. Especially if you have a 16 bit heightmap @ 8k resolution. (Like I do).
          Would it be possible to modify the Ocean blueprints and shader to allow for a smaller sized 8-bit heightmap?
          Alternatively, do you think it would be possible to do modulation based on Distancefields instead? Like using distance to nearest surface, for example. Though I guess there would be interference from other objects with distance fields...

          Another thing I've been thinking about doing is to use a flowmap for wave direction. Mainly so that the waves travel towards the island and not necessarily away from it. I think perhaps a couple of gerstners could go the other way to fake some sorts of wave-bounce-thingy. Has this been tried before?

          Comment


            Originally posted by Sir_Manfred View Post

            Thanks, I think I got it to work. It seems that sometimes it doesn't update but that might be a memory issue on my side. Not sure yet.

            As for memory, when you insert the heightmap into the modulation, that'll eat a lot of memory I imagine. Especially if you have a 16 bit heightmap @ 8k resolution. (Like I do).
            Would it be possible to modify the Ocean blueprints and shader to allow for a smaller sized 8-bit heightmap?
            Alternatively, do you think it would be possible to do modulation based on Distancefields instead? Like using distance to nearest surface, for example. Though I guess there would be interference from other objects with distance fields...

            Another thing I've been thinking about doing is to use a flowmap for wave direction. Mainly so that the waves travel towards the island and not necessarily away from it. I think perhaps a couple of gerstners could go the other way to fake some sorts of wave-bounce-thingy. Has this been tried before?
            You can feed 8-bit, since it uses a Texture2D class inside the code and do:

            Tex2D->SRGB = true;
            Tex2D->CompressionSettings = TC_VectorDisplacementmap;
            Tex2D->UpdateResource();

            meaning that even if you feed 16bit it will become 8bit which is the VectorDisplacement format.

            Using Distance Fields will get interference from other objects, so it is required to mask out anything else which is not a Landscape, I am not sure yet how to accomplish it. Other objects you can use a SphereMask or BoxMask inverted and multiplied by the GetDistanceToNearestSurface node, but it wont work since there might be other objects in physical contact with the Landscape while inside the water mass, which in the end will make the modulation weird.

            For the wave direction thing thou, there might be other ways to make it work. If you are not with the camera above (flying in the sky) and following the cost, you can change the Wave Direction vector to face the camera, but to be a good effect, it must be really smoothed out to not get pops coming from the sudden change in direction. This way suppose you walk arond the entire island, it would appear the waves are always crashing to the shore. Its easier said then done, think in a situation you just give your back to the ocean, where the direction should point to? Now think you are now with the Ocean at your left or your right side, where the direction should point? With this in mind, you need to smooth the change into the direction as much as you can, meaning the more you are facing the ocean (90 degrees) the wave direction would be 100% facing the camera and a scalar to smooth the lerping to a different angle when moving to face the opposite direction. The nodes will get tricky, because you can walk into a hill and see both sides of the Island and when you rotate the camera, funny pops might appear.

            I know you will need to read the text above more than twice to picture the scene described, Im sorry but speaking my mind in another language to describe my thoughts can result in long and not well ponctuated sentences.
            Nilson Lima
            Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
            Join us at Discord: https://discord.gg/FUwTvzr

            UE4 Marketplace: Cloudscape Seasons
            supporting: Community FREE Ocean plugin

            Comment


              Hi everyone,

              thanks for the beautiful ocean!
              But it seems to have problems in local multiplayer with split screen. When player 1 moves or rotates his camera it changes the reflections and shading for player 2 (although, not the other way around). Does someone know a way I can fix that or get around it?
              Last edited by SchattenJäger42; 05-02-2018, 02:47 AM.

              Comment


                Here is an illustration of the problem in the island map. When I add a second local player in split screen the second player uses the reflections calculated by the first player's camera transform...
                Attached Files

                Comment


                  Originally posted by Sir_Manfred View Post

                  Thanks, I think I got it to work. It seems that sometimes it doesn't update but that might be a memory issue on my side. Not sure yet.

                  As for memory, when you insert the heightmap into the modulation, that'll eat a lot of memory I imagine. Especially if you have a 16 bit heightmap @ 8k resolution. (Like I do).
                  Would it be possible to modify the Ocean blueprints and shader to allow for a smaller sized 8-bit heightmap?
                  Alternatively, do you think it would be possible to do modulation based on Distancefields instead? Like using distance to nearest surface, for example. Though I guess there would be interference from other objects with distance fields...

                  Another thing I've been thinking about doing is to use a flowmap for wave direction. Mainly so that the waves travel towards the island and not necessarily away from it. I think perhaps a couple of gerstners could go the other way to fake some sorts of wave-bounce-thingy. Has this been tried before?
                  Very interesting I like the idea of a flow map. but I think you would have it is the same "size and resolution" as the heightmap and use the same placement mechanism. But that doesnt sound like a problem. I'm very curious about this.
                  James Brad Barnette
                  Senior Creative Artist
                  Sleeper Agent Creative

                  Comment


                    Originally posted by MagicBlueFrog View Post
                    Here is an illustration of the problem in the island map. When I add a second local player in split screen the second player uses the reflections calculated by the first player's camera transform...
                    I will check this for you, but as far as I remember the Ocean was not finalized in the multiplayer portion, but I might be wrong... lets hope it is just something missing somewhere. A question tho, why are you using split screen? Is that part of your gameplay or is it a way to realize if the multiplayer part is ok?
                    Nilson Lima
                    Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                    Join us at Discord: https://discord.gg/FUwTvzr

                    UE4 Marketplace: Cloudscape Seasons
                    supporting: Community FREE Ocean plugin

                    Comment


                      Originally posted by NilsonLima View Post
                      Is that part of your gameplay or is it a way to realize if the multiplayer part is ok?
                      Yeah, it is a local multiplayer project. I am actually a physicist, so I'm not new to programming but I am a bit new to game dev and Unreal. I searched around and I cannot find any discussion of reflections in split screen mode or for multiplayer, so I am surprised this is an issue for me here... Thanks for looking into it.

                      Comment


                        Originally posted by MagicBlueFrog View Post

                        Yeah, it is a local multiplayer project. I am actually a physicist, so I'm not new to programming but I am a bit new to game dev and Unreal. I searched around and I cannot find any discussion of reflections in split screen mode or for multiplayer, so I am surprised this is an issue for me here... Thanks for looking into it.
                        Technically, multiplayer uses what we call network replication, and the part which touches the point is the word "network" because to allow replication of a status for a material in multiplayer you relly on different processes to have the executable perform differently: one is the server part and the other is the client part, or in case of session hosting for cooperative mode, one is set as the hosting session while others join this one sharing the same map/environment etc.

                        What looks here is that split screen are using the same set of data, so besides having different cameras per display tile, they are using the exactly same data, therefore obtaining the wrong perspective for the reflection (that part is the planar reflections, which is a separate component built-in Unreal Engine).

                        You can start a coop mode the following way:

                        - check your console key inside your project: Menu Edit -> Project Settings -> Engine: Input -> Console Keys ( I usually use the "[" key since it works best for my international keyboard)
                        - you need to package your project for Windows (or Mac if you use it) with shortcut: Menu File -> Package Project -> Windows -> Windows 64bit
                        - run the executable file generated as : your_project_name.exe or OceanProject.exe
                        - you need to remember the name for your Map where you created your level or if using the Ocean project the one described bring up the console and type: open IslandMap?listen
                        - run another executable in the same machine or in another machine
                        - if you run in another machine, you need to know the IP address for the 1st one, here Im showing if you do in the same machine once the executable is loaded, bring the console and type: open 127.0.0.1

                        The way I described above you will have a correct way for testing multiplayer.

                        I will proceed the testings here to see if that issue with planar reflection is a wrong setup on the multiplayer part or something really caused by the split screen.
                        Nilson Lima
                        Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                        Join us at Discord: https://discord.gg/FUwTvzr

                        UE4 Marketplace: Cloudscape Seasons
                        supporting: Community FREE Ocean plugin

                        Comment


                          Originally posted by NilsonLima View Post
                          I will proceed the testings here to see if that issue with planar reflection is a wrong setup on the multiplayer part or something really caused by the split screen.
                          I strongly suspect it is not a problem with the normal multiplayer but the fact that I am trying to use a network game as a local split screen game. Do you think it would be difficult for me to repurpose the project into a local multiplayer (I'm assuming this would fix the reflection problem) and do you have a pointer for where to start with that? Can I just delete all the network references?

                          Comment


                            Originally posted by MagicBlueFrog View Post

                            I strongly suspect it is not a problem with the normal multiplayer but the fact that I am trying to use a network game as a local split screen game. Do you think it would be difficult for me to repurpose the project into a local multiplayer (I'm assuming this would fix the reflection problem) and do you have a pointer for where to start with that? Can I just delete all the network references?
                            The steps I provided above are common to any project since the multiplayer is a built-in feature inside the Engine. The only changes we do with blueprints is to set if they are replicated through network or not, and if so which variables should be replicated. The variables could be anything inside.

                            I have followed the steps above and the replication is fine for the waves and the reflections are ok too. The issue you are experiencing is really because the split screen is not a feature which allows the built-in multiplayer to work, since for it to work you need to network distinct process running in order to have an exchange of replicated values. So one single process can't handle multiplayer from the core, but as two process which matches the real situation in real world it works perfectly!

                            Later I will post a small video showing the steps above in action, get back in 1 hour that the video should be up!

                            The link is bellow:




                            Last edited by NilsonLima; 05-03-2018, 09:22 AM.
                            Nilson Lima
                            Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                            Join us at Discord: https://discord.gg/FUwTvzr

                            UE4 Marketplace: Cloudscape Seasons
                            supporting: Community FREE Ocean plugin

                            Comment


                              Originally posted by NilsonLima View Post
                              The only changes we do with blueprints is to set if they are replicated through network or not, and if so which variables should be replicated. The variables could be anything inside. The issue you are experiencing is really because the split screen is not a feature which allows the built-in multiplayer to work, since for it to work you need to network distinct process running in order to have an exchange of replicated values. So one single process can't handle multiplayer from the core, but as two process which matches the real situation in real world it works perfectly!
                              Thanks for the video. It is a little hard to hear, especially when the waves come in (but I could mostly follow).

                              But it is not really what I want. I really want a single process for a local split screen (not cool anymore?). I checked all the relevant Blueprints and the only one that had replication set was the skydome. Unsetting replication for that didn't help. I also checked all the C++ and none of them had replication explicitly (though the engine probably takes care of that in the background). I think the main issue is in the materials for the ocean shader since they all have references to camera position and direction, so assuming only one camera. There is also the InfiniteSystemComponent which follows Player 0, but setting follow mode to "stationary" just makes the waves very small and doesn't fix my split screen problem. I think in order to make it split screen compatible I need to edit the materials and make them not depend on the camera position, but I am not very familiar with materials and their functions, so the more I try to hack it the worse it looks and doesn't seem to get rid of the camera dependence. I wonder if I could create two materials and make one invisible to the other player or something like that... but I don't know how to make that work.

                              Comment


                                Originally posted by MagicBlueFrog View Post

                                Thanks for the video. It is a little hard to hear, especially when the waves come in (but I could mostly follow).

                                But it is not really what I want. I really want a single process for a local split screen (not cool anymore?). I checked all the relevant Blueprints and the only one that had replication set was the skydome. Unsetting replication for that didn't help. I also checked all the C++ and none of them had replication explicitly (though the engine probably takes care of that in the background). I think the main issue is in the materials for the ocean shader since they all have references to camera position and direction, so assuming only one camera. There is also the InfiniteSystemComponent which follows Player 0, but setting follow mode to "stationary" just makes the waves very small and doesn't fix my split screen problem. I think in order to make it split screen compatible I need to edit the materials and make them not depend on the camera position, but I am not very familiar with materials and their functions, so the more I try to hack it the worse it looks and doesn't seem to get rid of the camera dependence. I wonder if I could create two materials and make one invisible to the other player or something like that... but I don't know how to make that work.
                                Replication is only related to different processes, it won't work for a singtle process, so no change regarding that will make that work. Your issue on having the solution running on single process with a split screen will require a deep analysis. Is it the only thing messed up the reflections?

                                The infinite Ocean to work really need a single camera reference, because the Infinite Ocean is an ilusion. It is just a plane very large which is moved with the camera giving a fake infinite ocean feeling.
                                Last edited by NilsonLima; 05-04-2018, 02:02 PM.
                                Nilson Lima
                                Technical Director @ Rigel Studios Ltda - twitter: @RigelStudios
                                Join us at Discord: https://discord.gg/FUwTvzr

                                UE4 Marketplace: Cloudscape Seasons
                                supporting: Community FREE Ocean plugin

                                Comment

                                Working...
                                X