diff options
author | Juan Linietsky <reduzio@gmail.com> | 2018-04-08 17:11:16 -0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-08 17:11:16 -0300 |
commit | 217a95868afd076765c376d8bd5ce294b81df221 (patch) | |
tree | 34e6354c1ec48df52a0c1ecc990fa007692175ae | |
parent | 24cf58f91780b006ebe57f43ca7224f1b2f980dd (diff) | |
parent | 973be3711afe2585aa654fb3fa42783b42aa5587 (diff) |
Merge pull request #16707 from Web-eWorks/atlasfixes
Fix Sprite3D's incorrect behavior when using AtlasTextures.
-rw-r--r-- | scene/3d/sprite_3d.cpp | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 232855c978..bc44c91f64 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -366,11 +366,17 @@ void Sprite3D::_draw() { final_rect.position * pixel_size, }; + + // Properly setup UVs for impostor textures (AtlasTexture). + RID texture_rid = texture->get_rid(); + Vector2 src_tsize = Vector2( + VS::get_singleton()->texture_get_width(texture_rid), + VS::get_singleton()->texture_get_height(texture_rid)); Vector2 uvs[4] = { - final_src_rect.position / tsize, - (final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / tsize, - (final_src_rect.position + final_src_rect.size) / tsize, - (final_src_rect.position + Vector2(0, final_src_rect.size.y)) / tsize, + final_src_rect.position / src_tsize, + (final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / src_tsize, + (final_src_rect.position + final_src_rect.size) / src_tsize, + (final_src_rect.position + Vector2(0, final_src_rect.size.y)) / src_tsize, }; if (is_flipped_h()) { @@ -649,18 +655,23 @@ void AnimatedSprite3D::_draw() { float pixel_size = get_pixel_size(); Vector2 vertices[4] = { - (final_rect.position + Vector2(0, final_rect.size.y)) * pixel_size, (final_rect.position + final_rect.size) * pixel_size, (final_rect.position + Vector2(final_rect.size.x, 0)) * pixel_size, final_rect.position * pixel_size, }; + + // Properly setup UVs for impostor textures (AtlasTexture). + RID texture_rid = texture->get_rid(); + Vector2 src_tsize = Vector2( + VS::get_singleton()->texture_get_width(texture_rid), + VS::get_singleton()->texture_get_height(texture_rid)); Vector2 uvs[4] = { - final_src_rect.position / tsize, - (final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / tsize, - (final_src_rect.position + final_src_rect.size) / tsize, - (final_src_rect.position + Vector2(0, final_src_rect.size.y)) / tsize, + final_src_rect.position / src_tsize, + (final_src_rect.position + Vector2(final_src_rect.size.x, 0)) / src_tsize, + (final_src_rect.position + final_src_rect.size) / src_tsize, + (final_src_rect.position + Vector2(0, final_src_rect.size.y)) / src_tsize, }; if (is_flipped_h()) { |