How can I detect if I am inside a volumetric cloud? UE5.1.1

I want to add effects when the player is inside a volumetric cloud. Can someone give me an idea how to do it? Thank you.

Well to do so, how are you implementing the volumetric cloud?

I am using a volume material based on this tutorial:

My version is a little more complex, since I use more textures to generate the shape of the cloud, but the operation is the same.

Thanks in advance.

Ok so you made a material what are you attaching it to to in editor to make the cloud appear ingame?

Is the “Cloud material” of the “Volumetric Cloud Component”

it allows for a physics material not sure if you can manipulate that in any way. thing is im not sure the component has collisions, and im guessing if it did, it would be volume wide and not just where the clouds are. I think im at my limits on this, unless when you create each cloud you can spawn in a volume of some sort per cloud (which may get intense for the engine) then im not the one sorry!

Here’s a public UE project that implements, among other things, how to sample a volumetric cloud material using a dynamic material instance and render targets in UE. The basic steps are as follows:

  1. Make a copy of your cloud material or use the conservative density, which needs to have a parameter for the UVW coordinates so you can change where it samples the cloud material. Ensure all other settings for the material are the same, so if you set the UVW coordinates to a position in the world, it’s the same as the cloud material.
  2. Create a 1px render target and make a dynamic material instance of your cloud material duplicate so you can change the UVW coordinates at runtime to the player position or wherever else you need to sample.
  3. Update the render target and then sample the texture on the CPU using either blueprints, which is very inefficient, or C++, which works faster. In the example project, a single pixel sample every second should not cause any noticeable performance drop.
  4. Use the information from the sample for whatever you want. In the linked example, it is used for wind vectors and rain density to be in sync with the clouds.

I hope this helps!

1 Like

Hello. Thanks for the reply.
Today, before reading you, I had come to a similar solution. Unfortunately, the read operation causes performance drops, even when I am reading only 1 pixel.
I’ll have to see how to implement it in c++ (never code in c++ for unreal). I’ll see what I’ll do
If you can guide me I would appreciate it.

I would recommend watching a beginner guide for Visual Studio for UE.

You can optimize the blueprint version by delaying the texture reads to only read every few seconds and not every frame. You could also only updating it if the clouds or the player move far enough.

If most of your code is in blueprints, you could create a C++ function with the functionality and make it BlueprintCallable, so you don’t have to bother with C++ again.

To read textures in a more performant way you want async readback from the GPU, you can use FRHIGPU Readback, which is how the engine does it. There are many resources online for this, and ChatGPT can also provide further information. I haven’t implemented it with C++ yet, but I plan to do so in a month or two.