Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Jolly <charlie>2021-11-02 18:58:13 +0300
committerCharlie Jolly <mistajolly@gmail.com>2021-11-02 18:58:17 +0300
commit6981bee2c77f826570df36e9e7cf90adfae4d409 (patch)
tree9a9f33c0cd1e1276f21afd3996424540667fc06d
parent89c9fa8b737e07c84c1ff35919d211699592e6b5 (diff)
Fix T92736: Hole in mesh after Set Position
The geometry node port of voronoi_smooth_f1 function has a division by zero when smoothness is set to zero. Using a safe_divide within the function causes issues and was noted in the original patch D12725. Solution in this case is to clamp zero smoothness to FLT_EPSILON. Reviewed By: JacquesLucke Maniphest Tasks: T92736 Differential Revision: https://developer.blender.org/D13069
-rw-r--r--source/blender/blenlib/intern/noise.cc12
1 files changed, 8 insertions, 4 deletions
diff --git a/source/blender/blenlib/intern/noise.cc b/source/blender/blenlib/intern/noise.cc
index 4259237af6e..bc78ded63a0 100644
--- a/source/blender/blenlib/intern/noise.cc
+++ b/source/blender/blenlib/intern/noise.cc
@@ -1548,6 +1548,7 @@ void voronoi_smooth_f1(const float w,
{
const float cellPosition = floorf(w);
const float localPosition = w - cellPosition;
+ const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
float smoothDistance = 8.0f;
float smoothPosition = 0.0f;
@@ -1558,7 +1559,7 @@ void voronoi_smooth_f1(const float w,
hash_float_to_float(cellPosition + cellOffset) * randomness;
const float distanceToPoint = voronoi_distance(pointPosition, localPosition);
const float h = smoothstep(
- 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
+ 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness_clamped);
float correctionFactor = smoothness * h * (1.0f - h);
smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
if (r_color != nullptr || r_w != nullptr) {
@@ -1752,6 +1753,7 @@ void voronoi_smooth_f1(const float2 coord,
{
const float2 cellPosition = float2::floor(coord);
const float2 localPosition = coord - cellPosition;
+ const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
float smoothDistance = 8.0f;
float3 smoothColor = float3(0.0f, 0.0f, 0.0f);
@@ -1764,7 +1766,7 @@ void voronoi_smooth_f1(const float2 coord,
const float distanceToPoint = voronoi_distance(
pointPosition, localPosition, metric, exponent);
const float h = smoothstep(
- 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
+ 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness_clamped);
float correctionFactor = smoothness * h * (1.0f - h);
smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
if (r_color != nullptr || r_position != nullptr) {
@@ -1999,6 +2001,7 @@ void voronoi_smooth_f1(const float3 coord,
{
const float3 cellPosition = float3::floor(coord);
const float3 localPosition = coord - cellPosition;
+ const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
float smoothDistance = 8.0f;
float3 smoothColor = float3(0.0f, 0.0f, 0.0f);
@@ -2012,7 +2015,7 @@ void voronoi_smooth_f1(const float3 coord,
const float distanceToPoint = voronoi_distance(
pointPosition, localPosition, metric, exponent);
const float h = smoothstep(
- 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
+ 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness_clamped);
float correctionFactor = smoothness * h * (1.0f - h);
smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
if (r_color != nullptr || r_position != nullptr) {
@@ -2262,6 +2265,7 @@ void voronoi_smooth_f1(const float4 coord,
{
const float4 cellPosition = float4::floor(coord);
const float4 localPosition = coord - cellPosition;
+ const float smoothness_clamped = max_ff(smoothness, FLT_MIN);
float smoothDistance = 8.0f;
float3 smoothColor = float3(0.0f, 0.0f, 0.0f);
@@ -2277,7 +2281,7 @@ void voronoi_smooth_f1(const float4 coord,
const float distanceToPoint = voronoi_distance(
pointPosition, localPosition, metric, exponent);
const float h = smoothstep(
- 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness);
+ 0.0f, 1.0f, 0.5f + 0.5f * (smoothDistance - distanceToPoint) / smoothness_clamped);
float correctionFactor = smoothness * h * (1.0f - h);
smoothDistance = mix(smoothDistance, distanceToPoint, h) - correctionFactor;
if (r_color != nullptr || r_position != nullptr) {