Vector displacement for the sculpting draw brush #104481

Merged
Jeroen Bakker merged 18 commits from robin.hohni/blender:sculpt-vector-displacement into main 2023-02-14 15:29:40 +01:00
3 changed files with 9 additions and 4 deletions
Showing only changes of commit 3cea9dd4a1 - Show all commits

View File

@ -2719,9 +2719,14 @@ void SCULPT_brush_strength_color(struct SculptSession *ss,
mul_v4_fl(r_rgba, masks_combined);
}
void SCULPT_calc_vertex_displacement(SculptSession *ss, float rgba[4], float out_offset[3])
void SCULPT_calc_vertex_displacement(SculptSession *ss, const struct Brush *brush, float rgba[4], float out_offset[3])
{
rgba[2] *= ss->cache->bstrength;
mul_v3_fl(rgba, ss->cache->bstrength);
rgba[0] *= 1.0f / (brush->mtex.size[0] == 0.0f ? 1.0f : brush->mtex.size[0] * brush->mtex.size[0]);
robin.hohni marked this conversation as resolved
Review

For readability would suggest to first square the size, and then do the inf check using math::safe_divide. Seems we currently don't have a safe divide in math for 2 vector types.

rgba[i] *= math::safe_divide(1.0f, POW2(brush->mtex.size[i])); perhaps?

For readability would suggest to first square the size, and then do the inf check using `math::safe_divide`. Seems we currently don't have a safe divide in math for 2 vector types. `rgba[i] *= math::safe_divide(1.0f, POW2(brush->mtex.size[i]));` perhaps?
Review

Thanks for the hint! Made a commit :)

Thanks for the hint! Made a commit :)
rgba[1] *= 1.0f / (brush->mtex.size[1] == 0.0f ? 1.0f : brush->mtex.size[1] * brush->mtex.size[1]);
rgba[2] *= 1.0f / (brush->mtex.size[2] == 0.0f ? 1.0f : brush->mtex.size[2] * brush->mtex.size[2]);
mul_mat3_m4_v3(ss->cache->brush_local_mat_inv, rgba);
if (ss->cache->radial_symmetry_pass) {

View File

@ -280,7 +280,7 @@ static void do_draw_brush_task_cb_ex(void *__restrict userdata,
thread_id,
&automask_data,
r_rgba);
SCULPT_calc_vertex_displacement(ss, r_rgba, proxy[vd.i]);
SCULPT_calc_vertex_displacement(ss, brush, r_rgba, proxy[vd.i]);
}
else {
float fade = SCULPT_brush_strength_factor(ss,

View File

@ -1273,7 +1273,7 @@ void SCULPT_brush_strength_color(struct SculptSession *ss,
/**
* Calculates the vertex offset for a single vertex depending on the brush setting rgb as vector displacement.
*/
void SCULPT_calc_vertex_displacement(SculptSession *ss, float rgba[3], float out_offset[3]);
void SCULPT_calc_vertex_displacement(SculptSession *ss, const struct Brush *brush, float rgba[3], float out_offset[3]);
/**
* Tilts a normal by the x and y tilt values using the view axis.