Fix #146886: Zero division in Distance Key node

Pull Request: https://projects.blender.org/blender/blender/pulls/147550
This commit is contained in:
Omar Emara
2025-10-07 17:22:36 +02:00
committed by Omar Emara
parent a113121562
commit 7d99ac26cc
2 changed files with 4 additions and 2 deletions

View File

@@ -3,6 +3,7 @@
* SPDX-License-Identifier: GPL-2.0-or-later */
#include "gpu_shader_common_color_utils.glsl"
#include "gpu_shader_math_safe_lib.glsl"
#define CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_RGBA 0
#define CMP_NODE_DISTANCE_MATTE_COLOR_SPACE_YCCA 1
@@ -30,7 +31,7 @@ void node_composite_distance_matte(const float4 color,
float difference = distance(color_vector.xyz(), key_vector.xyz());
bool is_opaque = difference > tolerance + falloff;
float alpha = is_opaque ? color.w : max(0.0f, difference - tolerance) / falloff;
float alpha = is_opaque ? color.w : safe_divide(max(0.0f, difference - tolerance), falloff);
matte = min(alpha, color.w);
result = color * matte;
}

View File

@@ -105,7 +105,8 @@ static void distance_key(const float4 color,
float difference = math::distance(color_vector.xyz(), key_vector.xyz());
bool is_opaque = difference > tolerance + falloff;
float alpha = is_opaque ? color.w : math::max(0.0f, difference - tolerance) / falloff;
float alpha = is_opaque ? color.w :
math::safe_divide(math::max(0.0f, difference - tolerance), falloff);
matte = math::min(alpha, color.w);
result = color * matte;
}