Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Single or double precision node transforms #2140

Open
FreakTheMighty opened this issue Apr 8, 2022 · 2 comments
Open

Single or double precision node transforms #2140

FreakTheMighty opened this issue Apr 8, 2022 · 2 comments
Assignees
Milestone

Comments

@FreakTheMighty
Copy link

Does the specification indicate whether the node matrix and translation properties support double precision numbers?

https://github.com/KhronosGroup/glTF/blob/main/specification/2.0/schema/node.schema.json

I think accessors are specifically limited to single precision and it seems that some viewers, such as Babylon.js and Unity, have issues rendering transform hierarchies with double precision. As such I’m curious whether there is an expectation that these values be kept in single precision range?

@javagl
Copy link
Contributor

javagl commented Apr 9, 2022

There has been some discussion about this, for example in #1574 .

The storage format for accessors is defined in the spec because this describes the actual binary representation.

In contrast to that, when referring to the JSON part: The tl;dr here is that whatever applies to JSON implicitly applies to glTF, because glTF cannot sensibly define a "subset of JSON". The JSON spec also remains a bit vague here, but strongly suggests that numbers from JSON are supposed to be handled at least as 64 bit floating point values. (There may be libraries that can handle more, or treat integer values differently, but 64 bit (aka double) should be a reasonable baseline to ensure interoperability).

That said: The glTF spec does not specify some of the details that you refer to when you mention 'rendering issues'. When you have an implementation (i.e. a rendering engine) that stores all its matrices with float, then you'll inevietably encounter problems when, for example, a node has a transform that contains values that cannot sensibly be represented as float. The general recommendation here would be ~"to use 64 bit wherever possible".

So to summarize that, roughly speaking:

  • The JSON input can contain double values
  • The rendering (on the level of WebGL) basically always happens with float values
  • The rendering engine should try to cope with that by converting the data to float "as late as possible", only directly before passing it to the GPU

(The last point might be elaborated by someone who can describe this more profoundly on a technical level...)

@lexaknyazev
Copy link
Member

The spec should mention that JSON-encoded numbers usually imply double precision.

@lexaknyazev lexaknyazev added this to the 2.0.x milestone Sep 27, 2023
@lexaknyazev lexaknyazev self-assigned this Oct 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants