Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeroen Bakker <jeroen@blender.org>2022-10-04 14:26:44 +0300
committerJeroen Bakker <jeroen@blender.org>2022-10-04 14:26:44 +0300
commit6cd0c80d97435a888f514fc3b33fffe6c7d82e13 (patch)
treea6574d94d14c5db3ba40a2e43fa0b1a60ff3177c /source/blender/gpu/shaders
parentdf5e02ec4767d8cc8d13f12544a94923bae1b1ef (diff)
Falloff curve. (WIP)
Diffstat (limited to 'source/blender/gpu/shaders')
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/infos/sculpt_paint_image_info.hh27
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_comp.glsl4
-rw-r--r--source/blender/gpu/shaders/sculpt_paint/sculpt_paint_image_lib.glsl65
3 files changed, 93 insertions, 3 deletions
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 * p * p * (p * (p * 6.0 - 15.0) + 10.0);
+ default:
+ return factor;
+ }
+
+ return factor;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Brush testing
+ * \{ */
+float SCULPT_hardness_factor(float dist, float hardness, float radius)
+{
+ float p = dist / radius;
+ if (p < hardness) {
+ return 0.0;
+ }
+ else if (hardness >= 1.0) {
+ return 1.0;
+ }
+ return (p - hardness / (1.0 - hardness));
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Brush testing
+ * \{ */
+
bool SCULPT_brush_test_sphere(PaintBrushTestData test_data,
PaintStepData step_data,
vec3 co,
@@ -27,6 +90,8 @@ bool SCULPT_brush_test_circle(PaintBrushTestData test_data,
return SCULPT_brush_test_sphere(test_data, step_data, proj, dist);
}
+/** \} */
+
void SCULPT_get_row_pos_and_delta(vec3 co1,
vec3 co2,
vec3 co3,