[Bf-blender-cvs] [71bb98ca976] temp-texture-painting-gpu: Initial blending mode.

Jeroen Bakker noreply at git.blender.org
Tue Oct 4 15:04:55 CEST 2022


Commit: 71bb98ca97617a4d2102b6f08198015f66e835ad
Author: Jeroen Bakker
Date:   Tue Oct 4 15:04:51 2022 +0200
Branches: temp-texture-painting-gpu
https://developer.blender.org/rB71bb98ca97617a4d2102b6f08198015f66e835ad

Initial blending mode.

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

M	source/blender/editors/sculpt_paint/sculpt_paint_image.cc
M	source/blender/gpu/GPU_sculpt_shader_shared.h
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_paint_image.cc b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
index 5925d5b6121..00759007ccf 100644
--- a/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
+++ b/source/blender/editors/sculpt_paint/sculpt_paint_image.cc
@@ -521,9 +521,9 @@ static void init_paint_brush_color(const SculptSession &ss,
   r_paint_brush.color[3] = 1.0f;
 }
 
-static void init_paint_brush_strength(const SculptSession &ss, PaintBrushData &r_paint_brush)
+static void init_paint_brush_alpha(const Brush &brush, PaintBrushData &r_paint_brush)
 {
-  r_paint_brush.strength = ss.cache->bstrength;
+  r_paint_brush.alpha = brush.alpha;
 }
 
 /* TODO: Currently only spherical is supported. */
@@ -537,7 +537,7 @@ static void init_paint_brush(const SculptSession &ss,
                              PaintBrushData &r_paint_brush)
 {
   init_paint_brush_color(ss, brush, r_paint_brush);
-  init_paint_brush_strength(ss, r_paint_brush);
+  init_paint_brush_alpha(brush, r_paint_brush);
   init_paint_brush_test(ss, r_paint_brush);
 }
 
@@ -771,6 +771,7 @@ static void init_paint_step(const SculptSession &ss,
   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;
+  r_paint_step.strength = ss.cache->bstrength;
 
   if (brush.falloff_shape == PAINT_FALLOFF_SHAPE_TUBE) {
     plane_from_point_normal_v3(
diff --git a/source/blender/gpu/GPU_sculpt_shader_shared.h b/source/blender/gpu/GPU_sculpt_shader_shared.h
index 3b621ba10e2..d4ff5b72db0 100644
--- a/source/blender/gpu/GPU_sculpt_shader_shared.h
+++ b/source/blender/gpu/GPU_sculpt_shader_shared.h
@@ -50,8 +50,7 @@ BLI_STATIC_ASSERT_ALIGN(PaintBrushTestData, 16)
 struct PaintBrushData {
   float4 color;
   PaintBrushTestData test;
-  float strength;
-
+  float alpha;
   float _pad0;
   float _pad1;
   float _pad2;
@@ -64,7 +63,8 @@ struct PaintStepData {
   /* Circle falloff. */
   float4 plane_view;
   float hardness;
+  float strength;
   int mirror_symmetry_pass;
-  int _pad0[2];
+  int _pad0[1];
 };
 BLI_STATIC_ASSERT_ALIGN(PaintStepData, 16);
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 2d64d9f2699..4fea3dd353d 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
@@ -49,7 +49,10 @@ void main()
         // TODO: blend with 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);
+        vec4 final_paint_color = SCULPT_blend_color(
+            color, paint_brush_buf.color * curve_factor * step_data.strength);
+        final_paint_color *= paint_brush_buf.alpha;
+        color = SCULPT_blend_color(color, final_paint_color);
       }
     }
     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 8ea29f4bbae..68ec47d7fd3 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,4 +1,15 @@
 
+/* -------------------------------------------------------------------- */
+/** \name Brush testing
+ * \{ */
+
+vec4 SCULPT_blend_color(vec4 src1, vec4 src2)
+{
+  return src1 * (1.0 - src2.a) + src2;
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Brush testing
  * \{ */



More information about the Bf-blender-cvs mailing list