[Updated] Fluid Flow 2.5 - Realtime Flow Simulation

I’m still at a bit of a loss here. Disabling the compression did not work. Went through the adb log and added my own log entries when I press the the controller button to activate the projector and no errors in the log.

Double checked the URP render settings on my older project VS the new one and can’t find anything. Am I missing something stupid like a decal renderer on the URP?

I do get these warnings after I build the APK.

Shader warning in ‘FluidFlow/Fluid (Surface Shader)’: Cannot concatenate ‘,’ and ‘_FluidTex’ at line 102

Shader warning in ‘Shader Graphs/FluidShaderGraph’: ‘UnityMetaVertexPosition’: implicit truncation of vector type at (1)/Library/PackageCache/com.unity.render-pipelines.universal@14.0.11/Editor/ShaderGraph/Includes/Varyings.hlsl(131) (on gles3)

Hello.

I would like to duplicate an object with a material generated by FFCanvas at runtime, keeping the material. However, when I actually duplicate the object, the fluid that was written in the material will disappear. Is such a thing possible?

Also, if possible, I would like to save the texture of the fluid at the time and use it as a material with the saved fluid pre-written once I exit the scene. Is such usage possible?

What I tried are I got the RenderTexture from _ffCanvas.TextureChannels["Fluid"] and saved it as a png, and attached it to the material Fluid(Internal). However, that did not work.

Hello, yes this should be possible, and your approach looks promising too.

I assume saving the fluid texture as a .png worked properly, right?

If your copied object also has a FFCanvas attached, and if it is set to initialize automatically, then it will internally create its own fluid RenderTexture, and overwrite the textures you assign in the material via a MaterialPropertyBlock.
I would guess that that is the reason you don’t see any fluid, even after applying the texture to the material directly.

If you want to use FluidFlow on the copied object too, you can just copy the RenderTextures’ contents using Graphics.Blit(sourceFluidTex, copiedFluidTex).

If you don’t want the FFCanvas to control the copied model, you can call canvas.Uninitialize(); on the copied model, to free up any allocated resources and unset the MaterialPropertyBlocks. (ideally, you would not even initialize the FFCanvas in this case).

Note that if you are packing multiple renderers into the same FFCanvas, you may also have to set the texture atlas scale/offset of each renderer for the texture to be displayed correctly…

Best regards
Christian

Dear Christian,

Thanks for your helping, I finally got what I wanted.

This is the final code which worked correctly.

 async UniTaskVoid DuplicateFFObject(GameObject originalObject)
        {
            GameObject clone = Instantiate(originalObject);
            clone.transform.position = originalObject.transform.position;
            clone.transform.rotation = originalObject.transform.rotation;
            FFCanvas originalFFCanvas = GetComponent<FFCanvas>();
            FFCanvas duplicateFFCanvas = clone.GetComponent<FFCanvas>();

            await UniTask.Yield(destroyCancellationToken); // waiting for initialization
            
            var originalFluidTexture = originalFFCanvas.TextureChannels["Fluid"];
                
            var fluidTextureOnClone = duplicateFFCanvas.TextureChannels["Fluid"];
            
            Graphics.Blit(originalFluidTexture, fluidTextureOnClone);
        }

I really appreciate, thank you!!

1 Like

Hi Christian :slight_smile: I have a problem when I do a build, everything works fine in the editor, my npc have the fluid effect applied etc, but when I do a build, it doesn’t work as if the UV were incorrect, it applies the effect anyhow. I’ve tried putting everything in the Resources folder to see, but it doesn’t change anything. Do you know what could be causing this? Thanks a lot!

Hello @lordsamain
are there any error messages, when running the standalone version?
It sounds like something failed during the initialization of the FFCanvas, but without an error log or more information about the problem, this is pretty hard to debug.
Are you using secondary UV maps for the FFCanvas of the affected model?

Hi :slight_smile: no, I don’t have any errors and I don’t understand why everything works fine in the editor, it only does that when I launch in build mode.

I hadn’t answered all your questions, sorry. No, I don’t use secondary UV. Do you have to put FF model cache or special shaders in Resources for example?

Hi,
no, generally all shaders etc. which need to be in a Resources folder should already be in one.
And if you are not using secondary UVs, the FFModelCache would only store stitch data, so it should not mess up your models’ UVs in build.

I don’t really have any ideas what is going wrong here right now… so I can only really give you some further debugging steps…

Could you send me some screenshots from the editor vs the build?
Does this only happen with a specific mesh? Can you send me the mesh/ a small part of the scene, so I can try to replicate this locally?
Have you tried opening the demo scene in an empty project, and does it work in a build?
Is the standalone build running locally, or on some mobile device?

Hi ! it’s a PCVR game. I’ve tried it in build developpement and it works like in the editor, in build, it has the same problem. I’ve tried changing the size of the projector but it doesn’t change anything. I’m sending you two screenshots, there’s only one impact on the npc, one is small and normal and the other takes up the whole body and doesn’t follow the UV.


I tried it with just the decals and the hdrp lit shader, and it did the same thing: the decals were poorly applied. I just got this warning in the logs : Shader warning in ‘FluidFlow/Fluid (Surface Shader)’: Cannot concatenate ‘,’ and ‘_FluidTex’ at line 103

Compiling Subshader: 0, Pass: FORWARD, Fragment program with POINT
Platform defines: SHADER_API_DESKTOP UNITY_ENABLE_DETAIL_NORMALMAP UNITY_ENABLE_REFLECTION_BUFFERS UNITY_LIGHTMAP_FULL_HDR UNITY_LIGHT_PROBE_PROXY_VOLUME UNITY_PASS_FORWARDADD UNITY_PBS_USE_BRDF1 UNITY_SPECCUBE_BLENDING UNITY_SPECCUBE_BOX_PROJECTION UNITY_USE_DITHER_MASK_FOR_ALPHABLENDED_SHADOWS
Disabled keywords: DIRECTIONAL DIRECTIONAL_COOKIE FF_UV1 FOG_EXP FOG_EXP2 FOG_LINEAR LIGHTMAP_SHADOW_MIXING POINT_COOKIE SHADER_API_GLES30 SHADOWS_CUBE SHADOWS_DEPTH SHADOWS_SCREEN SHADOWS_SHADOWMASK SHADOWS_SOFT SPOT UNITY_ASTC_NORMALMAP_ENCODING UNITY_COLORSPACE_GAMMA UNITY_FRAMEBUFFER_FETCH_AVAILABLE UNITY_HALF_PRECISION_FRAGMENT_SHADER_REGISTERS UNITY_HARDWARE_TIER1 UNITY_HARDWARE_TIER2 UNITY_HARDWARE_TIER3 UNITY_LIGHTMAP_DLDR_ENCODING UNITY_LIGHTMAP_RGBM_ENCODING UNITY_METAL_SHADOWS_USE_POINT_FILTERING UNITY_NO_DXT5nm UNITY_NO_FULL_STANDARD_SHADER UNITY_NO_SCREENSPACE_SHADOWS UNITY_PBS_USE_BRDF2 UNITY_PBS_USE_BRDF3 UNITY_PRETRANSFORM_TO_DISPLAY_ORIENTATION UNITY_UNIFIED_SHADER_PRECISION_MODEL UNITY_VIRTUAL_TEXTURING

Hi, sorry I have been away for the last week…

The warning you see should not cause any problems. It seems like I have just messed up a define in FFShaderUtil.cginc. Replacing ##fluid_sampler##_TexelSize with just fluid_sampler##_TexelSize should fix the warning… (not sure if these defines even help, or just complicate things)


Sadly, I don’t think this will fix the issue…

Does it work with other meshes, or when building the demo scene? Which graphics api are you using in the build (directx, opengl, vulkan)?
Without being able to recreate this locally, this is pretty hard to debug…

Hi :slight_smile: Thanks for your reply :slight_smile: I’m using DX11, what’s strange is that in development mode build everything works fine while in full build, I have this problem. I’m using HDRP for graphics rendering in VR.

Dear Christian

I have another question, is it possible to erase the fluid that is already generated?

Kojima

Hi, if you just want to clear all the fluid, you can simply just clear the Fluid RenderTexture with (0,0,0,0).
Something like: Graphics.SetRenderTarget(fluidRT); GL.Clear(false, true, Color.clear);

If you want something like an eraser, you can simply set a negative fluid amount in your decal/brush.

Thanks,

But I’m using AddParticle(this FFSimulatorParticle sim, Vector2 uv, float amount, float speed, Color color) of ParticlesExtension.cs because it provides me what I exactly want.

I’d like to use eraser-style and tried to set a negative amount to the method, but it doesn’t work.

Hi,
ok, so just to be sure: you want to spawn a particle, which erases previously added fluid while dripping down the object, right?
If you just want the fluid trail to fade out over time, you could just add a FFEffects component and enable evaporation.

You are right, negative fluid amount would not work for the particle, as the amount is also used for tracking the particles “lifetime”. Each particle looses some of its initial amount, and once the remaining amount is too small, it is destroyed. So setting an amount <0 likely just disables it instantly.
It would be possible to support this, but this would require some non-trivial adjustments to the particle-simulator.
Though, I can think of a relatively simple workaround:

  • add a new eraser-TextureChannel to your FFCanvas
  • create a separate FFParticleSimulator targeting this new TextureChannel
  • each frame then subtract the fluid amount in this new eraser-TextureChannel from your main-fluid-TextureChannel
  • clear the contents of the eraser-TextureChannel

Not sure if this is really what you meant, but this should not be too hard to implement

Is it possible to use this with moving objects taking their velocity into account? I am working on a boat racing sim and was thinking this would be cool for when water splashes hit the boat/windshield and stream off.