thebookofshaders/glossary/clamp.md
Patricio Gonzalez Vivo 2c96f43dcf adding more functions
2015-04-17 14:16:45 -04:00

969 B

Clamp

Constrain a value to lie between two further values

float clamp(float x, float minVal, float maxVal)  
vec2 clamp(vec2 x, vec2 minVal, vec2 maxVal)  
vec3 clamp(vec3 x, vec3 minVal, vec3 maxVal)  
vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal)
vec2 clamp(vec2 x, float minVal, float maxVal)  
vec3 clamp(vec3 x, float minVal, float maxVal)  
vec4 clamp(vec4 x, float minVal, float maxVal) 

Parameters

x Specify the value to constrain.

minVal Specify the lower end of the range into which to constrain x.

maxVal Specify the upper end of the range into which to constrain x.

Description

clamp() returns the value of x constrained to the range minVal to maxVal. The returned value is computed as min(max(x, minVal), maxVal).

See Also

min, abs, max