Skip to content

Commit

Permalink
fixed glitch on npBrushSmooth() with negative strength
Browse files Browse the repository at this point in the history
  • Loading branch information
i-saint committed Jul 19, 2017
1 parent 4b3dd14 commit 872514a
Showing 1 changed file with 16 additions and 15 deletions.
31 changes: 16 additions & 15 deletions Plugin/NormalPainter/NormalPainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -863,12 +863,13 @@ npAPI int npBrushReplace(
{
auto normals = model->normals;
auto selection = model->selection;
auto sign = strength < 0.0f ? -1.0f : 1.0f;

return SelectInside(*model, pos, radius, [&](int vi, float d, float3 p) {
float s = GetBrushSample(d, radius, bsamples, num_bsamples) * strength;
float s = GetBrushSample(d, radius, bsamples, num_bsamples) * abs(strength);
if (mask) s *= selection[vi];

normals[vi] = normalize(normals[vi] + value * s);
normals[vi] = normalize(normals[vi] + value * (s * sign));
}, true);
return 0;
}
Expand All @@ -879,13 +880,14 @@ npAPI int npBrushPaint(
{
auto normals = model->normals;
auto selection = model->selection;
auto sign = strength < 0.0f ? -1.0f : 1.0f;

float3 ln = n;
n = normalize(mul_v(model->transform, n));
auto itrans = invert(model->transform);
return SelectInside(*model, pos, radius, [&](int vi, float d, float3 p) {
int bsi = GetBrushSampleIndex(d, radius, num_bsamples);
float s = saturate(bsamples[bsi] * strength * 2.0f);
float s = saturate(bsamples[bsi] * abs(strength) * 2.0f);
if (mask) s *= selection[vi];

float slope;
Expand All @@ -909,13 +911,9 @@ npAPI int npBrushPaint(
t *= -1.0f;
slope *= -1.0f;
}
if (s < 0.0f) {
t *= -1.0f;
s *= -1.0f;
}

float3 vn = normals[vi];
float3 r = lerp(n, t, clamp01(slope * 0.5f));
float3 r = lerp(n, t * sign, clamp01(slope * 0.5f));
r = normalize(mul_v(itrans, r));

// maybe add something here later
Expand All @@ -933,13 +931,13 @@ npAPI int npBrushLerp(
{
auto normals = model->normals;
auto selection = model->selection;
auto sign = strength < 0.0f ? -1.0f : 1.0f;

return SelectInside(*model, pos, radius, [&](int vi, float d, float3 p) {
float s = GetBrushSample(d, radius, bsamples, num_bsamples) * strength;
float s = GetBrushSample(d, radius, bsamples, num_bsamples) * abs(strength);
if (mask) s *= selection[vi];

float sign = strength < 0.0f ? -1.0f : 1.0f;
normals[vi] = normalize(lerp(n1[vi], n0[vi] * sign, abs(s)));
normals[vi] = normalize(lerp(n1[vi], n0[vi] * sign, s));
}, true);
}

Expand All @@ -960,8 +958,10 @@ npAPI int npBrushSmooth(
average += normals[p.first];
}
average = normalize(average);

for (auto& p : inside) {
float s = GetBrushSample(p.second, radius, bsamples, num_bsamples) * strength;
// ignore sign of strength
float s = GetBrushSample(p.second, radius, bsamples, num_bsamples) * abs(strength);
if (mask) s *= selection[p.first];

normals[p.first] = normalize(normals[p.first] + average * s);
Expand Down Expand Up @@ -990,8 +990,10 @@ inline int BrushProjectionImpl(
pvertices[vi] = mul_p(to_local, normal_source->vertices[vi]);
}

auto sign = strength < 0.0f ? -1.0f : 1.0f;

return SelectInside(*model, pos, radius, [&](int vi, float d, float3 p) {
float s = GetBrushSample(d, radius, bsamples, num_bsamples) * strength;
float s = GetBrushSample(d, radius, bsamples, num_bsamples) * abs(strength);
if (mask) s *= selection[vi];

float3 rpos = vertices[vi];
Expand All @@ -1011,8 +1013,7 @@ inline int BrushProjectionImpl(
pnormals[pindices[ti * 3 + 2]]);

result = normalize(mul_v(to_local, result));
float sign = strength < 0.0f ? -1.0f : 1.0f;
normals[vi] = normalize(lerp(normals[vi], result * sign, abs(s)));
normals[vi] = normalize(lerp(normals[vi], result * sign, s));
}
}, true);
}
Expand Down

0 comments on commit 872514a

Please sign in to comment.