Skip to content

Dynamic Model Vertex Compression #957

@bjornbytes

Description

@bjornbytes

Compressing vertex data is good, but isn't appropriate for all models. Some models are fine with reduced precision for positions, UVs, normals, but certain use cases (huge models) might need full precision. So LÖVR should see if it can provide configuration for whether/how model vertex attributes are compressed.

Possible sketch could be:

lovr.graphics.newModel('thing.glb', {
  compress = {
    position = true,
    normal = true,
    uv = true,
    uv2 = true,
    color = true,
    tangent = true
  }
})

Each "compressed" variant of an attribute would have a specific meaning.

  • position: use un16x4, bake the scale/bias into the node's transform matrix.
  • normal/tangent: either un10x3 like it is today, or maybe 8 bit or octahedral
  • UVs: 16 bit unsigned normalized
  • colors: un8x4

One thing this API doesn't support is removing attributes entirely. You can't say "skip tangent import".

This means model vertex formats can be more dynamic, which can reduce batching. But if you use the same compression flags for most of your models, they'll still be able to batch well.

The existing rendering machinery shouldn't have an issue handling this. The hardest part will be the animation compute shaders, but since they only need to handle compressed vs. uncompressed for normals/tangents, it shouldn't be too difficult.

This is also good for WebGPU which doesn't support the vertex format used for compressed normals/tangents.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions