Thought I would just give an update. I am able now to create fluid surface’s that are 3x greater than the previous version by making the vertex/index buffers static and updating via a texture in a custom vertex shader. The down side to this is it can no longer be a plugin and I have had to merge the code directly into the engine. (Seems you can’t use IMPLEMENT_VERTEX_FACTORY_TYPE from a plugin as it has to have been initialized before Shader Core). Unless someone can tell me of another way. I won’t be releasing the code at the moment as its a little unstable, plus I want to add in compute shader support for the algorithm. This should hopefully (Fingers crossed) allow surfaces up to 4096x4096 cells in size with little loss of speed.
Anyways here is a screenshot showing the current size I hit before slow downs occur:
RE: the IMPLEMENT_VERTEX_FACTORY_TYPE issue, you might be able to make another module in your plugin with that code in it, and set the loading phase to “PostConfigInit”. I’m not sure if this is early enough or not, but it’s much earlier than the default phase for plugin modules.
No worries, it has been an exciting trip into the deepest and darkest sections of the engine, learning about the rendering. On that note I have created a Compute Shader and moved the simulation on to the GPU. Now I can create surfaces at 2048x2048 cells with very little performance hit. Thats about an 11x increase from the original if anyone is keeping score.
Version 0.0.2 has been released to github. I have a new branch “FluidSurface” which contains the source code. You’ll need the following files/folders for it to work:
Engine/Plugins/Runtime/FluidSurface/* - Main plugin code
Engine/Shaders/FluidSurfaceShader.usf - Compute shader to perform simulation
Engine/Shaders/FluidSurfaceVertexFactory.usf - Vertex factory shader for FluidSurface rendering
Engine/Shaders/FluidSurfaceVertexFactoryCommon.usf - Common code for vertex factory
Engine/Shaders/FlatTessellation.usf - Had to make a small change to this to allow the FluidSurfaceVertexFactory to modify the world displacement prior to the material (Will explain further down why)
Engine/Shaders/PNTriangles.usf - Same as above.
It is very important to get the shaders. The plugin will not work without them.
The plugin contains the following new features:
GPU based simulation
The simulation has moved from the CPU to a Compute Shader and vertex shader/domain shader additions. This allows for larger areas to be calculated quicker. I have been able to run up to 2048x2048 tiles (About 491m wide with standard grid spacing) at realtime.
New tessellation modifications
If you enable tessellation, it will actually reduce the number of vertices/indices in needs to store in the buffers, and then uses the tessellation world displacement to offset the fluid surface (Rather than vertex world offset). It actually runs faster on larger surfaces to have tessellation enabled. New options have been added to the editor:
Build Tessellation data: This will tell the component to use the new algorithm to build the surface. If you don’t apply a tessellation material, you will see a very low quality simulation, this is because of the reduced triangle count.
Tessellation Ratio: This allows you to tweak the amount of triangles to use for tessellation, the value can go from 0.1 - 2.0 (Max is twice the normal tessellated resolution, not recommended. The recommended value is 0.125)
As stated above, I had to add some code to both FlatTessellation.usf and PNTriangles.usf (So these are mandatory for execution) which can be found wrapped within the USE_FLUIDSURFACE macro to allow the Vertex factory to apply displacement prior to the material.
Version 0.0.3 has been released to github. Moved pling calculations onto GPU and increased compute shader thread count. With tessellation and the right material setup, can now render 4096x4096 cells at realtime. Speed of all other cell counts should be increased.
Absolutely great work Ehamloptiran, a great plugin already and would really be awesome if integrated in ue4 (i think thats what is meant by pull request, im a bit of a noob when it comes to development nomenclature)
Does it work with 4.1.1? Because when I copied this to my UE4 folder, when trying to generate visual studio project to compile the engine, I got many errors in CMD command.
Please an installtaion tutorial would be appreciated. Thanks.
Hi, I have had no issues running it with 4.1.1. Are you able to post some of the error messages? Also yes I am working on a more thorough installation tutorial, I will also provide some prebuilt binaries for the more common engine versions at some point.