FGA to 3D Texture question

Hey! I am trying to import some vector fields into Unity’s new particle system but it seems like Unity can only read vector fields from a 3D Texture. That is all fine and dandy, I bought Mega Flow plugin to convert a FGA to a 3D Texture in Unity but I am seeing these weird artifacts on the seams. Am I an idiot? The 3D Texture included with the sample pack for the new particle system (called “vectorfield”) has no such seams. What am I doing wrong? How do people on this board create 3D Textures in Unity?

1 Like

Unfortunately, I wasn’t able to get the new SRP to work :frowning:
But I have a script that can read FGA files and export (normalized) 3D textures:

public static Texture3D DeserializeVectorField(TextAsset fgaFile)
{
        string FullFile = fgaFile.text;
        string[] AllFloats = FullFile.Split(',');
        float Length = (float)AllFloats.Length - 10;
        int LengthPerSide = Mathf.RoundToInt(Mathf.Pow(Length / 3f, 1f / 3f));

        Texture3D VectorField = new Texture3D(LengthPerSide, LengthPerSide, LengthPerSide, TextureFormat.RGBAFloat, false);
        VectorField.wrapMode = TextureWrapMode.Repeat;

        float[] ConvertedFloats = new float[(int)Length];

        for (int i = 0; i < ConvertedFloats.Length - 1; i++)
        {
            ConvertedFloats[i] = float.Parse(AllFloats[i + 9]);
        }

        Color[] col = new Color[Mathf.RoundToInt(Length / 3f)];

        for (int i = 0; i < col.Length - 1; i++)
        {
            Vector3 v = Vector3.Normalize(new Vector3(ConvertedFloats[i * 3], ConvertedFloats[i * 3 + 1], ConvertedFloats[i * 3 + 2]));
            col[i] = new Color(v.x, v.y, v.z, 1f);
        }

        VectorField.SetPixels(col);
        VectorField.Apply(false);
        return VectorField;
    }

It does not take the meta data into consideration though!

Cool, thanks! That… probably would have saved me sixty bucks yesterday!

I got in touch with the maker of Mega Flow and he said the texture export is straightforward, much like yours. I am at my wits end as to why I am getting these artifacts at the edge of the vector field. It’s almost like the texture sampling mode is wrong… as if there is padding on the 3D texture such that the particle system is reading (0, 0, 0) as the vector when it starts clamping.

ANYWAYS your code would also be great to re-use to start generating SDF textures. I’m gonna get right on it!

Hey, Max, sorry to dig up this older thread. How would I use this script? Any help is much appreciated.

Hey bodycheater,

if you work in Unity, you can import the script and reference it in your own (editor) scripts. The problem: Unity can’t save 3D textures like normal textures so you have to make them during runtime. This script can convert a text asset (your fga file) and return a texture3D, that you can reference in a shader.

To make it work, you first have to import your fga file and reference it in your script (where you need it). The ending has to be changed to .txt in order for Unity to recognise it as a text asset.
Then simply call the script and it will return a texture3D for you.

Is this what you want to do with it?

got same wired lines here:
and do not know why

Ok, I make it goes well in VFX, because of sth about transfrom, you should use your 3d texture like this:

do not use the defaulr block VectorFIeldForce!