Common Functions
2013-03-05 18:22 三戒1993 阅读(124) 评论(0) 编辑 收藏 举报describes the built-in common functions. These functions can be used within vertex and fragment shaders. These functions operate component-wise.
Syntax | Description |
---|---|
float abs (float x) vec2 abs (vec2 x) vec3 abs (vec3 x) vec4 abs (vec4 x) |
Returns x if x >= 0, otherwise it returns – x. |
float sign (float x) vec2 sign (vec2 x) vec3 sign (vec3 x) vec4 sign (vec4 x) |
Returns 1.0 if x > 0, 0.0 if x = 0, or – 1.0 if x < 0. |
float floor (float x) vec2 floor (vec2 x) vec3 floor (vec3 x) vec4 floor (vec4 x) |
Returns a value equal to the nearest integer that is less than or equal to x. |
float ceil (float x) vec2 ceil (vec2 x) vec3 ceil (vec3 x) vec4 ceil (vec4 x) |
Returns a value equal to the nearest integer that is greater than or equal to x. |
float fract (float x) vec2 fract (vec2 x) vec3 fract (vec3 x) vec4 fract (vec4 x) |
Returns x – floor (x). |
float mod (float x, float y) vec2 mod (vec2 x, vec2 y) vec3 mod (vec3 x, vec3 y) vec4 mod (vec4 x, vec4 y) |
Modulus (modulo). Returns x – y * floor (x/y). |
float mod (float x, float y) vec2 mod (vec2 x, float y) vec3 mod (vec3 x, float y) vec4 mod (vec4 x, float y) |
Modulus (modulo). Returns x – y * floor(x/y). |
float min (float x, float y) vec2 min (vec2 x, vec2 y) vec3 min (vec3 x, vec3 y) vec4 min (vec4 x, vec4 y) |
Returns y if y < x, otherwise it returns x. |
float min (float x, float y) vec2 min (vec2 x, float y) vec3 min (vec3 x, float y) vec4 min (vec4 x, float y) |
Returns y if y < x, otherwise it returns x. |
float max (float x, float y) vec2 max (vec2 x, vec2 y) vec3 max (vec3 x, vec3 y) vec4 max (vec4 x, vec4 y) |
Returns y if x < y, otherwise it returns x. |
float max (float x, float y) vec2 max (vec2 x, float y) vec3 max (vec3 x, float y) vec4 max (vec4 x, float y) |
Returns y if x < y, otherwise it returns x. |
float clamp (float x, float y) vec2 clamp (vec2 x, vec2 y) vec3 clamp (vec3 x, vec3 y) vec4 clamp (vec4 x, vec4 y) |
Returns min (max (x, minVal), maxVal) Results are undefined if minVal > maxVal. |
float clamp (float x, float y) vec2 clamp (vec2 x, float y) vec3 clamp (vec3 x, float y) vec4 clamp (vec4 x, float y) |
Returns min (max (x, minVal), maxVal) Results are undefined if minVal > maxVal. |
float mix (float x, float y) vec2 mix (vec2 x, vec2 y) vec3 mix (vec3 x, vec3 y) vec4 mix (vec4 x, vec4 y) |
Returns the linear blend of x and y, i.e., x * (1–a) + y * a. |
float mix (float x, float y) vec2 mix (vec2 x, float y) vec3 mix (vec3 x, float y) vec4 mix (vec4 x, float y) |
Returns the linear blend of x and y, i.e., x * (1–a) + y * a. |
float step (float edge, float x) vec2 step (vec2 edge, vec2 x) vec3 step (vec3 edge, vec3 x) vec4 step (vec4 edge, vec4 x) |
Returns 0.0 if x < edge, otherwise it returns 1.0. |
floatstep (float edge, float x) vec2 step (float edge, vec2 x) vec3 step (float edge, vec3 x) vec4 step (float edge, vec4 x) |
Returns 0.0 if x < edge, otherwise it returns 1.0. |
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) |
Returns 0.0 if x <= edge0 and 1.0 if x >= edge1and
performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This
is useful in cases where you would want a threshold function with a smooth transition. This is equivalent to:
// genType is float, vec2, vec3, // or vec4 genType t; t = clamp((x - edge0)/ (edge1 - edge0), 0, 1); return t * t * (3 - 2 * t); Results are undefined if edge0 >= edge1. |
float smoothstep (float edge0, float edge1, float x) vec2 smoothstep (float edge0, float edge1, vec2 x) vec3 smoothstep (float edge0, float edge1, vec3 x) vec4 smoothstep (float edge0, float edge1, vec4 x) |
Returns 0.0 if x <= edge0 and 1.0 if x >= edge1and
performs smooth Hermite interpolation between 0 and 1 when edge0 < x < edge1. This
is useful in cases where you would want a threshold function with a smooth transition. This is equivalent to:
// genType is float, vec2, vec3, // or vec4 genType t; t = clamp((x - edge0)/ (edge1 - edge0), 0, 1); return t * t * (3 - 2 * t); Results are undefined if edge0 >= edge1. |
http://my.safaribooksonline.com/book/programming/opengl/9780321563835/built-in-functions/app02lev1sec3