Fix order of SDF arguments

master
Marc Gilleron 2021-04-07 00:05:38 +01:00
parent bcba1a8c0f
commit 2c6eb114b2
3 changed files with 5 additions and 5 deletions

View File

@ -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:

View File

@ -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);

View File

@ -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);