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

[FIX] Adopt top-left texture origin #3335

Merged
merged 12 commits into from
Jul 15, 2021

Conversation

slimbuck
Copy link
Member

Fixes: #3322

This PR changes the orientation of textures in the engine from bottom-left to top-left, bringing it inline with WebGL and glTF.

Specifically, the following changes are made:

  • stop flipping png/jpg textures vertically at load time
  • stop inverting glTF texture coordinates at load time
  • start inverting JSON model texture coordinates at load time
  • invert dynamically-generated texture coordinates for:
    • text
    • images
    • particles
    • sprites
  • invert texture coordinates of built-in shapes
  • update the basis texture engine example so it's not ugliest of all

Screenshot 2021-07-15 at 11 09 09

NOTE: the following shader chunks have been changed in this PR:

  • particle.frag
  • particle_cpu.vert
  • particle_normalMap.frag
  • startNineSliced.frag
  • startNiceSlicedTiled.frag

Users who have custom versions of these chunks will have to update these accordingly.

@slimbuck slimbuck added enhancement area: graphics Graphics related issue labels Jul 15, 2021
@slimbuck slimbuck requested a review from a team July 15, 2021 10:13
@slimbuck slimbuck self-assigned this Jul 15, 2021
@Maksims
Copy link
Contributor

Maksims commented Jul 15, 2021

This change has the potential to break a lot of advanced users projects who render their own textures and use them in shaders.
Could this change be added to respect backwards compatibility, and have a project default setting to use the bottom-left coordinate system. And for the new projects, flipping the switch?

So it won't break any existing projects and ensure a smooth transition, which can be done by the developer by choice.

Copy link
Contributor

@mvaligursky mvaligursky left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks great to me, glad to have this sorted out!

@slimbuck
Copy link
Member Author

Hi @Maksims ,

Yes you're right. This change has the potential to impact projects, especially ones that dynamically generate texture coordinates or have custom chunks generating UVs. Fortunately in most cases the fix is simple, place uv.y = 1.0 - uv.y; at the end.

Keeping backwards compatibility would be difficult in the engine (think different chunks etc) and would leave us having to maintain quite a complicated global option. Over time we'd expect to see bugs creep in and ultimately we decided that making a clean break is the best approach here.

Also, with this change in place we can finally support new features that weren't possible before (glTF texture transform, glTF quantising, gltf compressed textures). If we were to keep backwards compatibility those features would also be compromised.

Along with this change we have also updated the backend to stop flipping compressed textures. When this PR goes live, users will get an alert in the editor saying textures need recompressing. A single click will recompress all textures in the project.

This is a big change which might be a little painful, but we are preparing to make the transition hopefully as smooth as possible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: graphics Graphics related issue
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Orient images correctly
4 participants