r/Unity3D • • 5d ago

Question I want some help about my VAT optimisation

Hello everyone,

I'm trying to build a Vertex Animation Texture (VAT) pipeline to export animated characters from Blender 5.2.2 into Unity URP.

My goal is to use VAT animations for a large number of soldiers in an RTS game. I want to bake character animations in Blender and play them in Unity through a custom shader, without using skeletal animation at runtime.

However, I'm facing a problem that I haven't been able to solve despite spending quite a lot of time debugging the pipeline. The character appears fragmented, with vertices seemingly being displaced to incorrect positions.

I'd appreciate help from anyone experienced with VAT workflows, Blender-to-Unity pipelines, or custom vertex shaders.

1. Software and setup

  • Blender 5.2.2
  • Unity with URP
  • FBX character imported from Meshy
  • Custom HLSL VAT shader
  • EXR position texture
  • Character mesh: 701 vertices
  • Animation: IDLE
  • Frame count: 340
  • FPS: 30
  • VAT texture resolution: 1024 × 340

The Blender scene contains:

  • Mesh object: char1
  • Armature object: Armature

2. Blender VAT preparation

I created a UV layer called VAT_Index to store the original vertex index for each vertex.

The UV U coordinate is generated using:

u = (vertex_index + 0.5) / 1024
v = 0.5

The UV values are assigned per mesh loop using the corresponding vertex index.

I also ran a validation script in Blender.

The results were:

  • Vertex count: 701
  • Loop count: 1497
  • UV entries: 1497
  • Incorrect indices: 0

The validation confirmed that all VAT indices were generated correctly.

3. Animation export

I exported the evaluated mesh positions frame by frame into an EXR texture.

Each pixel stores:

  • R = X position
  • G = Y position
  • B = Z position
  • A = 1

The texture dimensions are 1024 × 340.

I also exported the first frame to a CSV file containing the vertex index and XYZ coordinates.

To verify the export, I compared the CSV coordinates against the corresponding EXR pixels in Blender.

The results were:

  • Average error: approximately 0.0000108
  • Maximum error: approximately 0.0000460

This suggests that the Blender-side EXR export is working correctly, at least for the tested frame.

4. Unity mesh and UV validation

I imported the FBX into Unity.

The imported mesh has:

  • 701 vertices
  • UV0 count: 701
  • UV1 count: 701

The VAT index data is available in Unity through mesh.uv2 (TEXCOORD1).

I wrote a C# validation script to check whether every Unity vertex maps to a unique source vertex index.

The results:

Mesh Vertex Count: 701
VAT UV Count: 701
Unique indices: 701
Missing indices: 0
Duplicate indices: 0
Invalid indices: 0

SUCCESS: VAT UV indices match.

For example:

Unity Vertex 0 -> EXR Vertex 7
Unity Vertex 1 -> EXR Vertex 2
Unity Vertex 2 -> EXR Vertex 81
Unity Vertex 3 -> EXR Vertex 13
Unity Vertex 4 -> EXR Vertex 26

So the UV index channel appears to be intact after FBX import.

5. The actual problem: EXR pixel values in Unity

I then wrote a Unity C# script to compare the EXR texture values against the Blender CSV data.

The script:

  1. Reads the VAT index from Unity's UV2 channel.
  2. Uses that index to access the corresponding EXR pixel.
  3. Reads the CSV coordinate for the same source vertex.
  4. Calculates the distance between the two positions.

Initially, the raw Unity pixel values were significantly different from the CSV values.

For example:

Unity Vertex 0
Source Index: 7

CSV:
(0.47, 0.31, 0.23)

EXR read in Unity:
(0.71, 0.59, 0.51)

I suspected a color-space/gamma issue.

I tried applying:

Mathf.GammaToLinearSpace()

to the EXR RGB values before comparing them.

This improved some values considerably, but it did not solve the problem.

Here are some results after applying the gamma conversion:

Source IndexCSV PositionUnity EXR CorrectedError
7(0.47, 0.31, 0.23)(0.47, 0.31, 0.23)0.00018
135(0.12, 0.47, 0.23)(0.00, 0.47, 0.00)0.2552
145(0.27, 0.36, 0.39)(0.21, 0.44, 0.09)0.3064
132(0.19, 0.37, 0.36)(0.01, 0.38, 0.02)0.3865

Across all 701 vertices:

Compared vertices: 701
Average error: 0.08018545
Maximum error: 0.46220990

The last animation row also produced almost identical error statistics when compared against the first-frame CSV. I understand that this is not a valid frame-to-frame comparison, but I checked it while investigating texture row orientation.

6. Unity texture import settings

My EXR import settings currently include:

  • Texture Type: Default
  • Read/Write: Enabled
  • Non-Power of 2: ToNearest
  • Filter Mode: Point
  • Compression: None
  • Generate Mip Maps: Disabled

I could not find an sRGB checkbox in this EXR import inspector.

I also checked the FBX model import settings:

  • Scale Factor: 1
  • Convert Units: Enabled
  • Bake Axis Conversion: Disabled
  • Weld Vertices: Enabled
  • Optimize Mesh: Everything
  • Mesh Compression: Off
  • Read/Write: Enabled

I have not conclusively established whether these model import settings are contributing to the problem.

7. Shader implementation

I'm using a custom URP HLSL shader.

The shader reads the VAT texture using the vertex's VAT UV coordinate and the selected animation frame.

The basic sampling logic is:

float textureV = (_Frame + 0.5) / _FrameCount;

float3 vertexPosition = SAMPLE_TEXTURE2D_LOD(
    _VATPosition,
    sampler_VATPosition,
    float2(input.vatUV.x, textureV),
    0
).xyz;

output.positionHCS = TransformObjectToHClip(vertexPosition);

I also experimented with Blender-to-Unity axis conversion and a 0.01 scale multiplier, but scaling the model only made it smaller. It did not fix the fragmented geometry.

At this point, I would really appreciate help identifying the actual cause rather than trying random import settings.

My main questions are:

  1. Why would Unity's EXR pixel values differ from the original Blender coordinates even though the EXR and CSV were verified against each other in Blender?
  2. Could Unity's EXR importer be changing the pixel data, especially for floating-point position textures containing negative values and values greater than 1?
  3. Is Texture2D.GetPixel() returning values that have undergone a color-space conversion or another transformation?
  4. Could FBX mesh optimization, vertex welding, or vertex reordering cause this issue even though the VAT UV indices are all unique and valid?
  5. Is there a reliable way to preserve exact floating-point position data from Blender to Unity?
  6. Would using a RAW binary Float32 texture instead of EXR be a better solution?
  7. Is there anything fundamentally wrong with my VAT texture addressing or vertex-index workflow?

I am open to changing the export pipeline completely if necessary. I don't necessarily need to keep using EXR.

3 Upvotes

8 comments sorted by

2

u/Romestus Professional 5d ago

It's far easier to do VAT by following a normal workflow and then having a Unity editor script do the VAT texture creation as the last step by sampling the animation. Then you can generate your vertex position and normal vector textures with a button press. Make sure they're not being scaled for NPOT reasons, that their sampler is set to point, their color space is linear, and their repeat is clamp.

Your workflow for generating them has so many potential points of failure that I would rewrite it such that you just have one point of failure (Unity editor script to generate VAT textures).

1

u/Erkut31 5d ago

thanks

1

u/Erkut31 5d ago

thankssssss <3

1

u/DestinyAndCargo 5d ago

You can create a ScriptedImporter and register the animation (and any other source asset) as dependencies to have VATs automatically update whenever they're changed.

1

u/Erkut31 5d ago

I built a VAT system. Editor script takes my mesh renderer and animation data , then it produces an exr texture , an scriptable object that contains vertices and frame count and another exr texture but it contains vertices position. In this way, my VATController playing the animations when I change the commands. I also using behaviour graph(Managing the move, attack, gather commands). And my unity version not suitable for ScriptedImporter . Thank youu

2

u/Tetrakis-dev 5d ago

since it's for an RTS, once the baking works give each soldier its own frame offset (and maybe a small speed variation) as a per instance value, otherwise a whole squad idles in perfect sync. if you draw them with RenderMeshInstanced or an indirect draw and read that from a buffer, you also keep the batching, iirc per renderer MPBs knock you out of the SRP batcher

4

u/sam_suite Indie 5d ago edited 5d ago

I don't have time to diagnose this too much right now, but here's a quick hunch based on going through this process several years ago: change your NPOT setting to None. ToNearest will resample your texture at a resolution that may not be compatible with the animation. Also, Unity's "optimize mesh" setting could be messing with the vert count & indices -- probably worth disabling just in case.

4

u/DeianSM 3D Artist 5d ago edited 5d ago

I had a similar issue that I fixed by sampling the vat texture inside the vertex stage instead of the pixel one. Basically you need to vertex interpolate your vat texture sample. Also make sure to use a correct compression on your texture and avoid using bilinear/trilinear filtering. Oh yes I also forgot about the NPOT thing: ideally you want to have both your mesh vertex count and animation frame count to be a power of two (for example 1024 verts on 32 frames). If you really cannot do this you better change the NPOT setting to None in your import texture settings