Page MenuHome

Fix T74354: Avoid division by 0 when calculating hardness
ClosedPublic

Authored by Pablo Dobarro (pablodp606) on Mar 2 2020, 11:45 AM.

Details

Summary

I could not reproduce the issue, but it looks like it was produced by
this division by 0. In any case, the code here was wrong.

Diff Detail

Repository
rB Blender
Branch
T74354 (branched from master)
Build Status
Buildable 6869
Build 6869: arc lint + arc unit

Event Timeline

This will give a hard cut-over between 0.9999 and 1.0. Perhaps better to max the hardness to 0.9999

I was trying to avoid doing that to avoid future confusion in the UI when we allow mapping this property to pen pressure or tilt. I think all brush properties should have all the 0 - 1 range available by default.

I didn't expect to change the UI Property. That can still be from 0-1. Just in the code to make sure that the formular doesn't have any hard cut-overs.
I would expect something like the next snippit would mitigate the hard cutover.

else {
    float clamped_hardness = MIN2(hardness, 0.9999);
    p = (p - clamped_hardness) / (1.0f - clamped_hardness);
    final_len = p * cache->radius;
}

I don't see any issue approving the current patch. It could be a good exercise to see how all the curve functions act and where we can improve.

This revision is now accepted and ready to land.Mar 9 2020, 1:36 PM

@Jeroen Bakker (jbakker) I commited the fix as it was in the patch, I hope it does not cause any problems. For sculpt mode we could probably implement you solution, but for texture/vertex painting the hard cut in the hardness function is important. If hardness is set to 1, the function should only output 0 or 1, if it outputs something else it will cause artifacts in some brushes.