Support for rake in 2D image painting.
authorAntony Riakiotakis <kalast@gmail.com>
Fri, 15 Mar 2013 09:48:51 +0000 (09:48 +0000)
committerAntony Riakiotakis <kalast@gmail.com>
Fri, 15 Mar 2013 09:48:51 +0000 (09:48 +0000)
source/blender/blenkernel/intern/brush.c
source/blender/editors/sculpt_paint/paint_image_2d.c

index d341a2c06e1c045c6931377256370cce1b04ba2b..6adcdbd2c3ea2a6cf035f19516cda11053b1fedb 100644 (file)
@@ -565,15 +565,37 @@ float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br,
 /* Brush Sampling for 2D brushes. when we unify the brush systems this will be necessarily a separate function */
 float BKE_brush_sample_tex_2D(const Scene *scene, Brush *brush, const float xy[2], float rgba[4], struct ImagePool *pool)
 {
+       UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
        MTex *mtex = &brush->mtex;
 
        if (mtex && mtex->tex) {
                float co[3], tin, tr, tg, tb, ta;
+               float x = xy[0], y = xy[1];
                int hasrgb;
-               const int radius = BKE_brush_size_get(scene, brush);
+               int radius = BKE_brush_size_get(scene, brush);
+               float rotation = -mtex->rot;
+
+               if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
+                       rotation += ups->brush_rotation;
+                       radius = ups->pixel_radius;
+               }
+
+               x /= radius;
+               y /= radius;
+
+               if (rotation > 0.001f || rotation < -0.001f) {
+                       const float angle    = atan2f(y, x) + rotation;
+                       const float flen     = sqrtf(x * x + y * y);
+
+                       x = flen * cosf(angle);
+                       y = flen * sinf(angle);
+               }
+
+               x *= brush->mtex.size[0];
+               y *= brush->mtex.size[1];
 
-               co[0] = xy[0] / radius;
-               co[1] = xy[1] / radius;
+               co[0] = x + brush->mtex.ofs[0];
+               co[1] = y + brush->mtex.ofs[1];
                co[2] = 0.0f;
 
                hasrgb = externtex(mtex, co, &tin, &tr, &tg, &tb, &ta, 0, pool);
index e2e448646b26c5c456df06ba16107896d77cac9a..8db1b1817b54dcbb132d1a8bd8c52af38f995c58 100644 (file)
@@ -96,6 +96,7 @@ typedef struct BrushPainterCache {
        int lastsize;
        float lastalpha;
        float lastjitter;
+       float last_rotation;
 
        ImBuf *ibuf;
        ImBuf *texibuf;
@@ -335,6 +336,7 @@ static void brush_painter_2d_tiled_tex_partial_update(BrushPainter *painter, con
 static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float pos[2], int use_color_correction)
 {
        const Scene *scene = painter->scene;
+       UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings;
        Brush *brush = painter->brush;
        BrushPainterCache *cache = &painter->cache;
        MTex *mtex = &brush->mtex;
@@ -343,10 +345,16 @@ static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float po
        const int diameter = 2 * BKE_brush_size_get(scene, brush);
        const float alpha = BKE_brush_alpha_get(scene, brush);
        const bool do_tiled = ELEM(brush->mtex.brush_map_mode, MTEX_MAP_MODE_TILED, MTEX_MAP_MODE_3D);
+       float rotation = -mtex->rot;
+
+       if (mtex->brush_map_mode == MTEX_MAP_MODE_VIEW) {
+               rotation += ups->brush_rotation;
+       }
 
        if (diameter != cache->lastsize ||
            alpha != cache->lastalpha ||
-           brush->jitter != cache->lastjitter)
+           brush->jitter != cache->lastjitter ||
+           rotation != cache->last_rotation)
        {
                if (cache->ibuf) {
                        IMB_freeImBuf(cache->ibuf);
@@ -370,6 +378,7 @@ static void brush_painter_2d_refresh_cache(BrushPainter *painter, const float po
                cache->lastsize = diameter;
                cache->lastalpha = alpha;
                cache->lastjitter = brush->jitter;
+               cache->last_rotation = rotation;
        }
        else if (do_tiled && mtex && mtex->tex) {
                int dx = (int)painter->lastpaintpos[0] - (int)pos[0];