89 const GSpan color_attribute,
93 const T *colors_typed =
static_cast<const T *
>(color_attribute.
data());
96 for (
const int face : vert_to_face_map[vert]) {
98 r_color +=
to_float(colors_typed[corner]);
100 return r_color /
float(vert_to_face_map[vert].
size());
102 return to_float(colors_typed[vert]);
115 for (
const int i_face : vert_to_face_map[vert]) {
121 if (face_verts[i] == vert) {
128 from_float(color,
static_cast<T *
>(color_attribute.
data())[vert]);
135 const GSpan color_attribute,
141 using T = decltype(dummy);
142 color = color_vert_get<T>(
143 faces, corner_verts, vert_to_face_map, color_attribute, color_domain, vert);
157 using T = decltype(dummy);
159 faces, corner_verts, vert_to_face_map, color_attribute, color_domain, vert, color);
168 using T = decltype(dummy);
169 T *colors_typed = static_cast<T *>(color_attribute.data());
170 for (const int i : indices.index_range()) {
171 T temp = colors_typed[indices[i]];
172 from_float(r_colors[i], colors_typed[indices[i]]);
173 r_colors[i] = to_float(temp);
183 using T = decltype(dummy);
184 const T *colors_typed = static_cast<const T *>(color_attribute.data());
185 for (const int i : indices.index_range()) {
186 r_colors[i] = to_float(colors_typed[indices[i]]);
194 const GSpan color_attribute,
199 if (color_domain == bke::AttrDomain::Point) {
204 using T = decltype(dummy);
205 for (const int i : verts.index_range()) {
206 r_colors[i] = color_vert_get<T>(
207 faces, corner_verts, vert_to_face_map, color_attribute, color_domain, verts[i]);
216 const StringRef name = mesh.active_color_attribute;
221 const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(colors.varray.type());
234 const StringRef name = mesh.active_color_attribute;
239 const eCustomDataType data_type = bke::cpp_type_to_custom_data_type(colors.span.type());
302 for (
const int i :
verts.index_range()) {
306 color_attribute.
span,
318 smooth::neighbor_color_average(faces,
321 color_attribute.
span,
326 for (
const int i : colors.index_range()) {
330 for (
const int i :
verts.index_range()) {
337 color_attribute.
span);
353 const float4 wet_mix_sampled_color,
393 auto_mask.
fill(1.0f);
402 if (density < 1.0f) {
403 for (
const int i :
verts.index_range()) {
404 const float hash_noise =
float(
406 if (hash_noise > density) {
407 const float noise = density * hash_noise;
416 float4 brush_color(brush_color_rgb, 1.0f);
443 for (
const int i :
verts.index_range()) {
447 color_attribute.
span,
452 for (
const int i :
verts.index_range()) {
464 float automasking = auto_mask.
is_empty() ? 1.0f : auto_mask[i];
465 const float4 buffer_color =
float4(color_buffer[i]) * alpha * automasking;
468 new_colors[i] =
math::clamp(new_colors[i], 0.0f, 1.0f);
473 for (
const int i :
verts.index_range()) {
480 color_attribute.
span);
495 const GSpan color_attribute,
517 for (
const int i :
verts.index_range()) {
518 if (factors[i] > 0.0f) {
520 faces, corner_verts, vert_to_face_map, color_attribute, color_domain,
verts[i]);
570 const Span<int> corner_verts = mesh.corner_verts();
574 if (!color_attribute) {
611 ColorPaintLocalData &tls = all_tls.local();
612 node_mask.slice(range).foreach_index([&](const int i) {
613 do_sample_wet_paint_task(ob,
618 attribute_data.hide_vert,
619 color_attribute.span,
620 color_attribute.domain,
630 joined.
color = a.color +
b.color;
631 joined.tot_samples = a.tot_samples +
b.tot_samples;
635 if (swptd.tot_samples > 0 &&
is_finite_v4(swptd.color)) {
636 wet_color =
math::clamp(swptd.color /
float(swptd.tot_samples), 0.0f, 1.0f);
649 if (ss.cache->paint_brush.mix_colors.is_empty()) {
654 node_mask.foreach_index(
GrainSize(1), [&](
const int i) {
655 ColorPaintLocalData &tls = all_tls.
local();
656 do_paint_brush_task(scene,
671 ss.cache->paint_brush.mix_colors,
674 pbvh.tag_attribute_changed(node_mask, mesh.active_color_attribute);
675 color_attribute.finish();
729 for (
const int i :
verts.index_range()) {
730 if (factors[i] == 0.0f) {
733 const int vert =
verts[i];
734 const float3 &no = vert_normals[vert];
739 current_disp = brush_delta;
750 current_disp += no * -
math::dot(current_disp, no);
754 current_disp = current_disp_norm * strength;
769 faces, corner_verts, vert_to_face_map, attribute_data.
hide_poly, vert, neighbors))
771 const float3 &nco = vert_positions[neighbor];
779 if (neighbor_neighbor == vert) {
783 float3 vert_disp = vert_positions[neighbor_neighbor] - vert_positions[vert];
804 vert_disp += no * -
math::dot(no, vert_disp);
807 if (
math::dot(current_disp_norm, vert_disp_norm) >= 0.0f) {
812 float color_interp = -
math::dot(current_disp_norm, vert_disp_norm);
815 w *= color_interp * color_interp;
817 accum += neighbor_color *
w;
827 faces, corner_verts, vert_to_face_map, color_attribute.
span, color_attribute.
domain, vert);
835 color_attribute.
span);
855 const Span<int> corner_verts = mesh.corner_verts();
862 if (!color_attribute) {
869 for (const int vert : range) {
870 ss.cache->paint_brush.prev_colors[vert] = color_vert_get(faces,
873 color_attribute.span,
874 color_attribute.domain,
883 if (ss.cache->alt_smooth) {
885 node_mask.foreach_index(
GrainSize(1), [&](
const int i) {
886 ColorPaintLocalData &tls = all_tls.
local();
903 node_mask.foreach_index(
GrainSize(1), [&](
const int i) {
904 for (
const int vert : nodes[i].
verts()) {
905 ss.cache->paint_brush.prev_colors[vert] = color_vert_get(faces,
908 color_attribute.span,
909 color_attribute.domain,
913 threading::EnumerableThreadSpecific<ColorPaintLocalData> all_tls;
914 node_mask.foreach_index(GrainSize(1), [&](
const int i) {
915 ColorPaintLocalData &tls = all_tls.local();
930 pbvh.tag_attribute_changed(node_mask, mesh.active_color_attribute);
931 color_attribute.finish();
#define ATTR_DOMAIN_MASK_COLOR
#define ATTR_DOMAIN_AS_MASK(domain)
const float * BKE_brush_secondary_color_get(const Scene *scene, const Paint *paint, const Brush *brush)
float BKE_brush_alpha_get(const Scene *scene, const Brush *brush)
const float * BKE_brush_color_get(const Scene *scene, const Paint *paint, const Brush *brush)
bool BKE_colorband_evaluate(const ColorBand *coba, float in, float out[4])
#define CD_TYPE_AS_MASK(_type)
const Brush * BKE_paint_brush_for_read(const Paint *paint)
A BVH for high poly meshes.
BLI_INLINE float BLI_hash_int_01(unsigned int k)
void linearrgb_to_srgb_v3_v3(float srgb[3], const float linear[3])
void rgba_uchar_to_float(float r_col[4], const unsigned char col_ub[4])
void rgba_float_to_uchar(unsigned char r_col[4], const float col_f[4])
void srgb_to_linearrgb_v3_v3(float linear[3], const float srgb[3])
MINLINE void blend_color_mix_float(float dst[4], const float src1[4], const float src2[4])
MINLINE void blend_color_interpolate_float(float dst[4], const float src1[4], const float src2[4], float t)
bool is_zero_m4(const float mat[4][4])
MINLINE void copy_v4_v4(float r[4], const float a[4])
bool is_finite_v4(const float v[4]) ATTR_WARN_UNUSED_RESULT
@ BRUSH_SMEAR_DEFORM_PINCH
@ BRUSH_SMEAR_DEFORM_EXPAND
@ BRUSH_SMEAR_DEFORM_DRAG
@ BRUSH_GRADIENT_SPACING_CLAMP
@ BRUSH_GRADIENT_PRESSURE
@ BRUSH_GRADIENT_SPACING_REPEAT
#define CD_MASK_COLOR_ALL
BLI_INLINE void IMB_colormanagement_srgb_to_scene_linear_v3(float scene_linear[3], const float srgb[3])
void IMB_blend_color_float(float dst[4], const float src1[4], const float src2[4], IMB_BlendMode mode)
Read Guarded memory(de)allocation.
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
SIMD_FORCE_INLINE const btScalar & w() const
Return the w value.
const CPPType & type() const
const CPPType & type() const
const void * data() const
constexpr int64_t size() const
constexpr bool is_empty() const
constexpr void fill(const T &value) const
constexpr Span< T > as_span() const
constexpr Span slice(int64_t start, int64_t size) const
void resize(const int64_t new_size)
void tag_attribute_changed(const IndexMask &node_mask, StringRef attribute_name)
Span< NodeT > nodes() const
IndexRange index_range() const
void foreach_index(Fn &&fn) const
local_group_size(16, 16) .push_constant(Type b
const Depsgraph * depsgraph
draw_view in_light_buf[] float
ccl_device_inline float2 fmod(const float2 a, const float b)
int face_find_corner_from_vert(const IndexRange face, const Span< int > corner_verts, const int vert)
bke::GSpanAttributeWriter active_color_attribute_for_write(Mesh &mesh)
static void do_paint_brush_task(const Scene &scene, const Depsgraph &depsgraph, Object &object, const Span< float3 > vert_positions, const Span< float3 > vert_normals, const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const MeshAttributeData &attribute_data, const Paint &paint, const Brush &brush, const float4x4 &mat, const float4 wet_mix_sampled_color, bke::pbvh::MeshNode &node, ColorPaintLocalData &tls, const MutableSpan< float4 > mix_colors, bke::GSpanAttributeWriter &color_attribute)
void gather_colors_vert(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, GSpan color_attribute, bke::AttrDomain color_domain, Span< int > verts, MutableSpan< float4 > r_colors)
void do_smear_brush(const Depsgraph &depsgraph, const Sculpt &sd, Object &ob, const IndexMask &node_mask)
float4 color_vert_get(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, GSpan color_attribute, bke::AttrDomain color_domain, int vert)
static void do_sample_wet_paint_task(const Object &object, const Span< float3 > vert_positions, const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const Span< bool > hide_vert, const GSpan color_attribute, const bke::AttrDomain color_domain, const Brush &brush, const bke::pbvh::MeshNode &node, ColorPaintLocalData &tls, SampleWetPaintData &swptd)
void gather_colors(GSpan color_attribute, Span< int > indices, MutableSpan< float4 > r_colors)
void color_vert_set(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face_map, bke::AttrDomain color_domain, int vert, const float4 &color, GMutableSpan color_attribute)
void swap_gathered_colors(Span< int > indices, GMutableSpan color_attribute, MutableSpan< float4 > r_colors)
void do_paint_brush(const Scene &scene, const Depsgraph &depsgraph, PaintModeSettings &paint_mode_settings, const Sculpt &sd, Object &ob, const IndexMask &node_mask, const IndexMask &texnode_mask)
void from_float(const float4 &src, T &dst)
static void do_smear_brush_task(const Depsgraph &depsgraph, Object &object, const Span< float3 > vert_positions, const Span< float3 > vert_normals, const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const MeshAttributeData &attribute_data, const Brush &brush, bke::pbvh::MeshNode &node, ColorPaintLocalData &tls, bke::GSpanAttributeWriter &color_attribute)
bke::GAttributeReader active_color_attribute(const Mesh &mesh)
void to_static_color_type(const CPPType &type, const Func &func)
static void do_color_smooth_task(const Depsgraph &depsgraph, const Object &object, const Span< float3 > vert_positions, const Span< float3 > vert_normals, const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face_map, const MeshAttributeData &attribute_data, const Brush &brush, const bke::pbvh::MeshNode &node, ColorPaintLocalData &tls, bke::GSpanAttributeWriter &color_attribute)
float4 to_float(const T &src)
void fill_factor_from_hide_and_mask(Span< bool > hide_vert, Span< float > mask, Span< int > verts, MutableSpan< float > r_factors)
void calc_brush_strength_factors(const StrokeCache &cache, const Brush &brush, Span< float > distances, MutableSpan< float > factors)
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 calc_brush_distances(const SculptSession &ss, Span< float3 > vert_positions, Span< int > vert_indices, eBrushFalloffShape falloff_shape, MutableSpan< float > r_distances)
void scale_factors(MutableSpan< float > factors, float strength)
void scatter_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
Span< float4 > orig_color_data_get_mesh(const Object &object, const bke::pbvh::MeshNode &node)
void gather_data_mesh(Span< T > src, Span< int > indices, MutableSpan< T > dst)
void calc_vert_neighbors(OffsetIndices< int > faces, Span< int > corner_verts, GroupedSpan< int > vert_to_face, Span< bool > hide_poly, Span< int > verts, MutableSpan< Vector< int > > result)
void calc_brush_cube_distances(const Brush &brush, const float4x4 &mat, Span< float3 > positions, Span< int > verts, MutableSpan< float > r_distances, MutableSpan< float > factors)
void calc_front_face(const float3 &view_normal, Span< float3 > normals, MutableSpan< float > factors)
Span< int > vert_neighbors_get_mesh(const OffsetIndices< int > faces, const Span< int > corner_verts, const GroupedSpan< int > vert_to_face, const Span< bool > hide_poly, const int vert, Vector< int > &r_neighbors)
void calc_brush_texture_factors(const SculptSession &ss, const Brush &brush, Span< float3 > vert_positions, Span< int > vert_indices, MutableSpan< float > factors)
void fill_factor_from_hide(Span< bool > hide_vert, Span< int > verts, MutableSpan< float > r_factors)
T clamp(const T &a, const T &min, const T &max)
T distance(const T &a, const T &b)
T length(const VecBase< T, Size > &a)
T dot(const QuaternionBase< T > &a, const QuaternionBase< T > &b)
MatBase< T, NumCol, NumRow > normalize(const MatBase< T, NumCol, NumRow > &a)
static void to_static_color_type(const eCustomDataType type, const Func &func)
bool SCULPT_stroke_is_first_brush_step_of_symmetry_pass(const blender::ed::sculpt_paint::StrokeCache &cache)
void SCULPT_cube_tip_init(const Sculpt &, const Object &ob, const Brush &brush, float mat[4][4])
bool SCULPT_stroke_is_first_brush_step(const blender::ed::sculpt_paint::StrokeCache &cache)
void SCULPT_do_paint_brush_image(const Scene &scene, const Depsgraph &depsgraph, PaintModeSettings &paint_mode_settings, const Sculpt &sd, Object &ob, const blender::IndexMask &node_mask)
bool SCULPT_use_image_paint_brush(PaintModeSettings &settings, Object &ob)
struct ColorBand * gradient
float wet_paint_radius_factor
struct CurveMapping * curve
char gradient_stroke_mode
struct SculptSession * sculpt
blender::ed::sculpt_paint::StrokeCache * cache
const c_style_mat & ptr() const
VArraySpan< bool > hide_poly
VArraySpan< bool > hide_vert
struct blender::ed::sculpt_paint::StrokeCache::@480 paint_brush
Array< float4 > prev_colors
float4 wet_mix_prev_color
std::unique_ptr< auto_mask::Cache > automasking
float3 last_location_symm
Vector< float > distances
Vector< Vector< int > > vert_neighbors
Vector< float > auto_mask
Vector< float4 > new_colors
Vector< float4 > mix_colors