-
Notifications
You must be signed in to change notification settings - Fork 103
Flip textures and UVs #611
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
base: main
Are you sure you want to change the base?
Conversation
…UV coordinates to comply with Unity U-right, V-up convention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @david-lively! I'm still building this locally to test it out, but figured I'd post my comments now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the changes @david-lively ! Just a few small things that I won't trouble you with; I'll batch into a commit so CI can start running.
…n.rowPitch for the row stride when flipping textures.
|
This branch breaks
Here's what it looks like in this branch: Presumably the problem is that the texture translation is going in the wrong direction now that the texture coordinates have been inverted. While this is probably easy to fix, we need to think about what else might break with the texture coordinate inversion. Anything with feature ID textures perhaps? Or, is it worth avoiding the issue by not inverting texure coordinates on load, but only inverting them when handing them off to mikktspace? Or, alternatively, computing tangents entirely with glTF conventions, and then transforming them for Unity? I can kind of argue either way. Creating models with texture and texture coordinates that violate the usual bottom-left-origin Unity convention is not great. But we can think of that as glTF textures arriving flipped and the texture coordinates are designed to assume that. It's perhaps a little weird but not wrong. By sticking with glTF conventions throughout, we perhaps make it easier / less error prone to support all the glTF things because everything uses the glTF conventions, except for a transformation to the Unity coordinate system at the end. |
|
KTX compressed textures aren't working right either. Unfortunately it's really subtle in these images, which come from the It makes sense this wouldn't work, though. Flipping rows of compressed images isn't going to work correctly. Unlike the problem above, it's not immediately obvious to me how to fix this one without reverting this PR. |
|
Metadata textures seem to be working well in this branch. 👍 |




Description
This PR modifies the texture and model import process to comply with Unity's U-right, V-up convention.
The glTF 2.0 spec mandates that textures are anchored at UV (0,0) and the upper-left corner of the texture, with UVs increasing to the right and down. (See https://registry.khronos.org/glTF/specs/2.0/glTF-2.0.html#images .)
Unity, however, assumes that UV (0,0) corresponds to the bottom-left corner of the image. Previously, the system did not flip either the textures OR the UVs, so it mostly worked, but has caused issues with tangent generation.
In the UV overlay debug images below, the six columns on the left were loaded by Cesium, while the six on the right were loaded by Unity glTFast. These were generated using the same glTF model:
This requires changes to
cesium-nativein CesiumGS/cesium-native#1259 .Before this change:

After this change:

With textures flipped:

Author checklist
CHANGES.mdwith a short summary of my change (for user-facing changes).Testing plan
Load a tileset. Use Unity's Render Debugger to visualize the

Texcoord0vertex attribute. Observe that UV coordinates increase in the right- and up-direction, and that textures are correctly flipped to match.