Sculpt: Simplify vector displacement brush calculation
Remove the need for a temporary array of colors. Just put the data directly into the translations vector. This should provide a small performance improvement.
This commit is contained in:
@@ -32,7 +32,6 @@ struct LocalData {
|
||||
Vector<float3> positions;
|
||||
Vector<float> factors;
|
||||
Vector<float> distances;
|
||||
Vector<float4> colors;
|
||||
Vector<float3> translations;
|
||||
};
|
||||
|
||||
@@ -40,8 +39,7 @@ static void calc_brush_texture_colors(SculptSession &ss,
|
||||
const Brush &brush,
|
||||
const Span<float3> vert_positions,
|
||||
const Span<int> verts,
|
||||
const Span<float> factors,
|
||||
const MutableSpan<float4> r_colors)
|
||||
const MutableSpan<float3> r_colors)
|
||||
{
|
||||
BLI_assert(verts.size() == r_colors.size());
|
||||
|
||||
@@ -54,15 +52,14 @@ static void calc_brush_texture_colors(SculptSession &ss,
|
||||
sculpt_apply_texture(
|
||||
ss, brush, vert_positions[verts[i]], thread_id, &texture_value, texture_rgba);
|
||||
|
||||
r_colors[i] = texture_rgba * factors[i];
|
||||
r_colors[i] = float3(texture_rgba);
|
||||
}
|
||||
}
|
||||
|
||||
static void calc_brush_texture_colors(SculptSession &ss,
|
||||
const Brush &brush,
|
||||
const Span<float3> positions,
|
||||
const Span<float> factors,
|
||||
const MutableSpan<float4> r_colors)
|
||||
const MutableSpan<float3> r_colors)
|
||||
{
|
||||
BLI_assert(positions.size() == r_colors.size());
|
||||
|
||||
@@ -73,8 +70,7 @@ static void calc_brush_texture_colors(SculptSession &ss,
|
||||
float4 texture_rgba;
|
||||
/* NOTE: This is not a thread-safe call. */
|
||||
sculpt_apply_texture(ss, brush, positions[i], thread_id, &texture_value, texture_rgba);
|
||||
|
||||
r_colors[i] = texture_rgba * factors[i];
|
||||
r_colors[i] = float3(texture_rgba);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,14 +107,12 @@ static void calc_faces(const Depsgraph &depsgraph,
|
||||
|
||||
auto_mask::calc_vert_factors(depsgraph, object, cache.automasking.get(), node, verts, factors);
|
||||
|
||||
tls.colors.resize(verts.size());
|
||||
const MutableSpan<float4> colors = tls.colors;
|
||||
calc_brush_texture_colors(ss, brush, position_data.eval, verts, factors, colors);
|
||||
|
||||
tls.translations.resize(verts.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_brush_texture_colors(ss, brush, position_data.eval, verts, translations);
|
||||
scale_translations(translations, factors);
|
||||
for (const int i : verts.index_range()) {
|
||||
SCULPT_calc_vertex_displacement(ss, brush, colors[i], translations[i]);
|
||||
SCULPT_calc_vertex_displacement(ss, brush, translations[i]);
|
||||
}
|
||||
|
||||
clip_and_lock_translations(sd, ss, position_data.eval, verts, translations);
|
||||
@@ -156,14 +150,12 @@ static void calc_grids(const Depsgraph &depsgraph,
|
||||
|
||||
auto_mask::calc_grids_factors(depsgraph, object, cache.automasking.get(), node, grids, factors);
|
||||
|
||||
tls.colors.resize(positions.size());
|
||||
const MutableSpan<float4> colors = tls.colors;
|
||||
calc_brush_texture_colors(ss, brush, positions, factors, colors);
|
||||
|
||||
tls.translations.resize(positions.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_brush_texture_colors(ss, brush, positions, translations);
|
||||
scale_translations(translations, factors);
|
||||
for (const int i : positions.index_range()) {
|
||||
SCULPT_calc_vertex_displacement(ss, brush, colors[i], translations[i]);
|
||||
SCULPT_calc_vertex_displacement(ss, brush, translations[i]);
|
||||
}
|
||||
|
||||
clip_and_lock_translations(sd, ss, positions, translations);
|
||||
@@ -200,14 +192,12 @@ static void calc_bmesh(const Depsgraph &depsgraph,
|
||||
|
||||
auto_mask::calc_vert_factors(depsgraph, object, cache.automasking.get(), node, verts, factors);
|
||||
|
||||
tls.colors.resize(verts.size());
|
||||
const MutableSpan<float4> colors = tls.colors;
|
||||
calc_brush_texture_colors(ss, brush, positions, factors, colors);
|
||||
|
||||
tls.translations.resize(verts.size());
|
||||
tls.translations.resize(positions.size());
|
||||
const MutableSpan<float3> translations = tls.translations;
|
||||
calc_brush_texture_colors(ss, brush, positions, translations);
|
||||
scale_translations(translations, factors);
|
||||
for (const int i : positions.index_range()) {
|
||||
SCULPT_calc_vertex_displacement(ss, brush, colors[i], translations[i]);
|
||||
SCULPT_calc_vertex_displacement(ss, brush, translations[i]);
|
||||
}
|
||||
|
||||
clip_and_lock_translations(sd, ss, positions, translations);
|
||||
|
||||
@@ -2321,30 +2321,30 @@ void sculpt_apply_texture(const SculptSession &ss,
|
||||
|
||||
void SCULPT_calc_vertex_displacement(const SculptSession &ss,
|
||||
const Brush &brush,
|
||||
float rgba[3],
|
||||
float r_offset[3])
|
||||
float translation[3])
|
||||
{
|
||||
mul_v3_fl(rgba, ss.cache->bstrength);
|
||||
mul_v3_fl(translation, ss.cache->bstrength);
|
||||
/* Handle brush inversion */
|
||||
if (ss.cache->bstrength < 0) {
|
||||
rgba[0] *= -1;
|
||||
rgba[1] *= -1;
|
||||
translation[0] *= -1;
|
||||
translation[1] *= -1;
|
||||
}
|
||||
|
||||
/* Apply texture size */
|
||||
for (int i = 0; i < 3; ++i) {
|
||||
rgba[i] *= blender::math::safe_divide(1.0f, pow2f(brush.mtex.size[i]));
|
||||
translation[i] *= blender::math::safe_divide(1.0f, pow2f(brush.mtex.size[i]));
|
||||
}
|
||||
|
||||
/* Transform vector to object space */
|
||||
mul_mat3_m4_v3(ss.cache->brush_local_mat_inv.ptr(), rgba);
|
||||
mul_mat3_m4_v3(ss.cache->brush_local_mat_inv.ptr(), translation);
|
||||
|
||||
/* Handle symmetry */
|
||||
if (ss.cache->radial_symmetry_pass) {
|
||||
mul_m4_v3(ss.cache->symm_rot_mat.ptr(), rgba);
|
||||
mul_m4_v3(ss.cache->symm_rot_mat.ptr(), translation);
|
||||
}
|
||||
copy_v3_v3(r_offset,
|
||||
blender::ed::sculpt_paint::symmetry_flip(rgba, ss.cache->mirror_symmetry_pass));
|
||||
copy_v3_v3(
|
||||
translation,
|
||||
blender::ed::sculpt_paint::symmetry_flip(translation, ss.cache->mirror_symmetry_pass));
|
||||
}
|
||||
|
||||
namespace blender::ed::sculpt_paint {
|
||||
|
||||
@@ -683,8 +683,7 @@ void sculpt_apply_texture(const SculptSession &ss,
|
||||
*/
|
||||
void SCULPT_calc_vertex_displacement(const SculptSession &ss,
|
||||
const Brush &brush,
|
||||
float rgba[3],
|
||||
float r_offset[3]);
|
||||
float translation[3]);
|
||||
|
||||
/**
|
||||
* Tilts a normal by the x and y tilt values using the view axis.
|
||||
|
||||
Reference in New Issue
Block a user