Common Functions

describes the built-in common functions. These functions can be used within vertex and fragment shaders. These functions operate component-wise.

Table B-3. Common Functions
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 ( xminVal),  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 ( xminVal),  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. float step (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

转载于:https://www.cnblogs.com/zsw-1993/archive/2013/03/05/4880337.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值