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

Texture coordinate origin is undefined #674

Closed
ilmola opened this issue Aug 8, 2016 · 4 comments
Closed

Texture coordinate origin is undefined #674

ilmola opened this issue Aug 8, 2016 · 4 comments

Comments

@ilmola
Copy link

ilmola commented Aug 8, 2016

The spec does not seem to define the origin for the texture coordinates.

One would then assume that the origin is bottom left like it is the case with OpenGL,
but looking at the Duck.gltf from the sample models it seem that it uses top left origin.

Texture coordinate origin needs to be defined.

If bottom left if chosen, then the sample models need to be fixed.

If top left is chosen, then it needs to be documented, that an implementation that renders
using OpenGL might need to flip texture coordinates or images.
(Or in the case of WebGL set gl.UNPACK_FLIP_Y_WEBGL to true.)

@pjcozzi
Copy link
Member

pjcozzi commented Aug 10, 2016

Good catch.

If top left is chosen, then it needs to be documented, that an implementation that renders
using OpenGL might need to flip texture coordinates or images.
(Or in the case of WebGL set gl.UNPACK_FLIP_Y_WEBGL to true.)

We need to document this...it matches the JavaScript Image object.

@lexaknyazev do you want to update the 1.0.1 spec for this?

CC #15.

@ilmola
Copy link
Author

ilmola commented Aug 11, 2016

You can't really define the coordinate system as "it matches the JavaScript Image object"
as the JavaScript Image object (unlike Canvas) has no method to access it's own data using
any coordinate system.

If you define the origin to be top left, you will run in trouble with the fact
that glTF files can contain shaders that can modify or even generate texture
coordinates. What origin should these shaders assume? How would a shader know if
the implementation has flipped the texture coordinates or the images?

A better option would be to define the origin to be the bottom left AND define
the pixel transfer from images to textures so that the top left pixel from
an image maps to the bottom left pixel of a texture and so on. This is (unfortunately)
what WebGL does by default anyway.

This is effectively the same as using top left origin, does not brake any sample
models and shaders can assume normal OpenGL conventions.

Later versions of glTF can add a way to set the pixel transfer behavior in the glTF file.
Maybe even per image.

ps.
As a funny detail it seem that UNPACK_FLIP_Y_WEBGL does the exact opposite
what it's name would imply.
Setting UNPACK_FLIP_Y_WEBGL to false (default) top left maps to bottom left (image flips)
Settings UNPACK_FLIP_Y_WEBGL to true maps top left to top left (no flip)

@lexaknyazev
Copy link
Member

When texture source is TexImageSource, WebGL defines origin as

The first pixel transferred from the source to the WebGL implementation corresponds to the upper left corner of the source.

Currently, glTF has nor desktop/embedded profiles, neither proper support for traditional GPU textures (both compressed and uncompressed).

So, I propose to add such clarification in master (since it doesn't change with 1.0.1).

Next glTF version shall have proper support for pixel storage/transfer options.

@pjcozzi
Copy link
Member

pjcozzi commented Aug 15, 2016

@lexaknyazev I agree this can go into master. Can you please open a PR with proposed wording? I think we are all in agreement, it is just a matter of wording, which I am flexible on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants