diff options
-rw-r--r-- | source/blender/blenkernel/BKE_brush.h | 4 | ||||
-rw-r--r-- | source/blender/blenkernel/BKE_paint.h | 3 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 68 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/paint.c | 2 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 34 |
5 files changed, 33 insertions, 78 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index a98f4802991..4d728002c87 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -119,10 +119,6 @@ float BKE_brush_sample_masktex(const struct Scene *scene, int thread, struct ImagePool *pool); -/* Texture. */ - -unsigned int *BKE_brush_gen_texture_cache(struct Brush *br, int half_side, bool use_secondary); - /** * Radial control. */ diff --git a/source/blender/blenkernel/BKE_paint.h b/source/blender/blenkernel/BKE_paint.h index a47e4a24f75..93a5e0a4072 100644 --- a/source/blender/blenkernel/BKE_paint.h +++ b/source/blender/blenkernel/BKE_paint.h @@ -552,8 +552,7 @@ typedef struct SculptSession { float (*deform_cos)[3]; /* Coords of deformed mesh but without stroke displacement. */ float (*deform_imats)[3][3]; /* Crazy-space deformation matrices. */ - /* Used to cache the render of the active texture */ - unsigned int texcache_side, *texcache, texcache_actual; + /* Pool for texture evaluations. */ struct ImagePool *tex_pool; struct StrokeCache *cache; diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 083d5af063a..1cda0e8a4bb 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -2469,71 +2469,55 @@ float BKE_brush_curve_strength_clamped(const Brush *br, float p, const float len } /* TODO: should probably be unified with BrushPainter stuff? */ -unsigned int *BKE_brush_gen_texture_cache(Brush *br, int half_side, bool use_secondary) +static bool brush_gen_texture(const Brush *br, + const int side, + const bool use_secondary, + float *rect) { - unsigned int *texcache = NULL; - MTex *mtex = (use_secondary) ? &br->mask_mtex : &br->mtex; - float intensity; - float rgba_dummy[4]; - int ix, iy; - int side = half_side * 2; + const MTex *mtex = (use_secondary) ? &br->mask_mtex : &br->mtex; + if (mtex->tex == NULL) { + return false; + } - if (mtex->tex) { - float x, y, step = 2.0 / side, co[3]; + const float step = 2.0 / side; + int ix, iy; + float x, y; - texcache = MEM_callocN(sizeof(int) * side * side, "Brush texture cache"); + /* Do normalized canonical view coords for texture. */ + for (y = -1.0, iy = 0; iy < side; iy++, y += step) { + for (x = -1.0, ix = 0; ix < side; ix++, x += step) { + const float co[3] = {x, y, 0.0f}; - /* do normalized canonical view coords for texture */ - for (y = -1.0, iy = 0; iy < side; iy++, y += step) { - for (x = -1.0, ix = 0; ix < side; ix++, x += step) { - co[0] = x; - co[1] = y; - co[2] = 0.0f; + float intensity; + float rgba_dummy[4]; + RE_texture_evaluate(mtex, co, 0, NULL, false, false, &intensity, rgba_dummy); - /* This is copied from displace modifier code */ - /* TODO(sergey): brush are always caching with CM enabled for now. */ - RE_texture_evaluate(mtex, co, 0, NULL, false, false, &intensity, rgba_dummy); - copy_v4_uchar((uchar *)&texcache[iy * side + ix], (char)(intensity * 255.0f)); - } + rect[iy * side + ix] = intensity; } } - return texcache; + return true; } struct ImBuf *BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary, bool display_gradient) { ImBuf *im = MEM_callocN(sizeof(ImBuf), "radial control texture"); - unsigned int *texcache; int side = 512; int half = side / 2; - int i, j; BKE_curvemapping_init(br->curve); - texcache = BKE_brush_gen_texture_cache(br, half, secondary); im->rect_float = MEM_callocN(sizeof(float) * side * side, "radial control rect"); im->x = im->y = side; - if (display_gradient || texcache) { - for (i = 0; i < side; i++) { - for (j = 0; j < side; j++) { - float magn = sqrtf(pow2f(i - half) + pow2f(j - half)); - im->rect_float[i * side + j] = BKE_brush_curve_strength_clamped(br, magn, half); - } - } - } + const bool have_texture = brush_gen_texture(br, side, secondary, im->rect_float); - if (texcache) { - /* Modulate curve with texture */ - for (i = 0; i < side; i++) { - for (j = 0; j < side; j++) { - const int col = texcache[i * side + j]; - im->rect_float[i * side + j] *= (((char *)&col)[0] + ((char *)&col)[1] + - ((char *)&col)[2]) / - 3.0f / 255.0f; + if (display_gradient || have_texture) { + for (int i = 0; i < side; i++) { + for (int j = 0; j < side; j++) { + float magn = sqrtf(pow2f(i - half) + pow2f(j - half)); + im->rect_float[i * side + j] *= BKE_brush_curve_strength_clamped(br, magn, half); } } - MEM_freeN(texcache); } return im; diff --git a/source/blender/blenkernel/intern/paint.c b/source/blender/blenkernel/intern/paint.c index 81c7e7f34da..8c91ea2b369 100644 --- a/source/blender/blenkernel/intern/paint.c +++ b/source/blender/blenkernel/intern/paint.c @@ -1485,8 +1485,6 @@ void BKE_sculptsession_free(Object *ob) BM_log_free(ss->bm_log); } - MEM_SAFE_FREE(ss->texcache); - if (ss->tex_pool) { BKE_image_pool_free(ss->tex_pool); } diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 4f7cb291364..94ae5459d19 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -2381,7 +2381,7 @@ float SCULPT_brush_strength_factor(SculptSession *ss, /* Get strength by feeding the vertex location directly into a texture. */ avg = BKE_brush_sample_tex_3d(scene, br, point, rgba, 0, ss->tex_pool); } - else if (ss->texcache) { + else { float symm_point[3], point_2d[2]; /* Quite warnings. */ float x = 0.0f, y = 0.0f; @@ -3937,27 +3937,6 @@ static void do_symmetrical_brush_actions(Sculpt *sd, } } -static void sculpt_update_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) -{ - Brush *brush = BKE_paint_brush(&sd->paint); - const int radius = BKE_brush_size_get(scene, brush); - - MEM_SAFE_FREE(ss->texcache); - - if (ss->tex_pool) { - BKE_image_pool_free(ss->tex_pool); - ss->tex_pool = NULL; - } - - /* Need to allocate a bigger buffer for bigger brush size. */ - ss->texcache_side = 2 * radius; - if (!ss->texcache || ss->texcache_side > ss->texcache_actual) { - ss->texcache = BKE_brush_gen_texture_cache(brush, radius, false); - ss->texcache_actual = ss->texcache_side; - ss->tex_pool = BKE_image_pool_new(); - } -} - bool SCULPT_mode_poll(bContext *C) { Object *ob = CTX_data_active_object(C); @@ -5040,7 +5019,7 @@ bool SCULPT_stroke_get_location(bContext *C, float out[3], const float mval[2]) return hit; } -static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession *ss) +static void sculpt_brush_init_tex(Sculpt *sd, SculptSession *ss) { Brush *brush = BKE_paint_brush(&sd->paint); MTex *mtex = &brush->mtex; @@ -5051,14 +5030,13 @@ static void sculpt_brush_init_tex(const Scene *scene, Sculpt *sd, SculptSession ntreeTexBeginExecTree(mtex->tex->nodetree); } - /* TODO: Shouldn't really have to do this at the start of every stroke, but sculpt would need - * some sort of notification when changes are made to the texture. */ - sculpt_update_tex(scene, sd, ss); + if (ss->tex_pool == NULL) { + ss->tex_pool = BKE_image_pool_new(); + } } static void sculpt_brush_stroke_init(bContext *C, wmOperator *op) { - Scene *scene = CTX_data_scene(C); Object *ob = CTX_data_active_object(C); Sculpt *sd = CTX_data_tool_settings(C)->sculpt; SculptSession *ss = CTX_data_active_object(C)->sculpt; @@ -5077,7 +5055,7 @@ static void sculpt_brush_stroke_init(bContext *C, wmOperator *op) } view3d_operator_needs_opengl(C); - sculpt_brush_init_tex(scene, sd, ss); + sculpt_brush_init_tex(sd, ss); need_pmap = sculpt_needs_connectivity_info(sd, brush, ss, mode); needs_colors = SCULPT_TOOL_NEEDS_COLOR(brush->sculpt_tool); |