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

  • replied
    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.

    Leave a comment:


  • replied
    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?

    Leave a comment:


  • replied
    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?

    Leave a comment:


  • replied

    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.

    Leave a comment:


  • replied
    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!

    Leave a comment:


  • replied
    Originally posted by ShaNexxx View Post

    Thanks. Can you migrate the calm ocean for me?
    I am still missing the missing .dll
    ShaNexxx, if you followed the steps in the video, there will be nothing left to migrate... all is already there. To have a calm ocean, you need to play with the blueprint ocean settings. Go to the Ocean Manger section inside BP_Ocean. There you have setting to change wave direction, to change the wave speed and to change wave amplitude. Try 0.6 for speed and 0.7 for Amplitude and see the results.

    For the missing .dll, again, doing the build as told in the video would compile and generate all the necessary dlls, so again, repeat the procedures, your results must end the same way or something is missing in your Unreal installation or Visual Studio installation.
    Last edited by NilsonLima; 04-25-2018, 06:44 AM.

    Leave a comment:


  • replied
    Hello all,

    My project is now packaging fine with no error, but when i try and run my packaged build it crashed with a "fatal error".
    I have tried rebuilding and recompiling the project and everything, but it keeps happening. Any ideas?

    Leave a comment:


  • replied
    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_Ocean 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_Ocean, 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!
    Last edited by Perregrinne; 04-27-2018, 11:55 AM. Reason: I meant to say BP_Ocean can crash the editor, not BP_Skydome, sorry.

    Leave a comment:


  • replied
    Originally posted by NilsonLima View Post

    I have just started the publishing process into Youtube and it might take a while since I don't have Adobe Premiere in this machine, so it won't go the easy and fast way. The link will be available here: https://youtu.be/1W6Z5XnUyAI in about 40-50min from this post.

    Let me know if you got it right and share your success here!
    Thanks. Can you migrate the calm ocean for me?
    I am still missing the missing .dll

    Leave a comment:


  • replied
    Originally posted by Grot13
    Hi Nilson,
    I use the plugin since UE 4.12 and each upgrade I had to redownload the project and migrate my stuff in it. Thanks to your procedure (I guess it was on last page or maybe before) I've finally succeed in creating a new one and it was easy and straightforward. My packages now have the game name and I think my project is cleaner now. Really thank you very much.

    About landscape modulation I made a post on this thread months ago with pictures to explain, unfortunately the picture hoster no longer exists and my post has vanished...



    It is also super usefull as material parameter, I made tries some times ago with the sea level parameter in a landscape material : https://youtu.be/hr7GVhHhClY
    On the video you can see the caustic function also uses this parameter to constraint it under water. It follows the water volume (not the "physics volume" checked as water") that's great
    Some shaders should react differently under water and it is possible with this simple float.
    I deal with this plugin since Dotcam released it and as gratitude I help with support for everyone wanting to use it. It is great and teaches a lot.

    Leave a comment:


  • replied
    ShaNexxx video is up with instructions to take the project from github, make it work and migrate everything to another project: https://youtu.be/1W6Z5XnUyAI

    Leave a comment:


  • replied
    Originally posted by ShaNexxx View Post

    Thanks you very much man.. waiting...
    I have just started the publishing process into Youtube and it might take a while since I don't have Adobe Premiere in this machine, so it won't go the easy and fast way. The link will be available here: https://youtu.be/1W6Z5XnUyAI in about 40-50min from this post.

    Let me know if you got it right and share your success here!

    Leave a comment:


  • replied
    Originally posted by NilsonLima View Post

    Could you please give me some time to upload a small video teaching the whole procedure?

    Come back in 1 hour and I think it will be ready.
    Thanks you very much man.. waiting...

    Leave a comment:


  • replied
    Originally posted by ShaNexxx View Post




    .
    It does not work , it gives this error ;

    Missing OceanProject Modules

    UE4Editor-OceanProject.dll
    UE4Editor-OceanPlugin.dll


    I started from visual studio, I reset the motors , transfer to another project etc. etc. but did not work..



    On another project, the plugin says old and disabling..
    Could you please give me some time to upload a small video teaching the whole procedure?

    Come back in 1 hour and I think it will be ready.

    Leave a comment:


  • replied
    Originally posted by NilsonLima View Post

    In the post 2368 above there is a complete set of steps on how to add it to a project. First thing thou is download it from GitHub and be able to successfully run it.



    .
    It does not work , it gives this error ;

    Missing OceanProject Modules

    UE4Editor-OceanProject.dll
    UE4Editor-OceanPlugin.dll


    I started from visual studio, I reset the motors , transfer to another project etc. etc. but did not work..



    On another project, the plugin says old and disabling..

    Leave a comment:

Working...
X