diff options
author | Campbell Barton <ideasman42@gmail.com> | 2017-10-03 10:43:18 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2017-10-03 10:43:18 +0300 |
commit | 515e69999e63aab7720e48b0c85233f61facce65 (patch) | |
tree | 425d29c58447b6dc205635cc0cbe1d45bc04e5dc | |
parent | 2b3ff61d805ccbb219e773e1a5c69e02b0c90109 (diff) |
Weight Paint: don't set weight w/ average brush
Also use 'const' for brush.
-rw-r--r-- | source/blender/blenkernel/BKE_brush.h | 2 | ||||
-rw-r--r-- | source/blender/blenkernel/intern/brush.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_intern.h | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_utils.c | 4 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/paint_vertex.c | 34 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt.c | 52 | ||||
-rw-r--r-- | source/blender/editors/sculpt_paint/sculpt_intern.h | 6 | ||||
-rw-r--r-- | source/blender/render/extern/include/RE_render_ext.h | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/render_texture.c | 8 |
9 files changed, 59 insertions, 57 deletions
diff --git a/source/blender/blenkernel/BKE_brush.h b/source/blender/blenkernel/BKE_brush.h index c1e107e101a..c6d4217780e 100644 --- a/source/blender/blenkernel/BKE_brush.h +++ b/source/blender/blenkernel/BKE_brush.h @@ -74,7 +74,7 @@ float BKE_brush_curve_strength(const struct Brush *br, float p, const float len) /* sampling */ float BKE_brush_sample_tex_3D( - const struct Scene *scene, struct Brush *br, const float point[3], + const struct Scene *scene, const struct Brush *br, const float point[3], float rgba[4], const int thread, struct ImagePool *pool); float BKE_brush_sample_masktex( const struct Scene *scene, struct Brush *br, const float point[2], diff --git a/source/blender/blenkernel/intern/brush.c b/source/blender/blenkernel/intern/brush.c index 0300dfe5891..4a54ab26373 100644 --- a/source/blender/blenkernel/intern/brush.c +++ b/source/blender/blenkernel/intern/brush.c @@ -521,13 +521,13 @@ int BKE_brush_clone_image_delete(Brush *brush) * region space mouse coordinates, or 3d world coordinates for 3D mapping. * * rgba outputs straight alpha. */ -float BKE_brush_sample_tex_3D(const Scene *scene, Brush *br, +float BKE_brush_sample_tex_3D(const Scene *scene, const Brush *br, const float point[3], float rgba[4], const int thread, struct ImagePool *pool) { UnifiedPaintSettings *ups = &scene->toolsettings->unified_paint_settings; - MTex *mtex = &br->mtex; + const MTex *mtex = &br->mtex; float intensity = 1.0; bool hasrgb = false; diff --git a/source/blender/editors/sculpt_paint/paint_intern.h b/source/blender/editors/sculpt_paint/paint_intern.h index bd35218bb64..f6fcbfdfbee 100644 --- a/source/blender/editors/sculpt_paint/paint_intern.h +++ b/source/blender/editors/sculpt_paint/paint_intern.h @@ -242,8 +242,8 @@ void paint_calc_redraw_planes(float planes[4][4], const struct rcti *screen_rect); float paint_calc_object_space_radius(struct ViewContext *vc, const float center[3], float pixel_radius); -float paint_get_tex_pixel(struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread); -void paint_get_tex_pixel_col(struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert, struct ColorSpace *colorspace); +float paint_get_tex_pixel(const struct MTex *mtex, float u, float v, struct ImagePool *pool, int thread); +void paint_get_tex_pixel_col(const struct MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert, struct ColorSpace *colorspace); void paint_sample_color(struct bContext *C, struct ARegion *ar, int x, int y, bool texpaint_proj, bool palette); diff --git a/source/blender/editors/sculpt_paint/paint_utils.c b/source/blender/editors/sculpt_paint/paint_utils.c index 10628d8cccb..7668b8ebd99 100644 --- a/source/blender/editors/sculpt_paint/paint_utils.c +++ b/source/blender/editors/sculpt_paint/paint_utils.c @@ -171,7 +171,7 @@ float paint_calc_object_space_radius(ViewContext *vc, const float center[3], return len_v3(delta) / scale; } -float paint_get_tex_pixel(MTex *mtex, float u, float v, struct ImagePool *pool, int thread) +float paint_get_tex_pixel(const MTex *mtex, float u, float v, struct ImagePool *pool, int thread) { float intensity, rgba[4]; float co[3] = {u, v, 0.0f}; @@ -182,7 +182,7 @@ float paint_get_tex_pixel(MTex *mtex, float u, float v, struct ImagePool *pool, return intensity; } -void paint_get_tex_pixel_col(MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert_to_linear, struct ColorSpace *colorspace) +void paint_get_tex_pixel_col(const MTex *mtex, float u, float v, float rgba[4], struct ImagePool *pool, int thread, bool convert_to_linear, struct ColorSpace *colorspace) { float co[3] = {u, v, 0.0f}; int hasrgb; diff --git a/source/blender/editors/sculpt_paint/paint_vertex.c b/source/blender/editors/sculpt_paint/paint_vertex.c index 4dd218114f6..c61d250446c 100644 --- a/source/blender/editors/sculpt_paint/paint_vertex.c +++ b/source/blender/editors/sculpt_paint/paint_vertex.c @@ -262,12 +262,12 @@ uint vpaint_get_current_col(Scene *scene, VPaint *vp) /* wpaint has 'wpaint_blend' */ static uint vpaint_blend( - VPaint *vp, uint color_curr, uint color_orig, + const VPaint *vp, uint color_curr, uint color_orig, uint color_paint, const int alpha_i, /* pre scaled from [0-1] --> [0-255] */ const int brush_alpha_value_i) { - Brush *brush = BKE_paint_brush(&vp->paint); + const Brush *brush = vp->paint.brush; const int tool = brush->vertexpaint_tool; uint color_blend = ED_vpaint_blend_tool(tool, color_curr, color_paint, alpha_i); @@ -383,12 +383,12 @@ static float calc_vp_alpha_col_dl( /* vpaint has 'vpaint_blend' */ static float wpaint_blend( - VPaint *wp, float weight, + const VPaint *wp, float weight, const float alpha, float paintval, const float UNUSED(brush_alpha_value), const short do_flip) { - Brush *brush = BKE_paint_brush(&wp->paint); + const Brush *brush = wp->paint.brush; int tool = brush->vertexpaint_tool; if (do_flip) { @@ -698,7 +698,7 @@ typedef struct WeightPaintInfo { static void do_weight_paint_vertex_single( /* vars which remain the same for every vert */ - VPaint *wp, Object *ob, const WeightPaintInfo *wpi, + const VPaint *wp, Object *ob, const WeightPaintInfo *wpi, /* vars which change on each stroke */ const uint index, float alpha, float paintweight) { @@ -847,7 +847,7 @@ static void do_weight_paint_vertex_single( static void do_weight_paint_vertex_multi( /* vars which remain the same for every vert */ - VPaint *wp, Object *ob, const WeightPaintInfo *wpi, + const VPaint *wp, Object *ob, const WeightPaintInfo *wpi, /* vars which change on each stroke */ const uint index, float alpha, float paintweight) { @@ -945,7 +945,7 @@ static void do_weight_paint_vertex_multi( static void do_weight_paint_vertex( /* vars which remain the same for every vert */ - VPaint *wp, Object *ob, const WeightPaintInfo *wpi, + const VPaint *wp, Object *ob, const WeightPaintInfo *wpi, /* vars which change on each stroke */ const uint index, float alpha, float paintweight) { @@ -1199,12 +1199,12 @@ struct WPaintData { /* Initialize the stroke cache invariants from operator properties */ static void vwpaint_update_cache_invariants( - bContext *C, VPaint *vp, SculptSession *ss, wmOperator *op, const float mouse[2]) + bContext *C, const VPaint *vp, SculptSession *ss, wmOperator *op, const float mouse[2]) { StrokeCache *cache; Scene *scene = CTX_data_scene(C); UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; - Brush *brush = BKE_paint_brush(&vp->paint); + const Brush *brush = vp->paint.brush; ViewContext *vc = paint_stroke_view_context(op->customdata); Object *ob = CTX_data_active_object(C); float mat[3][3]; @@ -1667,7 +1667,7 @@ static void do_wpaint_brush_smear_task_cb_ex( /* Apply weight to vertex */ if (do_color) { const float brush_fade = BKE_brush_curve_strength(brush, 0.0f, cache->radius); - float final_alpha = + const float final_alpha = brush_fade * brush_strength * grid_alpha * brush_alpha_pressure; do_weight_paint_vertex( @@ -1692,7 +1692,9 @@ static void do_wpaint_brush_draw_task_cb_ex( const Brush *brush = data->brush; const StrokeCache *cache = ss->cache; - const float paintweight = BKE_brush_weight_get(scene, brush); + /* note: normally `BKE_brush_weight_get(scene, brush)` is used, + * however in this case we calculate a new weight each time. */ + const float paintweight = data->strength; float brush_size_pressure, brush_alpha_value, brush_alpha_pressure; get_brush_alpha_data(scene, ss, brush, &brush_size_pressure, &brush_alpha_value, &brush_alpha_pressure); const bool use_normal = vwpaint_use_normal(data->vp); @@ -1820,10 +1822,7 @@ static void calculate_average_weight(SculptThreadedTaskData *data, PBVHNode **UN } if (accum_len != 0) { accum_weight /= accum_len; - if (ups->flag & UNIFIED_PAINT_WEIGHT) - ups->weight = (float)accum_weight; - else - data->brush->weight = (float)accum_weight; + data->strength = (float)accum_weight; } MEM_SAFE_FREE(data->custom_data); /* 'accum' */ @@ -1834,7 +1833,7 @@ static void wpaint_paint_leaves( bContext *C, Object *ob, Sculpt *sd, VPaint *vp, struct WPaintData *wpd, WeightPaintInfo *wpi, Mesh *me, PBVHNode **nodes, int totnode) { - Brush *brush = ob->sculpt->cache->brush; + const Brush *brush = ob->sculpt->cache->brush; /* threaded loop over nodes */ SculptThreadedTaskData data = { @@ -2733,6 +2732,7 @@ static void do_vpaint_brush_smear_task_cb_ex( const int p_index = gmap->vert_to_poly[v_index].indices[j]; const int l_index = gmap->vert_to_loop[v_index].indices[j]; BLI_assert(data->me->mloop[l_index].v == v_index); + UNUSED_VARS_NDEBUG(l_index); const MPoly *mp = &data->me->mpoly[p_index]; if (!use_face_sel || mp->flag & ME_FACE_SEL) { const MLoop *ml_other = &data->me->mloop[mp->loopstart]; @@ -2829,7 +2829,7 @@ static void vpaint_paint_leaves( bContext *C, Sculpt *sd, VPaint *vp, struct VPaintData *vpd, Object *ob, Mesh *me, PBVHNode **nodes, int totnode) { - Brush *brush = ob->sculpt->cache->brush; + const Brush *brush = ob->sculpt->cache->brush; SculptThreadedTaskData data = { .sd = sd, .ob = ob, .brush = brush, .nodes = nodes, .vp = vp, .vpd = vpd, diff --git a/source/blender/editors/sculpt_paint/sculpt.c b/source/blender/editors/sculpt_paint/sculpt.c index 1698ab9e5c7..e8ea7f6709c 100644 --- a/source/blender/editors/sculpt_paint/sculpt.c +++ b/source/blender/editors/sculpt_paint/sculpt.c @@ -634,7 +634,7 @@ bool sculpt_brush_test_cube(SculptBrushTest *test, const float co[3], float loca } } -static float frontface(Brush *br, const float sculpt_normal[3], +static float frontface(const Brush *br, const float sculpt_normal[3], const short no[3], const float fno[3]) { if (br->flag & BRUSH_FRONTFACE) { @@ -1128,7 +1128,7 @@ static float brush_strength( } /* Return a multiplier for brush strength on a particular vertex. */ -float tex_strength(SculptSession *ss, Brush *br, +float tex_strength(SculptSession *ss, const Brush *br, const float brush_point[3], const float len, const short vno[3], @@ -1138,7 +1138,7 @@ float tex_strength(SculptSession *ss, Brush *br, { StrokeCache *cache = ss->cache; const Scene *scene = cache->vc->scene; - MTex *mtex = &br->mtex; + const MTex *mtex = &br->mtex; float avg = 1; float rgba[4]; float point[3]; @@ -1556,7 +1556,7 @@ static void do_smooth_brush_mesh_task_cb_ex( SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; - Brush *brush = data->brush; + const Brush *brush = data->brush; const bool smooth_mask = data->smooth_mask; float bstrength = data->strength; @@ -1604,7 +1604,7 @@ static void do_smooth_brush_bmesh_task_cb_ex( SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; - Brush *brush = data->brush; + const Brush *brush = data->brush; const bool smooth_mask = data->smooth_mask; float bstrength = data->strength; @@ -1652,7 +1652,7 @@ static void do_smooth_brush_multires_task_cb_ex( SculptDoBrushSmoothGridDataChunk *data_chunk = userdata_chunk; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; - Brush *brush = data->brush; + const Brush *brush = data->brush; const bool smooth_mask = data->smooth_mask; float bstrength = data->strength; @@ -1866,7 +1866,7 @@ static void do_mask_brush_draw_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float bstrength = ss->cache->bstrength; PBVHVertexIter vd; @@ -1923,7 +1923,7 @@ static void do_draw_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *offset = data->offset; PBVHVertexIter vd; @@ -1978,7 +1978,7 @@ static void do_crease_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; SculptProjectVector *spvc = data->spvc; const float flippedbstrength = data->flippedbstrength; const float *offset = data->offset; @@ -2066,7 +2066,7 @@ static void do_pinch_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; PBVHVertexIter vd; SculptBrushTest test; @@ -2112,7 +2112,7 @@ static void do_grab_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *grab_delta = data->grab_delta; PBVHVertexIter vd; @@ -2172,7 +2172,7 @@ static void do_nudge_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *cono = data->cono; PBVHVertexIter vd; @@ -2226,7 +2226,7 @@ static void do_snake_hook_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; SculptProjectVector *spvc = data->spvc; const float *grab_delta = data->grab_delta; @@ -2327,7 +2327,7 @@ static void do_thumb_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *cono = data->cono; PBVHVertexIter vd; @@ -2387,7 +2387,7 @@ static void do_rotate_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float angle = data->angle; PBVHVertexIter vd; @@ -2449,7 +2449,7 @@ static void do_layer_brush_task_cb_ex( SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; Sculpt *sd = data->sd; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *offset = data->offset; PBVHVertexIter vd; @@ -2533,7 +2533,7 @@ static void do_inflate_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; PBVHVertexIter vd; SculptBrushTest test; @@ -2691,7 +2691,7 @@ static void do_flatten_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; @@ -2767,7 +2767,7 @@ static void do_clay_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; @@ -2851,7 +2851,7 @@ static void do_clay_strips_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; float (*mat)[4] = data->mat; const float *area_no_sp = data->area_no_sp; const float *area_co = data->area_co; @@ -2961,7 +2961,7 @@ static void do_fill_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; @@ -3040,7 +3040,7 @@ static void do_scrape_brush_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; const float *area_no = data->area_no; const float *area_co = data->area_co; @@ -3119,7 +3119,7 @@ static void do_gravity_task_cb_ex( { SculptThreadedTaskData *data = userdata; SculptSession *ss = data->ob->sculpt; - Brush *brush = data->brush; + const Brush *brush = data->brush; float *offset = data->offset; PBVHVertexIter vd; @@ -4654,6 +4654,7 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str if (ss->cache) { UnifiedPaintSettings *ups = &CTX_data_tool_settings(C)->unified_paint_settings; Brush *brush = BKE_paint_brush(&sd->paint); + BLI_assert(brush == ss->cache->brush); /* const, so we shouldn't change. */ ups->draw_inverted = false; sculpt_stroke_modifiers_check(C, ob); @@ -4664,11 +4665,10 @@ static void sculpt_stroke_done(const bContext *C, struct PaintStroke *UNUSED(str brush->mask_tool = ss->cache->saved_mask_brush_tool; } else { - Paint *p = &sd->paint; - BKE_brush_size_set(scene, ss->cache->brush, ss->cache->saved_smooth_size); + BKE_brush_size_set(scene, brush, ss->cache->saved_smooth_size); brush = (Brush *)BKE_libblock_find_name(ID_BR, ss->cache->saved_active_brush_name); if (brush) { - BKE_paint_brush_set(p, brush); + BKE_paint_brush_set(&sd->paint, brush); } } } diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h index 425cecb0010..b9b662f4157 100644 --- a/source/blender/editors/sculpt_paint/sculpt_intern.h +++ b/source/blender/editors/sculpt_paint/sculpt_intern.h @@ -132,7 +132,7 @@ typedef struct SculptThreadedTaskData { struct bContext *C; struct Sculpt *sd; struct Object *ob; - struct Brush *brush; + const struct Brush *brush; struct PBVHNode **nodes; int totnode; @@ -214,7 +214,7 @@ bool sculpt_brush_test_circle_sq(SculptBrushTest *test, const float co[3]); bool sculpt_search_sphere_cb(PBVHNode *node, void *data_v); bool sculpt_search_circle_cb(PBVHNode *node, void *data_v); float tex_strength( - struct SculptSession *ss, struct Brush *br, + struct SculptSession *ss, const struct Brush *br, const float point[3], const float len, const short vno[3], @@ -268,7 +268,7 @@ typedef struct StrokeCache { /* Clean this up! */ struct ViewContext *vc; - struct Brush *brush; + const struct Brush *brush; float special_rotation; float grab_delta[3], grab_delta_symmetry[3]; diff --git a/source/blender/render/extern/include/RE_render_ext.h b/source/blender/render/extern/include/RE_render_ext.h index 2b5d0ca4e14..1779ccc5d19 100644 --- a/source/blender/render/extern/include/RE_render_ext.h +++ b/source/blender/render/extern/include/RE_render_ext.h @@ -45,7 +45,7 @@ struct Scene; /* render_texture.c */ /* used by particle.c, effect.c, editmesh_modes.c and brush.c, returns 1 if rgb, 0 otherwise */ int externtex( - struct MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, float *tb, float *ta, + const struct MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, float *tb, float *ta, const int thread, struct ImagePool *pool, const bool skip_load_image, const bool texnode_preview); void texture_rgb_blend(float in[3], const float tex[3], const float out[3], float fact, float facg, int blendtype); float texture_value_blend(float tex, float out, float fact, float facg, int blendtype); diff --git a/source/blender/render/intern/source/render_texture.c b/source/blender/render/intern/source/render_texture.c index 22dc2b28900..91d1f63a1be 100644 --- a/source/blender/render/intern/source/render_texture.c +++ b/source/blender/render/intern/source/render_texture.c @@ -781,7 +781,8 @@ static int cubemap_glob(const float n[3], float x, float y, float z, float *adr1 /* ------------------------------------------------------------------------- */ /* mtex argument only for projection switches */ -static int cubemap(MTex *mtex, VlakRen *vlr, const float n[3], float x, float y, float z, float *adr1, float *adr2) +static int cubemap( + const MTex *mtex, VlakRen *vlr, const float n[3], float x, float y, float z, float *adr1, float *adr2) { int proj[4]={0, ME_PROJXY, ME_PROJXZ, ME_PROJYZ}, ret= 0; @@ -873,7 +874,8 @@ static int cubemap_ob(Object *ob, const float n[3], float x, float y, float z, f /* ------------------------------------------------------------------------- */ -static void do_2d_mapping(MTex *mtex, float texvec[3], VlakRen *vlr, const float n[3], float dxt[3], float dyt[3]) +static void do_2d_mapping( + const MTex *mtex, float texvec[3], VlakRen *vlr, const float n[3], float dxt[3], float dyt[3]) { Tex *tex; Object *ob= NULL; @@ -3594,7 +3596,7 @@ void do_lamp_tex(LampRen *la, const float lavec[3], ShadeInput *shi, float col_r /* ------------------------------------------------------------------------- */ -int externtex(MTex *mtex, +int externtex(const MTex *mtex, const float vec[3], float *tin, float *tr, float *tg, float *tb, float *ta, const int thread, |