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 filtering/mipmapping mode on embedded textures is not applied from imported glTF scenes #45206

Open
arisu0 opened this issue Jan 15, 2021 · 16 comments

Comments

@arisu0
Copy link

arisu0 commented Jan 15, 2021

Godot version:
Godot 3.2.3

OS/device including version:
Gentoo Linux, Nvidia gtx 850m (nvidia-drivers) gles3
USE flags:
image

Issue description:
Nearest neighbor not applying when filter is disabled on import, textures are always filtered.

Minimal reproduction project:
game.zip
Behavior in my system:
image

@Calinou
Copy link
Member

Calinou commented Jan 15, 2021

This is because the wooden table is using an embedded texture in table.glb rather than wood.png on the filesystem. To solve this, you have to make the table model use the external texture rather than the internal one.

image

(Don't uncheck Filter there for anything else than preview purposes, as changes will be lost when running the project.)

@arisu0
Copy link
Author

arisu0 commented Jan 15, 2021

Yeah, you were right. Sorry about that and thank you!

@TheTophatDemon
Copy link
Contributor

The GLTF specs say that there are sampler objects that define texture filtering in the files, and the model file that @arisu0 provided contains magFilter of 9728 (NEAREST) and minFilter of 9984 (NEAREST_MIPMAP_NEAREST). This issue can be worked around, but shouldn't the imported model be getting texture filter information from the file anyways?

@Calinou Calinou reopened this Aug 21, 2021
@Calinou Calinou changed the title [3.2.3] Texture filtering not going off Texture filtering mode on embedded textures is not applied from imported glTF scenes Aug 21, 2021
@Calinou Calinou added this to the 3.4 milestone Sep 22, 2021
@Calinou
Copy link
Member

Calinou commented Sep 22, 2021

Note that this needs different PRs to be fixed in master and 3.x, since the glTF importer code differs and texture flags are set in the material on master (instead of being defined in the Texture resource).

@elvisish
Copy link

It also doesn't import the mipmap settings in the default, they always default to on.

@Calinou Calinou changed the title Texture filtering mode on embedded textures is not applied from imported glTF scenes Texture filtering/mipmapping mode on embedded textures is not applied from imported glTF scenes Sep 22, 2021
@TheTophatDemon
Copy link
Contributor

I've created a fork to try and fix this for the 3.x branch. This is my first time, and I'm pretty busy, so this may take awhile. Feel free to work ahead of me if necessary.
I've noticed that the GLTF module is not parsing the "samplers" array (the one under the root for textures, not the ones for the animations). This array includes information for texture filtering and wrapping, and so a solution would need to add code to parse and store that.
Also, the only way to configure mipmaps, as far as I can tell in the GLTF specs, is to choose the correct texture filter (NEAREST for no mipmaps, NEAREST_MIPMAP_[LINEAR/NEAREST] for mipmaps). The mipmaps are not stored in the file but are supposed to be generated by the program.

@fire
Copy link
Member

fire commented Oct 20, 2021

@TheTophatDemon Please submit for review.

@TheTophatDemon
Copy link
Contributor

TheTophatDemon commented Oct 20, 2021

@TheTophatDemon Please submit for review.
@fire

Here is a drafted pull request: #54044
The code seems to work for the table model given in this issue, but it doesn't work for other models I've used for testing.
I don't believe I'll have much time to fix this for the next couple of weeks or so. How urgent is this issue?

@fire
Copy link
Member

fire commented Oct 22, 2021

I expect alpha to be sometime soon, not sure for godot 4.

Here's my wip branch. It has a few unsolved problems with repeat/mirror mode being a singular global setting.

https://github.com/V-Sekai/godot/tree/gltf-texture-filter

@MrJoshBowman
Copy link

MrJoshBowman commented Nov 4, 2021

Yep, the current lack of being able to set non-filtered textures visually breaks my tile-based models significantly on export. The below image was made in PowerPoint fromt exported GLBs

Untitled 2

@MrJoshBowman
Copy link

MrJoshBowman commented Nov 4, 2021

So i added this into the .gltf file exported out of Godot, and when importing that file into Blender everything worked porperly and looked crisp. I had to re-export a GLB file from Blender though to be able to view the model in PowerPoint.

"textures": [{ "sampler": 0, "source": 0 }],
"samplers": [
  {
    "magFilter": 9728,
    "minFilter": 9728,
    "wrapS": 10497,
    "wrapT": 10497
  }
]

Also curious as to why the option to embed .gltf files with mesh data and textures (like the .glb) isn't an export option in Godot? I understand that it adds to the file size by about 30% to encode things as base64, but when things like the inability to not filter a texture isn't working, tweaking the text file becomes very convenient. I've come from Three.js where exported .gltf files have embedded texture files with the ability to turn off filtering and the embedded texture files save a lot of hassles when moving things around.

@akien-mga akien-mga modified the milestones: 3.4, 3.5 Nov 8, 2021
@elvisish
Copy link

Is this being fixed for 3.6? It’s nice to import a glb into Godot 4.0 and have it respect the filter settings (or easily override them in the project settings) but I still have to use the clunky gltf with separate material imports in 3.5.

@Calinou
Copy link
Member

Calinou commented Nov 16, 2022

Is this being fixed for 3.6?

There's a draft pull request, but it appears to be abandoned by its author: #54044

Edit: This was implemented in #66856, which was merged after 3.5 was released. Can you try building the latest 3.x branch from source?

@elvisish
Copy link

elvisish commented Feb 1, 2023

Is this being fixed for 3.6?

There's a draft pull request, but it appears to be abandoned by its author: #54044

Edit: This was implemented in #66856, which was merged after 3.5 was released. Can you try building the latest 3.x branch from source?

I've never been able to build from source, it doesn't look as though it's been added to the latest 3.x release though?

@lyuma
Copy link
Contributor

lyuma commented Dec 24, 2023

Can someone using 3.x test if this is still an issue?

@TheTophatDemon
Copy link
Contributor

@lyuma
Just tried it on 3.x branch and release 3.5.3. The bug is still present.

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

9 participants