Godot: AtlasTexture Region and Margin ignored for Line2D

Created on 1 Nov 2020  路  1Comment  路  Source: godotengine/godot

Godot version:
v3.2.3.stable.mono.official

OS/device including version:
Microsoft Windows 10 Pro, version 10.0.18363 Build 18363

Issue description:
It's all in the title: Line2D nodes don't make use of AtlasTexture Region and Margin properties and instead use the full texture.
This makes using them with sprite sheets a hassle as you can't specify what rect is visible.
It seems that this issue has existed for at least a couple years now, judging from this Q&A page.

Steps to reproduce:

  1. Create a Line2D node in the editor and add 2 or more points
  2. Set its Texture to an AtlasTexture
  3. Modify the Region and/or Margin properties; note how nothing changes on the line

Minimal reproduction project:
AtlasBug.zip

bug core

Most helpful comment

This issue has the same cause as the following areas of the engine:

  • Polygon2D (https://github.com/godotengine/godot/issues/25049)
  • MeshInstance, MultiMeshInstance and CSG nodes (https://github.com/godotengine/godot-proposals/issues/1708)
  • Shaders (https://github.com/godotengine/godot/issues/25895)
  • NinePatchRect (partially fixed by https://github.com/godotengine/godot/pull/21156 because it's slightly simpler to implement there, but some configurations can still break it)
  • Repeat/Clamp won't work in general https://github.com/godotengine/godot/issues/5660, which was flagged as documentation issue
  • And if we are at it, get_data() will also return the whole texture, and get_rid() will give you the RID of the whole texture too.

And the reason is simple: AtlasTexture is NOT a texture. It inherits Texture but that's only a facade. It barely just holds a reference to a real texture, with a rectangle, and just so happen to work if used on some simple 2D nodes because these nodes happen to generate their simple quads with special UVs. VisualServer doesnt even have a concept of it.
For anything more complex, it would be a shitshow of geometry workarounds to implement throughout the upper layer of the engine. Basically, it was never made to work together with other types of nodes. It's meant only for nodes that render simple, regular quads, which don't repeat.

I believe if we want to solve this, either we have to:

  • Make it clear that this kind of "texture" can only be used with certain 2D nodes, and that it's not a bug, but an expected limitation
  • Or make it so this kind of texture is handled at rendering engine level in such a way the sampler2D would be bound to an image region (instead of the whole image), which would make things work naturally without any UV hacks, even with repeat or clamp flags on (does Vulkan allow to do this now?). This would make such texture behave like a regular full texture without having to break up vertices to account for repetition or clamping.

In the case of Line2D specifically:
In the current state of the renderer, it would be possible to make the STRETCH texture mode work without much changes, by interpolating through the sub-rectangle of the texture instead of the full region, since the algorithm does that already. But TILE won't work for the reasons cited above, so you will need a dedicated texture or a shader.

>All comments

This issue has the same cause as the following areas of the engine:

  • Polygon2D (https://github.com/godotengine/godot/issues/25049)
  • MeshInstance, MultiMeshInstance and CSG nodes (https://github.com/godotengine/godot-proposals/issues/1708)
  • Shaders (https://github.com/godotengine/godot/issues/25895)
  • NinePatchRect (partially fixed by https://github.com/godotengine/godot/pull/21156 because it's slightly simpler to implement there, but some configurations can still break it)
  • Repeat/Clamp won't work in general https://github.com/godotengine/godot/issues/5660, which was flagged as documentation issue
  • And if we are at it, get_data() will also return the whole texture, and get_rid() will give you the RID of the whole texture too.

And the reason is simple: AtlasTexture is NOT a texture. It inherits Texture but that's only a facade. It barely just holds a reference to a real texture, with a rectangle, and just so happen to work if used on some simple 2D nodes because these nodes happen to generate their simple quads with special UVs. VisualServer doesnt even have a concept of it.
For anything more complex, it would be a shitshow of geometry workarounds to implement throughout the upper layer of the engine. Basically, it was never made to work together with other types of nodes. It's meant only for nodes that render simple, regular quads, which don't repeat.

I believe if we want to solve this, either we have to:

  • Make it clear that this kind of "texture" can only be used with certain 2D nodes, and that it's not a bug, but an expected limitation
  • Or make it so this kind of texture is handled at rendering engine level in such a way the sampler2D would be bound to an image region (instead of the whole image), which would make things work naturally without any UV hacks, even with repeat or clamp flags on (does Vulkan allow to do this now?). This would make such texture behave like a regular full texture without having to break up vertices to account for repetition or clamping.

In the case of Line2D specifically:
In the current state of the renderer, it would be possible to make the STRETCH texture mode work without much changes, by interpolating through the sub-rectangle of the texture instead of the full region, since the algorithm does that already. But TILE won't work for the reasons cited above, so you will need a dedicated texture or a shader.

Was this page helpful?
0 / 5 - 0 ratings