Fix: Dilate node clamps negative values on GPU

The Dilate node clamps negative values on GPU but works fine on CPU.
This is because the minimum value was used as FLT_MIN, but it should
actually be -FLT_MAX.

Pull Request: https://projects.blender.org/blender/blender/pulls/141144
This commit is contained in:
Tenkai Raiko
2025-06-30 18:35:10 +02:00
committed by Omar Emara
parent fe346a32ec
commit 8efcc0475d
4 changed files with 4 additions and 4 deletions

View File

@@ -22,7 +22,7 @@ void main()
* larger than the given radius are skipped and not considered. Consequently, the dilation or
* erosion that take place produces round results as opposed to squarish ones. This is
* essentially a morphological operator with a circular structuring element. The LIMIT value
* should be FLT_MAX if OPERATOR is min and FLT_MIN if OPERATOR is max. */
* should be FLT_MAX if OPERATOR is min and -FLT_MAX if OPERATOR is max. */
float value = LIMIT;
for (int y = start.y; y < end.y; y++) {
int yy = y * y;

View File

@@ -11,7 +11,7 @@ void main()
/* Find the minimum/maximum value in the window of the given radius around the pixel. This is
* essentially a morphological operator with a square structuring element. The LIMIT value should
* be FLT_MAX if OPERATOR is min and FLT_MIN if OPERATOR is max. */
* be FLT_MAX if OPERATOR is min and -FLT_MAX if OPERATOR is max. */
float value = LIMIT;
for (int i = -radius; i <= radius; i++) {
value = OPERATOR(value, texture_load(input_tx, texel + int2(i, 0), float4(LIMIT)).x);

View File

@@ -15,7 +15,7 @@ GPU_SHADER_CREATE_END()
GPU_SHADER_CREATE_INFO(compositor_morphological_distance_dilate)
ADDITIONAL_INFO(compositor_morphological_distance_shared)
DEFINE_VALUE("OPERATOR(a, b)", "max(a, b)")
DEFINE_VALUE("LIMIT", "FLT_MIN")
DEFINE_VALUE("LIMIT", "-FLT_MAX")
DO_STATIC_COMPILATION()
GPU_SHADER_CREATE_END()

View File

@@ -15,7 +15,7 @@ GPU_SHADER_CREATE_END()
GPU_SHADER_CREATE_INFO(compositor_morphological_step_dilate)
ADDITIONAL_INFO(compositor_morphological_step_shared)
DEFINE_VALUE("OPERATOR(a, b)", "max(a, b)")
DEFINE_VALUE("LIMIT", "FLT_MIN")
DEFINE_VALUE("LIMIT", "-FLT_MAX")
DO_STATIC_COMPILATION()
GPU_SHADER_CREATE_END()