Revision: 47954
          
http://projects.blender.org/scm/viewvc.php?view=rev&root=bf-blender&revision=47954
Author:   psy-fi
Date:     2012-06-15 13:40:17 +0000 (Fri, 15 Jun 2012)
Log Message:
-----------
Texture Size Randomize
======================
* Refactor the code to be less obtrusive to other modes. If a randomized
size is required, it is explicitly requested. I will probably have to
change the texture sample functions too to explicitly return a
randomized result.

Modified Paths:
--------------
    
branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
    branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
    branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
    
branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
    branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h
    branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c

Modified: 
branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
===================================================================
--- 
branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
   2012-06-15 13:35:24 UTC (rev 47953)
+++ 
branches/soc-2012-bratwurst/release/scripts/startup/bl_ui/space_view3d_toolbar.py
   2012-06-15 13:40:17 UTC (rev 47954)
@@ -643,6 +643,9 @@
             self.prop_unified_size(row, context, brush, "use_pressure_size")
 
             row = col.row(align=True)
+            row.prop(brush, "random_size", slider=True)
+
+            row = col.row(align=True)
             self.prop_unified_strength(row, context, brush, "strength", 
text="Strength")
             self.prop_unified_strength(row, context, brush, 
"use_pressure_strength")
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h   
2012-06-15 13:35:24 UTC (rev 47953)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/BKE_brush.h   
2012-06-15 13:40:17 UTC (rev 47954)
@@ -91,7 +91,7 @@
 struct ImBuf *BKE_brush_gen_radial_control_imbuf(struct Brush *br);
 
 /* unified strength and size */
-
+int BKE_brush_size_randomized_get(const struct Scene *scene, struct Brush 
*brush);
 int  BKE_brush_size_get(const struct Scene *scene, struct Brush *brush);
 void BKE_brush_size_set(struct Scene *scene, struct Brush *brush, int value);
 

Modified: branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c        
2012-06-15 13:35:24 UTC (rev 47953)
+++ branches/soc-2012-bratwurst/source/blender/blenkernel/intern/brush.c        
2012-06-15 13:40:17 UTC (rev 47954)
@@ -102,7 +102,8 @@
        brush->rate = 0.1f; /* time delay between dots of paint or sculpting 
when doing airbrush mode */
 
        brush->jitter = 0.0f;
-
+       brush->random_size = 0.0;
+       brush->random_factor_cache = 1.0;
        /* BRUSH TEXTURE SETTINGS */
        default_mtex(&brush->mtex);
 
@@ -296,6 +297,8 @@
        BR_TEST_FLAG(BRUSH_CUSTOM_ICON);
 
        BR_TEST(jitter, f);
+       BR_TEST(random_size, f);
+       BR_TEST(random_factor_cache, f);
        BR_TEST(spacing, d);
        BR_TEST(smooth_stroke_radius, d);
        BR_TEST(smooth_stroke_factor, f);
@@ -485,6 +488,15 @@
        return 0;
 }
 
+/* reset the random size cache to a random value, proportional to the size of 
the brush.
+ * due to the many places BKE_brush_size_get is called it is not safe to 
generate a random
+ * number for every call. Instead we will generate a random number before each 
stroke */
+void BKE_brush_randomize_size(Brush *brush)
+{
+       brush->random_factor_cache = (1.0 - brush->random_size/2.0) + 
brush->random_size*BLI_frand();
+}
+
+
 /* Brush Sampling */
 void BKE_brush_sample_tex(const Scene *scene, Brush *brush, const float xy[2], 
float rgba[4], const int thread, float angle)
 {
@@ -494,7 +506,7 @@
                float co_angle, length;
                float co[3], tin, tr, tg, tb, ta;
                int hasrgb;
-               const int radius = BKE_brush_size_get(scene, brush);
+               const int radius = BKE_brush_size_randomized_get(scene, brush);
 
                co[0] = xy[0] / radius;
                co[1] = xy[1] / radius;
@@ -541,11 +553,11 @@
        ImBuf *ibuf;
        float xy[2], rgba[4], *dstf;
        int x, y, rowbytes, xoff, yoff, imbflag;
-       const int radius = BKE_brush_size_get(scene, brush);
+       const int radius = BKE_brush_size_randomized_get(scene, brush);
        unsigned char *dst, crgb[3];
        const float alpha = BKE_brush_alpha_get(scene, brush);
        float brush_rgb[3];
-    
+
        imbflag = (flt) ? IB_rectfloat : IB_rect;
        xoff = -bufsize / 2.0f + 0.5f;
        yoff = -bufsize / 2.0f + 0.5f;
@@ -664,6 +676,13 @@
        return (ups->flag & UNIFIED_PAINT_SIZE) ? ups->size : brush->size;
 }
 
+int BKE_brush_size_randomized_get(const Scene *scene, Brush *brush)
+{
+       UnifiedPaintSettings *ups = 
&scene->toolsettings->unified_paint_settings;
+
+       return (ups->flag & UNIFIED_PAINT_SIZE) ? 
brush->random_factor_cache*ups->size : brush->random_factor_cache*brush->size;
+}
+
 int BKE_brush_use_locked_size(const Scene *scene, Brush *brush)
 {
        const short us_flag = scene->toolsettings->unified_paint_settings.flag;
@@ -1022,7 +1041,7 @@
        MTex *mtex = &brush->mtex;
        int size;
        short flt;
-       const int diameter = 2 * BKE_brush_size_get(scene, brush);
+       const int diameter = 2 * BKE_brush_size_randomized_get(scene, brush);
        const float alpha = BKE_brush_alpha_get(scene, brush);
        const float rotation = 
scene->toolsettings->unified_paint_settings.last_angle;
 
@@ -1116,6 +1135,8 @@
        Brush *brush = painter->brush;
        int totpaintops = 0;
 
+       BKE_brush_randomize_size(brush);
+
        if (pressure == 0.0f) {
                if (painter->lastpressure) // XXX - hack, operator misses
                        pressure = painter->lastpressure;
@@ -1180,7 +1201,7 @@
        else {
                float startdistance, spacing, step, paintpos[2], dmousepos[2], 
finalpos[2];
                float t, len, press;
-               const int radius = BKE_brush_size_get(scene, brush);
+               const int radius = BKE_brush_size_randomized_get(scene, brush);
 
                /* compute brush spacing adapted to brush radius, spacing may 
depend
                 * on pressure, so update it */

Modified: 
branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c
===================================================================
--- 
branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c   
    2012-06-15 13:35:24 UTC (rev 47953)
+++ 
branches/soc-2012-bratwurst/source/blender/editors/sculpt_paint/paint_image.c   
    2012-06-15 13:40:17 UTC (rev 47954)
@@ -3601,7 +3601,7 @@
 {
        if (ps->source == PROJ_SRC_VIEW) {
                float min_brush[2], max_brush[2];
-               const float radius = (float)BKE_brush_size_get(ps->scene, 
ps->brush);
+               const float radius = 
(float)BKE_brush_size_randomized_get(ps->scene, ps->brush);
 
                /* so we don't have a bucket bounds that is way too small to 
paint into */
                // if (radius < 1.0f) radius = 1.0f; // this doesn't work yet :/
@@ -3865,7 +3865,7 @@
        float co[2];
        float mask = 1.0f; /* airbrush wont use mask */
        unsigned short mask_short;
-       const float radius = (float)BKE_brush_size_get(ps->scene, ps->brush);
+       const float radius = (float)BKE_brush_size_randomized_get(ps->scene, 
ps->brush);
        const float radius_squared = radius * radius; /* avoid a square root 
with every dist comparison */
        
        short lock_alpha = ELEM(ps->brush->blend, IMB_BLEND_ERASE_ALPHA, 
IMB_BLEND_ADD_ALPHA) ? 0 : ps->brush->flag & BRUSH_LOCK_ALPHA;

Modified: branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h       
2012-06-15 13:35:24 UTC (rev 47953)
+++ branches/soc-2012-bratwurst/source/blender/makesdna/DNA_brush_types.h       
2012-06-15 13:40:17 UTC (rev 47954)
@@ -102,6 +102,9 @@
 
        float add_col[3];
        float sub_col[3];
+
+       float random_size;
+       float random_factor_cache;
 } Brush;
 
 /* Brush.flag */

Modified: branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c
===================================================================
--- branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c      
2012-06-15 13:35:24 UTC (rev 47953)
+++ branches/soc-2012-bratwurst/source/blender/makesrna/intern/rna_brush.c      
2012-06-15 13:40:17 UTC (rev 47954)
@@ -618,6 +618,12 @@
        RNA_def_property_ui_text(prop, "Unprojected Radius", "Radius of brush 
in Blender units");
        RNA_def_property_update(prop, 0, "rna_Brush_update");
 
+       prop = RNA_def_property(srna, "random_size", PROP_FLOAT, PROP_NONE);
+       RNA_def_property_float_sdna(prop, NULL, "random_size");
+       RNA_def_property_range(prop, 0.0f, 1.0f);
+       RNA_def_property_ui_text(prop, "Randomize Radius", "Radius of brush 
changes while painting");
+       RNA_def_property_update(prop, 0, "rna_Brush_update");
+
        prop = RNA_def_property(srna, "jitter", PROP_FLOAT, PROP_NONE);
        RNA_def_property_float_sdna(prop, NULL, "jitter");
        RNA_def_property_range(prop, 0.0f, 1.0f);

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

Reply via email to