[Bf-blender-cvs] [bc05599bd0c] temp-udim-images: Start supporting tiled images in 3D texture painting
Lukas Stockner
noreply at git.blender.org
Wed Jun 13 16:17:34 CEST 2018
Commit: bc05599bd0c4823ced6cc6a448a1c71ce9c4ec1d
Author: Lukas Stockner
Date: Wed Jun 13 15:01:44 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rBbc05599bd0c4823ced6cc6a448a1c71ce9c4ec1d
Start supporting tiled images in 3D texture painting
===================================================================
M source/blender/blenkernel/intern/image.c
M source/blender/editors/sculpt_paint/paint_image_proj.c
M source/blender/editors/sculpt_paint/paint_utils.c
===================================================================
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index 5e482da2546..03ebd2e5397 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -576,6 +576,10 @@ bool BKE_image_has_opengl_texture(Image *ima)
int BKE_image_get_tile_from_pos(struct Image *ima, float uv[2], float new_uv[2], float ofs[2])
{
+ float local_ofs[2];
+ if (!ofs)
+ ofs = local_ofs;
+
copy_v2_v2(new_uv, uv);
zero_v2(ofs);
diff --git a/source/blender/editors/sculpt_paint/paint_image_proj.c b/source/blender/editors/sculpt_paint/paint_image_proj.c
index f6cf0f56764..4ffd9cf8025 100644
--- a/source/blender/editors/sculpt_paint/paint_image_proj.c
+++ b/source/blender/editors/sculpt_paint/paint_image_proj.c
@@ -200,6 +200,7 @@ typedef struct ProjPaintImage {
* Here we store the mask rectangle */
bool **valid; /* store flag to enforce validation of undo rectangle */
bool touch;
+ float uv_ofs[2];
} ProjPaintImage;
/**
@@ -662,7 +663,7 @@ static bool project_paint_PickColor(
interp_v2_v2v2v2(uv, UNPACK3(lt_tri_uv), w);
ima = project_paint_face_paint_image(ps, tri_index);
- ibuf = BKE_image_get_first_ibuf(ima); /* we must have got the imbuf before getting here */
+ ibuf = BKE_image_get_first_ibuf(ima); /* we must have got the imbuf before getting here */ /* TODO */
if (!ibuf) return 0;
if (interp) {
@@ -1315,25 +1316,40 @@ static float screen_px_line_point_factor_v2_persp(
return line_point_factor_v2(zero, v1_proj, v2_proj);
}
-
-static void project_face_pixel(
- const float *lt_tri_uv[3], ImBuf *ibuf_other, const float w[3],
- unsigned char rgba_ub[4], float rgba_f[4])
+static bool project_face_pixel(
+ const float *lt_tri_uv[3], Image *ima_other, const float w[3],
+ unsigned char rgba_ub[4], float rgba_f[4], bool *is_float)
{
+ if (!ima_other)
+ return false;
+
float uv_other[2], x, y;
interp_v2_v2v2v2(uv_other, UNPACK3(lt_tri_uv), w);
+ ImageUser iuser = {NULL};
+ iuser.ok = true;
+ iuser.tile = BKE_image_get_tile_from_pos(ima_other, uv_other, uv_other, NULL);
+ ImBuf *ibuf_other = BKE_image_acquire_ibuf(ima_other, &iuser, NULL);
+
+ if (!ibuf_other)
+ return false;
+
/* use */
uvco_to_wrapped_pxco(uv_other, ibuf_other->x, ibuf_other->y, &x, &y);
if (ibuf_other->rect_float) { /* from float to float */
+ *is_float = true;
bilinear_interpolation_color_wrap(ibuf_other, NULL, rgba_f, x, y);
}
else { /* from char to float */
+ *is_float = false;
bilinear_interpolation_color_wrap(ibuf_other, rgba_ub, NULL, x, y);
}
+ BKE_image_release_ibuf(ima_other, ibuf_other, NULL);
+
+ return true;
}
/* run this outside project_paint_uvpixel_init since pixels with mask 0 don't need init */
@@ -1347,28 +1363,22 @@ static float project_paint_uvpixel_mask(
/* Image Mask */
if (ps->do_layer_stencil) {
/* another UV maps image is masking this one's */
- ImBuf *ibuf_other;
Image *other_tpage = ps->stencil_ima;
-
- if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) {
- const MLoopTri *lt_other = &ps->dm_mlooptri[tri_index];
- const float *lt_other_tri_uv[3] = { PS_LOOPTRI_AS_UV_3(ps->dm_mloopuv, lt_other) };
-
- /* BKE_image_acquire_ibuf - TODO - this may be slow */
- unsigned char rgba_ub[4];
- float rgba_f[4];
-
- project_face_pixel(lt_other_tri_uv, ibuf_other, w, rgba_ub, rgba_f);
-
- if (ibuf_other->rect_float) { /* from float to float */
+ const MLoopTri *lt_other = &ps->dm_mlooptri[tri_index];
+ const float *lt_other_tri_uv[3] = { PS_LOOPTRI_AS_UV_3(ps->dm_mloopuv, lt_other) };
+
+ unsigned char rgba_ub[4];
+ float rgba_f[4];
+ bool is_float;
+ /* BKE_image_acquire_ibuf - TODO - this may be slow */
+ if (project_face_pixel(lt_other_tri_uv, other_tpage, w, rgba_ub, rgba_f, &is_float)) {
+ if (is_float) { /* from float to float */
mask = ((rgba_f[0] + rgba_f[1] + rgba_f[2]) * (1.0f / 3.0f)) * rgba_f[3];
}
else { /* from char to float */
mask = ((rgba_ub[0] + rgba_ub[1] + rgba_ub[2]) * (1.0f / (255.0f * 3.0f))) * (rgba_ub[3] * (1.0f / 255.0f));
}
- BKE_image_release_ibuf(other_tpage, ibuf_other, NULL);
-
if (!ps->do_layer_stencil_inv) /* matching the gimps layer mask black/white rules, white==full opacity */
mask = (1.0f - mask);
@@ -1553,8 +1563,15 @@ static ProjPixel *project_paint_uvpixel_init(
ImBuf *ibuf = projima->ibuf;
/* wrap pixel location */
- x_px = mod_i(x_px, ibuf->x);
- y_px = mod_i(y_px, ibuf->y);
+ if (projima->ima->source == IMA_SRC_TILED) {
+ if (x_px < 0 || y_px < 0 || x_px >= ibuf->x || y_px >= ibuf->y) {
+ return NULL;
+ }
+ }
+ else {
+ x_px = mod_i(x_px, ibuf->x);
+ y_px = mod_i(y_px, ibuf->y);
+ }
BLI_assert(ps->pixel_sizeof == project_paint_pixel_sizeof(ps->tool));
projPixel = BLI_memarena_alloc(arena, ps->pixel_sizeof);
@@ -1614,23 +1631,20 @@ static ProjPixel *project_paint_uvpixel_init(
/* done with view3d_project_float inline */
if (ps->tool == PAINT_TOOL_CLONE) {
if (ps->dm_mloopuv_clone) {
- ImBuf *ibuf_other;
Image *other_tpage = project_paint_face_clone_image(ps, tri_index);
+ const MLoopTri *lt_other = &ps->dm_mlooptri[tri_index];
+ const float *lt_other_tri_uv[3] = { PS_LOOPTRI_AS_UV_3(ps->dm_mloopuv_clone, lt_other) };
- if (other_tpage && (ibuf_other = BKE_image_acquire_ibuf(other_tpage, NULL, NULL))) {
- const MLoopTri *lt_other = &ps->dm_mlooptri[tri_index];
- const float *lt_other_tri_uv[3] = { PS_LOOPTRI_AS_UV_3(ps->dm_mloopuv_clone, lt_other) };
-
- /* BKE_image_acquire_ibuf - TODO - this may be slow */
-
+ unsigned char rgba_ub[4];
+ float rgba[4];
+ bool is_float;
+ /* BKE_image_acquire_ibuf - TODO - this may be slow */
+ if (project_face_pixel(lt_other_tri_uv, other_tpage, w, rgba_ub, rgba, &is_float)) {
if (ibuf->rect_float) {
- if (ibuf_other->rect_float) { /* from float to float */
- project_face_pixel(lt_other_tri_uv, ibuf_other, w, NULL, ((ProjPixelClone *)projPixel)->clonepx.f);
+ if (is_float) { /* from float to float */
+ copy_v4_v4(((ProjPixelClone *)projPixel)->clonepx.f, rgba);
}
else { /* from char to float */
- unsigned char rgba_ub[4];
- float rgba[4];
- project_face_pixel(lt_other_tri_uv, ibuf_other, w, rgba_ub, NULL);
if (ps->use_colormanagement) {
srgb_to_linearrgb_uchar4(rgba, rgba_ub);
}
@@ -1641,9 +1655,7 @@ static ProjPixel *project_paint_uvpixel_init(
}
}
else {
- if (ibuf_other->rect_float) { /* float to char */
- float rgba[4];
- project_face_pixel(lt_other_tri_uv, ibuf_other, w, NULL, rgba);
+ if (is_float) { /* float to char */
premul_to_straight_v4(rgba);
if (ps->use_colormanagement) {
linearrgb_to_srgb_uchar3(((ProjPixelClone *)projPixel)->clonepx.ch, rgba);
@@ -1654,11 +1666,9 @@ static ProjPixel *project_paint_uvpixel_init(
((ProjPixelClone *)projPixel)->clonepx.ch[3] = rgba[3] * 255;
}
else { /* char to char */
- project_face_pixel(lt_other_tri_uv, ibuf_other, w, ((ProjPixelClone *)projPixel)->clonepx.ch, NULL);
+ copy_v4_v4_uchar(((ProjPixelClone *)projPixel)->clonepx.ch, rgba_ub);
}
}
-
- BKE_image_release_ibuf(other_tpage, ibuf_other, NULL);
}
else {
if (ibuf->rect_float) {
@@ -2494,7 +2504,7 @@ static bool IsectPoly2Df_twoside(const float pt[2], float uv[][2], const int tot
static void project_paint_face_init(
const ProjPaintState *ps,
const int thread_index, const int bucket_index, const int tri_index, const int image_index,
- const rctf *clip_rect, const rctf *bucket_bounds, ImBuf *ibuf, ImBuf **tmpibuf)
+ const rctf *clip_rect, const rctf *bucket_bounds, ImBuf *ibuf, ImBuf **tmpibuf, float uv_ofs[2])
{
/* Projection vars, to get the 3D locations into screen space */
MemArena *arena = ps->arena_mt[thread_index];
@@ -2526,7 +2536,7 @@ static void project_paint_face_init(
float w[3], wco[3];
- float *uv1co, *uv2co, *uv3co; /* for convenience only, these will be assigned to lt_tri_uv[0],1,2 or lt_tri_uv[0],2,3 */
+ float uv1co[2], uv2co[2], uv3co[3];
float pixelScreenCo[4];
bool do_3d_mapping = ps->brush->mtex.brush_map_mode == MTEX_MAP_MODE_3D;
@@ -2576,9 +2586,9 @@ static void project_paint_face_init(
lt_uv_pxoffset[2][1] = lt_tri_uv[2][1] - yhalfpx;
{
- uv1co = lt_uv_pxoffset[0]; // was lt_tri_uv[i1];
- uv2co = lt_uv_pxoffset[1]; // was lt_tri_uv[i2];
- uv3co = lt_uv_pxoffset[2]; // was lt_tri_uv[i3];
+ sub_v2_v2v2(uv1co, lt_uv_pxoffset[0], uv_ofs);
+ sub_v2_v2v2(uv2co, lt_uv_pxoffset[1], uv_ofs);
+ sub_v2_v2v2(uv3co, lt_uv_pxoffset[2], uv_ofs);
v1coSS = ps->screenCoords[lt_vtri[0]];
v2coSS = ps->screenCoords[lt_vtri[1]];
@@ -2650,12 +2660,16 @@ static void project_paint_face_init(
mask = project_paint_uvpixel_mask(ps, tri_index, w);
if (mask > 0.0f) {
- BLI_linklist_prepend_arena(
- bucketPixelNodes,
- project_paint_uvpixel_init(ps, arena, &tinf, x, y, mask, tri_index,
- pixelScreenCo, wco, w),
- arena
- );
+ ProjPixel *pixel;
+ pixel = project_paint_uvpixel_init(ps, arena, &tinf, x, y, mask, tri_index,
+ pixelScreenCo, wco, w);
+ if (pixel) {
+ BLI_linklist_prepend_arena(
+ bucketPixelNodes,
+ pixel,
+ arena
+ );
+ }
}
}
@@ -2765,6 +2779,9 @@ static void project_paint_face_init(
interp_v2_v2v2(seam_subsection[2], outset_uv[fidx1], outset_uv[fidx2], fac2);
interp_v2_v2v2(seam_subsection[3], outset_uv[fidx1], outset_uv[fidx2], fac1);
+ for(int i = 0; i < 4; i++)
+ sub_v2_v2(seam_subsection[i], uv_ofs);
+
/* if the bucket_clip_edges values Z values was kept we could avoid this
* Inset needs to be added so occlusion tests wont hit adjacent faces */
interp_v3_v3v3(edge_verts_inset_clip[0], insetCos[fidx1], insetCos[fidx2], fac1);
@@ -2842,12 +2859,16 @@ static void project_paint_face_init(
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list