[Bf-blender-cvs] [6cd0c80d974] temp-texture-painting-gpu: Falloff curve. (WIP)

Jeroen Bakker noreply at git.blender.org
Tue Oct 4 13:26:57 CEST 2022


Commit: 6cd0c80d97435a888f514fc3b33fffe6c7d82e13
Author: Jeroen Bakker
Date:   Tue Oct 4 13:26:44 2022 +0200
Branches: temp-texture-painting-gpu
https://developer.blender.org/rB6cd0c80d97435a888f514fc3b33fffe6c7d82e13

Falloff curve. (WIP)

===================================================================

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 6a9e2a58089..bda3bd53f06 100644
--- a/source/blender/editors/sculpt_paint/sculpt_intern.h
+++ b/source/blender/editors/sculpt_paint/sculpt_intern.h
@@ -1878,13 +1878,28 @@ void SCULPT_bmesh_topology_rake(
 /* end sculpt_brush_types.c */
 
 /* sculpt_shaders.cc */
-
 typedef enum BrushVariationFlags {
   BRUSH_TEST_SPHERE = (0 << 0),
   BRUSH_TEST_CIRCLE = (1 << 1),
   BRUSH_TEST_CLIPPING = (1 << 2),
-  BRUSH_MAX_VARIATIONS = (1 << 3),
+  BRUSH_VARIATION_FALLOFF_CUSTOM = (BRUSH_CURVE_CUSTOM << 3),
+  BRUSH_VARIATION_FALLOFF_SMOOTH = (BRUSH_CURVE_SMOOTH << 3),
+  BRUSH_VARIATION_FALLOFF_SPHERE = (BRUSH_CURVE_SPHERE << 3),
+  BRUSH_VARIATION_FALLOFF_ROOT = (BRUSH_CURVE_ROOT << 3),
+  BRUSH_VARIATION_FALLOFF_SHARP = (BRUSH_CURVE_SHARP << 3),
+  BRUSH_VARIATION_FALLOFF_LIN = (BRUSH_CURVE_LIN << 3),
+  BRUSH_VARIATION_FALLOFF_POW4 = (BRUSH_CURVE_POW4 << 3),
+  BRUSH_VARIATION_FALLOFF_INVSQUARE = (BRUSH_CURVE_INVSQUARE << 3),
+  BRUSH_VARIATION_FALLOFF_CONSTANT = (BRUSH_CURVE_CONSTANT << 3),
+  BRUSH_VARIATION_FALLOFF_SMOOTHER = (BRUSH_CURVE_SMOOTHER << 3),
+  BRUSH_MAX_VARIATIONS = (1 << 8),
 } BrushVariationFlags;
+#define BRUSH_VARIATION_FALLOFF_MASK \
+  (BRUSH_VARIATION_FALLOFF_CUSTOM | BRUSH_VARIATION_FALLOFF_SMOOTH | \
+   BRUSH_VARIATION_FALLOFF_SPHERE | BRUSH_VARIATION_FALLOFF_ROOT | \
+   BRUSH_VARIATION_FALLOFF_SHARP | BRUSH_VARIATION_FALLOFF_LIN | BRUSH_VARIATION_FALLOFF_POW4 | \
+   BRUSH_VARIATION_FALLOFF_INVSQUARE | BRUSH_VARIATION_FALLOFF_CONSTANT | \
+   BRUSH_VARIATION_FALLOFF_SMOOTHER)
 struct GPUShader *SCULPT_shader_paint_image_get(BrushVariationFlags variation_flags);
 struct GPUShader *SCULPT_shader_paint_image_merge_get(void);
 
diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
index 7e3ac5ed51e..ff4bbda0883 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
@@ -653,6 +653,14 @@ static BrushVariationFlags determine_shader_variation_flags(const Brush &brush)
   if (brush.falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
     result = static_cast<BrushVariationFlags>(result | BRUSH_TEST_CIRCLE);
   }
+
+  BrushVariationFlags curve = static_cast<BrushVariationFlags>(0);
+  switch (brush.curve_preset) {
+    case BRUSH_CURVE_SHARP:
+      curve = BRUSH_VARIATION_FALLOFF_SHARP;
+      break;
+  }
+  result = static_cast<BrushVariationFlags>(result | curve);
   return result;
 }
 
@@ -731,6 +739,7 @@ static void init_paint_step(const SculptSession &ss,
   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;
+  r_paint_step.hardness = ss.cache->paint_brush.hardness;
 
   if (brush.falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
     plane_from_point_normal_v3(
diff --git a/source/blender/editors/sculpt_paint/sculpt_shaders.cc b/source/blender/editors/sculpt_paint/sculpt_shaders.cc
index 1d2cd564de7..92df716c503 100644
--- a/source/blender/editors/sculpt_paint/sculpt_shaders.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_shaders.cc
@@ -26,6 +26,39 @@ GPUShader *SCULPT_shader_paint_image_get(BrushVariationFlags variation_flags)
     std::stringstream info_name;
     info_name << "sculpt_paint_image";
     info_name << (variation_flags & BRUSH_TEST_CIRCLE ? "_circle" : "_sphere");
+    BrushVariationFlags curve_falloff = static_cast<BrushVariationFlags>(
+        variation_flags & BRUSH_VARIATION_FALLOFF_MASK);
+    switch (curve_falloff) {
+      case BRUSH_VARIATION_FALLOFF_CUSTOM:
+        info_name << "_custom";
+        break;
+      case BRUSH_VARIATION_FALLOFF_SMOOTH:
+        info_name << "_smooth";
+        break;
+      case BRUSH_VARIATION_FALLOFF_SPHERE:
+        info_name << "_sphere";
+        break;
+      case BRUSH_VARIATION_FALLOFF_ROOT:
+        info_name << "_root";
+        break;
+      case BRUSH_VARIATION_FALLOFF_SHARP:
+        info_name << "_sharp";
+        break;
+      case BRUSH_VARIATION_FALLOFF_LIN:
+        info_name << "_lin";
+        break;
+      case BRUSH_VARIATION_FALLOFF_POW4:
+        info_name << "_pow4";
+        break;
+      case BRUSH_VARIATION_FALLOFF_INVSQUARE:
+        info_name << "_invsquare";
+        break;
+      case BRUSH_VARIATION_FALLOFF_SMOOTHER:
+        info_name << "_smoother";
+        break;
+      default:
+        BLI_assert_unreachable();
+    }
 
     printf("%s create shader %s\n", __func__, info_name.str().c_str());
 
diff --git a/source/blender/gpu/GPU_sculpt_shader_shared.h b/source/blender/gpu/GPU_sculpt_shader_shared.h
index 11b07d249ea..3b621ba10e2 100644
--- a/source/blender/gpu/GPU_sculpt_shader_shared.h
+++ b/source/blender/gpu/GPU_sculpt_shader_shared.h
@@ -63,7 +63,8 @@ struct PaintStepData {
   float radius;
   /* Circle falloff. */
   float4 plane_view;
+  float hardness;
   int mirror_symmetry_pass;
-  int _pad0[3];
+  int _pad0[2];
 };
 BLI_STATIC_ASSERT_ALIGN(PaintStepData, 16);
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 97eed0237f4..838a198a367 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
@@ -35,12 +35,35 @@ GPU_SHADER_CREATE_INFO(sculpt_paint_image_merge_compute)
 GPU_SHADER_CREATE_INFO(sculpt_paint_test_sphere).define("BRUSH_TEST_SPHERE");
 GPU_SHADER_CREATE_INFO(sculpt_paint_test_circle).define("BRUSH_TEST_CIRCLE");
 
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_custom).define("BRUSH_CURVE_PRESET 0");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_smooth).define("BRUSH_CURVE_PRESET 1");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_sphere).define("BRUSH_CURVE_PRESET 2");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_root).define("BRUSH_CURVE_PRESET 3");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_sharp).define("BRUSH_CURVE_PRESET 4");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_lin).define("BRUSH_CURVE_PRESET 5");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_pow4).define("BRUSH_CURVE_PRESET 6");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_invsquare).define("BRUSH_CURVE_PRESET 7");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_constant).define("BRUSH_CURVE_PRESET 8");
+GPU_SHADER_CREATE_INFO(sculpt_paint_falloff_smoother).define("BRUSH_CURVE_PRESET 9");
+
 #define SCULPT_PAINT_FINAL_VARIATION(name, ...) \
   GPU_SHADER_CREATE_INFO(name).additional_info(__VA_ARGS__).do_static_compilation(true);
 
+#define SCULPT_PAINT_CURVE_VARIATION(name, ...) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_custom, "sculpt_paint_falloff_custom", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_smooth, "sculpt_paint_falloff_smooth", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_sphere, "sculpt_paint_falloff_sphere", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_root, "sculpt_paint_falloff_root", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_sharp, "sculpt_paint_falloff_sharp", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_lin, "sculpt_paint_falloff_lin", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_pow4, "sculpt_paint_falloff_pow4", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_invsquare, "sculpt_paint_falloff_invsquare", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_constant, "sculpt_paint_falloff_constant", __VA_ARGS__) \
+  SCULPT_PAINT_FINAL_VARIATION(name##_smoother, "sculpt_paint_falloff_smoother", __VA_ARGS__)
+
 #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_CURVE_VARIATION(name##_sphere, "sculpt_paint_test_sphere", __VA_ARGS__) \
+  SCULPT_PAINT_CURVE_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 e85e894a25b..2d64d9f2699 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
@@ -47,7 +47,9 @@ void main()
           color_read = true;
         }
         // TODO: blend with color...
-        color = max(color, paint_brush_buf.color);
+        float factor = SCULPT_hardness_factor(distance, step_data.hardness, step_data.radius);
+        float curve_factor = SCULPT_curve_strength(factor, BRUSH_CURVE_PRESET);
+        color = max(color, paint_brush_buf.color * curve_factor);
       }
     }
     if (color_read) {
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 159e24112d8..a8b008ca7eb 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
@@ -1,3 +1,66 @@
+
+/* -------------------------------------------------------------------- */
+/** \name Brush testing
+ * \{ */
+
+float SCULPT_curve_strength(float factor, int curve_type)
+{
+  if (factor > 1.0) {
+    return 0.0;
+  }
+  float p = 1.0 - factor;
+
+  switch (curve_type) {
+    case 0 /*BRUSH_CURVE_CUSTOM*/:
+      return factor;
+    case 1 /*BRUSH_CURVE_SMOOTH*/:
+      return 3.0 * p * p - 2.0 * p * p * p;
+    case 2 /*BRUSH_CURVE_SPHERE*/:
+      return sqrt(2.0 * p - p * p);
+    case 3 /*BRUSH_CURVE_ROOT*/:
+      return sqrt(p);
+    case 4 /*BRUSH_CURVE_SHARP*/:
+      return p * p;
+    case 5 /*BRUSH_CURVE_LIN*/:
+      return p;
+    case 6 /*BRUSH_CURVE_POW4*/:
+      return p * p * p * p;
+    case 7 /*BRUSH_CURVE_INVSQUARE*/:
+      return p * (2.0 - p);
+    case 8 /*BRUSH_CURVE_CONSTANT*/:
+      return 1.0;
+    case 9 /*BRUSH_CURVE_SMOOTHER*/:
+      return p

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list