Niagara Grid 2D Rain Wetness mask


,

The project is an experiment to see if it is possible to use GPU particles to create a wetness mask.

Model is from Danila Davydov : https://sketchfab.com/3d-models/a-land-explorer-free-343551d39d87444997962ed73a924917


I had the idea after watching this video: https://www.youtube.com/watch?v=mkIRG9t6nwo
The Technic uses a Niagara Grid 2D, which is used as texture. So each cell is a pixel.
Now we use a baked UV texture, so we can paint on the texture. I use the same technique for my Unreal Painter : Unreal Painter
To get the position of the particles, we use a “Particle Attribute Reader”.
A small HLSL script is used to check whether the particles have hit the object. Here is also the problem, the HLSL script has to check all particles per pixel if they have hit the pixel. This makes the whole thing quite slow. That’s why we only look at every 10 particles in the script.
It was a pretty interesting experiment, but unfortunately you can’t really use this technique at the moment.
Nevertheless, I am simply fascinated by how good Unreal’s Niagara system is.

float Res = 0;
float Radius = InRadius;

int NumSpawned = 0;
InAttributeReader.GetNumParticles(NumSpawned);

bool ParticleValid;
bool HasCollided;

float3 ParticlePosition;
float3 uv = InCoords;

float timeScale = 0.2;

float4 lastPixel = InRGBA;
if(lastPixel.r > 0)
{
    lastPixel = lastPixel - (InDeltaTime * timeScale);
    if(lastPixel.r <= 0.01)
    {
        lastPixel = 0;
    }
}

for(int Index = 0; Index <= NumSpawned; Index+=10)
{
   InAttributeReader.GetPositionByIndex<Attribute="Position">(Index, ParticleValid, ParticlePosition);
   if(!ParticleValid)
   {
      continue;
   }
   Res = saturate(1 - (length(uv - ParticlePosition) * (1 / Radius)));
   if(Res > 0)
   {
     break;
   }
}

OutRGBA = saturate(Res + lastPixel);
HLSL