[Bf-blender-cvs] [0c50f9c4aaf] master: Fix T98672: Noise texture shows incorrect behaviour for large scales

2022-10-15 Thread Lukas Stockner
Commit: 0c50f9c4aaf90eb26240c31fbeff12af519a8ab0
Author: Lukas Stockner
Date:   Sun Oct 16 01:57:44 2022 +0200
Branches: master
https://developer.blender.org/rB0c50f9c4aaf90eb26240c31fbeff12af519a8ab0

Fix T98672: Noise texture shows incorrect behaviour for large scales

This was a floating point precision issue - or, to be more precise,
an issue with how Cycles split floats into the integer and fractional
parts for Perlin noise.
For coordinates below -2^24, the integer could be wrong, leading to
the fractional part being outside of 0-1 range, which breaks all sorts
of other things. 2^24 sounds like a lot, but due to how the detail
octaves work, it's not that hard to reach when combined with a large
scale.

Since this code is originally based on OSL, I checked if they changed
it in the meantime, and sure enough, there's a fix for it:
https://github.com/OpenImageIO/oiio/commit/5c9dc68391e9

So, this basically just ports over that change to Cycles.

The original code mentions being faster, but as pointed out in the
linked commit, the performance impact is actually irrelevant.

I also checked in a simple scene with eight Noise textures at
detail 15 (with >90% of render time being spent on the noise), and
the render time went from 13.06sec to 13.05sec. So, yeah, no issue.

===

M   intern/cycles/util/math.h
M   intern/cycles/util/math_float3.h
M   intern/cycles/util/ssef.h

===

diff --git a/intern/cycles/util/math.h b/intern/cycles/util/math.h
index 0905b3ec5c9..3a2e0e074a2 100644
--- a/intern/cycles/util/math.h
+++ b/intern/cycles/util/math.h
@@ -417,15 +417,11 @@ ccl_device_inline int floor_to_int(float f)
   return float_to_int(floorf(f));
 }
 
-ccl_device_inline int quick_floor_to_int(float x)
-{
-  return float_to_int(x) - ((x < 0) ? 1 : 0);
-}
-
 ccl_device_inline float floorfrac(float x, ccl_private int *i)
 {
-  *i = quick_floor_to_int(x);
-  return x - *i;
+  float f = floorf(x);
+  *i = float_to_int(f);
+  return x - f;
 }
 
 ccl_device_inline int ceil_to_int(float f)
diff --git a/intern/cycles/util/math_float3.h b/intern/cycles/util/math_float3.h
index c408eadf195..eec7122b9dc 100644
--- a/intern/cycles/util/math_float3.h
+++ b/intern/cycles/util/math_float3.h
@@ -535,18 +535,6 @@ ccl_device_inline float3 pow(float3 v, float e)
   return make_float3(powf(v.x, e), powf(v.y, e), powf(v.z, e));
 }
 
-ccl_device_inline int3 quick_floor_to_int3(const float3 a)
-{
-#ifdef __KERNEL_SSE__
-  int3 b = int3(_mm_cvttps_epi32(a.m128));
-  int3 isneg = int3(_mm_castps_si128(_mm_cmplt_ps(a.m128, _mm_set_ps1(0.0f;
-  /* Unsaturated add 0x is the same as subtract -1. */
-  return b + isneg;
-#else
-  return make_int3(quick_floor_to_int(a.x), quick_floor_to_int(a.y), 
quick_floor_to_int(a.z));
-#endif
-}
-
 ccl_device_inline bool isfinite_safe(float3 v)
 {
   return isfinite_safe(v.x) && isfinite_safe(v.y) && isfinite_safe(v.z);
diff --git a/intern/cycles/util/ssef.h b/intern/cycles/util/ssef.h
index a2fff94303e..7f9e332a997 100644
--- a/intern/cycles/util/ssef.h
+++ b/intern/cycles/util/ssef.h
@@ -5,6 +5,8 @@
 #ifndef __UTIL_SSEF_H__
 #define __UTIL_SSEF_H__
 
+#include 
+
 #include "util/ssei.h"
 
 CCL_NAMESPACE_BEGIN
@@ -534,6 +536,12 @@ __forceinline const ssef ceil(const ssef &a)
   return _mm_round_ps(a, _MM_FROUND_TO_POS_INF);
 #endif
 }
+#  else
+/* Non-SSE4.1 fallback, needed for floorfrac. */
+__forceinline const ssef floor(const ssef &a)
+{
+  return _mm_set_ps(floorf(a.f[3]), floorf(a.f[2]), floorf(a.f[1]), 
floorf(a.f[0]));
+}
 #  endif
 
 __forceinline ssei truncatei(const ssef &a)
@@ -541,20 +549,11 @@ __forceinline ssei truncatei(const ssef &a)
   return _mm_cvttps_epi32(a.m128);
 }
 
-/* This is about 25% faster than straightforward floor to integer conversion
- * due to better pipelining.
- *
- * Unsaturated add 0x (a < 0) is the same as subtract -1.
- */
-__forceinline ssei floori(const ssef &a)
-{
-  return truncatei(a) + cast((a < 0.0f).m128);
-}
-
 __forceinline ssef floorfrac(const ssef &x, ssei *i)
 {
-  *i = floori(x);
-  return x - ssef(*i);
+  ssef f = floor(x);
+  *i = truncatei(f);
+  return x - f;
 }
 
 


___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [b898330c374] master: Fix T99450: Animated Holdout not updating on frame change

2022-10-15 Thread Lukas Stockner
Commit: b898330c3744669a8c3805f1560130821422cca1
Author: Lukas Stockner
Date:   Sat Oct 15 22:51:21 2022 +0200
Branches: master
https://developer.blender.org/rBb898330c3744669a8c3805f1560130821422cca1

Fix T99450: Animated Holdout not updating on frame change

Problem here was that layer_collection_objects_sync wasn't called when
the holdout property is updated due to frame change, so the changed
visibility flag was never applied to ob->base_flag.

Turns out there's no real reason to handle the per-object holdout
property through the layer system. So, instead of merging both the
layer holdout and object holdout into base_flag and checking that
from the render engines, only handle the layer holdout (which can't
be animated, so no issue here) through base_flag and explicitly also
check the object holdout in the render engines.

===

M   source/blender/blenkernel/intern/layer.c
M   source/blender/draw/engines/eevee/eevee_materials.c
M   source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
M   source/blender/makesrna/intern/rna_object_api.c

===

diff --git a/source/blender/blenkernel/intern/layer.c 
b/source/blender/blenkernel/intern/layer.c
index fcb0adfde34..06d69b6ff61 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -1049,7 +1049,7 @@ static void layer_collection_objects_sync(ViewLayer 
*view_layer,
 }
 
 /* Holdout and indirect only */
-if ((layer->flag & LAYER_COLLECTION_HOLDOUT) || 
(base->object->visibility_flag & OB_HOLDOUT)) {
+if ((layer->flag & LAYER_COLLECTION_HOLDOUT)) {
   base->flag_from_collection |= BASE_HOLDOUT;
 }
 if (layer->flag & LAYER_COLLECTION_INDIRECT_ONLY) {
diff --git a/source/blender/draw/engines/eevee/eevee_materials.c 
b/source/blender/draw/engines/eevee/eevee_materials.c
index f79e4e1d568..b5f81f3a307 100644
--- a/source/blender/draw/engines/eevee/eevee_materials.c
+++ b/source/blender/draw/engines/eevee/eevee_materials.c
@@ -759,7 +759,8 @@ BLI_INLINE Material *eevee_object_material_get(Object *ob, 
int slot, bool holdou
 BLI_INLINE EeveeMaterialCache eevee_material_cache_get(
 EEVEE_Data *vedata, EEVEE_ViewLayerData *sldata, Object *ob, int slot, 
bool is_hair)
 {
-  const bool holdout = (ob->base_flag & BASE_HOLDOUT) != 0;
+  const bool holdout = ((ob->base_flag & BASE_HOLDOUT) != 0) ||
+   ((ob->visibility_flag & OB_HOLDOUT) != 0);
   EeveeMaterialCache matcache;
   Material *ma = eevee_object_material_get(ob, slot, holdout);
   switch (ma->blend_method) {
diff --git 
a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp 
b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
index 19589491bc4..0d41b5a773d 100644
--- a/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
+++ b/source/blender/freestyle/intern/blender_interface/BlenderFileLoader.cpp
@@ -73,7 +73,8 @@ NodeGroup *BlenderFileLoader::Load()
   break;
 }
 
-if (ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) {
+if ((ob->base_flag & (BASE_HOLDOUT | BASE_INDIRECT_ONLY)) ||
+(ob->visibility_flag & OB_HOLDOUT)) {
   continue;
 }
 
diff --git a/source/blender/makesrna/intern/rna_object_api.c 
b/source/blender/makesrna/intern/rna_object_api.c
index c99c5fb723d..366a3597ce6 100644
--- a/source/blender/makesrna/intern/rna_object_api.c
+++ b/source/blender/makesrna/intern/rna_object_api.c
@@ -199,7 +199,7 @@ static bool rna_Object_holdout_get(Object *ob, bContext *C, 
PointerRNA *view_lay
 return false;
   }
 
-  return ((base->flag & BASE_HOLDOUT) != 0);
+  return ((base->flag & BASE_HOLDOUT) != 0) || ((ob->visibility_flag & 
OB_HOLDOUT) != 0);
 }
 
 static bool rna_Object_indirect_only_get(Object *ob, bContext *C, PointerRNA 
*view_layer_ptr)

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [7a59876397a] temp-angavrilov: Armature: apply Y scale to B-Bone segments.

2022-10-15 Thread Alexander Gavrilov
Commit: 7a59876397acce7ef04e5cc5c88bd988fe7b8185
Author: Alexander Gavrilov
Date:   Tue Jun 15 13:52:23 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB7a59876397acce7ef04e5cc5c88bd988fe7b8185

Armature: apply Y scale to B-Bone segments.

This fixes a strange behavior where the segments were not actually
scaled in the Y direction to match their actual length, thus
producing gaps or overlap depending on the shape of the curve. For
transformation the change should be very small if enough segments
are used, but this will affect the results of the Copy Transforms
and Armature constraints, so a backwards compatibility option is
provided. Newly created bones default to the new behavior.

===

M   release/scripts/startup/bl_ui/properties_data_bone.py
M   source/blender/blenkernel/BKE_armature.h
M   source/blender/blenkernel/intern/armature.c
M   source/blender/draw/engines/overlay/overlay_armature.cc
M   source/blender/makesdna/DNA_armature_types.h
M   source/blender/makesrna/intern/rna_armature.c

===

diff --git a/release/scripts/startup/bl_ui/properties_data_bone.py 
b/release/scripts/startup/bl_ui/properties_data_bone.py
index 8e1808949b3..026e581b2ba 100644
--- a/release/scripts/startup/bl_ui/properties_data_bone.py
+++ b/release/scripts/startup/bl_ui/properties_data_bone.py
@@ -162,6 +162,8 @@ class BONE_PT_curved(BoneButtonsPanel, Panel):
 col.prop(bbone, "bbone_easeout", text="Out", 
text_ctxt=i18n_contexts.id_armature)
 col.prop(bone, "use_scale_easing")
 
+topcol.prop(bone, "use_unscaled_segments")
+
 col = topcol.column(align=True)
 col.prop(bone, "bbone_handle_type_start", text="Start Handle")
 
diff --git a/source/blender/blenkernel/BKE_armature.h 
b/source/blender/blenkernel/BKE_armature.h
index ee0f41937e2..2b217ca3025 100644
--- a/source/blender/blenkernel/BKE_armature.h
+++ b/source/blender/blenkernel/BKE_armature.h
@@ -469,7 +469,7 @@ typedef struct BBoneSplineParameters {
   float length;
 
   /* Non-uniform scale correction. */
-  bool do_scale;
+  bool do_scale, do_scale_segments;
   float scale[3];
 
   /* Handle control bone data. */
diff --git a/source/blender/blenkernel/intern/armature.c 
b/source/blender/blenkernel/intern/armature.c
index 2e73cac99b5..8a8bc48d49a 100644
--- a/source/blender/blenkernel/intern/armature.c
+++ b/source/blender/blenkernel/intern/armature.c
@@ -944,6 +944,8 @@ void BKE_pchan_bbone_spline_params_get(struct bPoseChannel 
*pchan,
   param->segments = bone->segments;
   param->length = bone->length;
 
+  param->do_scale_segments = (bone->bbone_flag & BBONE_SCALE_SEGMENTS) != 0;
+
   if (!rest) {
 float scale[3];
 
@@ -1309,6 +1311,7 @@ static void 
make_bbone_spline_matrix(BBoneSplineParameters *param,
  const float axis[3],
  float roll,
  float scalex,
+ float scaley,
  float scalez,
  float result[4][4])
 {
@@ -1326,6 +1329,7 @@ static void 
make_bbone_spline_matrix(BBoneSplineParameters *param,
 
   /* BBone scale... */
   mul_v3_fl(result[0], scalex);
+  mul_v3_fl(result[1], scaley);
   mul_v3_fl(result[2], scalez);
 }
 
@@ -1393,6 +1397,8 @@ int BKE_pchan_bbone_spline_compute(BBoneSplineParameters 
*param,
   equalize_cubic_bezier(
   bezt_controls, MAX_BBONE_SUBDIV, param->segments, segment_scales, 
bezt_points);
 
+  const float scale_fac = param->segments / length;
+
   /* Deformation uses N+1 matrices computed at points between the segments. */
   if (for_deform) {
 /* Bezier derivatives. */
@@ -1405,6 +1411,32 @@ int BKE_pchan_bbone_spline_compute(BBoneSplineParameters 
*param,
   sub_v3_v3v3(bezt_deriv2[i], bezt_deriv1[i + 1], bezt_deriv1[i]);
 }
 
+/* Inner segment points. */
+float points[MAX_BBONE_SUBDIV][3], tangents[MAX_BBONE_SUBDIV][3];
+
+copy_v3_v3(points[0], bezt_controls[0]);
+
+for (int a = 1; a < param->segments; a++) {
+  evaluate_cubic_bezier(bezt_controls, bezt_points[a], points[a], 
tangents[a]);
+}
+
+/* Segment lengths. */
+float seg_length[MAX_BBONE_SUBDIV + 1];
+
+if (param->do_scale_segments) {
+  for (int a = 1; a < param->segments; a++) {
+seg_length[a] = len_v3v3(points[a - 1], points[a]) * scale_fac;
+  }
+
+  seg_length[param->segments] = len_v3v3(points[param->segments - 1], 
bezt_controls[3]) *
+scale_fac;
+}
+else {
+  for (int a = 1; a <= param->segments; a++) {
+seg_length[a] = 1;
+  }
+}
+
 /* End points require special handling to fix zero length handles. */
 ease_handle_axis(bezt_deriv1[0], bezt_deriv2[0], axis);
 make_bbone_spline_matrix(param,
@@ 

[Bf-blender-cvs] [8532e08676c] temp-angavrilov: Shrinkwrap: support smoothing the mesh after wrapping.

2022-10-15 Thread Alexander Gavrilov
Commit: 8532e08676c27662dbec0502a952fc37d6ef8e3f
Author: Alexander Gavrilov
Date:   Thu Sep 1 19:18:51 2022 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB8532e08676c27662dbec0502a952fc37d6ef8e3f

Shrinkwrap: support smoothing the mesh after wrapping.

Adds a smoothing post-processing option for the shrinkwrap modifier.
On any other setting than 0 iterations, the algorithm adds the laplacian
of the deltas to the base mesh to produce a smooth-looking deformed
mesh -- this makes it possible to avoid losing detail on parts of the
mesh that are not affected by the shrinkwrap displacement.

Deltas that would otherwise lose magnitude as a result of smoothing
are not updated to avoid further volume loss; this keeps the result
much closer to the surface of the target while still adjusting other
shrinkwrapped (and non-shrinkwrapped) vertexes to follow the smooth
surface.

Differential Revision: https://developer.blender.org/D6414

===

M   source/blender/blenkernel/intern/shrinkwrap.cc
M   source/blender/makesdna/DNA_modifier_types.h
M   source/blender/makesrna/intern/rna_modifier.c
M   source/blender/modifiers/intern/MOD_shrinkwrap.c

===

diff --git a/source/blender/blenkernel/intern/shrinkwrap.cc 
b/source/blender/blenkernel/intern/shrinkwrap.cc
index 65226a5db9d..d27d09b5119 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.cc
+++ b/source/blender/blenkernel/intern/shrinkwrap.cc
@@ -63,6 +63,10 @@ struct ShrinkwrapCalcData {
   const float (*vert_normals)[3];
   /* Vertices being shrink-wrapped. */
   float (*vertexCos)[3];
+  /* Cached vertex deltas. */
+  float (*deltas)[3];
+  /* Cached vertex weights */
+  float *weights;
   int numVerts;
 
   const MDeformVert *dvert; /* Pointer to mdeform array */
@@ -330,6 +334,19 @@ void BKE_shrinkwrap_compute_boundary_data(Mesh *mesh)
   mesh->runtime->shrinkwrap_data = shrinkwrap_build_boundary_data(mesh);
 }
 
+/** Output the computed vertex position either to the final coordinate or the 
delta array. */
+BLI_INLINE void shrinkwrap_save_result(
+ShrinkwrapCalcData *calc, int i, float *co, float *result, float weight)
+{
+  if (calc->deltas) {
+sub_v3_v3v3(calc->deltas[i], result, co);
+mul_v3_fl(calc->deltas[i], weight);
+  }
+  else {
+interp_v3_v3v3(co, co, result, weight); /* linear interpolation */
+  }
+}
+
 /**
  * Shrink-wrap to the nearest vertex
  *
@@ -358,6 +375,10 @@ static void shrinkwrap_calc_nearest_vertex_cb_ex(void 
*__restrict userdata,
 return;
   }
 
+  if (calc->weights) {
+calc->weights[i] = weight;
+  }
+
   /* Convert the vertex to tree coordinates */
   if (calc->vert) {
 copy_v3_v3(tmp_co, calc->vert[i].co);
@@ -394,7 +415,7 @@ static void shrinkwrap_calc_nearest_vertex_cb_ex(void 
*__restrict userdata,
 copy_v3_v3(tmp_co, nearest->co);
 BLI_space_transform_invert(&calc->local2target, tmp_co);
 
-interp_v3_v3v3(co, co, tmp_co, weight); /* linear interpolation */
+shrinkwrap_save_result(calc, i, co, tmp_co, weight);
   }
 }
 
@@ -521,6 +542,10 @@ static void shrinkwrap_calc_normal_projection_cb_ex(void 
*__restrict userdata,
 return;
   }
 
+  if (calc->weights) {
+calc->weights[i] = weight;
+  }
+
   if (calc->vert != nullptr && calc->smd->projAxis == 
MOD_SHRINKWRAP_PROJECT_OVER_NORMAL) {
 /* calc->vert contains verts from evaluated mesh. */
 /* These coordinates are deformed by vertexCos only for normal projection
@@ -611,7 +636,7 @@ static void shrinkwrap_calc_normal_projection_cb_ex(void 
*__restrict userdata,
hit->co);
 }
 
-interp_v3_v3v3(co, co, hit->co, weight);
+shrinkwrap_save_result(calc, i, co, hit->co, weight);
   }
 }
 
@@ -1119,6 +1144,10 @@ static void 
shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdat
 return;
   }
 
+  if (calc->weights) {
+calc->weights[i] = weight;
+  }
+
   /* Convert the vertex to tree coordinates */
   if (calc->vert) {
 copy_v3_v3(tmp_co, calc->vert[i].co);
@@ -1163,7 +1192,8 @@ static void 
shrinkwrap_calc_nearest_surface_point_cb_ex(void *__restrict userdat
 
 /* Convert the coordinates back to mesh coordinates */
 BLI_space_transform_invert(&calc->local2target, tmp_co);
-interp_v3_v3v3(co, co, tmp_co, weight); /* linear interpolation */
+
+shrinkwrap_save_result(calc, i, co, tmp_co, weight);
   }
 }
 
@@ -1363,6 +1393,137 @@ static void 
shrinkwrap_calc_nearest_surface_point(ShrinkwrapCalcData *calc)
   0, calc->numVerts, &data, shrinkwrap_calc_nearest_surface_point_cb_ex, 
&settings);
 }
 
+static void shrinkwrap_smooth(
+ShrinkwrapCalcData *calc, Object *ob, Mesh *mesh, float (*vertexCos)[3], 
int numVerts)
+{
+  if (mesh == NULL) {
+return;
+  }
+
+  /* Number of neighboring vertices for the given vertex. */
+  uint *num_neighbor_verts = static_cast(
+  M

[Bf-blender-cvs] [665b37f96e4] temp-angavrilov: Eevee: implement conditional evaluation of Mix node branches.

2022-10-15 Thread Alexander Gavrilov
Commit: 665b37f96e4806a0e8e077b0d8a1f7b1764cdcd1
Author: Alexander Gavrilov
Date:   Sun Oct 9 21:15:48 2022 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB665b37f96e4806a0e8e077b0d8a1f7b1764cdcd1

Eevee: implement conditional evaluation of Mix node branches.

If the material effectively combines multiple distinct materials
using some kind of mask texture, it is wasteful to evaluate all
of them when the mask fully excludes some. Cycles already supports
this optimization for Mix Shader nodes.

This implements a similar feature for Mix Shader and Mix Color Blend
nodes in Eevee: shader matches Cycles, and mixing colors can be used
for a similar purpose in NPR shaders.

To achieve that, a Conditional node type directly supported by code
generation is added. Shader nodes can add these conditionals as needed,
and the code generator partitions the node graph into a branch tree
and appropriately generates conditionals. Empty conditionals are
automatically eliminated to avoid any performance impact. This
processing is done separately for every sub-graph to minimize
dependency cross-contamination.

Differential Revision: https://developer.blender.org/D16218

===

M   source/blender/gpu/GPU_material.h
M   source/blender/gpu/intern/gpu_codegen.cc
M   source/blender/gpu/intern/gpu_node_graph.c
M   source/blender/gpu/intern/gpu_node_graph.h
M   source/blender/nodes/shader/nodes/node_shader_mix.cc
M   source/blender/nodes/shader/nodes/node_shader_mix_shader.cc

===

diff --git a/source/blender/gpu/GPU_material.h 
b/source/blender/gpu/GPU_material.h
index 3dad2a1a19a..7b04439823d 100644
--- a/source/blender/gpu/GPU_material.h
+++ b/source/blender/gpu/GPU_material.h
@@ -195,6 +195,51 @@ bool GPU_stack_link(GPUMaterial *mat,
 GPUNodeStack *out,
 ...);
 
+/** Comparison operator for conditionals. */
+typedef enum {
+  GPU_CMP_NE = 0,
+  GPU_CMP_LT,
+  GPU_CMP_LE,
+  GPU_CMP_EQ,
+  GPU_CMP_GE,
+  GPU_CMP_GT,
+} GPUComparisonOp;
+
+/**
+ * Create a runtime ternary conditional, choosing between two inputs based on
+ * comparing a scalar float input with a constant threshold.
+ *
+ * \param cmp_input: Input to compare with the threshold.
+ * \param result_type: Type of value to produce.
+ * \param if_true: Input to use when the condition is true.
+ * \param if_false: Input to use when the condition is false. If null, this 
signifies
+ * the conditional is an optimization hint the input is unused if the 
condition is false.
+ * Depending on context, a valid default value is used, or the conditional may 
be discarded
+ * if it produces no performance benefit.
+ */
+GPUNodeLink *GPU_link_conditional(GPUMaterial *mat,
+  GPUNodeLink *cmp_input,
+  GPUComparisonOp cmp,
+  float threshold,
+  eGPUType result_type,
+  GPUNodeLink *if_true,
+  GPUNodeLink *if_false);
+
+/**
+ * Introduces a predicate for evaluating a stack input only when necessary.
+ * The conditional is only added if both inputs are non-constant.
+ *
+ * \param cmp_input: Input to compare with the threshold.
+ * \param inout_if_true: Stack entry to wrap in the conditional, suppressing 
evaluation when false.
+ * The link field within the entry is updated in place.
+ * \return true if the conditional was actually added.
+ */
+bool GPU_stack_link_conditional(GPUMaterial *mat,
+GPUNodeStack *cmp_input,
+GPUComparisonOp cmp,
+float threshold,
+GPUNodeStack *inout_if_true);
+
 void GPU_material_output_surface(GPUMaterial *material, GPUNodeLink *link);
 void GPU_material_output_volume(GPUMaterial *material, GPUNodeLink *link);
 void GPU_material_output_displacement(GPUMaterial *material, GPUNodeLink 
*link);
diff --git a/source/blender/gpu/intern/gpu_codegen.cc 
b/source/blender/gpu/intern/gpu_codegen.cc
index 4adeac1b49a..21e5699e357 100644
--- a/source/blender/gpu/intern/gpu_codegen.cc
+++ b/source/blender/gpu/intern/gpu_codegen.cc
@@ -40,6 +40,7 @@
 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -197,9 +198,25 @@ static std::ostream &operator<<(std::ostream &stream, 
const GPUInput *input)
   }
 }
 
-static std::ostream &operator<<(std::ostream &stream, const GPUOutput *output)
+static std::ostream &operator<<(std::ostream &stream, GPUComparisonOp cmp)
 {
-  return stream << "tmp" << output->id;
+  switch (cmp) {
+case GPU_CMP_NE:
+  return stream << "!=";
+case GPU_CMP_LT:
+  return stream << "<";
+case GPU_CMP_LE:
+  return stream << "<=";
+case GPU_CMP_EQ:
+  return stream << "==";
+case GPU_CMP_GE:
+

[Bf-blender-cvs] [bf3c47226bc] temp-angavrilov: Weight Paint: relax heuristic to determine when final mesh can be used.

2022-10-15 Thread Alexander Gavrilov
Commit: bf3c47226bc5ad2dbaf12363917c0eca417ed23b
Author: Alexander Gavrilov
Date:   Sat Oct 15 22:07:03 2022 +0300
Branches: temp-angavrilov
https://developer.blender.org/rBbf3c47226bc5ad2dbaf12363917c0eca417ed23b

Weight Paint: relax heuristic to determine when final mesh can be used.

Checking for polygon and loop data to be referenced is too fragile
re changes in geometry node implementations. Instead, compare counts
of polygons, face corners and vertices: topology changes are unlikely
to keep all three unchanged.

Ref D15501

===

M   source/blender/blenkernel/intern/paint.cc

===

diff --git a/source/blender/blenkernel/intern/paint.cc 
b/source/blender/blenkernel/intern/paint.cc
index 934cfb3cc46..98e026831c5 100644
--- a/source/blender/blenkernel/intern/paint.cc
+++ b/source/blender/blenkernel/intern/paint.cc
@@ -1785,8 +1785,8 @@ static void sculpt_update_object(
   /* If the fully evaluated mesh has the same topology as the deform-only 
version, use it.
* This matters because crazyspace evaluation is very restrictive and 
excludes even modifiers
* that simply recompute vertex weights (which can even include Geometry 
Nodes). */
-  if (me_eval_deform->polys().data() == me_eval->polys().data() &&
-  me_eval_deform->loops().data() == me_eval->loops().data() &&
+  if (me_eval_deform->totpoly == me_eval->totpoly &&
+  me_eval_deform->totloop == me_eval->totloop &&
   me_eval_deform->totvert == me_eval->totvert) {
 BKE_sculptsession_free_deformMats(ss);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [32a1c56d81e] temp-angavrilov: Bone Overlay: support bone wireframe opacity depth fade.

2022-10-15 Thread Alexander Gavrilov
Commit: 32a1c56d81ef35e365284e73f3879b7041dacccb
Author: Alexander Gavrilov
Date:   Sat Dec 11 18:04:34 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB32a1c56d81ef35e365284e73f3879b7041dacccb

Bone Overlay: support bone wireframe opacity depth fade.

Add an option that allows fade based on the depth from the camera,
using exponential decay with the slider specifying the 'half-life'
depth. This is intended as a way to automatically hide bones
in distant parts of the mesh while focused on a specific part.

===

M   release/scripts/startup/bl_ui/space_view3d.py
M   source/blender/blenloader/intern/versioning_300.cc
M   source/blender/draw/CMakeLists.txt
M   source/blender/draw/engines/overlay/overlay_armature.cc
M   source/blender/draw/engines/overlay/overlay_private.hh
M   
source/blender/draw/engines/overlay/shaders/infos/overlay_armature_info.hh
A   
source/blender/draw/engines/overlay/shaders/overlay_armature_alpha_lib.glsl
M   
source/blender/draw/engines/overlay/shaders/overlay_armature_dof_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/overlay_armature_envelope_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/overlay_armature_shape_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/overlay_armature_sphere_solid_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/overlay_armature_stick_frag.glsl
M   
source/blender/draw/engines/overlay/shaders/overlay_armature_wire_frag.glsl
M   source/blender/makesdna/DNA_view3d_defaults.h
M   source/blender/makesdna/DNA_view3d_types.h
M   source/blender/makesrna/intern/rna_space.c

===

diff --git a/release/scripts/startup/bl_ui/space_view3d.py 
b/release/scripts/startup/bl_ui/space_view3d.py
index 3a02492635a..5ad4d679d06 100644
--- a/release/scripts/startup/bl_ui/space_view3d.py
+++ b/release/scripts/startup/bl_ui/space_view3d.py
@@ -6773,6 +6773,12 @@ class VIEW3D_PT_overlay_bones(Panel):
 if VIEW3D_PT_overlay_bones.is_using_wireframe(context):
 col.prop(overlay, "bone_wire_alpha")
 
+row = col.row()
+row.prop(overlay, "bone_wire_use_fade_depth", text="")
+sub = row.row()
+sub.active = overlay.bone_wire_use_fade_depth
+sub.prop(overlay, "bone_wire_fade_depth")
+
 
 class VIEW3D_PT_overlay_texture_paint(Panel):
 bl_space_type = 'VIEW_3D'
diff --git a/source/blender/blenloader/intern/versioning_300.cc 
b/source/blender/blenloader/intern/versioning_300.cc
index b08d482f43b..496de377b65 100644
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -3635,5 +3635,19 @@ void blo_do_versions_300(FileData *fd, Library * 
/*lib*/, Main *bmain)
*/
   {
 /* Keep this block, even when empty. */
+
+/* Initialize the bone wireframe opacity depth fade setting. */
+if (!DNA_struct_elem_find(fd->filesdna, "View3DOverlay", "float", 
"bone_wire_fade_depth")) {
+  LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
+LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
+  LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
+if (sl->spacetype == SPACE_VIEW3D) {
+  View3D *v3d = (View3D *)sl;
+  v3d->overlay.bone_wire_fade_depth = 1.0f;
+}
+  }
+}
+  }
+}
   }
 }
diff --git a/source/blender/draw/CMakeLists.txt 
b/source/blender/draw/CMakeLists.txt
index a645bd6b6af..31a5544f24a 100644
--- a/source/blender/draw/CMakeLists.txt
+++ b/source/blender/draw/CMakeLists.txt
@@ -552,6 +552,7 @@ set(GLSL_SRC
   engines/basic/shaders/basic_depth_frag.glsl
 
   engines/overlay/shaders/overlay_antialiasing_frag.glsl
+  engines/overlay/shaders/overlay_armature_alpha_lib.glsl
   engines/overlay/shaders/overlay_armature_dof_solid_frag.glsl
   engines/overlay/shaders/overlay_armature_dof_vert.glsl
   engines/overlay/shaders/overlay_armature_envelope_outline_vert.glsl
diff --git a/source/blender/draw/engines/overlay/overlay_armature.cc 
b/source/blender/draw/engines/overlay/overlay_armature.cc
index 174e7280deb..f0d6a6a47f3 100644
--- a/source/blender/draw/engines/overlay/overlay_armature.cc
+++ b/source/blender/draw/engines/overlay/overlay_armature.cc
@@ -86,6 +86,8 @@ struct ArmatureDrawContext {
   bool transparent;
   bool show_relations;
 
+  float *p_fade_depth_bias;
+
   const ThemeWireColor *bcolor; /* pchan color */
 };
 
@@ -126,7 +128,14 @@ void OVERLAY_armature_cache_init(OVERLAY_Data *vedata)
draw_ctx->object_pose != nullptr;
 
   const float wire_alpha = pd->overlay.bone_wire_alpha;
-  const bool use_wire_alpha = (wire_alpha < 1.0f);
+  const float wire_fade = (pd->overlay.flag & V3D_OVERLAY_BONE_FADE_DEPTH) ?
+

[Bf-blender-cvs] [a0c534f77ff] temp-angavrilov: Shrinkwrap: fix stability of the Target Normal Project mode.

2022-10-15 Thread Alexander Gavrilov
Commit: a0c534f77ffd4a19e4daa5bec8a61e2dd89d0720
Author: Alexander Gavrilov
Date:   Sat Sep 3 17:03:11 2022 +0300
Branches: temp-angavrilov
https://developer.blender.org/rBa0c534f77ffd4a19e4daa5bec8a61e2dd89d0720

Shrinkwrap: fix stability of the Target Normal Project mode.

This mode works by using an iterative process to solve a system
of equations for each triangle to find a point on its surface that
has the smooth normal pointing at the original point. If a point
within the triangle is not found, the next triangle is searched.

All instability with vertices jumping to the opposite side of
the mesh is caused by incorrectly discarding triangles for various
reasons when the solution is close to the triangle edge.

In order to optimize performance the old code was aggressively
aborting iteration when the local gradient at the edge was
pointing outside domain. However, it is wrong because it can be
caused by a sharp valley diagonal to the domain boundary with
the bottom gently sloping towards a minimum within the domain.

Now iteration is only aborted either if the solution deviates
nonsensically far from the domain, or if the gradient is proven
to slope towards the outside perpendicular to the boundary.
Until either condition is met, values are simply clamped to
the domain.

In addition, custom correction clearly has to be done after
the linear search phase of the iterative solver, because the
linear correction math assumes running after a normal Newton
method step, not some kind of custom clamping.

Differential Revision: https://developer.blender.org/D15892

===

M   source/blender/blenkernel/intern/shrinkwrap.cc
M   source/blender/blenlib/intern/math_solvers.c

===

diff --git a/source/blender/blenkernel/intern/shrinkwrap.cc 
b/source/blender/blenkernel/intern/shrinkwrap.cc
index d27d09b5119..01fbbf919de 100644
--- a/source/blender/blenkernel/intern/shrinkwrap.cc
+++ b/source/blender/blenkernel/intern/shrinkwrap.cc
@@ -781,18 +781,30 @@ static void target_project_tri_jacobian(void *userdata, 
const float x[3], float
 }
 
 /* Clamp barycentric weights to the triangle. */
-static void target_project_tri_clamp(float x[3])
+static float target_project_tri_clamp(float x[3])
 {
+  float error = 0.0f;
+
   if (x[0] < 0.0f) {
+error = max_ff(error, -x[0]);
+
 x[0] = 0.0f;
   }
+
   if (x[1] < 0.0f) {
+error = max_ff(error, -x[1]);
+
 x[1] = 0.0f;
   }
+
   if (x[0] + x[1] > 1.0f) {
+error = max_ff(error, x[0] + x[1] - 1.0f);
+
 x[0] = x[0] / (x[0] + x[1]);
 x[1] = 1.0f - x[0];
   }
+
+  return error;
 }
 
 /* Correct the Newton's method step to keep the coordinates within the 
triangle. */
@@ -801,71 +813,36 @@ static bool target_project_tri_correct(void * 
/*userdata*/,
float step[3],
float x_next[3])
 {
-  /* Insignificant correction threshold */
-  const float epsilon = 1e-5f;
-  /* Dot product threshold for checking if step is 'clearly' pointing outside. 
*/
-  const float dir_epsilon = 0.5f;
-  bool fixed = false, locked = false;
-
-  /* The barycentric coordinate domain is a triangle bounded by
-   * the X and Y axes, plus the x+y=1 diagonal. First, clamp the
-   * movement against the diagonal. Note that step is subtracted. */
-  float sum = x[0] + x[1];
-  float sstep = -(step[0] + step[1]);
-
-  if (sum + sstep > 1.0f) {
-float ldist = 1.0f - sum;
-
-/* If already at the boundary, slide along it. */
-if (ldist < epsilon * float(M_SQRT2)) {
-  float step_len = len_v2(step);
-
-  /* Abort if the solution is clearly outside the domain. */
-  if (step_len > epsilon && sstep > step_len * dir_epsilon * 
float(M_SQRT2)) {
-return false;
-  }
+  const float error = target_project_tri_clamp(x_next);
 
-  /* Project the new position onto the diagonal. */
-  add_v2_fl(step, (sum + sstep - 1.0f) * 0.5f);
-  fixed = locked = true;
-}
-else {
-  /* Scale a significant step down to arrive at the boundary. */
-  mul_v3_fl(step, ldist / sstep);
-  fixed = true;
-}
+  /* Immediately abort on a clearly wrong point.
+   *
+   * It is not appropriate to abort unless the value is extremely
+   * wrong, because if the goal function gradient forms a sharp
+   * valley with a gently sloping bottom, the iterative process may
+   * be dragged against the edge of the domain by local gradients
+   * for a number of steps even when the ultimate minimum is within
+   * the domain.
+   *
+   * This threshold basically represents an estimate of something so
+   * far outside the domain that all assumptions about the solution
+   * behavior start to break down.
+   */
+  if (error > 1.0f) {
+return false;
   }
 
-  /* Weight 0 and 1 boundary checks - along axis. */
-  for (int i = 0; i < 2; i++) {
-if (step[i] > x[i])

[Bf-blender-cvs] [70952c71c31] temp-angavrilov: Force Fields: implement new true power and custom falloff options.

2022-10-15 Thread Alexander Gavrilov
Commit: 70952c71c31529f8e8a56e96a7b26abd23f15bb4
Author: Alexander Gavrilov
Date:   Sun Sep 12 19:35:48 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB70952c71c31529f8e8a56e96a7b26abd23f15bb4

Force Fields: implement new true power and custom falloff options.

The 'power' falloff option in Blender force fields does not actually
generate a true power falloff function, as pointed out in D2389.
However, that patch adds a special 'gravity' falloff option to Force
fields, without addressing the shortcoming in the common options.

The reason for not using the true curve in the options, as far as
one can tell, is that the power curve goes up to infinity as the
distance is reduced to 0, while the falloff options are designed
so that the maximum value of the curve is 1.

However, in reality forces with a power falloff don't actually go
to infinity, because real objects have a nonzero size, and the force
reaches its maximum at the surface of the object. This can be used
to integrate an option to use a true power falloff with the design
of falloff settings, if it requires a nonzero 'minimum' distance
to be set, and uses a curve that reaches 1 at that distance.

Since this is adding a new feature to the minimum distance value,
it is also a good opportunity to add a feature to the maximum
distance. Specifically, the new options can be used to apply
arbitrary brush-style falloff curves between min and max,
including a fully custom curve option. When used together with
power falloff, the two curves are multiplied together.

While the true power option allows creating more physically
correct forces, the custom curves aid artistic effects.

Differential Revision: https://developer.blender.org/D8075

===

M   release/scripts/startup/bl_ui/properties_physics_common.py
M   release/scripts/startup/bl_ui/properties_physics_field.py
M   source/blender/blenkernel/BKE_effect.h
M   source/blender/blenkernel/BKE_particle.h
M   source/blender/blenkernel/intern/effect.c
M   source/blender/blenkernel/intern/object.cc
M   source/blender/blenkernel/intern/particle.c
M   source/blender/makesdna/DNA_object_force_types.h
M   source/blender/makesrna/intern/rna_object_force.c

===

diff --git a/release/scripts/startup/bl_ui/properties_physics_common.py 
b/release/scripts/startup/bl_ui/properties_physics_common.py
index 60f384a3839..757e3015cf1 100644
--- a/release/scripts/startup/bl_ui/properties_physics_common.py
+++ b/release/scripts/startup/bl_ui/properties_physics_common.py
@@ -337,6 +337,10 @@ def basic_force_field_falloff_ui(self, field):
 sub.prop(field, "distance_min", text="")
 row.prop_decorator(field, "distance_min")
 
+col = layout.column()
+col.active = field.use_min_distance and field.distance_min > 0
+col.prop(field, "use_true_power")
+
 col = layout.column(align=False, heading="Max Distance")
 col.use_property_decorate = False
 row = col.row(align=True)
@@ -347,6 +351,13 @@ def basic_force_field_falloff_ui(self, field):
 sub.prop(field, "distance_max", text="")
 row.prop_decorator(field, "distance_max")
 
+col = layout.column()
+col.active = field.use_max_distance and field.distance_max > 
field.distance_min
+col.prop(field, "falloff_curve_type", text="Curve")
+
+if field.falloff_curve_type == 'CUSTOM':
+col.template_curve_mapping(field, "falloff_curve", type='NONE', 
brush=True)
+
 
 classes = (
 PHYSICS_PT_add,
diff --git a/release/scripts/startup/bl_ui/properties_physics_field.py 
b/release/scripts/startup/bl_ui/properties_physics_field.py
index 36d5dc7f68d..635897247c9 100644
--- a/release/scripts/startup/bl_ui/properties_physics_field.py
+++ b/release/scripts/startup/bl_ui/properties_physics_field.py
@@ -238,20 +238,36 @@ class 
PHYSICS_PT_field_falloff_angular(PhysicButtonsPanel, Panel):
 col = flow.column()
 col.prop(field, "radial_falloff", text="Power")
 
-col = flow.column()
-col.prop(field, "use_radial_min", text="Use Min Angle")
-
-sub = col.column()
+col = layout.column(align=False, heading="Min Angle")
+col.use_property_decorate = False
+row = col.row(align=True)
+sub = row.row(align=True)
+sub.prop(field, "use_radial_min", text="")
+sub = sub.row(align=True)
 sub.active = field.use_radial_min
-sub.prop(field, "radial_min", text="Min Angle")
-
-col = flow.column()
-col.prop(field, "use_radial_max", text="Use Max Angle")
+sub.prop(field, "radial_min", text="")
+row.prop_decorator(field, "radial_min")
 
-sub = col.column()
+col = layout.column()
+col.active = field.use_radial_min and field.radial_min > 0
+col.prop(field, "use_radial_true_power")
+
+col = layout.column(align=False, heading="Max

[Bf-blender-cvs] [809c63d7432] temp-angavrilov: Temporary Hack: provide B-Bone scale versioning for files with old patch.

2022-10-15 Thread Alexander Gavrilov
Commit: 809c63d743288e67c06244e89cf3c39c5061837d
Author: Alexander Gavrilov
Date:   Tue Jun 22 16:38:26 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB809c63d743288e67c06244e89cf3c39c5061837d

Temporary Hack: provide B-Bone scale versioning for files with old patch.

Run the versioning code for the conversion of bbone scale to an xyz
vector if it has fields that correspond to the old version of the
patch before that change requiring versioning.

The actual Y (length) scale value from the old patch isn't versioned
and will be lost, requiring manual fixing.

===

M   source/blender/blenloader/intern/versioning_300.cc

===

diff --git a/source/blender/blenloader/intern/versioning_300.cc 
b/source/blender/blenloader/intern/versioning_300.cc
index 5328107e1f2..b08d482f43b 100644
--- a/source/blender/blenloader/intern/versioning_300.cc
+++ b/source/blender/blenloader/intern/versioning_300.cc
@@ -2041,7 +2041,8 @@ void blo_do_versions_300(FileData *fd, Library * /*lib*/, 
Main *bmain)
 }
 
 /* Initialize length-wise scale B-Bone settings. */
-if (!DNA_struct_elem_find(fd->filesdna, "Bone", "int", "bbone_flag")) {
+if (!DNA_struct_elem_find(fd->filesdna, "Bone", "int", "bbone_flag") ||
+DNA_struct_elem_find(fd->filesdna, "Bone", "float", "scale_in_len")) {
   /* Update armature data and pose channels. */
   LISTBASE_FOREACH (bArmature *, arm, &bmain->armatures) {
 do_version_bones_bbone_len_scale(&arm->bonebase);

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [f32c822729a] temp-angavrilov: Animation: support filtering for curves that have cycle issues.

2022-10-15 Thread Alexander Gavrilov
Commit: f32c822729a5466cefe3ed0e2ce4975b95713244
Author: Alexander Gavrilov
Date:   Mon May 3 17:27:53 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rBf32c822729a5466cefe3ed0e2ce4975b95713244

Animation: support filtering for curves that have cycle issues.

It is possible to have curves with cyclic extrapolation that
have a mismatch in their end keyframes, causing a jump.

Also, since the looping behavior is defined per curve rather than at
action level, it is possible for curve loop periods to get out of
sync with each other. This commit adds an option to compare curves
against the manual frame range specified in the action, and treat
any mismatches as errors for the purpose of F-Curve filtering.

When enabled, the check verifies that end values of cyclic curves
match, curves within a cyclic action have valid cyclic extrapolation,
and the action period evenly divides by the curve period (since
a curve looping at e.g. half of the action period length still
repeats in sync with the action).

Ref: D11803

Differential Revision: https://developer.blender.org/D13349

===

M   release/scripts/startup/bl_ui/space_dopesheet.py
M   source/blender/blenkernel/BKE_fcurve.h
M   source/blender/blenkernel/intern/fcurve.c
M   source/blender/editors/animation/anim_filter.c
M   source/blender/makesdna/DNA_action_types.h
M   source/blender/makesrna/intern/rna_action.c

===

diff --git a/release/scripts/startup/bl_ui/space_dopesheet.py 
b/release/scripts/startup/bl_ui/space_dopesheet.py
index f95650ccc23..a857daa6561 100644
--- a/release/scripts/startup/bl_ui/space_dopesheet.py
+++ b/release/scripts/startup/bl_ui/space_dopesheet.py
@@ -63,6 +63,12 @@ class DopesheetFilterPopoverBase:
 else:  # graph and dopesheet editors - F-Curves and drivers only
 col.prop(dopesheet, "show_only_errors", icon='NONE')
 
+col.separator()
+
+col2 = col.column(align=True)
+col2.active = dopesheet.show_only_errors
+col2.prop(dopesheet, "show_cycle_errors")
+
 # Name/Membership Filters
 # XXX: Perhaps these should just stay in the headers (exclusively)?
 @classmethod
diff --git a/source/blender/blenkernel/BKE_fcurve.h 
b/source/blender/blenkernel/BKE_fcurve.h
index c11e6353bc0..2144c21d0d6 100644
--- a/source/blender/blenkernel/BKE_fcurve.h
+++ b/source/blender/blenkernel/BKE_fcurve.h
@@ -448,7 +448,7 @@ typedef enum eFCU_Cycle_Type {
 /**
  * Checks if the F-Curve has a Cycles modifier, and returns the type of the 
cycle behavior.
  */
-eFCU_Cycle_Type BKE_fcurve_get_cycle_type(struct FCurve *fcu);
+eFCU_Cycle_Type BKE_fcurve_get_cycle_type(const struct FCurve *fcu);
 
 /**
  * Recompute bezier handles of all three given BezTriples, so that `bezt` can 
be inserted between
diff --git a/source/blender/blenkernel/intern/fcurve.c 
b/source/blender/blenkernel/intern/fcurve.c
index beea3217126..0468fa5a2d3 100644
--- a/source/blender/blenkernel/intern/fcurve.c
+++ b/source/blender/blenkernel/intern/fcurve.c
@@ -1156,7 +1156,7 @@ void fcurve_samples_to_keyframes(FCurve *fcu, const int 
start, const int end)
  * that the handles are correct.
  */
 
-eFCU_Cycle_Type BKE_fcurve_get_cycle_type(FCurve *fcu)
+eFCU_Cycle_Type BKE_fcurve_get_cycle_type(const FCurve *fcu)
 {
   FModifier *fcm = fcu->modifiers.first;
 
diff --git a/source/blender/editors/animation/anim_filter.c 
b/source/blender/editors/animation/anim_filter.c
index 3a04873588d..f4f08b684b4 100644
--- a/source/blender/editors/animation/anim_filter.c
+++ b/source/blender/editors/animation/anim_filter.c
@@ -63,6 +63,7 @@
 #include "BLI_alloca.h"
 #include "BLI_blenlib.h"
 #include "BLI_ghash.h"
+#include "BLI_math.h"
 #include "BLI_string.h"
 #include "BLI_utildefines.h"
 
@@ -1207,6 +1208,53 @@ static bool skip_fcurve_with_name(
   return true;
 }
 
+/* Check if the F-Curve doesn't cycle properly based on action settings. */
+static bool fcurve_has_cycle_errors(const FCurve *fcu, const bAction *act)
+{
+  /* Check if the curve is cyclic. */
+  const eFCU_Cycle_Type cycle_type = BKE_fcurve_get_cycle_type(fcu);
+
+  if (cycle_type == FCU_CYCLE_NONE) {
+/* Curves in a cyclic action should be cyclic; in an ordinary action 
either way is fine. */
+return BKE_action_is_cyclic(act);
+  }
+
+  /* Check if the curve has enough points. */
+  if (fcu->totvert < 2 || !fcu->bezt) {
+return true;
+  }
+
+  const BezTriple *first = &fcu->bezt[0], *last = &fcu->bezt[fcu->totvert - 1];
+
+  if (BKE_action_is_cyclic(act)) {
+/* Check that it has a nonzero period length. */
+const float curve_period = last->vec[1][0] - first->vec[1][0];
+
+if (curve_period < 0.1f) {
+  return true;
+}
+
+/* Check that the action period is divisible by the curve period. */
+const float action_period = act->frame_end - act->frame_start;
+cons

[Bf-blender-cvs] [129c19fe609] temp-angavrilov: Dope Sheet: distinguish Constant and Linear from other interpolation modes.

2022-10-15 Thread Alexander Gavrilov
Commit: 129c19fe609d84f38e58802c12d9a6316be68d96
Author: Alexander Gavrilov
Date:   Sat Feb 5 14:11:29 2022 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB129c19fe609d84f38e58802c12d9a6316be68d96

Dope Sheet: distinguish Constant and Linear from other interpolation modes.

There is an option to display handles and interpolation modes in
the dope sheet, but the only interpolation mode it distinguishes
is Bezier. This adds distinct display for Constant and Linear:

- Constant is drawn as a thicker line.
- Linear is drawn the same as now.
- Other non-Bezier modes are drawn as a double line.

Constant, Linear and Bezier are the most common modes, so it makes
sense to distinguish them from all others.

Differential Revision: https://developer.blender.org/D15855

===

M   source/blender/editors/animation/keyframes_draw.c
M   source/blender/editors/animation/keyframes_keylist.cc
M   source/blender/editors/include/ED_keyframes_keylist.h

===

diff --git a/source/blender/editors/animation/keyframes_draw.c 
b/source/blender/editors/animation/keyframes_draw.c
index 6df9dc1e86d..673e68b2e95 100644
--- a/source/blender/editors/animation/keyframes_draw.c
+++ b/source/blender/editors/animation/keyframes_draw.c
@@ -287,14 +287,30 @@ static void draw_keylist_block_interpolation_line(const 
DrawKeylistUIData *ctx,
   const ActKeyColumn *ab,
   float ypos)
 {
+  float width = ctx->ipo_size;
+  bool fill = true;
+
+  switch (ab->block.ipo) {
+case BEZT_IPO_CONST:
+  width *= 1.7f;
+  break;
+
+case BEZT_IPO_LIN:
+  break;
+
+default:
+  width *= 2.0f;
+  fill = false;
+  }
+
   UI_draw_roundbox_4fv(
   &(const rctf){
   .xmin = ab->cfra,
   .xmax = ab->next->cfra,
-  .ymin = ypos - ctx->ipo_size,
-  .ymax = ypos + ctx->ipo_size,
+  .ymin = ypos - width,
+  .ymax = ypos + width,
   },
-  true,
+  fill,
   3.0f,
   (ab->block.conflict & ACTKEYBLOCK_FLAG_NON_BEZIER) ? ctx->ipo_color_mix 
: ctx->ipo_color);
 }
diff --git a/source/blender/editors/animation/keyframes_keylist.cc 
b/source/blender/editors/animation/keyframes_keylist.cc
index 9b3cabb6c79..6cae1003966 100644
--- a/source/blender/editors/animation/keyframes_keylist.cc
+++ b/source/blender/editors/animation/keyframes_keylist.cc
@@ -749,6 +749,10 @@ static void compute_keyblock_data(ActKeyBlockInfo *info,
   /* Remember non-bezier interpolation info. */
   if (prev->ipo != BEZT_IPO_BEZ) {
 info->flag |= ACTKEYBLOCK_FLAG_NON_BEZIER;
+info->ipo = prev->ipo;
+  }
+  else {
+info->ipo = -1;
   }
 
   info->sel = BEZT_ISSEL_ANY(prev) || BEZT_ISSEL_ANY(beztn);
@@ -765,6 +769,13 @@ static void add_keyblock_info(ActKeyColumn *col, const 
ActKeyBlockInfo *block)
 col->block.conflict |= (col->block.flag ^ block->flag);
 col->block.flag |= block->flag;
 col->block.sel |= block->sel;
+
+/* Combine interpolations; detect conflicts and use max value. */
+if (col->block.ipo != block->ipo) {
+  col->block.conflict |= ACTKEYBLOCK_FLAG_NON_BEZIER;
+}
+
+col->block.ipo = MAX2(col->block.ipo, block->ipo);
   }
 
   if (block->flag) {
diff --git a/source/blender/editors/include/ED_keyframes_keylist.h 
b/source/blender/editors/include/ED_keyframes_keylist.h
index 251b6e4d83d..d82d98777b8 100644
--- a/source/blender/editors/include/ED_keyframes_keylist.h
+++ b/source/blender/editors/include/ED_keyframes_keylist.h
@@ -37,6 +37,9 @@ typedef struct ActKeyBlockInfo {
 
   /* Selection flag. */
   char sel;
+
+  /* Interpolation mode. */
+  signed char ipo;
 } ActKeyBlockInfo;
 
 /* Keyframe Column Struct */

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [0f37f0a9f55] temp-angavrilov: Depsgraph: connect up drivers on various physics properties.

2022-10-15 Thread Alexander Gavrilov
Commit: 0f37f0a9f553eee1285e88d7fe5f1a6c559a449c
Author: Alexander Gavrilov
Date:   Sat Jan 9 21:19:37 2021 +0300
Branches: temp-angavrilov
https://developer.blender.org/rB0f37f0a9f553eee1285e88d7fe5f1a6c559a449c

Depsgraph: connect up drivers on various physics properties.

It seems drivers for physics properties weren't being linked to
evaluation nodes. This connects settings used by modifiers
to Geometry; particle settings and rigid body data to Transform
which seems to contain rigid body evaluation; and force fields
to object Transform, since fields can exist on empties.

Differential Revision: https://developer.blender.org/D10088

===

M   source/blender/depsgraph/intern/builder/deg_builder_relations.cc
M   source/blender/depsgraph/intern/builder/deg_builder_rna.cc

===

diff --git a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc 
b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
index b657d39df69..07ef4c43d98 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_relations.cc
@@ -2029,6 +2029,27 @@ void DepsgraphRelationBuilder::build_rigidbody(Scene 
*scene)
 }
 FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
   }
+  /* Constraints. */
+  if (rbw->constraints != nullptr) {
+build_collection(nullptr, nullptr, rbw->constraints);
+FOREACH_COLLECTION_OBJECT_RECURSIVE_BEGIN (rbw->constraints, object) {
+  if (object->rigidbody_constraint == nullptr) {
+continue;
+  }
+  if (object->rigidbody_object != nullptr) {
+/* Avoid duplicate relations for constraints attached to objects. */
+continue;
+  }
+
+  /* Simulation uses object transformation after parenting and solving 
constraints. */
+  OperationKey object_transform_simulation_init_key(
+  &object->id, NodeType::TRANSFORM, 
OperationCode::TRANSFORM_SIMULATION_INIT);
+  add_relation(object_transform_simulation_init_key,
+   rb_simulate_key,
+   "Object Transform -> Rigidbody Sim Eval");
+}
+FOREACH_COLLECTION_OBJECT_RECURSIVE_END;
+  }
 }
 
 void DepsgraphRelationBuilder::build_particle_systems(Object *object)
diff --git a/source/blender/depsgraph/intern/builder/deg_builder_rna.cc 
b/source/blender/depsgraph/intern/builder/deg_builder_rna.cc
index 1a4356c4a92..b300490066b 100644
--- a/source/blender/depsgraph/intern/builder/deg_builder_rna.cc
+++ b/source/blender/depsgraph/intern/builder/deg_builder_rna.cc
@@ -283,7 +283,16 @@ RNANodeIdentifier 
RNANodeQuery::construct_node_identifier(const PointerRNA *ptr,
RNA_struct_is_a(ptr->type, &RNA_MeshUVLoop) ||
RNA_struct_is_a(ptr->type, &RNA_MeshLoopColor) ||
RNA_struct_is_a(ptr->type, &RNA_VertexGroupElement) ||
-   RNA_struct_is_a(ptr->type, &RNA_ShaderFx)) {
+   RNA_struct_is_a(ptr->type, &RNA_ShaderFx) ||
+   ELEM(ptr->type,
+&RNA_CollisionSettings,
+&RNA_SoftBodySettings,
+&RNA_ClothSettings,
+&RNA_ClothCollisionSettings,
+&RNA_DynamicPaintSurface,
+&RNA_DynamicPaintCanvasSettings,
+&RNA_DynamicPaintBrushSettings) ||
+   (ELEM(ptr->type, &RNA_EffectorWeights) && 
GS(node_identifier.id->name) == ID_OB)) {
 /* When modifier is used as FROM operation this is likely referencing to
  * the property (for example, modifier's influence).
  * But when it's used as TO operation, this is geometry component. */
@@ -383,6 +392,20 @@ RNANodeIdentifier 
RNANodeQuery::construct_node_identifier(const PointerRNA *ptr,
 node_identifier.type = NodeType::GEOMETRY;
 return node_identifier;
   }
+  else if (GS(node_identifier.id->name) == ID_PA &&
+   ELEM(ptr->type, &RNA_EffectorWeights, &RNA_FieldSettings, 
&RNA_ParticleSettings)) {
+node_identifier.type = NodeType::PARTICLE_SETTINGS;
+return node_identifier;
+  }
+  else if (ELEM(ptr->type,
+&RNA_EffectorWeights,
+&RNA_RigidBodyWorld,
+&RNA_FieldSettings,
+&RNA_RigidBodyObject,
+&RNA_RigidBodyConstraint)) {
+node_identifier.type = NodeType::TRANSFORM;
+return node_identifier;
+  }
   if (prop != nullptr) {
 /* All unknown data effectively falls under "parameter evaluation". */
 node_identifier.type = NodeType::PARAMETERS;

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [78b008d20d6] temp-pbvh-split: temp-pbvh-split: Fix various crashes and memory corruption

2022-10-15 Thread Joseph Eagar
Commit: 78b008d20d64bc564cd25564586781535d821925
Author: Joseph Eagar
Date:   Sat Oct 15 00:55:45 2022 -0700
Branches: temp-pbvh-split
https://developer.blender.org/rB78b008d20d64bc564cd25564586781535d821925

temp-pbvh-split: Fix various crashes and memory corruption

===

M   source/blender/blenkernel/intern/pbvh.c
M   source/blender/blenkernel/intern/pbvh_pixels.cc
M   source/blender/draw/intern/draw_shader_shared.h
M   source/blender/editors/sculpt_paint/sculpt.c

===

diff --git a/source/blender/blenkernel/intern/pbvh.c 
b/source/blender/blenkernel/intern/pbvh.c
index 2b989885ebc..b012cb7c098 100644
--- a/source/blender/blenkernel/intern/pbvh.c
+++ b/source/blender/blenkernel/intern/pbvh.c
@@ -3069,9 +3069,24 @@ void BKE_pbvh_draw_debug_cb(PBVH *pbvh,
 PBVHNodeFlags flag),
 void *user_data)
 {
+  PBVHNodeFlags flag = PBVH_Leaf;
+
   for (int a = 0; a < pbvh->totnode; a++) {
 PBVHNode *node = &pbvh->nodes[a];
 
+if (node->flag & PBVH_TexLeaf) {
+  flag = PBVH_TexLeaf;
+  break;
+}
+  }
+
+  for (int a = 0; a < pbvh->totnode; a++) {
+PBVHNode *node = &pbvh->nodes[a];
+
+if (!(node->flag & flag)) {
+  continue;
+}
+
 draw_fn(node, user_data, node->vb.bmin, node->vb.bmax, node->flag);
   }
 }
diff --git a/source/blender/blenkernel/intern/pbvh_pixels.cc 
b/source/blender/blenkernel/intern/pbvh_pixels.cc
index cbbd25d3f4b..a0c796168ed 100644
--- a/source/blender/blenkernel/intern/pbvh_pixels.cc
+++ b/source/blender/blenkernel/intern/pbvh_pixels.cc
@@ -243,6 +243,8 @@ static void split_pixel_node(PBVH *pbvh,
 BKE_image_release_ibuf(image, image_buffer, nullptr);
   }
 
+  data.undo_regions.clear();
+
   if (node->flag & PBVH_Leaf) {
 data.clear_data();
   }
@@ -250,8 +252,6 @@ static void split_pixel_node(PBVH *pbvh,
 pbvh_pixels_free(node);
   }
 
-  data.undo_regions.clear();
-
   BLI_thread_queue_push(tdata->new_nodes, static_cast(split1));
   BLI_thread_queue_push(tdata->new_nodes, static_cast(split2));
 
@@ -481,7 +481,7 @@ static void do_encode_pixels(void *__restrict userdata,
 
 static bool should_pixels_be_updated(PBVHNode *node)
 {
-  if ((node->flag & PBVH_Leaf) == 0) {
+  if ((node->flag & (PBVH_Leaf|PBVH_TexLeaf)) == 0) {
 return false;
   }
   if (node->children_offset != 0) {
diff --git a/source/blender/draw/intern/draw_shader_shared.h 
b/source/blender/draw/intern/draw_shader_shared.h
index 75a7e28fa75..9348f8748e7 100644
--- a/source/blender/draw/intern/draw_shader_shared.h
+++ b/source/blender/draw/intern/draw_shader_shared.h
@@ -292,7 +292,7 @@ struct DRWDebugVert {
 BLI_STATIC_ASSERT_ALIGN(DRWDebugVert, 16)
 
 /* Take the header (DrawCommand) into account. */
-#define DRW_DEBUG_DRAW_VERT_MAX (64 * 1024) - 1
+#define DRW_DEBUG_DRAW_VERT_MAX (64 * 8192) - 1
 
 /* The debug draw buffer is laid-out as the following struct.
  * But we use plain array in shader code instead because of driver issues. */
diff --git a/source/blender/editors/sculpt_paint/sculpt.c 
b/source/blender/editors/sculpt_paint/sculpt.c
index 37a630b8065..af6afdd1d6e 100644
--- a/source/blender/editors/sculpt_paint/sculpt.c
+++ b/source/blender/editors/sculpt_paint/sculpt.c
@@ -3368,6 +3368,7 @@ static void do_brush_action(Sculpt *sd,
 
   const bool use_original = sculpt_tool_needs_original(brush->sculpt_tool) ? 
true :
  
ss->cache->original;
+  const bool use_pixels = sculpt_needs_pbvh_pixels(paint_mode_settings, brush, 
ob);
 
   if (sculpt_needs_pbvh_pixels(paint_mode_settings, brush, ob)) {
 sculpt_pbvh_update_pixels(paint_mode_settings, ss, ob);
@@ -3404,11 +3405,6 @@ static void do_brush_action(Sculpt *sd,
 nodes = sculpt_pbvh_gather_generic(ob, sd, brush, use_original, 
radius_scale, &totnode);
   }
 
-  const bool use_pixels = sculpt_needs_pbvh_pixels(paint_mode_settings, brush, 
ob);
-  if (use_pixels) {
-sculpt_pbvh_update_pixels(paint_mode_settings, ss, ob);
-  }
-
   /* Draw Face Sets in draw mode makes a single undo push, in alt-smooth mode 
deforms the
* vertices and uses regular coords undo. */
   /* It also assigns the paint_face_set here as it needs to be done regardless 
of the stroke type

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs


[Bf-blender-cvs] [aa1f2f243dd] temp-pbvh-split: Merge branch 'master' into temp-pbvh-split

2022-10-15 Thread Joseph Eagar
Commit: aa1f2f243ddb7ed340856ddf97ec650407ad386b
Author: Joseph Eagar
Date:   Fri Oct 14 23:22:01 2022 -0700
Branches: temp-pbvh-split
https://developer.blender.org/rBaa1f2f243ddb7ed340856ddf97ec650407ad386b

Merge branch 'master' into temp-pbvh-split

===



===

diff --cc source/blender/blenkernel/BKE_pbvh.h
index 6d103eab8a7,42cd1536dcf..c3100dd2345
--- a/source/blender/blenkernel/BKE_pbvh.h
+++ b/source/blender/blenkernel/BKE_pbvh.h
@@@ -125,7 -125,8 +125,9 @@@ typedef enum 
PBVH_UpdateTopology = 1 << 13,
PBVH_UpdateColor = 1 << 14,
PBVH_RebuildPixels = 1 << 15,
 -  PBVH_TopologyUpdated = 1 << 16, /* Used internally by pbvh_bmesh.c */
 +  PBVH_TexLeaf = 1 << 16,
++  PBVH_TopologyUpdated = 1 << 17, /* Used internally by pbvh_bmesh.c */
+ 
  } PBVHNodeFlags;
  
  typedef struct PBVHFrustumPlanes {

___
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
List details, subscription details or unsubscribe:
https://lists.blender.org/mailman/listinfo/bf-blender-cvs