thebookofshaders/glossary/clamp/README.md

30 lines
985 B
Markdown
Raw Normal View History

2015-04-17 18:16:45 +00:00
## Clamp
Constrain a value to lie between two further values
2015-04-18 14:41:34 +00:00
### Declaration
2015-04-17 18:16:45 +00:00
```glsl
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)
2017-08-19 10:11:58 +00:00
vec4 clamp(vec4 x, float minVal, float maxVal)
2015-04-17 18:16:45 +00:00
```
### Parameters
2015-04-18 14:41:34 +00:00
```x``` specify the value to constrain.
2015-04-17 18:16:45 +00:00
2015-04-18 14:41:34 +00:00
```minVal``` specify the lower end of the range into which to constrain x.
2015-04-17 18:16:45 +00:00
2015-04-18 14:41:34 +00:00
```maxVal``` specify the upper end of the range into which to constrain x.
2015-04-17 18:16:45 +00:00
### 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)```.
<div class="simpleFunction" data="y = clamp(x,0.,1.); "></div>
### See Also
2017-08-19 10:11:58 +00:00
[min](/glossary/?search=min), [abs](/glossary/?search=abs), [max](/glossary/?search=max)