Vertex Animation texture compression

Hello !
I have been working on creating a workflow for VAT(vertex animation texture) aka morph textures that run in local vertex space. I have for the most part a complete working process and shader in defold. However I have had an issue with distortion in the mesh and have been going over the whole process of encoding animation to texture and making sure the math in the shader is right , comparing vertices positions from baked animation to the vertex positions in the encoded textures and have suspected texture compression issues. Vat settings that are needed is no mipmaps and no compression or lossless compression to be able to preserve vertex position/normal values in the encoded textures.

I needed to check if texture compression was the issue, so I enabled texture compression in editor preferences
pref_compression

Then created a custom texture profile and set it as default in project settings.

I then tested most settings and realized there is not a setting for no compression then I read there is DEFAULT compression that is supposed to be lossless? Took a closed look, I believe the default setting for texture compression is set to -

COMPRESSION_TYPE_DEFAULT : All formats Generic lossless data compression

  • This generic lossless compression seems to not be lossless at all. So to confirm my suspicion, using the same assets I recreated the scene and shader in Godot and tested compression to make sure its not just a problem with my animation encoding or bad math. Here is a video confirming that it is a compression issue in defold and the “Generic” lossless compression is causing the distortion in the mesh/animation.


(Video updated with working VAT :slight_smile: )
The video shows the generic lossless compression in defold on the left and on the right is the same assets in godot and compression with lossy is very similar results to defold and then later in the video godot texture compression is set to lossless and it works , also note that no compression works well.

With this knowledge I can rest easy on trying to figure out where it went wrong and now I think it would be awesome to have a working lossless compression and or option for no compression at all in defold. What do you all think?

Thanks for reading and Happy Halloween ! :ghost: :jack_o_lantern:

Notes: Big inspiration from Mario Palmero and his GDC talk here:

3 Likes

If you don’t enable texture compression, then you aren’t using texture compression at all.
This is the default.
If your project doesn’t work in this case, then I’d take a look at your shader.

The COMPRESSION_TYPE_DEFAULT doesn’t pass any compression code. It does convert to RGBA8888 to the pixel format you’ve chosen.
But, again, if you really want to test without any modification, then simply don’t use texture compression/texture profiles.

1 Like

Thanks for your reply. I do get the same distortion in mesh results without compression enabled and the default built-ins texture_profile set in project settings , or maybe I am missing another setting somewhere? That is why I wanted to experiment with compression and different compression settings. I tested all viable formats. I am not sure where to go next as the shader I believe to be correct and the encoded texture is correct, when I take the same shader and assets into godot using gles2 and gles3 I get correct results without compression and with lossless compression.

This brings up a good point as well , what if compression and no compression or lossless compression is needed in different paths of a defold project? Is this possible?

and the default built-ins texture_profile set in project settings

It’s just a settings file, and it won’t be used unless you enable compression (in the editor, or when using bob.jar)

Yes, this is “no compression”.
Also, if your texture doesn’t match any profile in the texture profiles, it won’t be compressed.

Could it be shader precision?
Do you use lowp,mediump,highp precision in the shader?

If nothing else, perhaps you can share the project here and someone may be able to help you?

Thanks for clearing this up, makes sense.

Yes I did check mediump and highp and it made no difference. Also when I change the filter min/mag to nearest it looks just like lossy compression. I also did test the uv positions from the set being read from in the shader.

I will keep thinking on possible solutions, and may be willing to share the project privately if anyone would like to help. Thanks for your time!

What platform? Yes please share the project with me if it’s a small repro or if it’s easily debuggable :slight_smile:

1 Like

Hopefully it should work with most platforms , in my case I am focused on windows PC. Thanks

Thanks @jhonny.goransson for taking a look. I believe I have found solutions to my vat issues. I do need to create a custom texture profile to disable mipmaps, they where being created by default. Mathias has pointed out to me that COMPRESSION_TYPE_DEFAULT is lossless. The reason why it seemed like compression is because the vat texture has a resolution of 1344x160 px and Defold prefers textures at power of two resolutions and on build the vat texture was being scaled down to 1024x128 px , this meant that the encoded values where being lost and that was the cause of the distortion in the mesh. So with this knowledge I should now be able to get this project working correctly in Defold ! Cheers~

2 Likes

I’m glad you found the issue!

To clarify: Unless overridden with a texture profile, we create all mip maps of a texture.
And as you mention, we need to create textures with sizes of power-of-two for legacy reasons (older GPUs).
In your case, we created a Mip0 texture of size 2048x256. Then the Mip1 (1024x128) and so on down to 1x1.
And, when rendering your model, the camera wasn’t close enough to the object, and it would then select the Mip1 instead of the Mip0 for texture sampling.

2 Likes