Community Tutorial: Ocean Simulation

The opacity variable is grey for opaque surfaces.

change blend mode to singlelayerwater, you might have to change stuff though and it might break the material.

Hi,

Thank you for this tutorial, I have managed to get ocean simulating in UE5.1.

How can I, now, implement buoyancy to this so object can float on this surface?

follow this tutorial: https://www.youtube.com/watch?v=ESXwS17Lya0

Hi,
Thank you so much for the tutorial!

I have followed the tutorial and everything went well till the Roughness Integrator Stage.
The roughness effect is done and compiled correctly, but as soon as I get to this stage it shows me the mistake and I cannot understand where I made a mistake

Issues with ocean and UE5 (mostly rendering related but i may follow up with others later as i test this):

1- TSR AA sampling doesn’t like single layer water shader, it will smear badly all water motion movements and textures, its because single water is not outputting velocity correctly.

2 - Translucent shaders can output velocity by checking “output velocity” in the material, however this will break depth fade since it creates a cyclic loop and without depth fade hard to get any water surface to look nice on edges.

However other than the cost translucent shader has other problems such as self occlusion and doesn’t play well at all with Lumen.

3 - Single layer water shader has issues with reflections and roughness, regardless of the roughness parameters (lets say you want a fully matte water surface) there seems to be a “coat” of very sharp reflections layer on top you never have control over and can’t get rid off. (it may well be Lumen sky causing this or not playing well with that shader)

Other major issues:

1 - This shader doesn’t seem to work with nanite at all or nanite tessellation displacements! not even in 5.4

2 - with UE4 style mesh tessellation gone in UE5 we are left with no options other than using a high poly mesh plane to deform the ocean correctly unless the source code of the engine is modified to re-enable mesh the original mesh tessellation back.

currently the way it stands i can’t see a method forward unless the following is done:

1 - Write a custom shader for water that is a modified version of the single water shader to solve those reflection problems and somehow enable the output of velocity to work well with AA!

2 - Make nanite displacement/tessellation compatible with output of this shader. (I wonder if this shader is outputting vector displacements which nanite is not yet compatible with? Or there may be another valid reason under the hood).

Splash Foam particles on Water surface:

Niagara has a serious problem not being able to detect displaced triangles via World offset. This is something I’m still investigating, however the question has come up for years with no documentation anywhere to help make or fake this happen correctly and keeping performance in mind.

I want to save some performance when the ocean is not visible. Setting the active flag on the UNiagaraComponent works once to deactivate it, but it will not activate after that, so I tried pause which seems to work nicely. I am seeing less than 1 ms improvement with it paused. Does pausing the UNiagaraComponent stop all the texture sampling and shaders from running temporarily, or is it just using a constant time when paused? I cannot tell other than the slight improvement. I am wondering if more performance would be gained by destroying the effect and creating it, but I don’t want to do that if creating it is going to cause the performance to spike. Is there another way to temporarily disable the effect for a performance gain?

It is trivial to have velocity written for SLW

with UE4 style mesh tessellation gone in UE5 we are left with no options other than using a high poly mesh plane to deform the ocean correctly unless the source code of the engine is modified to re-enable mesh the original mesh tessellation back.

There is a whole range of options to work with. And these days with niagara you don’t need source modified. Neither you need to rely on tessellation at all to get water surface geo. Not even it is geo that you need at all, but that is different story.

Niagara has a serious problem not being able to detect displaced triangles via World offset. This is something I’m still investigating, however the question has come up for years with no documentation anywhere to help make or fake this happen correctly and keeping performance in mind.

No, niagara does not have that problem at all. You want to get vertex data, you get it through mesh DI, and then repeat the same node network you use for WPO in niagara. Nothing of that is applicable to splashes, for which you need nothing but displacement render target.

1 Like

You will need to check output log for specific error message.

@CursorOverkill

I want to save some performance when the ocean is not visible. Setting the active flag on the UNiagaraComponent works once to deactivate it, but it will not activate after that, so I tried pause which seems to work nicely. I am seeing less than 1 ms improvement with it paused. Does pausing the UNiagaraComponent stop all the texture sampling and shaders from running temporarily, or is it just using a constant time when paused? I cannot tell other than the slight improvement. I am wondering if more performance would be gained by destroying the effect and creating it, but I don’t want to do that if creating it is going to cause the performance to spike. Is there another way to temporarily disable the effect for a performance gain?

1ms is about right cost for the whole system.

congrats to your badge Deathrey :wink:

3 Likes

Thank you! I’m getting these errors

Warnings are fine. Errors are likely caused by wrong spelling of variable name.

This part sounds very interesting, how do you mean no geo? Are you able to generate a mesh surface from particles somehow and then apply the shader on top?

Hey, quick quiestion. Anyone tried this nice ocean in UE5.4? I have working sample in 5.3 but am not able to get it into 5.4 :frowning: Thanks

2 Likes

Also i want to ask if its possible to enable collision for that ocean? So when it hits landscape it does not continue more into landscape

Hello, I am a beginner and I hope to create an ocean, so I finally found this tutorial. But this is too difficult for me. I want to know where I should go and what prerequisite knowledge to learn so that I can understand this quite complex system? I hope to learn UE related operations. I am not familiar with this system, not the algorithm for waves. I have found relevant tutorials.

Thank you very much for your efforts, and I offer the highest respect to you and the open source community.

(Text is translated using translation software)

@Deathrey this model uses Philips spectrum. Can I ask you why have you chosen this approach and if you ever considered implementing ocean using JONSWAP spectrum?

Late reply to this but it may help someone else

I had the same THREADGROUP_SIZE error while trying to compile the following modules

FX_OceanWater_Rowpass
and
FX_OceanWater_Colpass

I don’t know what any of it all means, I’m not a coder and Niagara is fairly new to me, but I was able to solve it thanks to chatgpt.

I basically copied the text from the OceanWater.ush file found in the Content folder (open it in notepad) and copied it into chatgpt asking it to search for errors and it provided me with an updated script which I pasted back into notepad and saved it (making sure the file extension is the same), then recompiled and it worked. It basically told me that the threadgroup size wasn’t defined and added a few lines of code to define it. It gave an entry of 16 in the script which I changed to 64 before saving.

System still wasn’t showing any waves so I opened the M_PreviewOceanWater material and it showed that there was an error in a texture type in one of the material functions, so I changed it to what it suggested and then saved it and everything is working now.

This was in 5.3 but is working in 5.4 also

So, someone might be interested to know how I got to that stage, I didn’t follow the tutorial as my time is limited, instead I opened the 5.1 project file provided. The 5.3 versions provided by users on this thread wouldn’t open as they gave the following error when loading the project -

”The following modules are missing or built with a different engine version: ShaderDirectory. Would you like to rebuild them now?”

but they were useful as I had an issue with the ‘FX_OceanWater_RoughnessIntegrator.uasset’ when I tried following the steps mentioned by DeathreyCG somewhere above to get it working in 5.3. So, instead I copied this asset from one of the unloadable 5.3 projects given (I can’t remember which one I used) and replaced the one that I had, then saved it, closed the engine then reopened it.

Also, I did the steps mentioned at the end of the tutorial -

!! If you choose to download sample files, keep in mind, that niagara includes, used with custom HLSL expressions in steps 7,8,9, use absolute paths, so you will need to edit relevant modules with custom HLSL expressions and adjust include path. Shader include files are in Content folder of the project. !!!

  • Open FX_OceanWater_Timestep Niagara Module Script , select Custom HLSL expression, and on selected details tab, next to an entry in Absolute Include File Paths, click button and browse to the OceanTutorial/Content/OceanWater, selecting OceanComplexMath.ush file.

  • Open FX_OceanWater_Rowpass Niagara Module Script , select Custom HLSL expression, and on selected details tab, next to an entry in Absolute Include File Paths, click … button and browse to the OceanTutorial/Content/OceanWater, selecting OceanWater.ush file.

  • Open FX_OceanWater_Colpass Niagara Module Script , select Custom HLSL expression, and on selected details tab, next to an entry in Absolute Include File Paths, click … button and browse to the OceanTutorial/Content/OceanWater, selecting OceanWater.ush file.

  • Open FX_OceanWater_ExportData Niagara Module Script , select Custom HLSL expression, and on selected details tab, next to an entry in Absolute Include File Paths, click … button and browse to the OceanTutorial/Content/OceanWater, selecting OceanExport.ush file.

I think you need to do that everytime you migrate. Anyway, I loaded a copy of the working 5.3 version in 5.4 and repeated those last steps and it’s working and it looks great.

So, basically my run down -

  • open the 5.1 project in 5.3
  • used chatgpt to check the content of OceanWater.ush for errors and updated the script
  • swapped the FX_OceanWater_RoughnessIntegrator.uasset for one from one of the 5.3 projects
    provided in the thread.
  • follow the last steps of the tutorial to fix file paths
  • open each module and recompile them
  • open the M_PreviewOceanWater material and fix any errors with texture types. i.e. wrong sampler type.
  • opened in 5.4
  • re-did the file path steps.

Hopefully I’ve not missed anything, I hope this helps someone to get it working!

5.4 screen shot (with ultra dynamic sky) and the plane duplicated a few times (I also reduced the foam by tweaking it in the niagara sytem details panel (selected from the outliner)

1 Like

Hi, does anyone know if this can work for nDisplay where all nodes will need to be synchronised together?

Yes I used it and it works on ndisplay, multiple nodes.