adding more functions
parent
28f372e311
commit
2c96f43dcf
@ -0,0 +1,20 @@
|
|||||||
|
## Ceil
|
||||||
|
Find the nearest integer that is greater than or equal to the parameter
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float ceil(float x)
|
||||||
|
vec2 ceil(vec2 x)
|
||||||
|
vec3 ceil(vec3 x)
|
||||||
|
vec4 ceil(vec4 x)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```x``` Specify the value to evaluate.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```ceil()``` returns a value equal to the nearest integer that is greater than or equal to ```x```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = ceil(x); "></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[floor](index.html#floor.md), [fract](index.html#fract.md), [mod](index.html#mod.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,30 @@
|
|||||||
|
## Clamp
|
||||||
|
Constrain a value to lie between two further values
|
||||||
|
|
||||||
|
```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)
|
||||||
|
```
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
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)```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = clamp(x,0.,1.); "></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[min](index.html#min.md), [abs](index.html#abs.md), [max](index.html#max.md)
|
@ -0,0 +1,20 @@
|
|||||||
|
## Fract
|
||||||
|
Compute the fractional part of the argument
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float fract(float x)
|
||||||
|
vec2 fract(vec2 x)
|
||||||
|
vec3 fract(vec3 x)
|
||||||
|
vec4 fract(vec4 x)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```x``` Specify the value to evaluate.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```fract()``` returns the fractional part of ```x```. This is calculated as ```x - floor(x)```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = fract(x); "></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[floor](index.html#floor.md), [ceil](index.html#ceil.md), [mod](index.html#mod.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,28 @@
|
|||||||
|
## Max
|
||||||
|
Return the greater of two values
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float max(float x, float y)
|
||||||
|
vec2 max(vec2 x, vec2 y)
|
||||||
|
vec3 max(vec3 x, vec3 y)
|
||||||
|
vec4 max(vec4 x, vec4 y)
|
||||||
|
```
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
vec2 max(vec2 x, float y)
|
||||||
|
vec3 max(vec3 x, float y)
|
||||||
|
vec4 max(vec4 x, float y)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```x``` Specify the first value to compare.
|
||||||
|
|
||||||
|
```y``` Specify the second value to compare.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```max()``` returns the maximum of the two parameters. It returns ```y``` if ```y``` is greater than ```x```, otherwise it returns ```x```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = max(x,0.5); "></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[min](index.html#min.md), [abs](index.html#abs.md), [clamp](index.html#clamp.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,28 @@
|
|||||||
|
## Min
|
||||||
|
Return the lesser of two values
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float min(float x, float y)
|
||||||
|
vec2 min(vec2 x, vec2 y)
|
||||||
|
vec3 min(vec3 x, vec3 y)
|
||||||
|
vec4 min(vec4 x, vec4 y)
|
||||||
|
```
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
vec2 min(vec2 x, float y)
|
||||||
|
vec3 min(vec3 x, float y)
|
||||||
|
vec4 min(vec4 x, float y)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```x``` Specify the first value to compare.
|
||||||
|
|
||||||
|
```y``` Specify the second value to compare.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```min()``` returns the minimum of the two parameters. It returns ```y``` if ```y``` is less than ```x```, otherwise it returns ```x```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = min(x,0.5); "></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[max](index.html#max.md), [abs](index.html#abs.md), [clamp](index.html#clamp.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,27 @@
|
|||||||
|
## Mod
|
||||||
|
Compute value of one parameter modulo another
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float mod(float x, float y)
|
||||||
|
vec2 mod(vec2 x, vec2 y)
|
||||||
|
vec3 mod(vec3 x, vec3 y)
|
||||||
|
vec4 mod(vec4 x, vec4 y)
|
||||||
|
```
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
vec2 mod(vec2 x, float y)
|
||||||
|
vec3 mod(vec3 x, float y)
|
||||||
|
vec4 mod(vec4 x, float y)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```x``` Specify the value to evaluate.
|
||||||
|
```y``` Specify the value to obtain the modulo of.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```mod()``` returns the value of ```x``` modulo ```y```. This is computed as ```x - y * floor(x/y)```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = mod(x,1.5); "></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[floor](index.html#floor.md), [fract](index.html#fract.md), [ceil](index.html#ceil.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,39 @@
|
|||||||
|
## Smoothstep
|
||||||
|
Perform Hermite interpolation between two values
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float smoothstep(float edge0, float edge1, float x)
|
||||||
|
vec2 smoothstep(vec2 edge0, vec2 edge1, vec2 x)
|
||||||
|
vec3 smoothstep(vec3 edge0, vec3 edge1, vec3 x)
|
||||||
|
vec4 smoothstep(vec4 edge0, vec4 edge1, vec4 x)
|
||||||
|
```
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
vec2 smoothstep(float edge0, float edge1, vec2 x)
|
||||||
|
vec3 smoothstep(float edge0, float edge1, vec3 x)
|
||||||
|
vec4 smoothstep(float edge0, float edge1, vec4 x)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```edge0``` Specifies the value of the lower edge of the Hermite function.
|
||||||
|
|
||||||
|
```edge1``` Specifies the value of the upper edge of the Hermite function.
|
||||||
|
|
||||||
|
```x``` Specifies the source value for interpolation.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```smoothstep()``` performs smooth Hermite interpolation between ```0``` and ```1``` when ```edge0 < x < edge1```. This is useful in cases where a threshold function with a smooth transition is desired. ```smoothstep()``` is equivalent to:
|
||||||
|
```glsl
|
||||||
|
genType t; /* Or genDType t; */
|
||||||
|
t = clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
|
||||||
|
return t * t * (3.0 - 2.0 * t);
|
||||||
|
```
|
||||||
|
|
||||||
|
Results are undefined ```if edge0 ≥ edge1```.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = smoothstep(0.0,1.0,x); "></div>
|
||||||
|
|
||||||
|
<div class="codeAndCanvas" data="../05/smoothstep.frag"></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[mix](index.html#mix.md), [step](index.html#step.md), [Chapter 05: Shaping Functions](../05/)
|
@ -0,0 +1,32 @@
|
|||||||
|
## Step
|
||||||
|
Generate a step function by comparing two values
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
float step(float edge, float x)
|
||||||
|
vec2 step(vec2 edge, vec2 x)
|
||||||
|
vec3 step(vec3 edge, vec3 x)
|
||||||
|
vec4 step(vec4 edge, vec4 x)
|
||||||
|
```
|
||||||
|
|
||||||
|
```glsl
|
||||||
|
vec2 step(float edge, vec2 x)
|
||||||
|
vec3 step(float edge, vec3 x)
|
||||||
|
vec4 step(float edge, vec4 x)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Parameters
|
||||||
|
```edge``` Specifies the location of the edge of the step function.
|
||||||
|
|
||||||
|
```x``` Specify the value to be used to generate the step function.
|
||||||
|
|
||||||
|
### Description
|
||||||
|
```step()``` generates a step function by comparing ```x``` to ```edge```.
|
||||||
|
|
||||||
|
For element ```i``` of the return value, ```0.0``` is returned ```if x[i] < edge[i]```, and ```1.0``` is returned otherwise.
|
||||||
|
|
||||||
|
<div class="simpleFunction" data="y = step(0.5,x); "></div>
|
||||||
|
|
||||||
|
<div class="codeAndCanvas" data="../05/step.frag"></div>
|
||||||
|
|
||||||
|
### See Also
|
||||||
|
[mix](index.html#mix.md), [smoothstep](index.html#smoothstep.md), [Chapter 05: Shaping Functions](../05/)
|
Loading…
Reference in New Issue