[Community Project] WIP Weather & Water Shader

I ended up getting it to work by copying the from one of the example maps and replacing the heightmap with my own. And it seemed to work :slight_smile:
However, I have been doing some editing on the landscape heightmap since then, so now I replaced the old one with the new one, but the update don’t show in the wave modulation. It’s basically the same problem I had before. I could try to copy the again from the example map and hope that workaround works one more time, but that is kind of a hassle and I’d have to redo all my custom settings again.
Something seems off.

Did you play with the modulation settings?

  • Enable modulation checkbox
  • Modulation Start Height
  • Modulation Height
  • Modulation Power (it is a Power node exponent)
  • Landscape (landscape asset created)
  • Heightmap Texture (your landscape heightmap)

Start Height, Height and Power should do the adjustment trick. Also the texture size should be the same as the landscape preferably in PNG since it is a lossless format. Don’t use JPEG.

I have played with those settings before and they never really made any difference. But then I don’t really have any reference to what Start Height/Height refers to. Is it height of the ? Height of the terrain? If so is it the height of the terrain below the waterline? Is it the heightmap? And if it’s refering to the heightmap, shouldn’t the values be between 0.0 and 1.0 in that case?

I would never use a JPEG though :smiley: Oh man that would be awful.
What I did try once was to use an 8-bit version of my heightmap at a lower resolution. But that just crashed UE4 everytime I tried to run the game. That made me think that the settings are only applied once you run the game, but when I checked (with the proper heightmap), there was still no difference with an updated heightmap. It was as if the old one was still being used.

So I’m still confused :slight_smile:

I will check the code and tell you how the Start Height and Height works.

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-> 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 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 level to the 200 cm above 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.

.
It does not work , it gives 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… :frowning:

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…

I have just started the publishing process into Youtube and it might take a while since I don’t have Adobe Premiere in 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 post.

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

@ShaNexxx video is up with instructions to take the project from , make it work and migrate everything to another project: UE4 - WIP Community FREE Ocean - how to migrate to a new project from start! - YouTube

I deal with plugin since released it and as gratitude I help with support for wanting to use it. It is great and teaches a lot.

Thanks. Can you migrate the calm for me?
I am still missing the missing .dll

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 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 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 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 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 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 project and keep up the good work!

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?

ShaNexxx, if you followed the steps in the video, there will be nothing left to migrate… all is already there. To have a calm , you need to play with the blueprint settings. Go to the 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.

As project has about 4 years now and it is a community effort to keep it up, mostly we are focusing on making the 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 given for free are a huge opportunity for knowledge, to experiment and understand complex systems, to maintain the code while engine evolves, and 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, is something that only experimentation can provide and I think a project like 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 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!

Thanks… Worked finally… :slight_smile:
So how does the sun work? Is there a tutorial on ?
Or weather conditions available?

how can i change size bp_ocean.

The project is more oriented towards the 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 one in the future, you can ask him.

For now, from what you get in 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 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 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?

Thanks, I think I got it to work. It seems that sometimes it doesn’t update but that might be a memory 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 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 been tried before?

You can feed 8-bit, since it uses a Texture2D class inside the code and do:

Tex2D-&gt;SRGB = true;
Tex2D-&gt;CompressionSettings = TC_VectorDisplacementmap;
Tex2D-&gt;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. 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 , where the direction should point to? Now think you are now with the at your left or your right side, where the direction should point? With in mind, you need to smooth the change into the direction as much as you can, meaning the more you are facing the (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.