[Bf-blender-cvs] [140d32d3620] temp-texture-painting-gpu: Add support for projected falloff.
Jeroen Bakker
noreply at git.blender.org
Tue Oct 4 11:17:33 CEST 2022
Commit: 140d32d36206572dea9708b2df6f3b535c12b2f9
Author: Jeroen Bakker
Date: Tue Oct 4 11:17:20 2022 +0200
Branches: temp-texture-painting-gpu
https://developer.blender.org/rB140d32d36206572dea9708b2df6f3b535c12b2f9
Add support for projected falloff.
===================================================================
M source/blender/editors/sculpt_paint/sculpt_intern.h
M source/blender/editors/sculpt_paint/sculpt_paint_image.cc
M source/blender/editors/sculpt_paint/sculpt_shaders.cc
M source/blender/gpu/GPU_sculpt_shader_shared.h
M source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
M source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
M source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl
===================================================================
diff --git a/source/blender/editors/sculpt_paint/sculpt_intern.h b/source/blender/editors/sculpt_paint/sculpt_intern.h
index bc22e496013..6a9e2a58089 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1879,8 +1879,15 @@ void SCULPT_bmesh_topology_rake(
/* sculpt_shaders.cc */
-struct GPUShader *SCULPT_shader_paint_image_get(void);
+typedef enum BrushVariationFlags {
+ BRUSH_TEST_SPHERE = (0 << 0),
+ BRUSH_TEST_CIRCLE = (1 << 1),
+ BRUSH_TEST_CLIPPING = (1 << 2),
+ BRUSH_MAX_VARIATIONS = (1 << 3),
+} BrushVariationFlags;
+struct GPUShader *SCULPT_shader_paint_image_get(BrushVariationFlags variation_flags);
struct GPUShader *SCULPT_shader_paint_image_merge_get(void);
+
void SCULPT_shader_free(void);
/* end sculpt_shadders.cc */
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
index 3bb2db62932..29cd5d1e5cd 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
@@ -653,7 +653,7 @@ static void gpu_painting_paint_step(TexturePaintingUserData &data,
ImBuf *image_buffer,
int2 paint_step_range)
{
- GPUShader *shader = SCULPT_shader_paint_image_get();
+ GPUShader *shader = SCULPT_shader_paint_image_get(BRUSH_TEST_SPHERE);
batches.ensure_tile_texture(int2(image_buffer->x, image_buffer->y));
bool texture_needs_clearing = true;
@@ -714,11 +714,21 @@ static void gpu_painting_image_merge(TexturePaintingUserData &UNUSED(data),
GPU_compute_dispatch(shader, image_buffer.x, image_buffer.y, 1);
}
-static void init_paint_step(const SculptSession &ss, PaintStepData &r_paint_step)
+static void init_paint_step(const SculptSession &ss,
+ const Brush &brush,
+ PaintStepData &r_paint_step)
{
r_paint_step.location = ss.cache->location;
r_paint_step.radius = ss.cache->radius;
r_paint_step.mirror_symmetry_pass = ss.cache->mirror_symmetry_pass;
+
+ if (brush.falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
+ plane_from_point_normal_v3(
+ r_paint_step.plane_view, r_paint_step.location, ss.cache->view_normal);
+ }
+ else {
+ r_paint_step.plane_view = float4(0.0f);
+ }
}
static void dispatch_gpu_painting(TexturePaintingUserData &data)
@@ -728,7 +738,7 @@ static void dispatch_gpu_painting(TexturePaintingUserData &data)
GPUSculptPaintData &batches = *static_cast<GPUSculptPaintData *>(ss.mode.texture_paint.gpu_data);
PaintStepData paint_step;
- init_paint_step(ss, paint_step);
+ init_paint_step(ss, *data.brush, paint_step);
batches.steps.append(paint_step);
}
diff --git a/source/blender/editors/sculpt_paint/sculpt_shaders.cc b/source/blender/editors/sculpt_paint/sculpt_shaders.cc
index f998fab30c3..1d2cd564de7 100644
--- a/source/blender/editors/sculpt_paint/sculpt_shaders.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_shaders.cc
@@ -9,18 +9,29 @@
#include "sculpt_intern.h"
+#include <sstream>
+
static struct SCULPT_Shaders {
- GPUShader *paint_image_comp_sh;
+ GPUShader *paint_image_comp_sh[BRUSH_MAX_VARIATIONS];
GPUShader *paint_image_merge_comp_sh;
} sh_data;
extern "C" {
-GPUShader *SCULPT_shader_paint_image_get(void)
+GPUShader *SCULPT_shader_paint_image_get(BrushVariationFlags variation_flags)
{
- if (sh_data.paint_image_comp_sh == nullptr) {
- sh_data.paint_image_comp_sh = GPU_shader_create_from_info_name("sculpt_paint_image_compute");
+ int index = static_cast<int>(variation_flags);
+
+ if (sh_data.paint_image_comp_sh[index] == nullptr) {
+
+ std::stringstream info_name;
+ info_name << "sculpt_paint_image";
+ info_name << (variation_flags & BRUSH_TEST_CIRCLE ? "_circle" : "_sphere");
+
+ printf("%s create shader %s\n", __func__, info_name.str().c_str());
+
+ sh_data.paint_image_comp_sh[index] = GPU_shader_create_from_info_name(info_name.str().c_str());
}
- return sh_data.paint_image_comp_sh;
+ return sh_data.paint_image_comp_sh[index];
}
GPUShader *SCULPT_shader_paint_image_merge_get(void)
diff --git a/source/blender/gpu/GPU_sculpt_shader_shared.h b/source/blender/gpu/GPU_sculpt_shader_shared.h
index ac09ed71525..11b07d249ea 100644
--- a/source/blender/gpu/GPU_sculpt_shader_shared.h
+++ b/source/blender/gpu/GPU_sculpt_shader_shared.h
@@ -61,6 +61,8 @@ BLI_STATIC_ASSERT_ALIGN(PaintBrushData, 16)
struct PaintStepData {
float3 location;
float radius;
+ /* Circle falloff. */
+ float4 plane_view;
int mirror_symmetry_pass;
int _pad0[3];
};
diff --git a/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh b/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
index 1a834ff6516..97eed0237f4 100644
--- a/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
+++ b/source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh
@@ -18,9 +18,7 @@ GPU_SHADER_CREATE_INFO(sculpt_paint_image_compute)
.push_constant(Type::INT, "pixel_row_offset")
.push_constant(Type::IVEC2, "paint_step_range")
.compute_source("sculpt_paint_image_comp.glsl")
- .typedef_source("GPU_sculpt_shader_shared.h")
- .define("BRUSH_TEST_SPHERE")
- .do_static_compilation(true);
+ .typedef_source("GPU_sculpt_shader_shared.h");
GPU_SHADER_CREATE_INFO(sculpt_paint_image_merge_compute)
.local_group_size(1, 1, 1)
@@ -29,3 +27,21 @@ GPU_SHADER_CREATE_INFO(sculpt_paint_image_merge_compute)
.compute_source("sculpt_paint_image_merge_comp.glsl")
.typedef_source("GPU_sculpt_shader_shared.h")
.do_static_compilation(true);
+
+/* -------------------------------------------------------------------- */
+/** \name Brush variations
+ * \{ */
+
+GPU_SHADER_CREATE_INFO(sculpt_paint_test_sphere).define("BRUSH_TEST_SPHERE");
+GPU_SHADER_CREATE_INFO(sculpt_paint_test_circle).define("BRUSH_TEST_CIRCLE");
+
+#define SCULPT_PAINT_FINAL_VARIATION(name, ...) \
+ GPU_SHADER_CREATE_INFO(name).additional_info(__VA_ARGS__).do_static_compilation(true);
+
+#define SCULPT_PAINT_TEST_VARIATIONS(name, ...) \
+ SCULPT_PAINT_FINAL_VARIATION(name##_sphere, "sculpt_paint_test_sphere", __VA_ARGS__) \
+ SCULPT_PAINT_FINAL_VARIATION(name##_circle, "sculpt_paint_test_circle", __VA_ARGS__)
+
+SCULPT_PAINT_TEST_VARIATIONS(sculpt_paint_image, "sculpt_paint_image_compute")
+
+/** \} */
diff --git a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
index 2a43b3c8ebc..e85e894a25b 100644
--- a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
+++ b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl
@@ -5,8 +5,10 @@ bool SCULPT_brush_test(PaintBrushTestData test_data,
vec3 co,
out float dist)
{
-#ifdef BRUSH_TEST_SPHERE
+#if defined(BRUSH_TEST_SPHERE)
return SCULPT_brush_test_sphere(test_data, step_data, co, dist);
+#elif defined(BRUSH_TEST_CIRCLE)
+ return SCULPT_brush_test_circle(test_data, step_data, co, dist);
#else
dist = 0.0;
return true;
diff --git a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl
index bb6529fe966..159e24112d8 100644
--- a/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl
+++ b/source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl
@@ -7,6 +7,26 @@ bool SCULPT_brush_test_sphere(PaintBrushTestData test_data,
return dist <= step_data.radius;
}
+float plane_point_side_v3(vec4 plane, vec3 co)
+{
+ return dot(co, vec3(plane)) + plane.w;
+}
+
+vec3 closest_to_plane_normalized_v3(vec4 plane, vec3 co)
+{
+ float side = plane_point_side_v3(plane, co);
+ return (vec3(plane) * -side) + co;
+}
+
+bool SCULPT_brush_test_circle(PaintBrushTestData test_data,
+ PaintStepData step_data,
+ vec3 co,
+ out float dist)
+{
+ vec3 proj = closest_to_plane_normalized_v3(step_data.plane_view, co);
+ return SCULPT_brush_test_sphere(test_data, step_data, proj, dist);
+}
+
void SCULPT_get_row_pos_and_delta(vec3 co1,
vec3 co2,
vec3 co3,
More information about the Bf-blender-cvs
mailing list