33inline namespace layer_cc {
48 for (
const int i : displacement_factors.
index_range()) {
49 displacement_factors[i] += factors[i] * strength * (1.05f - std::abs(displacement_factors[i]));
65 for (
const int i : displacement_factors.
index_range()) {
66 displacement_factors[i] += std::abs(factors[i] * strength * displacement_factors[i]) *
67 (displacement_factors[i] > 0.0f ? -1.0f : 1.0f);
74 if (masks.is_empty()) {
75 for (
const int i : displacement_factors.
index_range()) {
76 displacement_factors[i] = std::clamp(displacement_factors[i], -1.0f, 1.0f);
80 for (
const int i : displacement_factors.
index_range()) {
95 for (
const int i : positions.index_range()) {
96 const float3 offset = orig_normals[i] * height * displacement_factors[i];
97 const float3 translation = orig_positions[i] + offset - positions[i];
98 r_translations[i] = translation * factors[i];
111 for (
const int i : positions.index_range()) {
112 const float3 offset = base_normals[
verts[i]] * height * displacement_factors[i];
113 const float3 translation = base_positions[
verts[i]] + offset - positions[i];
114 r_translations[i] = translation * factors[i];
123 const bool use_persistent_base,
163 tls.masks.resize(
verts.size());
168 tls.displacement_factors.resize(
verts.size());
172 if (use_persistent_base) {
186 persistent_base_normals,
189 displacement_factors,
208 displacement_factors,
256 subdiv_ccg, layer_displacement_factor.
as_span(), grids, tls.displacement_factors);
260 tls.masks.resize(positions.size());
275 displacement_factors,
323 layer_displacement_factor.
as_span(),
verts, tls.displacement_factors);
327 tls.masks.resize(
verts.size());
339 displacement_factors,
360 switch (pbvh.
type()) {
362 Mesh &mesh = *
static_cast<Mesh *
>(
object.data);
368 const VArraySpan persistent_position = *attributes.lookup<
float3>(
".sculpt_persistent_co",
370 const VArraySpan persistent_normal = *attributes.lookup<
float3>(
".sculpt_persistent_no",
374 bool use_persistent_base =
false;
377 if (!persistent_position.
is_empty() && !persistent_normal.is_empty()) {
378 persistent_disp_attr = attributes.lookup_or_add_for_write_span<
float>(
380 if (persistent_disp_attr) {
381 use_persistent_base =
true;
382 displacement = persistent_disp_attr.span;
413 persistent_disp_attr.finish();
417 SubdivCCG &subdiv_ccg = *
object.sculpt->subdiv_ccg;
const Brush * BKE_paint_brush_for_read(const Paint *paint)
const blender::Set< BMVert *, 0 > & BKE_pbvh_bmesh_node_unique_verts(blender::bke::pbvh::BMeshNode *node)
CCGKey BKE_subdiv_ccg_key_top_level(const SubdivCCG &subdiv_ccg)
Object is a sort of wrapper for general info.
constexpr bool is_empty() const
constexpr Span< T > as_span() const
constexpr IndexRange index_range() const
constexpr bool is_empty() const
void resize(const int64_t new_size)
void tag_positions_changed(const IndexMask &node_mask)
Span< NodeT > nodes() const
void foreach_index(Fn &&fn) const
const Depsgraph * depsgraph
pbvh::Tree * pbvh_get(Object &object)
void update_node_bounds_bmesh(BMeshNode &node)
void update_node_bounds_mesh(Span< float3 > positions, MeshNode &node)
Span< float3 > vert_normals_eval(const Depsgraph &depsgraph, const Object &object_orig)
void update_node_bounds_grids(int grid_area, Span< float3 > positions, GridsNode &node)
void flush_bounds_to_parents(Tree &pbvh)
void calc_grids_factors(const Depsgraph &depsgraph, const Object &object, const Cache &cache, const bke::pbvh::GridsNode &node, Span< int > grids, MutableSpan< float > factors)
void calc_vert_factors(const Depsgraph &depsgraph, const Object &object, const Cache &cache, const bke::pbvh::MeshNode &node, Span< int > verts, MutableSpan< float > factors)
static void calc_bmesh(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const Brush &brush, const float3 &direction, const float strength, bke::pbvh::BMeshNode &node, LocalData &tls)
static void calc_faces(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, const float4 &test_plane, const float strength, const MeshAttributeData &attribute_data, const Span< float3 > vert_normals, const bke::pbvh::MeshNode &node, Object &object, LocalData &tls, const PositionDeformData &position_data)
static void calc_grids(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const Brush &brush, const float4 &test_plane, const float strength, bke::pbvh::GridsNode &node, LocalData &tls)
static BLI_NOINLINE void fill_factor_from_hide_and_mask(const Mesh &mesh, const Span< int > face_indices, const MutableSpan< float > r_factors)
static BLI_NOINLINE void offset_displacement_factors(const MutableSpan< float > displacement_factors, const Span< float > factors, const float strength)
static BLI_NOINLINE void clamp_displacement_factors(const MutableSpan< float > displacement_factors, const Span< float > masks)
static void calc_faces(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, const MeshAttributeData &attribute_data, const Span< float3 > vert_normals, const bool use_persistent_base, const Span< float3 > persistent_base_positions, const Span< float3 > persistent_base_normals, Object &object, bke::pbvh::MeshNode &node, LocalData &tls, MutableSpan< float > layer_displacement_factor, const PositionDeformData &position_data)
static void calc_bmesh(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, Object &object, bke::pbvh::BMeshNode &node, LocalData &tls, MutableSpan< float > layer_displacement_factor)
static BLI_NOINLINE void reset_displacement_factors(const MutableSpan< float > displacement_factors, const Span< float > factors, const float strength)
static BLI_NOINLINE void calc_translations(const Span< float3 > orig_positions, const Span< float3 > orig_normals, const Span< float3 > positions, const Span< float > displacement_factors, const Span< float > factors, const float height, const MutableSpan< float3 > r_translations)
static void calc_grids(const Depsgraph &depsgraph, const Sculpt &sd, const Brush &brush, Object &object, bke::pbvh::GridsNode &node, LocalData &tls, MutableSpan< float > layer_displacement_factor)
static BLI_NOINLINE void clamp_mask(const MutableSpan< float > masks)
void gather_mask_bmesh(const BMesh &bm, const Set< BMVert *, 0 > &verts, const MutableSpan< float > r_mask)
void gather_mask_grids(const SubdivCCG &subdiv_ccg, const Span< int > grids, const MutableSpan< float > r_mask)
MutableSpan< float3 > gather_grids_positions(const SubdivCCG &subdiv_ccg, const Span< int > grids, Vector< float3 > &positions)
void scatter_data_bmesh(Span< T > node_data, const Set< BMVert *, 0 > &verts, MutableSpan< T > dst)
void gather_bmesh_positions(const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions)
void calc_brush_strength_factors(const StrokeCache &cache, const Brush &brush, Span< float > distances, MutableSpan< float > factors)
void gather_data_grids(const SubdivCCG &subdiv_ccg, Span< T > src, Span< int > grids, MutableSpan< T > node_data)
void apply_hardness_to_distances(float radius, float hardness, MutableSpan< float > distances)
void filter_distances_with_radius(float radius, Span< float > distances, MutableSpan< float > factors)
void filter_region_clip_factors(const SculptSession &ss, Span< float3 > vert_positions, Span< int > verts, MutableSpan< float > factors)
void gather_data_bmesh(Span< T > src, const Set< BMVert *, 0 > &verts, MutableSpan< T > node_data)
void calc_brush_distances(const SculptSession &ss, Span< float3 > vert_positions, Span< int > vert_indices, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
void orig_position_data_gather_bmesh(const BMLog &bm_log, const Set< BMVert *, 0 > &verts, MutableSpan< float3 > positions, MutableSpan< float3 > normals)
void clip_and_lock_translations(const Sculpt &sd, const SculptSession &ss, Span< float3 > positions, Span< int > verts, MutableSpan< float3 > translations)
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void apply_translations(Span< float3 > translations, Span< int > verts, MutableSpan< float3 > positions)
OrigPositionData orig_position_data_get_mesh(const Object &object, const bke::pbvh::MeshNode &node)
void do_layer_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &object, const IndexMask &node_mask)
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
OrigPositionData orig_position_data_get_grids(const Object &object, const bke::pbvh::GridsNode &node)
void calc_front_face(const float3 &view_normal, Span< float3 > normals, MutableSpan< float > factors)
void calc_brush_texture_factors(const SculptSession &ss, const Brush &brush, Span< float3 > vert_positions, Span< int > vert_indices, MutableSpan< float > factors)
void scatter_data_grids(const SubdivCCG &subdiv_ccg, Span< T > node_data, Span< int > grids, MutableSpan< T > dst)
int SCULPT_vertex_count_get(const Object &object)
blender::ed::sculpt_paint::StrokeCache * cache
blender::Array< blender::float3 > positions
Vector< float > distances
Vector< float3 > translations
Vector< float3 > positions
VArraySpan< bool > hide_vert
Array< float > layer_displacement_factor
std::unique_ptr< auto_mask::Cache > automasking
Vector< float3 > translations
Vector< float > distances
Vector< float > displacement_factors
Vector< float3 > positions