Advertisement

Can the problem of particles occluded by a wall be easily solved?

Started by November 08, 2024 02:55 AM
2 comments, last by Aybe One 4 days, 16 hours ago

Here's a picture from which you will immediately understand the issue:

So, when the particles hit the wall, some of them do not render fully because of the track wall.

If using Z Test = Always for their shader, problem is fixed but they now render in unwanted places…

For instance, in a speed bump, they are seen through the track while with Z Test = LessEqual they weren't:

I tried using two cameras/layers, thought about stencil too but not sure about the latter.

Unity particle system also exhibit the same the problem:

Currently, I draw them manually because it's easy and there are only a dozen of them:

private void Update()
{
    var rotation = Camera.transform.rotation;

    foreach (var effect in RaceController.Instance.State.Effects)
    {
        if (effect.count <= 0)
        {
            continue;
        }

        Material.mainTexture = Textures[effect.Texture];

        var position = Constants.Transform.MultiplyPoint(effect.pos);

        var matrix = Matrix4x4.TRS(position, rotation, new Vector3(Scale, Scale, Scale));

        UnityEngine.Graphics.RenderMesh(new RenderParams(Material), Mesh, 0, matrix);
    }
}

If you have any suggestions, they're welcome! 😁

It's hard to tell what it should look like, since your art style is not realistic.

In a realistic renderer you could fade out the particle by reading from a copy of the depth buffer. If the current particle fragment depth is near to the depth of opaque geometry, reduce the alpha of the particle as the depth approaches that of the opaque geometry.

Another possible solution is to apply a depth bias, so that the depth used for the depth test is less than their actual depths. If you use a bias of the particle radius, then you can avoid particles being clipped until they are at least halfway inside the geometry.

Advertisement

In the first picture above, you can see that quads are cut by a track section drawn over.
What I'd like is them to be fully drawn, that is, over the track.
But trying to do so will make them visible even when they shouldn't be.

Whenever fiddling with z test, layers or queues, it will fix some but then break others.

Here's a picture with scene and game view, in real life one would be hidden by the track:

Although the problem is very simple, solution to fix it seemingly isn't.

Advertisement