diff --git a/edition/voxel_tool.cpp b/edition/voxel_tool.cpp index 26adbfa1..5e89db84 100644 --- a/edition/voxel_tool.cpp +++ b/edition/voxel_tool.cpp @@ -161,7 +161,7 @@ inline float sdf_blend(float src_value, float dst_value, VoxelTool::Mode mode) { case VoxelTool::MODE_REMOVE: // Relative complement (or difference) - res = sdf_subtract(src_value, dst_value); + res = sdf_subtract(dst_value, src_value); break; case VoxelTool::MODE_SET: diff --git a/generators/graph/range_utility.h b/generators/graph/range_utility.h index 93425e6c..a293ab08 100644 --- a/generators/graph/range_utility.h +++ b/generators/graph/range_utility.h @@ -24,7 +24,7 @@ inline Interval sdf_union(Interval a, Interval b) { // Does a - b inline Interval sdf_subtract(Interval a, Interval b) { - return max_interval(a, b); + return max_interval(a, -b); } Interval sdf_smooth_union(Interval p_b, Interval p_a, float p_s); diff --git a/util/math/sdf.h b/util/math/sdf.h index 818bb877..63f9665d 100644 --- a/util/math/sdf.h +++ b/util/math/sdf.h @@ -38,9 +38,9 @@ inline float sdf_union(float a, float b) { return min(a, b); } -// Subtracts SDF a from SDF b +// Subtracts SDF b from SDF a inline float sdf_subtract(float a, float b) { - return max(-a, b); + return max(a, -b); } inline float sdf_smooth_union(float a, float b, float s) { @@ -48,7 +48,7 @@ inline float sdf_smooth_union(float a, float b, float s) { return Math::lerp(b, a, h) - s * h * (1.0f - h); } -// Inverted a and b because it subtracts SDF b from SDF a +// Inverted a and b because it subtracts SDF a from SDF b inline float sdf_smooth_subtract(float b, float a, float s) { float h = clamp(0.5f - 0.5f * (b + a) / s, 0.0f, 1.0f); return Math::lerp(b, -a, h) + s * h * (1.0f - h);