From b481e886e5ad4c4ab6f1118f80933a4bf558c61e Mon Sep 17 00:00:00 2001 From: Alexander Gavrilov Date: Mon, 18 Apr 2016 18:47:16 +0300 Subject: Cloth: Use Geometrical Mean for averaging cloth shrink factor. This comes out of considering a one-dimensional transition in weight on a rectangular cloth grid. At the transition face loop, one side of each rectangular face would be scaled by k1, and the opposite one by k2, thus turning the rectangle into a trapezoid. Averaging would be used to choose the scale factor for the remaining two sides. If Geometrical Mean, i.e. sqrt(k1*k2) is used, it so happens that the diagonals of the trapezoid also end up scaled by sqrt(k1*k2) compared to the original rectangle. This means that the same scale factor is correct for both structural and shear springs, which is not the case with simple average. --- source/blender/blenkernel/intern/cloth.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source/blender/blenkernel/intern/cloth.c') diff --git a/source/blender/blenkernel/intern/cloth.c b/source/blender/blenkernel/intern/cloth.c index 137b6a3d599..d0796db6b54 100644 --- a/source/blender/blenkernel/intern/cloth.c +++ b/source/blender/blenkernel/intern/cloth.c @@ -747,7 +747,12 @@ static float cloth_shrink_factor(ClothModifierData *clmd, ClothVertex *verts, in float base = 1.0f - clmd->sim_parms->shrink_min; float delta = clmd->sim_parms->shrink_min - clmd->sim_parms->shrink_max; - return base + delta * 0.5f * (verts[i1].shrink_factor + verts[i2].shrink_factor); + float k1 = base + delta * verts[i1].shrink_factor; + float k2 = base + delta * verts[i2].shrink_factor; + + /* Use geometrical mean to average two factors since it behaves better + for diagonals when a rectangle transforms into a trapezoid. */ + return sqrtf(k1 * k2); } else return 1.0f; -- cgit v1.2.3