diff options
author | Brecht Van Lommel <brecht@blender.org> | 2022-04-22 21:44:49 +0300 |
---|---|---|
committer | Brecht Van Lommel <brecht@blender.org> | 2022-04-23 00:15:45 +0300 |
commit | 6787cc13d4efef19eb708e1912356f8c1d4d2e01 (patch) | |
tree | 7281d706ec6aad566306d12632cd6d7d6f8f462a /source/blender/blenkernel/intern/image.cc | |
parent | bdc537e0a7b4b62af049dd4d508d5b08a4fa8b3b (diff) |
Bake: add UDIM tile baking support
Works for both Cycles and multires bake. Triangles are baked to multiple
UDIM images if they span across them, though such UV layouts are generally
discouraged as there is no filtering across UDIM tiles.
The bake margin currently only works within UDIM tiles. For the extend method
this is logical, for the adjacent faces method it may be useful to support
copying pixels from other UDIM tiles, though this seems somewhat complicated.
Fixes T95190
Ref T72390
Diffstat (limited to 'source/blender/blenkernel/intern/image.cc')
-rw-r--r-- | source/blender/blenkernel/intern/image.cc | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/source/blender/blenkernel/intern/image.cc b/source/blender/blenkernel/intern/image.cc index 53ec148fd2d..dfa820519a5 100644 --- a/source/blender/blenkernel/intern/image.cc +++ b/source/blender/blenkernel/intern/image.cc @@ -829,10 +829,7 @@ ImageTile *BKE_image_get_tile_from_iuser(Image *ima, const ImageUser *iuser) return BKE_image_get_tile(ima, image_get_tile_number_from_iuser(ima, iuser)); } -int BKE_image_get_tile_from_pos(struct Image *ima, - const float uv[2], - float r_uv[2], - float r_ofs[2]) +int BKE_image_get_tile_from_pos(Image *ima, const float uv[2], float r_uv[2], float r_ofs[2]) { float local_ofs[2]; if (r_ofs == nullptr) { @@ -860,6 +857,18 @@ int BKE_image_get_tile_from_pos(struct Image *ima, return tile_number; } +void BKE_image_get_tile_uv(const Image *ima, const int tile_number, float r_uv[2]) +{ + if (ima->source != IMA_SRC_TILED) { + zero_v2(r_uv); + } + else { + const int tile_index = tile_number - 1001; + r_uv[0] = static_cast<float>(tile_index % 10); + r_uv[1] = static_cast<float>(tile_index / 10); + } +} + int BKE_image_find_nearest_tile(const Image *image, const float co[2]) { const float co_floor[2] = {floorf(co[0]), floorf(co[1])}; @@ -868,17 +877,15 @@ int BKE_image_find_nearest_tile(const Image *image, const float co[2]) int tile_number_best = -1; LISTBASE_FOREACH (const ImageTile *, tile, &image->tiles) { - const int tile_index = tile->tile_number - 1001; - /* Coordinates of the current tile. */ - const float tile_index_co[2] = {static_cast<float>(tile_index % 10), - static_cast<float>(tile_index / 10)}; + float uv_offset[2]; + BKE_image_get_tile_uv(image, tile->tile_number, uv_offset); - if (equals_v2v2(co_floor, tile_index_co)) { + if (equals_v2v2(co_floor, uv_offset)) { return tile->tile_number; } /* Distance between co[2] and UDIM tile. */ - const float dist_sq = len_squared_v2v2(tile_index_co, co); + const float dist_sq = len_squared_v2v2(uv_offset, co); if (dist_sq < dist_best_sq) { dist_best_sq = dist_sq; |