godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.1k stars 21.15k forks source link

Texture filtering/mipmapping mode on embedded textures is not applied from imported glTF scenes #45206

Open arisu0 opened 3 years ago

arisu0 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

TheTophatDemon commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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

TheTophatDemon commented 3 years ago

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, NEARESTMIPMAP[LINEAR/NEAREST] for mipmaps). The mipmaps are not stored in the file but are supposed to be generated by the program.

fire commented 2 years ago

@TheTophatDemon Please submit for review.

TheTophatDemon commented 2 years ago

@TheTophatDemon Please submit for review. @fire

Here is a drafted pull request: https://github.com/godotengine/godot/pull/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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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.

elvisish commented 1 year ago

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 commented 1 year ago

Is this being fixed for 3.6?

There's a draft pull request, but it appears to be abandoned by its author: https://github.com/godotengine/godot/pull/54044

Edit: This was implemented in https://github.com/godotengine/godot/pull/66856, which was merged after 3.5 was released. Can you try building the latest 3.x branch from source?

elvisish commented 1 year ago

Is this being fixed for 3.6?

There's a draft pull request, but it appears to be abandoned by its author: https://github.com/godotengine/godot/pull/54044

Edit: This was implemented in https://github.com/godotengine/godot/pull/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 commented 9 months ago

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

TheTophatDemon commented 9 months ago

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