Community Tutorial: Ocean Simulation

For simplicity of delivering information. It takes no extra effort to run any other spectrum or even power it off directly baked statistical data.

No reason for it not to work.

Hi very new to unreal engine and Niagara iv tried following your step to update to 5.4 but haven’t mange to get it to work got errors all over the place and have no clue if chatgpt has fixed the code or made it worse, is there any chance you can upload your project files somewhere would be much appreciated.

Sorry this didn’t work for you, I’ll try an upload it soon, I need to remove some things that I’ve added to the level.

Here -

https://www.dropbox.com/scl/fi/jq5t5ggc9sixeavnek3m5/OceanTutorial-5.4.zip?rlkey=5lt10yhx85fi2dtkad77uj9fi&dl=0

I can’t guarantee this will work on your machine but it works on mine.

EDIT - I forgot to mention, you need to fix the actor references mentioned in the last part of the tutorial otherwise you’ll get a load of errors. Basically when you move the project to another directory it doesn’t update those specific locations which it need to function.

1 Like

works amazingly thank you very much for saving me a bunch of time and effort

1 Like

i have the same problem with you, you sovled that?

Hi guys,

Do you have any idea how to force it to detect coast line and generate foam in this case?

Cheers!

Did you find a way how to rescale the waves?

When I received the project and opened it in Unreal Engine 5.4.4 and found an error message in Niagara Particle Spawn and Particle Update. Which part of the above should I add?

I’m not sure what you mean. If you’re loading my project from the above link, all you need to do is copy the extracted folder to your unreal engine projects folder, then when you open the epic launcher you should see the project listed as ‘OceanTutorial’, then you just load it. I didn’t have any errors, maybe you’re missing a plugin or something. Or, maybe it’s because I saved it in UE5.4.3? Though it should work regardless.

You’d need to share the error message if you want someone to help!

hello, i want to use Ocean Sample in UNREAL 5.2.0 , but while i open it , i get a map error.
Then all .uasset file can’t show in content browser.

Oh, it’s my mistake. I’m sorry.
I forgot to specify the path to the .ush file. It works fine now. Thank you!
By the way, what are the parameters involved in the color of the ocean??
I think I should follow the tutorial from the beginning, but it takes a lot of time to apply it as a test right away.

If the plane’s z position is the -value, color-related variables cannot be applied. Is there a way to make it apply the -value??

1 Like

Hi, first of all you did an amazing work with your cpu replication so I wanted to thank you. Secondly I was wondering if you achieved to understand how to change your code to make it work with different grid sizes(cpu smaller than gpu). Did you ? or/ and could you help me understand how I should proceed to do it ? thank you very much ( I tried to understand how to do it for more than two weeks now and I am loosing hope)

Ah, ok, my bad, I forgot that those file paths need to be changed when I posted the link to my working version (It was months before that I got it working.

Actually, It’s pretty simple to change the colour -

Go into the material on one of the planes and find the parent i.e. M_PreviewOceanWater, open that, look for the MF_scattering function node, there’s a vector 3 node going into it for DeepColor, right click on that and change it to a parameter and name it (makes it update in real time), save the material. Then change the values of that node to change the colour.

EDIT - sorry I just found that this doesn’t work when z value is negative like you said, in that case I don’t know, sorry.

System failed to compile with 24 errors.
/Engine/Generated/NiagaraEmitterInstance.ush:908:18: Err0r: use of undeclared identifier ‘BUTTERFLY_COUNT’
ButterflyPass(BUTTERFLY_COUNT-1,position.x,textureIndices.x,textureIndices.y,Real,Imaginary);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:879:2: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[textureIndices.w][position.x].xyz);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:878:65: Err0r: use of undeclared identifier ‘pingPongArray’
ButterflyPass(i,position.x,textureIndices.x,textureIndices.y,pingPongArray[textureIndices.z][position.x].xyz,
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:872:17: Err0r: use of undeclared identifier ‘BUTTERFLY_COUNT’
for(int i=0;i<BUTTERFLY_COUNT-1;i++)
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:866:3: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[1][position.x].xyz=float3(HK_DX_DY_Texture.ga,HK_DZ_Texture.g);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:864:6: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[0][position.x].xyz=float3(HK_DX_DY_Texture.rb,HK_DZ_Texture.r);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1014:32: Err0r: use of undeclared identifier ‘BUTTERFLY_COUNT’
ButterflyPassFinalNoI(BUTTERFLY_COUNT-1,position.x,textureIndices.x,textureIndices.y,Real);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:999:50: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[textureIndices.z][position.x].xyz,pingPongArray[textureIndices.w][position.x].xyz);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:999:2: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[textureIndices.z][position.x].xyz,pingPongArray[textureIndices.w][position.x].xyz);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:992:17: Err0r: use of undeclared identifier ‘BUTTERFLY_COUNT’
for(int i=0;i<BUTTERFLY_COUNT-1;i++)
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:986:3: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[1][position.x].xyz=float3(HK_DX_DY_Texture.ga,HK_DZ_Texture.g);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:984:6: Err0r: use of undeclared identifier ‘pingPongArray’
pingPongArray[0][position.x].xyz=float3(HK_DX_DY_Texture.rb,HK_DZ_Texture.r);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1128:14: Err0r: use of undeclared identifier ‘GetWrappedPosition’
SamplePos=GetWrappedPosition(position.xyz,SampleOffsets[q]);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1121:13: Err0r: use of undeclared identifier ‘GetWrappedPosition’
SamplePos=GetWrappedPosition(position.xyz,int2(0,0));
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1094:14: Err0r: use of undeclared identifier ‘GetWrappedPosition’
SamplePos=GetWrappedPosition(position.xyz,int2(-1,0));
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1090:14: Err0r: use of undeclared identifier ‘GetWrappedPosition’
SamplePos=GetWrappedPosition(position.xyz,int2(1,0));
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1086:14: Err0r: use of undeclared identifier ‘GetWrappedPosition’
SamplePos=GetWrappedPosition(position.xyz,int2(0,-1));
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1082:14: Err0r: use of undeclared identifier ‘GetWrappedPosition’
SamplePos=GetWrappedPosition(position.xyz,int2(0,1));
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:1073:19: Err0r: use of undeclared identifier ‘GetWrappedPosition’
int2 SamplePos=GetWrappedPosition(position.xyz,int2(0,0));
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:792:10: Err0r: use of undeclared identifier ‘jMul’
DispY = jMul(DispZ,dy);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:789:10: Err0r: use of undeclared identifier ‘jMul’
DispX = jMul(DispZ,dx);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:784:10: Err0r: use of undeclared identifier ‘jAdd’
DispZ = jAdd(c0, c1);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:781:14: Err0r: use of undeclared identifier ‘jMul’
float2 c1 = jMul(fourier_amp_conj, exponent_inv);
^ WaterSim, Particle GPU Compute Script,
/Engine/Generated/NiagaraEmitterInstance.ush:778:14: Err0r: use of undeclared identifier ‘jMul’
float2 c0 = jMul(fourier_amp, exponent);
^ WaterSim, Particle GPU Compute Script,

The Niagara file has all errors list up in my previous comment :
HELP!

weird, did you fix the references? (you need to do that last part of the tutorial, I’ll update my post to mention it)

Amazing sim, guys! Thank you for the great tut!

1 Like

Thanks for the positive feedback!

I wasn’t able to determine the source of my issue, although I didn’t spend a lot of additional time on it after posting my solution.

DeathreyCG had some suggestions in a subsequent post. If I understood correctly, his suggestion was to keep the grid size the same but to amortize the cost of the CPU simulation over a number of frames with some clever sampling to calculate a final displacement. However, I didn’t do any further research as I had to move on to other things.