WebGL GLSL Reference

Based on OpenGL ES Shading Language 1.0

By Sohail Ajmal

abs acos all any asin atan ceil clamp cos cross degrees distance dot equal exp exp2 faceforward floor fract greaterThan greaterThanEqual inversesqrt length lessThan lessThanEqual log log2 matrixCompMult max min mix mod normalize not notEqual pow radians reflect refract sign sin smoothstep sqrt step tan texture2D texture2DLod texture2DProj texture2DProjLod textureCube textureCubeLod

abs

Summary

return the absolute value of the parameter

Syntax

genType abs(genType)

Example

float x  = abs( 0.5 - 1.0);
// x = [ 0.5 - 1.0 ] = 0.5

See Also

sign

Links

acos

Summary

return the arccosine of the parameter

Syntax

genType acos(genType)

Example


See Also

sin cos tan asin atan

Links

all

Summary

check whether all elements of a boolean vector are true

Syntax

bool all(bvec)

Example


See Also

any not

Links

any

Summary

check whether any element of a boolean vector is true

Syntax

bool any(bvec)

Example


See Also

all not

Links

asin

Summary

return the arcsine of the parameter

Syntax

genType asin(genType)

Example


See Also

sin cos tan acos atan

Links

atan

Summary

return the arc-tangent of the parameters

Syntax

genType atan(genType, genType)genType atan(genType)

Example


See Also

sin cos tan asin acos

Links

ceil

Summary

find the nearest integer that is greater than or equal to the parameter

Syntax

genType ceil(genType)

Example


See Also

floor round

Links

clamp

Summary

constrain a value to lie between two further values

Syntax

genType clamp(genType, genType, genType)genType clamp(genType, float, float)

Example


See Also

min max

Links

cos

Summary

return the cosine of the parameter

Syntax

genType cos(genType)

Example


See Also

sin tan acos asin atan

Links

cross

Summary

calculate the cross product of two vectors

Syntax

vec3 cross(vec3, vec3)

Example


See Also

dot

Links

degrees

Summary

convert a quantity in radians to degrees

Syntax

genType degrees(genType)

Example


See Also

radians

Links

distance

Summary

calculate the distance between two points

Syntax

float distance(genType, genType)

Example


See Also

length normalize

Links

dot

Summary

calculate the dot product of two vectors

Syntax

float dot(genType, genType)

Example


See Also

cross

Links

equal

Summary

perform a component-wise equal-to comparison of two vectors

Syntax

bvec equal(vec, vec)

Example


See Also

lessThan lessThanEqual greaterThan greaterThanEqual notEqual any all not

Links

exp

Summary

return the natural exponentiation of the parameter

Syntax

genType exp(genType)

Example


See Also

exp2 pow

Links

exp2

Summary

return 2 raised to the power of the parameter

Syntax

genType exp2(genType)

Example


See Also

exp log log2

Links

faceforward

Summary

return a vector pointing in the same direction as another

Syntax

genType faceforward(genType, genType, genType)

Example


See Also

reflect refract

Links

floor

Summary

find the nearest integer less than or equal to the parameter

Syntax

genType floor(genType)

Example


See Also

trunc round

Links

fract

Summary

compute the fractional part of the argument

Syntax

genType fract(genType)

Example


See Also

floor round

Links

greaterThan

Summary

perform a component-wise greater-than comparison of two vectors

Syntax

bvec greaterThan(vec, vec)

Example


See Also

lessThan lessThanEqual greaterThanEqual equal notEqual any all not

Links

greaterThanEqual

Summary

perform a component-wise greater-than-or-equal comparison of two vectors

Syntax

bvec greaterThanEqual(vec, vec)

Example


See Also

lessThan lessThanEqual greaterThan equal notEqual any all not

Links

inversesqrt

Summary

return the inverse of the square root of the parameter

Syntax

genType inversesqrt(genType)

Example


See Also

sqrt

Links

length

Summary

calculate the length of a vector

Syntax

float length(genType)

Example


See Also

distance normalize

Links

lessThan

Summary

perform a component-wise less-than comparison of two vectors

Syntax

bvec lessThan(vec, vec)

Example


See Also

lessThanEqual greaterThan greaterThanEqual equal notEqual any all not

Links

lessThanEqual

Summary

perform a component-wise less-than-or-equal comparison of two vectors

Syntax

bvec lessThanEqual(vec, vec)

Example


See Also

lessThan greaterThan greaterThanEqual equal notEqual any all not

Links

log

Summary

return the natural logarithm of the parameter

Syntax

genType log(genType)

Example


See Also

exp exp2 log2

Links

log2

Summary

return the base 2 logarithm of the parameter

Syntax

genType log2(genType)

Example


See Also

exp log exp2

Links

matrixCompMult

Summary

perform a component-wise multiplication of two matrices

Syntax

mat matrixCompMult(mat, mat)

Example


See Also

dot reflect

Links

max

Summary

return the greater of two values

Syntax

genType max(genType, genType)genType max(genType, float)

Example


See Also

min abs

Links

min

Summary

return the lesser of two values

Syntax

genType min(genType, genType)genType min(genType, float)

Example


See Also

max abs

Links

mix

Summary

linearly interpolate between two values

Syntax

genType mix(genType, genType, genType)genType mix(genType, genType, float)

Example


See Also

min max

Links

mod

Summary

compute value of one parameter modulo another

Syntax

genType mod(genType, float)genType mod(genType, genType)

Example


See Also

modf floor

Links

normalize

Summary

calculate the normalize product of two vectors

Syntax

genType normalize(genType)

Example


See Also

length

Links

not

Summary

logically invert a boolean vector

Syntax

bvec not(bvec)

Example


See Also

any all

Links

notEqual

Summary

perform a component-wise not-equal-to comparison of two vectors

Syntax

bvec notEqual(vec, vec)

Example


See Also

lessThan lessThanEqual greaterThan greaterThanEqual equal any all not

Links

pow

Summary

return the value of the first parameter raised to the power of the second

Syntax

genType pow(genType, genType)

Example


See Also

exp

Links

radians

Summary

convert a quantity in degrees to radians

Syntax

genType radians(genType)

Example


See Also

degrees

Links

reflect

Summary

calculate the reflection direction for an incident vector

Syntax

genType reflect(genType, genType)

Example


See Also

dot refract

Links

refract

Summary

calculate the refraction direction for an incident vector

Syntax

genType refract(genType, genType, float)

Example


See Also

dot reflect

Links

sign

Summary

extract the sign of the parameter

Syntax

genType sign(genType)

Example


See Also

abs

Links

sin

Summary

return the sine of the parameter

Syntax

genType sin(genType)

Example


See Also

cos tan asin acos atan

Links

smoothstep

Summary

perform Hermite interpolation between two values

Syntax

genType smoothstep(genType, genType, genType)genType smoothstep(float, float, genType)

Example


See Also

mix step

Links

sqrt

Summary

return the square root of the parameter

Syntax

genType sqrt(genType)

Example


See Also

inversesqrt

Links

step

Summary

generate a step function by comparing two values

Syntax

genType step(genType, genType)genType step(float, genType)

Example


See Also

mix smoothstep

Links

tan

Summary

return the tangent of the parameter

Syntax

genType tan(genType)

Example


See Also

sin cos asin acos atan

Links