[Bf-blender-cvs] [479b0362ccf] temp-3d-texturing-brush-b: Combine innerloop data.
Jeroen Bakker
noreply at git.blender.org
Mon Mar 21 10:43:49 CET 2022
Commit: 479b0362ccfca6413ff795591c6199a18aee0b6f
Author: Jeroen Bakker
Date: Mon Mar 21 10:43:44 2022 +0100
Branches: temp-3d-texturing-brush-b
https://developer.blender.org/rB479b0362ccfca6413ff795591c6199a18aee0b6f
Combine innerloop data.
===================================================================
M source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc
M source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh
M source/blender/editors/sculpt_paint/sculpt_texture_paint_pixel_extraction_d.cc
===================================================================
diff --git a/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc b/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc
index 4ed33d3e4e3..804b04f6082 100644
--- a/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_texture_paint_d.cc
@@ -148,8 +148,9 @@ template<typename ImagePixelAccessor> class PaintingKernel {
init_brush_color(image_buffer);
}
image_accessor.set_image_position(image_buffer, encoded_pixels.start_image_coordinate);
- Pixel pixel = get_start_pixel(triangles, encoded_pixels);
- const Pixel add_pixel = get_delta_pixel(triangles, encoded_pixels, pixel);
+ const TrianglePaintInput triangle = triangles.get_paint_input(encoded_pixels.triangle_index);
+ Pixel pixel = get_start_pixel(triangle, encoded_pixels);
+ const Pixel add_pixel = get_delta_pixel(triangle, encoded_pixels, pixel);
bool pixels_painted = false;
for (int x = 0; x < encoded_pixels.num_pixels; x++) {
if (!brush_test_fn(&test, pixel.pos)) {
@@ -170,7 +171,7 @@ template<typename ImagePixelAccessor> class PaintingKernel {
normal,
face_normal,
mask,
- triangles.get_automasking_factor(encoded_pixels.triangle_index),
+ triangle.automasking_factor,
thread_id);
blend_color_interpolate_float(color, color, brush_color, falloff_strength * brush_strength);
@@ -213,31 +214,27 @@ template<typename ImagePixelAccessor> class PaintingKernel {
}
/** Extract the staring pixel from the given encoded_pixels belonging to the triangle. */
- Pixel get_start_pixel(const Triangles &triangles, const PixelsPackage &encoded_pixels) const
+ Pixel get_start_pixel(const TrianglePaintInput &triangle,
+ const PixelsPackage &encoded_pixels) const
{
- return init_pixel(
- triangles, encoded_pixels.triangle_index, encoded_pixels.start_barycentric_coord.decode());
+ return init_pixel(triangle, encoded_pixels.start_barycentric_coord.decode());
}
/**
* Extract the delta pixel that will be used to advance a Pixel instance to the next pixel. */
- Pixel get_delta_pixel(const Triangles &triangles,
+ Pixel get_delta_pixel(const TrianglePaintInput &triangle,
const PixelsPackage &encoded_pixels,
const Pixel &start_pixel) const
{
- Pixel result = init_pixel(
- triangles,
- encoded_pixels.triangle_index,
- encoded_pixels.start_barycentric_coord.decode() +
- triangles.get_add_barycentric_coord_x(encoded_pixels.triangle_index));
+ Pixel result = init_pixel(triangle,
+ encoded_pixels.start_barycentric_coord.decode() +
+ triangle.add_barycentric_coord_x);
return result - start_pixel;
}
- Pixel init_pixel(const Triangles &triangles,
- const int triangle_index,
- const float3 weights) const
+ Pixel init_pixel(const TrianglePaintInput &triangle, const float3 weights) const
{
- int3 vert_indices = triangles.get_vert_indices(triangle_index);
+ const int3 &vert_indices = triangle.vert_indices;
Pixel result;
interp_v3_v3v3v3(result.pos,
mvert[vert_indices[0]].co,
@@ -291,7 +288,8 @@ static void do_task_cb_ex(void *__restrict userdata,
Triangles &triangles = node_data->triangles;
for (int triangle_index = 0; triangle_index < triangles.size(); triangle_index++) {
- int3 vert_indices = triangles.get_vert_indices(triangle_index);
+ TrianglePaintInput &triangle = triangles.get_paint_input(triangle_index);
+ int3 &vert_indices = triangle.vert_indices;
for (int i = 0; i < 3; i++) {
triangle_brush_test_results[triangle_index] = triangle_brush_test_results[triangle_index] ||
data->vertex_brush_tests[vert_indices[i]];
diff --git a/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh b/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh
index ea0c8b59992..32b9db20131 100644
--- a/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh
+++ b/source/blender/editors/sculpt_paint/sculpt_texture_paint_intern.hh
@@ -5,7 +5,6 @@ namespace blender::ed::sculpt_paint::texture_paint {
struct Polygon {
};
-#if 0
/* Stores a barycentric coordinate in a float2. */
struct EncodedBarycentricCoord {
float2 encoded;
@@ -21,35 +20,6 @@ struct EncodedBarycentricCoord {
return float3(encoded.x, encoded.y, 1.0 - encoded.x - encoded.y);
}
};
-#else
-/* Alternative approach. Half the memory footprint. */
-struct EncodedBarycentricCoord {
- ushort2 encoded;
-
- EncodedBarycentricCoord &operator=(const float3 decoded)
- {
- encoded = ushort2(encode(decoded.x), encode(decoded.y));
- return *this;
- }
-
- float3 decode() const
- {
- float2 decoded(decode(encoded.x), decode(encoded.y));
- return float3(decoded.x, decoded.y, 1.0f - decoded.x - decoded.y);
- }
-
- static uint16_t encode(float value)
- {
- float clamped = clamp_f(value, 0.0f, 1.0f);
- return (uint16_t)clamped * 65535.0;
- }
-
- static float decode(uint16_t value)
- {
- return value / 65535.0f;
- }
-};
-#endif
/**
* Loop incides. Only stores 2 indices, the third one is always `loop_indices[1] + 1`.
@@ -76,27 +46,32 @@ struct Triangle {
float automasking_factor;
};
+struct TrianglePaintInput {
+ int3 vert_indices;
+ float3 add_barycentric_coord_x;
+ float automasking_factor;
+
+ TrianglePaintInput(const Triangle &triangle)
+ : vert_indices(triangle.vert_indices),
+ add_barycentric_coord_x(triangle.add_barycentric_coord_x),
+ automasking_factor(triangle.automasking_factor)
+ {
+ }
+};
+
struct Triangles {
+ Vector<TrianglePaintInput> paint_input;
Vector<EncodedLoopIndices> loop_indices;
- Vector<int3> vert_indices;
Vector<int> poly_indices;
- Vector<float3> add_barycentric_coords_x;
- Vector<float> automasking_factors;
public:
- void append(Triangle &triangle)
+ void append(const Triangle &triangle)
{
+ paint_input.append(TrianglePaintInput(triangle));
loop_indices.append(triangle.loop_indices);
- vert_indices.append(triangle.vert_indices);
poly_indices.append(triangle.poly_index);
- add_barycentric_coords_x.append(float3(0.0f));
- automasking_factors.append(0.0);
}
- int3 get_vert_indices(const int index) const
- {
- return vert_indices[index];
- }
int3 get_loop_indices(const int index) const
{
return loop_indices[index].decode();
@@ -106,22 +81,19 @@ struct Triangles {
return poly_indices[index];
}
- void set_add_barycentric_coord_x(const int index, const float3 add_barycentric_coord_x)
+ TrianglePaintInput &get_paint_input(const int index)
{
- add_barycentric_coords_x[index] = add_barycentric_coord_x;
+ return paint_input[index];
}
- float3 get_add_barycentric_coord_x(const int index) const
+
+ const TrianglePaintInput &get_paint_input(const int index) const
{
- return add_barycentric_coords_x[index];
+ return paint_input[index];
}
void set_automasking_factor(const int index, const float automasking_factor)
{
- automasking_factors[index] = automasking_factor;
- }
- float get_automasking_factor(const int index) const
- {
- return automasking_factors[index];
+ get_paint_input(index).automasking_factor = automasking_factor;
}
void cleanup_after_init()
@@ -129,15 +101,15 @@ struct Triangles {
loop_indices.clear();
}
- uint64_t size()
+ uint64_t size() const
{
- return vert_indices.size();
+ return paint_input.size();
}
- uint64_t mem_size()
+
+ uint64_t mem_size() const
{
- return loop_indices.size() * sizeof(EncodedLoopIndices) + vert_indices.size() * sizeof(int3) +
- poly_indices.size() * sizeof(int) + add_barycentric_coords_x.size() * sizeof(float3) +
- automasking_factors.size() * sizeof(float);
+ return loop_indices.size() * sizeof(EncodedLoopIndices) +
+ paint_input.size() * sizeof(TrianglePaintInput) + poly_indices.size() * sizeof(int);
}
};
diff --git a/source/blender/editors/sculpt_paint/sculpt_texture_paint_pixel_extraction_d.cc b/source/blender/editors/sculpt_paint/sculpt_texture_paint_pixel_extraction_d.cc
index 4224f5af5d2..239a745173e 100644
--- a/source/blender/editors/sculpt_paint/sculpt_texture_paint_pixel_extraction_d.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_texture_paint_pixel_extraction_d.cc
@@ -64,7 +64,7 @@ static bool has_been_visited(std::vector<bool> &visited_polygons, const int poly
static void extract_barycentric_pixels(TileData &tile_data,
const ImBuf *image_buffer,
- Triangles &triangles,
+ TrianglePaintInput &triangle,
const int triangle_index,
const float2 uvs[3],
const int minx,
@@ -100,9 +100,8 @@ static void extract_barycentric_pixels(TileData &tile_data,
}
package.num_pixels = x - package.start_image_coordinate.x;
if (package.num_pixels > best_num_pixels) {
- triangles.set_add_barycentric_coord_x(
- triangle_index,
- (barycentric - package.start_barycentric_coord.decode()) / package.num_pixels);
+ triangle.add_barycentric_coord_x = (barycentric - package.start_barycentric_coord.decode()) /
+ package.num_pixels;
best_num_pixels = package.num_pixels;
}
tile_data.encoded_pixels.append(package);
@@ -184,8 +183,9 @@ static void do_encode_pixels(void *__restrict userdata,
const float maxu = clamp_f(max_fff(uvs[0].x, uvs[1].x, uvs[2].x), 0.0f, 1.0f);
const int maxx = min_ii(ceil(maxu * image_buffer->x), image_buffer->x);
+ TrianglePaintInput &triangle = triangles.get_paint_input(triangle_index);
extract_barycentric_pixels(
- tile_data, image_buffer, triangles, triangle_index, uvs, minx, miny, maxx, maxy)
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list