This repository has been archived on 2023-10-09. You can view files and clone it, but cannot push or open issues or pull requests.
Files
blender-archive/source/blender/gpu/shaders/material/gpu_shader_material_clamp.glsl
Jeroen Bakker fe5d2448c6 Fix T83494: Eevee clamp node incorrect when min > max.
In glsl the clamp function has undefined behavior when min > max. For
the clamp node this resulted in differences between cycles and eevee.
This patch adds the expected implementation for minmax.

The old clamp function is still used in cases where we know for certain
that the input values are correct (math node clamp option). GPU uses
optimized code and silicon in these cases.
2020-12-18 10:26:02 +01:00

15 lines
404 B
GLSL

void clamp_value(float value, float min, float max, out float result)
{
result = clamp(value, min, max);
}
void clamp_minmax(float value, float min_allowed, float max_allowed, out float result)
{
result = min(max(value, min_allowed), max_allowed);
}
void clamp_range(float value, float min, float max, out float result)
{
result = (max > min) ? clamp(value, min, max) : clamp(value, max, min);
}