Commit: 4e2701410357db381681992beb00163b76968dbb
Author: Lukas Stockner
Date:   Wed Jun 13 18:43:21 2018 +0200
Branches: temp-udim-images
https://developer.blender.org/rB4e2701410357db381681992beb00163b76968dbb

Support anisotropic brush scaling to compensate for different tile aspect ratios

===================================================================

M       source/blender/blenlib/BLI_math_vector.h
M       source/blender/blenlib/intern/math_vector_inline.c
M       source/blender/editors/sculpt_paint/paint_image_2d.c

===================================================================

diff --git a/source/blender/blenlib/BLI_math_vector.h 
b/source/blender/blenlib/BLI_math_vector.h
index 20852f8fc82..26cc3bf69d6 100644
--- a/source/blender/blenlib/BLI_math_vector.h
+++ b/source/blender/blenlib/BLI_math_vector.h
@@ -261,6 +261,8 @@ MINLINE bool equals_v2v2(const float v1[2], const float 
v2[2])  ATTR_WARN_UNUSED
 MINLINE bool equals_v3v3(const float a[3], const float b[3])  
ATTR_WARN_UNUSED_RESULT;
 MINLINE bool equals_v4v4(const float a[4], const float b[4])  
ATTR_WARN_UNUSED_RESULT;
 
+MINLINE bool equals_v2v2_int(const int v1[2], const int v2[2])  
ATTR_WARN_UNUSED_RESULT;
+
 MINLINE bool compare_v2v2(const float a[2], const float b[2], const float 
limit)  ATTR_WARN_UNUSED_RESULT;
 MINLINE bool compare_v3v3(const float a[3], const float b[3], const float 
limit)  ATTR_WARN_UNUSED_RESULT;
 MINLINE bool compare_v4v4(const float a[4], const float b[4], const float 
limit)  ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/blenlib/intern/math_vector_inline.c 
b/source/blender/blenlib/intern/math_vector_inline.c
index 4c40921edb6..0730ea68980 100644
--- a/source/blender/blenlib/intern/math_vector_inline.c
+++ b/source/blender/blenlib/intern/math_vector_inline.c
@@ -1032,6 +1032,11 @@ MINLINE bool equals_v4v4(const float v1[4], const float 
v2[4])
        return ((v1[0] == v2[0]) && (v1[1] == v2[1]) && (v1[2] == v2[2]) && 
(v1[3] == v2[3]));
 }
 
+MINLINE bool equals_v2v2_int(const int v1[2], const int v2[2])
+{
+       return ((v1[0] == v2[0]) && (v1[1] == v2[1]));
+}
+
 MINLINE bool compare_v2v2(const float v1[2], const float v2[2], const float 
limit)
 {
        return (compare_ff(v1[0], v2[0], limit) &&
diff --git a/source/blender/editors/sculpt_paint/paint_image_2d.c 
b/source/blender/editors/sculpt_paint/paint_image_2d.c
index 5db4191de11..4f59d7b9994 100644
--- a/source/blender/editors/sculpt_paint/paint_image_2d.c
+++ b/source/blender/editors/sculpt_paint/paint_image_2d.c
@@ -82,7 +82,7 @@ typedef struct BrushPainterCache {
        bool is_texbrush;
        bool is_maskbrush;
 
-       int lastdiameter;
+       int lastdiameter[2];
        float last_tex_rotation;
        float last_mask_rotation;
        float last_pressure;
@@ -147,7 +147,7 @@ typedef struct ImagePaintState {
 
        ImageUser iuser;
        float uv_ofs[2];
-       float radius_fac;
+       float radius_fac[2];
 
        BlurKernel *blurkernel;
 } ImagePaintState;
@@ -160,7 +160,7 @@ static BrushPainter *brush_painter_2d_new(Scene *scene, 
Brush *brush, bool inver
        painter->brush = brush;
        painter->scene = scene;
        painter->firsttouch = 1;
-       painter->cache.lastdiameter = -1; /* force ibuf create in refresh */
+       painter->cache.lastdiameter[0] = -1; /* force ibuf create in refresh */
        painter->cache.invert = invert;
 
        return painter;
@@ -179,7 +179,7 @@ static void brush_painter_2d_require_imbuf(BrushPainter 
*painter, bool use_float
                painter->cache.ibuf = NULL;
                painter->cache.curve_mask = NULL;
                painter->cache.tex_mask = NULL;
-               painter->cache.lastdiameter = -1; /* force ibuf create in 
refresh */
+               painter->cache.lastdiameter[0] = -1; /* force ibuf create in 
refresh */
        }
 
        painter->cache.use_float = use_float;
@@ -206,7 +206,7 @@ static void brush_imbuf_tex_co(rctf *mapping, int x, int y, 
float texco[3])
 }
 
 /* create a mask with the mask texture */
-static unsigned short *brush_painter_mask_ibuf_new(BrushPainter *painter, int 
size)
+static unsigned short *brush_painter_mask_ibuf_new(BrushPainter *painter, 
const int size[2])
 {
        Scene *scene = painter->scene;
        Brush *brush = painter->brush;
@@ -217,11 +217,11 @@ static unsigned short 
*brush_painter_mask_ibuf_new(BrushPainter *painter, int si
        unsigned short *mask, *m;
        int x, y, thread = 0;
 
-       mask = MEM_mallocN(sizeof(unsigned short) * size * size, 
"brush_painter_mask");
+       mask = MEM_mallocN(sizeof(unsigned short) * size[0] * size[1], 
"brush_painter_mask");
        m = mask;
 
-       for (y = 0; y < size; y++) {
-               for (x = 0; x < size; x++, m++) {
+       for (y = 0; y < size[1]; y++) {
+               for (x = 0; x < size[0]; x++, m++) {
                        float res;
                        brush_imbuf_tex_co(&mask_mapping, x, y, texco);
                        res = BKE_brush_sample_masktex(scene, brush, texco, 
thread, pool);
@@ -235,7 +235,7 @@ static unsigned short 
*brush_painter_mask_ibuf_new(BrushPainter *painter, int si
 /* update rectangular section of the brush image */
 static void brush_painter_mask_imbuf_update(
         BrushPainter *painter, unsigned short *tex_mask_old,
-        int origx, int origy, int w, int h, int xt, int yt, int diameter)
+        int origx, int origy, int w, int h, int xt, int yt, const int 
diameter[2])
 {
        Scene *scene = painter->scene;
        Brush *brush = painter->brush;
@@ -257,8 +257,8 @@ static void brush_painter_mask_imbuf_update(
                        float texco[3];
 
                        /* handle byte pixel */
-                       unsigned short *b = tex_mask + (y * diameter + x);
-                       unsigned short *t = tex_mask_cur + (y * diameter + x);
+                       unsigned short *b = tex_mask + (y * diameter[0] + x);
+                       unsigned short *t = tex_mask_cur + (y * diameter[0] + 
x);
 
                        if (!use_texture_old) {
                                brush_imbuf_tex_co(&tex_mapping, x, y, texco);
@@ -284,7 +284,7 @@ static void brush_painter_mask_imbuf_update(
  * This can be considerably faster for brushes that change size due to 
pressure or
  * textures that stick to the surface where only part of the pixels are new
  */
-static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, 
const float pos[2], int diameter)
+static void brush_painter_mask_imbuf_partial_update(BrushPainter *painter, 
const float pos[2], const int diameter[2])
 {
        BrushPainterCache *cache = &painter->cache;
        unsigned short *tex_mask_old;
@@ -292,24 +292,25 @@ static void 
brush_painter_mask_imbuf_partial_update(BrushPainter *painter, const
 
        /* create brush image buffer if it didn't exist yet */
        if (!cache->tex_mask)
-               cache->tex_mask = MEM_mallocN(sizeof(unsigned short) * diameter 
* diameter, "brush_painter_mask");
+               cache->tex_mask = MEM_mallocN(sizeof(unsigned short) * 
diameter[0] * diameter[1], "brush_painter_mask");
 
        /* create new texture image buffer with coordinates relative to old */
        tex_mask_old = cache->tex_mask_old;
-       cache->tex_mask_old = MEM_mallocN(sizeof(unsigned short) * diameter * 
diameter, "brush_painter_mask");
+       cache->tex_mask_old = MEM_mallocN(sizeof(unsigned short) * diameter[0] 
* diameter[1], "brush_painter_mask");
 
        if (tex_mask_old) {
                ImBuf maskibuf;
                ImBuf maskibuf_old;
-               maskibuf.x = maskibuf.y = diameter;
+               maskibuf.x = diameter[0];
+               maskibuf.y = diameter[1];
                maskibuf_old.x = cache->tex_mask_old_w;
                maskibuf_old.y = cache->tex_mask_old_h;
 
                srcx = srcy = 0;
                w = cache->tex_mask_old_w;
                h = cache->tex_mask_old_h;
-               destx = (int)floorf(painter->lastpaintpos[0]) - 
(int)floorf(pos[0])  + (diameter / 2 - w / 2);
-               desty = (int)floorf(painter->lastpaintpos[1]) - 
(int)floorf(pos[1])  + (diameter / 2 - h / 2);
+               destx = (int)floorf(painter->lastpaintpos[0]) - 
(int)floorf(pos[0])  + (diameter[0] / 2 - w / 2);
+               desty = (int)floorf(painter->lastpaintpos[1]) - 
(int)floorf(pos[1])  + (diameter[1] / 2 - h / 2);
 
                /* hack, use temporary rects so that clipping works */
                IMB_rectclip(&maskibuf, &maskibuf_old, &destx, &desty, &srcx, 
&srcy, &w, &h);
@@ -320,10 +321,10 @@ static void 
brush_painter_mask_imbuf_partial_update(BrushPainter *painter, const
                w = h = 0;
        }
 
-       x1 = min_ii(destx, diameter);
-       y1 = min_ii(desty, diameter);
-       x2 = min_ii(destx + w, diameter);
-       y2 = min_ii(desty + h, diameter);
+       x1 = min_ii(destx, diameter[0]);
+       y1 = min_ii(desty, diameter[1]);
+       x2 = min_ii(destx + w, diameter[0]);
+       y2 = min_ii(desty + h, diameter[1]);
 
        /* blend existing texture in new position */
        if ((x1 < x2) && (y1 < y2))
@@ -333,40 +334,42 @@ static void 
brush_painter_mask_imbuf_partial_update(BrushPainter *painter, const
                MEM_freeN(tex_mask_old);
 
        /* sample texture in new areas */
-       if ((0 < x1) && (0 < diameter))
-               brush_painter_mask_imbuf_update(painter, NULL, 0, 0, x1, 
diameter, 0, 0, diameter);
-       if ((x2 < diameter) && (0 < diameter))
-               brush_painter_mask_imbuf_update(painter, NULL, x2, 0, diameter, 
diameter, 0, 0, diameter);
+       if ((0 < x1) && (0 < diameter[1]))
+               brush_painter_mask_imbuf_update(painter, NULL, 0, 0, x1, 
diameter[1], 0, 0, diameter);
+       if ((x2 < diameter[0]) && (0 < diameter[1]))
+               brush_painter_mask_imbuf_update(painter, NULL, x2, 0, 
diameter[0], diameter[1], 0, 0, diameter);
        if ((x1 < x2) && (0 < y1))
                brush_painter_mask_imbuf_update(painter, NULL, x1, 0, x2, y1, 
0, 0, diameter);
-       if ((x1 < x2) && (y2 < diameter))
-               brush_painter_mask_imbuf_update(painter, NULL, x1, y2, x2, 
diameter, 0, 0, diameter);
+       if ((x1 < x2) && (y2 < diameter[1]))
+               brush_painter_mask_imbuf_update(painter, NULL, x1, y2, x2, 
diameter[1], 0, 0, diameter);
 
        /* through with sampling, now update sizes */
-       cache->tex_mask_old_w = diameter;
-       cache->tex_mask_old_h = diameter;
+       cache->tex_mask_old_w = diameter[0];
+       cache->tex_mask_old_h = diameter[1];
 }
 
 /* create a mask with the falloff strength */
-static unsigned short *brush_painter_curve_mask_new(BrushPainter *painter, int 
diameter, float radius)
+static unsigned short *brush_painter_curve_mask_new(BrushPainter *painter, 
const int diameter[2], const float radius[2])
 {
        Brush *brush = painter->brush;
 
-       int xoff = -radius;
-       int yoff = -radius;
 
        unsigned short *mask, *m;
        int x, y;
 
-       mask = MEM_mallocN(sizeof(unsigned short) * diameter * diameter, 
"brush_painter_mask");
+       mask = MEM_mallocN(sizeof(unsigned short) * diameter[0] * diameter[1], 
"brush_painter_mask");
        m = mask;
 
-       for (y = 0; y < diameter; y++) {
-               for (x = 0; x < diameter; x++, m++) {
-                       float xy[2] = {x + xoff, y + yoff};
+       float max_radius = max_ff(radius[0], radius[1]);
+       float xfac = max_radius/radius[0];
+       float yfac = max_radius/radius[1];
+
+       for (y = 0; y < diameter[1]; y++) {
+               for (x = 0; x < diameter[0]; x++, m++) {
+                       float xy[2] = {x*xfac - max_radius, y*yfac - 
max_radius};
                        float len = len_v2(xy);
 
-                       *m = (unsigned short)(65535.0f * 
BKE_brush_curve_strength_clamped(brush, len, radius));
+                       *m = (unsigned short)(65535.0f * 
BKE_brush_curve_strength_clamped(brush, len, max_radius));
                }
        }
 
@@ -375,7 +378,7 @@ static unsigned short 
*brush_painter_curve_mask_new(BrushPainter *painter, int d
 
 
 /* create im

@@ Diff output truncated at 10240 characters. @@

_______________________________________________
Bf-blender-cvs mailing list
[email protected]
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to