Vfx graph in world space + floating point fix system

Hi,

I have rain and wind effects in a vfx graph system. They spawn around my player, and they keep falling in world space.

So far, so good.

However, I’m using a streaming solution that contains a floating point error fix. Basically, everytime I move by more than 1000 meters, the world gets moved around my player so that it now sits in world space (0,0,0).

When that happens, the particles that were alive are now at their true position, so not around (0,0,0) anymore. New particles are spawned correctly, but the ones that were alive look like they were teleported 1000 meters away.

How do I fix that? I can call a function when my world gets moved, but I don’t know what to do to move the particles when my world gets translated around my player.

Thanks for your help

Hey,

What you need is to set the simulation space for your Visual Effect Graphs to be according to another empty object. That object and the effects should get translated with the floating point fix system (or floating origin) every 1000m, and all the alive particles should move appropriately with it. The same thing is achieved in the Shuriken particle system when you set “Custom” as the simulation space and designate the transform there.

One of the Visual Effect Graph devs kindly put up a sample which is downloadable at the bottom of the following post:

Feedback Wanted: Visual Effect Graph page-11#post-4552234

Perhaps you can make it as a reusable sub graph for all your effects.

This is a frequently asked question here, because floating origin is a common workaround for floating point problems. While I’m thankful that there’s a way to achieve it, I really wish @VladVNeykov would consider adding this custom space functionality into VFX Graph natively, along with World and Local space, hopefully sooner rather than later.

@Korindian Thank you!

1 Like

Hi, sorry for necro and my english. But, this is wrong way to do FOS.

For example, i have a “dust” vfx that spawns flying particles around the camera.
I have an empty game object (at 0,0,0 and name it “VFXcenter”) with VFX
I binded VFX “Custom space” to it transform. (as shown in example post above)
Then everything shifts. (camera to center 0,0,0 and VFXCenter to delta)
And everything worked well, old particles moved, and new ones appeared in a new position.

But if the VFXcenter is far off center, a floating point error occurs.

so we are need something different for this.
something like void VisualEffect.ShiftSpawnedParticles( Vector3 delta ), or somekind event…

Problem solved:

Vfx update like this: (shift is vector3)

Full VFX graph

code:

public class FOSTest : MonoBehaviour
{
    Vector3 _oldShift = Vector3.zero;

    public Transform relativeCenter;
    public VisualEffect dust;
    public float maxRange = 100;
    public Vector3 cameraSpeed;

    private void Update() {
        // Camera movement animation
        relativeCenter.transform.position += cameraSpeed * Time.deltaTime;

        Vector3 shift = Vector3.zero;
        if(relativeCenter.transform.position.magnitude > maxRange) {
            // Perform shift camera
            shift = -relativeCenter.transform.position;
            relativeCenter.position += shift;
        }

        if(_oldShift != shift) {
            _oldShift = shift;
            // and particle system aka VFX
            dust.SetVector3( "Shift", shift );
        }
    }
}

Just FYI, there is a Tile/Warp Particles block in the VFX Graph which is great for environmental-type effects like rain and snow as it will “teleport” particles which leave the bounds seamlessly on one side to the opposite side to create the illusion of an infinite effect.

Depending on the setup this might or might not work in your cases, just thought it might be worth mentioning.

6939724--815617--Ycv6I5OhEg.gif

4 Likes

Exactly what I was searching for. Thank you!

1 Like