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

[3.x] Can't use DDS files w/ TextureArrays or Anisotropic Filtering #50900

Open
TokisanGames opened this issue Jul 26, 2021 · 4 comments
Open

Comments

@TokisanGames
Copy link
Contributor

TokisanGames commented Jul 26, 2021

Godot version

3.2.1 - 3.4.beta.custom_build.0b4080ba4

System information

Win 10/64 NVIDIA GeForce GTX 1060/PCIe/SSE2

Issue description

  1. DDS files can't have anisotropic filtering enabled automatically because there is no import file. I've worked around the latter by recursing through all materials in the tree and enabling anisotropic filtering at runtime.

  2. DDS files can't be used for TextureArrays, because there is no import file.

3. Can't enable Anisotropic Filtering on TextureArrays (DDS or PNG) because the option wasn't implemented. Addressed in #51402

Steps to reproduce

Click a DDS file, then look at the blank Import tab. Or click a PNG TextureArray and see no Anisotropic filtering option.

Minimal reproduction project

No response

@Calinou
Copy link
Member

Calinou commented Jul 26, 2021

The DDS loader code is here: https://github.com/godotengine/godot/blob/caf7cbd8715ce549aabf6d9412388558c11fdb51/modules/dds/texture_loader_dds.cpp

#37847 would resolve the issue with anisotropic filtering. For 3.x, we may have to add a project setting to enable anisotropic filtering for DDS textures.

I'm not sure how to solve the texture array issue though, since you wouldn't want to change the import status for every DDS file in the project.

@TokisanGames
Copy link
Contributor Author

I discovered EditorPlugin and EditorImportPlugin and was able to get the editor to make dds import files with parameters, in GDscript. I'm currently building out a C++ version to create the DDS import files, and a copy of ResourceImporterLayeredTexture which will do stuff based on import settings:

  1. If it's a texture, it will enable desired flags, but not generate the stex files.
  2. If it's an array or 3D texture, it will load and splice the image as texturelayered does, set flags, and not generate stex files.

@natopwns
Copy link

natopwns commented Apr 8, 2023

I just realized that it doesn't save the anisotropic setting for DDS files in 3.5.2, and found this thread. Is there a way I can resolve this without migrating to 4.x? @TokisanGames would you be willing to share that GDscript import code?

@natopwns
Copy link

natopwns commented Apr 8, 2023

To anyone stumbling across this thread in seach of an answer, here's a script that will force anisotropic filtering on all textures attached to any MeshInstances. You will have to run set_all_flags() on a scene after loading it, to make it work:

extends Node

func set_flags(texture):
	
	if texture == null: return
	if texture.flags & Texture.FLAG_ANISOTROPIC_FILTER == Texture.FLAG_ANISOTROPIC_FILTER: return
	
	texture.flags += Texture.FLAG_ANISOTROPIC_FILTER

func set_all_texture_flags(material):
	
	if material == null: return
	
	for tex in range(material.TEXTURE_MAX):
		set_flags(material.get_texture(tex))

func set_all_material_flags(mesh):
	
	for mat in mesh.get_surface_material_count():
		set_all_texture_flags(mesh.get_surface_material(mat))

func find_by_class(node: Node, cls_name: String, result: Array):
	
	if node.is_class(cls_name) :
		result.append(node)
	for child in node.get_children():
		find_by_class(child, cls_name, result)

func set_all_flags(node: Node):
	
	var meshes: Array = []
	find_by_class(node, "MeshInstance", meshes)
	
	for mesh in meshes:
		set_all_material_flags(mesh)

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

4 participants