Skip to content

Use low precision format for vertex attributes #21902

@beicause

Description

@beicause

What problem does this solve or what need does it fill?

Bevy mesh vertex attributes: normal, tangent, color, uv0, uv1 and joint weight all use float32 by default, which uses lots of memory and bandwidth. The high precision is not needed sometimes. See also arm gpu best practice: https://developer.arm.com/documentation/101897/0304/Vertex-shading/Attribute-precision

When making procedural mesh I can insert custom vertex attributes. But there is no way to customize vertex attributes precision of bevy gltf loader.

What solution would you like?

Use float16 for tangent, color, uv0, uv1 and joint weight by default.

For normal, there isn't float16x3 but we can use oct-encoded float16x2 which needs to change shaders to decode it.

Tangent can also be oct-encoded float16x2, as the handedness can be encoded as the sign of vec2.y

Update: Actually they can be unorm16 for more precision.

What alternative(s) have you considered?

Maybe we can add an option to gltf loader or mesh to use low or high precision vertex attributes.

However I think it should be fine to use low precision for attributes other than position by default.

Additional context

Godot's importer has an option to compresses mesh attributes and it's enabled by default. Even for uncompressed mesh, it uses oct-encoding unorm16x2 for normal and tangent, and float32 for position and uv. For compressed mesh, it uses unorm16/float16 for all and single angle for tangent. color is always rgba8.
https://github.com/godotengine/godot/blob/b79fe2e0205fd7ab70a155d16f00c0ca2a7a7a5b/servers/rendering/rendering_server.h#L278-L293

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-FeatureA new feature, making something new possibleC-PerformanceA change motivated by improving speed, memory usage or compile timesS-Needs-DesignThis issue requires design work to think about how it would best be accomplished

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions