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

AtlasTexture does not work with some Objects and Resources #33855

Open
dekaravanhoc opened this issue Nov 24, 2019 · 14 comments
Open

AtlasTexture does not work with some Objects and Resources #33855

dekaravanhoc opened this issue Nov 24, 2019 · 14 comments

Comments

@dekaravanhoc
Copy link

Godot version:
3.1.1

OS/device including version:
Windows 10

Issue description:
Using the AtlasTexture on some Objects and Ressources does not use the selected region but the whole image. I found this to be the case with AnimatedTexture and CPUParticles2D, but I am prety shure, this is are not the only two cases.

Steps to reproduce:

  • Create a AnimatedTexture or CPUParticles2D
  • Use a AtlasTexture as the Texture
  • The whole AtlasTexture is used instead of the selected Region

Note: The AtlasTexture is shown correctly in the Editor

Minimal reproduction project:

@genericFJS
Copy link

I get the same issue with Godot 3.2 beta 2 on Windows 10.

I created a minimal project:
AtlasTextureIssue.zip

Reproduce by:

  • Add frames to spriteframes via sprite sheet

1_spritesheet

  • Select atlas texture with only green part of image

2_atlastexture

  • Select some (green) frames

3_frames_green

  • Observe unexpected red frames
    4_animationframes_red

@clayjohn
Copy link
Member

clayjohn commented Nov 24, 2019

There is a PR to fix this for CpuParticles2D already. #32496

I guess similar changes need to be made for other nodes.

@arkology
Copy link
Contributor

I really think that all these problems are due to bad design/implementation of AtlasTexture. For example: #25895. Also it has bugs with progress bar node.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 25, 2019

AFAIK, AnimatedTexture will never support atlases due to how it works, but in exchange it has an excellent performance. Also docs state that it's not supported, so this case is ok.

As for others, we should probably find all places where AtlasTextures don't work and either fix this or document that it's impossible (if it's impossible ofc).

@dekaravanhoc
Copy link
Author

Were do the docs state it is not supported? It only states the textures should be the same size or they will be cropped.
And why should it not work? AnimatedTexture just animates the provided textures and AtlasTexture should just provide this texture. AnimatedTexture does not work with Atlases, thats wthat the AtlasTexture should be for.
I think arkology is right, that the implementation of AtlasTexture seems to be the problem here and in all the other cases.

@KoBeWi
Copy link
Member

KoBeWi commented Nov 25, 2019

Where do the docs state it is not supported?

https://docs.godotengine.org/en/latest/classes/class_animatedtexture.html#description
Last paragraph. Might be not in 3.1.

And why should it not work?

See the reduz's comment here: https://twitter.com/reduzio/status/1018869909781180427

I think arkology is right, that the implementation of AtlasTexture seems to be the problem here

Which doesn't mean it can be implemented in a better way. Especially without sacrificing performance.

@dekaravanhoc
Copy link
Author

Ah great, thank you. I'm using stable and the docs in that version, so I do not get anything mixed up - also thanks for the twitter post.
If it does not work together, thats fine by me. Just felt like a bug, as it is selectable and seem to work except for the result - and also for the other places where AtlasTexture does not seem to work as intended.
I am with you on the performance part, if it means worse performance overall. If it just means worse performance with AtlasTextures than with eg. StreamedTextures, I dont see the problem - as it is no performance at all at the moment. But as AnimatedTextures are a special issue and not connected to the rest, I think ressources should be spend elsewhere - as the pain is also not that big on this one, at least for me.

@akien-mga akien-mga changed the title AtlasTexture does not work with some Objects and Ressources AtlasTexture does not work with some Objects and Resources Apr 30, 2020
@geekrelief
Copy link
Contributor

Wow I just wasted an hour on this. The limitation of AnimatedTexture not being able to use AtlasTexture should be made much clearer in the docs. Right now it's the last sentence in Description. There should be a section labeled Warning or Limitations stating this.

@belzecue
Copy link

AtlasTexture certainly doesn't behave as one would expect. I suspect I'm not using it correctly in the way described below, but if that's the case then there should be an error message or the behavior should not be permitted.

  1. Create an AtlasTexture resource file and configure a clipped TextureRegion, which correctly shows in the Inspector as only the clipped part of the full texture.

  2. Create a quad mesh, add a SpatialMaterial, and drop the AtlasTexture resource file you created in Step 1 onto the material's texture param. In the Inspector, the texture param only displays the clipped texture region as you would expect. The assumption at this stage is, the material will only use the texture region from the AtlasTexture.

  3. But the quad mesh texture actually displays the entire texture atlas, not the clipped texture region used in the AtlasTexture, which is unexpected because the texture param also correctly displays only the clipped texture region.

Screenshot at 2021-09-11 18-03-05

@Calinou
Copy link
Member

Calinou commented Sep 11, 2021

AtlasTexture is only meant for use in 2D, not 3D. For 3D atlases, see godotengine/godot-proposals#651.

@Shadowblitz16
Copy link

Shadowblitz16 commented Dec 10, 2021

Godot should support any sort of texture nested into any sort of texture
Either support it or get rid of the animated texture resource and find us a alternative.
Godot doesn't need anymore edge cases. Right now it feels like the whole engine is nothing but edge cases.

@TamerSoup625
Copy link

TamerSoup625 commented Jul 13, 2022

I also had problem when trying to use AtlasTexture inside a ShaderMaterial.
I fixed it by creating my own version of AtlasTexture as a child of ImageTexture:

tool
extends ImageTexture
class_name ImageAtlasTexture


### NOTE: This script is far from being used as part of a plugin
### It basically gets a Texture's Image, uses Image.get_rect() on it and sets is as the image


export var atlas: Texture setget set_atlas
export var region: Rect2 setget set_region


func _init():
	update_image()


func set_atlas(val):
	atlas = val
	if atlas and not atlas.is_connected("changed", self, "update_image"):
		var __ = atlas.connect("changed", self, "update_image")
	update_image()
	emit_changed()


func set_region(val):
	region = val
	update_image()
	emit_changed()


func update_image():
	if !atlas: return
	if !region.size: return
	var p_flags = flags
	# Here is where the magic happens
	var p_image = atlas.get_data().get_rect(region)
	create_from_image(p_image)
	flags = p_flags

I've tested it and it works with materials, AnimatedTexture and Sprite3D and should work on everything else by the design of it (However I had to reload project for it to work on AnimatedTexture), I may turn this into a plugin.
The way I would fix this issue is by keeping the normal AtlasTexture but creating another version of it that is more focused on flexibility than performance, naming it to something like VersatileAtlasTexture, and maybe rename the current one to something like FastAtlasTexture so the difference between the *AtlasTextures is clearer.

Edit: I made the plugin and it is now in the Asset Library (https://godotengine.org/asset-library/asset/1414)

@clayjohn clayjohn added this to the 3.x milestone Dec 15, 2022
@Calinou Calinou removed this from the 3.x milestone Jan 7, 2023
@myyk
Copy link

myyk commented Nov 24, 2023

This issue seems still present on GPUParticles2D with AtlasTexture in Godot 4.1.

@hamitozdemir
Copy link

Still present in Godot 4.2.2. As mentioned even if you edit region to display a certain part of the AtlasTexture, it just doesn't apply the textures to the object surface. Doesn't work on QuadMesh or BoxMesh. Also possibly related (?) changing UV1 offset doesn't do anything, at all.

godot windows opt tools 64-old8_2024-05-11_19-30-13

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