[Bf-blender-cvs] [633dd0c47c8] temp-texture-painting-gpu: Fix hardness.

Jeroen Bakker noreply at git.blender.org
Tue Oct 4 14:24:08 CEST 2022


Commit: 633dd0c47c80cfd1b6b33deaf1648826e38fbb07
Author: Jeroen Bakker
Date:   Tue Oct 4 14:23:52 2022 +0200
Branches: temp-texture-painting-gpu
https://developer.blender.org/rB633dd0c47c80cfd1b6b33deaf1648826e38fbb07

Fix hardness.

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

M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc
M	source/blender/editors/sculpt_paint/sculpt_shaders.cc
M	source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl

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

diff --git a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
index ff4bbda0883..5925d5b6121 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
@@ -576,8 +576,12 @@ struct GPUSculptPaintData {
   void update_step_buf()
   {
     int requested_size = sizeof(PaintStepData) * steps.size();
+    /* Reallocate buffer when it doesn't fit, or is to big to correct reading from uninitialized
+     * memory. */
+    const bool reallocate_buf = (requested_size > step_buf_alloc_size) ||
+                                (sizeof(PaintStepData) * steps.capacity() < step_buf_alloc_size);
 
-    if (step_buf && requested_size > step_buf_alloc_size) {
+    if (step_buf && reallocate_buf) {
       GPU_storagebuf_free(step_buf);
       step_buf = nullptr;
     }
@@ -588,7 +592,7 @@ struct GPUSculptPaintData {
       step_buf_alloc_size = requested_size;
     }
 
-    BLI_assert_msg(sizeof(PaintStepData) * steps.capacity() > step_buf_alloc_size,
+    BLI_assert_msg(sizeof(PaintStepData) * steps.capacity() >= step_buf_alloc_size,
                    "Possible read from unallocated memory as storage buffer is larger than the "
                    "step capacity.");
     GPU_storagebuf_update(step_buf, steps.data());
@@ -656,9 +660,36 @@ static BrushVariationFlags determine_shader_variation_flags(const Brush &brush)
 
   BrushVariationFlags curve = static_cast<BrushVariationFlags>(0);
   switch (brush.curve_preset) {
+    case BRUSH_CURVE_CUSTOM:
+      curve = BRUSH_VARIATION_FALLOFF_CUSTOM;
+      break;
+    case BRUSH_CURVE_SMOOTH:
+      curve = BRUSH_VARIATION_FALLOFF_SMOOTH;
+      break;
+    case BRUSH_CURVE_SPHERE:
+      curve = BRUSH_VARIATION_FALLOFF_SPHERE;
+      break;
+    case BRUSH_CURVE_ROOT:
+      curve = BRUSH_VARIATION_FALLOFF_ROOT;
+      break;
     case BRUSH_CURVE_SHARP:
       curve = BRUSH_VARIATION_FALLOFF_SHARP;
       break;
+    case BRUSH_CURVE_LIN:
+      curve = BRUSH_VARIATION_FALLOFF_LIN;
+      break;
+    case BRUSH_CURVE_POW4:
+      curve = BRUSH_VARIATION_FALLOFF_POW4;
+      break;
+    case BRUSH_CURVE_INVSQUARE:
+      curve = BRUSH_VARIATION_FALLOFF_INVSQUARE;
+      break;
+    case BRUSH_CURVE_CONSTANT:
+      curve = BRUSH_VARIATION_FALLOFF_CONSTANT;
+      break;
+    case BRUSH_CURVE_SMOOTHER:
+      curve = BRUSH_VARIATION_FALLOFF_SMOOTHER;
+      break;
   }
   result = static_cast<BrushVariationFlags>(result | curve);
   return result;
diff --git a/source/blender/editors/sculpt_paint/sculpt_shaders.cc b/source/blender/editors/sculpt_paint/sculpt_shaders.cc
index 92df716c503..559bbb88882 100644
--- a/source/blender/editors/sculpt_paint/sculpt_shaders.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_shaders.cc
@@ -53,6 +53,9 @@ GPUShader *SCULPT_shader_paint_image_get(BrushVariationFlags variation_flags)
       case BRUSH_VARIATION_FALLOFF_INVSQUARE:
         info_name << "_invsquare";
         break;
+      case BRUSH_VARIATION_FALLOFF_CONSTANT:
+        info_name << "_constant";
+        break;
       case BRUSH_VARIATION_FALLOFF_SMOOTHER:
         info_name << "_smoother";
         break;
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 a8b008ca7eb..8ea29f4bbae 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
@@ -52,7 +52,7 @@ float SCULPT_hardness_factor(float dist, float hardness, float radius)
   else if (hardness >= 1.0) {
     return 1.0;
   }
-  return (p - hardness / (1.0 - hardness));
+  return (p - hardness) / (1.0 - hardness);
 }
 
 /** \} */



More information about the Bf-blender-cvs mailing list