diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-05-13 11:04:46 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-05-13 11:04:46 +0300 |
commit | a050d6063c78004de8b4b5945cb03bb43d84c8de (patch) | |
tree | 052e79fdb4f54fcb4876543f4a67b12365959056 /source/blender/blenlib | |
parent | 3e782756e386d036edce24d11ee092695b283cda (diff) |
Project Paint: resolve ugly bleed artifacts
Use the bilinear reverse to find the pixel to bleed from.
Was using pixel space which didn't work well.
Diffstat (limited to 'source/blender/blenlib')
-rw-r--r-- | source/blender/blenlib/BLI_math_geom.h | 1 | ||||
-rw-r--r-- | source/blender/blenlib/intern/math_geom.c | 37 |
2 files changed, 38 insertions, 0 deletions
diff --git a/source/blender/blenlib/BLI_math_geom.h b/source/blender/blenlib/BLI_math_geom.h index 4f7a3310ee6..4a75e83316e 100644 --- a/source/blender/blenlib/BLI_math_geom.h +++ b/source/blender/blenlib/BLI_math_geom.h @@ -259,6 +259,7 @@ void resolve_tri_uv_v3(float r_uv[2], const float st[3], const float st0[3], con void resolve_quad_uv_v2(float r_uv[2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]); void resolve_quad_uv_v2_deriv(float r_uv[2], float r_deriv[2][2], const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]); +float resolve_quad_u_v2(const float st[2], const float st0[2], const float st1[2], const float st2[2], const float st3[2]); /* use to find the point of a UV on a face */ void interp_bilinear_quad_v3(float data[4][3], float u, float v, float res[3]); diff --git a/source/blender/blenlib/intern/math_geom.c b/source/blender/blenlib/intern/math_geom.c index ba1f4480659..82062e80ae8 100644 --- a/source/blender/blenlib/intern/math_geom.c +++ b/source/blender/blenlib/intern/math_geom.c @@ -3101,6 +3101,43 @@ void resolve_quad_uv_v2_deriv(float r_uv[2], float r_deriv[2][2], } } +/* a version of resolve_quad_uv_v2 that only calculates the 'u' */ +float resolve_quad_u_v2( + const float st[2], + const float st0[2], const float st1[2], const float st2[2], const float st3[2]) +{ + const double signed_area = (st0[0] * st1[1] - st0[1] * st1[0]) + (st1[0] * st2[1] - st1[1] * st2[0]) + + (st2[0] * st3[1] - st2[1] * st3[0]) + (st3[0] * st0[1] - st3[1] * st0[0]); + + /* X is 2D cross product (determinant) + * A = (p0 - p) X (p0 - p3)*/ + const double a = (st0[0] - st[0]) * (st0[1] - st3[1]) - (st0[1] - st[1]) * (st0[0] - st3[0]); + + /* B = ( (p0 - p) X (p1 - p2) + (p1 - p) X (p0 - p3) ) / 2 */ + const double b = 0.5 * (double)(((st0[0] - st[0]) * (st1[1] - st2[1]) - (st0[1] - st[1]) * (st1[0] - st2[0])) + + ((st1[0] - st[0]) * (st0[1] - st3[1]) - (st1[1] - st[1]) * (st0[0] - st3[0]))); + + /* C = (p1-p) X (p1-p2) */ + const double fC = (st1[0] - st[0]) * (st1[1] - st2[1]) - (st1[1] - st[1]) * (st1[0] - st2[0]); + double denom = a - 2 * b + fC; + + if (IS_ZERO(denom) != 0) { + const double fDen = a - fC; + if (IS_ZERO(fDen) == 0) + return (float)(a / fDen); + else + return 0.0f; + } + else { + const double desc_sq = b * b - a * fC; + const double desc = sqrt(desc_sq < 0.0 ? 0.0 : desc_sq); + const double s = signed_area > 0 ? (-1.0) : 1.0; + + return (float)(((a - b) + s * desc) / denom); + } +} + + #undef IS_ZERO /* reverse of the functions above */ |