From 162286cff4ba060698b542ccec255970db8f0637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gilles=20Roudi=C3=A8re?= Date: Tue, 24 Oct 2023 13:10:06 +0200 Subject: [PATCH] Fix normals in TileSet when using CanvasTextures --- scene/resources/tile_set.cpp | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index 121d29b728d..7b4080517f9 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -4787,15 +4787,17 @@ Ref TileSetAtlasSource::_create_padded_image_texture(const Refblit_rect(*src_image, src_rect, base_pos); + // Sides image->blit_rect(*src_image, top_src_rect, base_pos + Vector2i(0, -1)); image->blit_rect(*src_image, bottom_src_rect, base_pos + Vector2i(0, src_rect.size.y)); image->blit_rect(*src_image, left_src_rect, base_pos + Vector2i(-1, 0)); image->blit_rect(*src_image, right_src_rect, base_pos + Vector2i(src_rect.size.x, 0)); - image->set_pixelv(base_pos + Vector2i(-1, -1), src_image->get_pixelv(src_rect.position)); - image->set_pixelv(base_pos + Vector2i(src_rect.size.x, -1), src_image->get_pixelv(src_rect.position + Vector2i(src_rect.size.x - 1, 0))); - image->set_pixelv(base_pos + Vector2i(-1, src_rect.size.y), src_image->get_pixelv(src_rect.position + Vector2i(0, src_rect.size.y - 1))); - image->set_pixelv(base_pos + Vector2i(src_rect.size.x, src_rect.size.y), src_image->get_pixelv(src_rect.position + Vector2i(src_rect.size.x - 1, src_rect.size.y - 1))); + // Corners + image->blit_rect(*src_image, Rect2i(src_rect.position, Vector2i(1, 1)), base_pos + Vector2i(-1, -1)); + image->blit_rect(*src_image, Rect2i(src_rect.position + Vector2i(src_rect.size.x - 1, 0), Vector2i(1, 1)), base_pos + Vector2i(src_rect.size.x, -1)); + image->blit_rect(*src_image, Rect2i(src_rect.position + Vector2i(0, src_rect.size.y - 1), Vector2i(1, 1)), base_pos + Vector2i(-1, src_rect.size.y)); + image->blit_rect(*src_image, Rect2i(src_rect.position + Vector2i(src_rect.size.x - 1, src_rect.size.y - 1), Vector2i(1, 1)), base_pos + Vector2i(src_rect.size.x, src_rect.size.y)); } } @@ -4831,31 +4833,20 @@ void TileSetAtlasSource::_update_padded_texture() { Ref src = src_canvas_texture->get_diffuse_texture(); Ref image_texture; if (src.is_valid()) { - image_texture = _create_padded_image_texture(src); - } else { - image_texture.instantiate(); + padded_texture->set_diffuse_texture(_create_padded_image_texture(src)); } - padded_texture->set_diffuse_texture(image_texture); // Normal src = src_canvas_texture->get_normal_texture(); - image_texture.instantiate(); if (src.is_valid()) { - image_texture = _create_padded_image_texture(src); - } else { - image_texture.instantiate(); + padded_texture->set_normal_texture(_create_padded_image_texture(src)); } - padded_texture->set_normal_texture(image_texture); // Specular src = src_canvas_texture->get_specular_texture(); - image_texture.instantiate(); if (src.is_valid()) { - image_texture = _create_padded_image_texture(src); - } else { - image_texture.instantiate(); + padded_texture->set_specular_texture(_create_padded_image_texture(src)); } - padded_texture->set_specular_texture(image_texture); // Other properties. padded_texture->set_specular_color(src_canvas_texture->get_specular_color());