函数说明
abs-取绝对值acos-反余弦函数acosh-反双曲余弦函数all-返回一个bool值,指示是否所有的值都为真any-返回一个bool值,指示是否有任何一个值为真asin-反正弦函数asinh-反双曲正弦函数atan-反正切函数atanh-反双曲正切函数ceil-向上取整clamp-将值限制在指定的范围内cos-余弦函数cosh-双曲余弦函数cross-计算向量叉积dFdx-返回一个向量或标量的x分量的导数dFdy-返回一个向量或标量的y分量的导数degrees-将弧度转换为角度determinant-计算矩阵的行列式distance-计算两个向量之间的距离dot-计算两个向量的点积equal-检查两个参数是否相等exp-计算自然指数函数的值exp2-计算2的幂次方faceforward-返回表面法线朝向floatBitsToInt-将浮点数转换为带符号整数floatBitsToUint-将浮点数转换为无符号整数floor-返回小于等于输入值的最大整数fract-返回输入值的小数部分fwidth-返回函数对输入值的x和y方向导数的绝对值之和gl_FragCoord-获取像素坐标信息gl_FragDepth-获取像素深度值gl_FrontFacing-判断面的方向gl_InstanceID-获取实例IDgl_PointCoord-获取点的纹理坐标gl_PointSize-获取点的大小gl_Position-获取顶点位置gl_VertexID-获取顶点IDgreaterThan-比较两个向量的大小greaterThanEqual-比较两个向量的大小intBitsToFloat-转换整型位表示的浮点数为单精度浮点数inverse-求逆矩阵inversesqrt-求倒数的平方根isinf-判断浮点数是否为正或负无穷大isnan-判断浮点数是否为NaNlength-返回向量长度lessThan-逐元素比较两个向量并返回bool向量lessThanEqual-逐元素比较两个向量并返回bool向量,小于或等于返回truelog-计算以e为底的对数log2-计算以2为底的对数matrixCompMult-Matrix元素逐一相乘max-返回两个数的较大值min-返回两个数的较小值mix-线性混合两个值mod-计算浮点数除法的余数modf-返回浮点数的整数和小数部分normalize-向量单位化not-按位求反notEqual-按位不等outerProduct-向量外积packHalf2x16-将两个浮点数压缩成半精度packSnorm2x16-将两个浮点数压缩成符号化半精度packUnorm2x16-将两个浮点数压缩成无符号半精度pow-幂函数radians-角度转弧度reflect-计算反射向量refract-计算折射向量round-四舍五入roundEven-根据奇偶性舍入sign-符号函数sin-正弦函数sinh-双曲正弦函数smoothstep-平滑阶梯函数sqrt-平方根step-阶梯函数tan-正切函数tanh-双曲正切函数texelFetch-获取纹素的颜色值texelFetchOffset-获取偏移量纹素的颜色值texture-对纹理进行采样textureGrad-对纹理进行采样,包括Mipmap层级计算textureGradOffset-对纹理进行采样,包括Mipmap层级计算和偏移量textureLod-根据给定的Mipmap层级对纹理进行采样textureLodOffset-根据给定的Mipmap层级和偏移量对纹理进行采样textureOffset-对纹理进行采样,包括偏移量textureProj-对投影纹理进行采样textureProjGrad-对投影纹理进行采样,包括Mipmap层级计算textureProjGradOffset-对投影纹理进行采样,包括Mipmap层级计算和偏移量textureProjLod-根据给定的Mipmap层级对投影纹理进行采样textureProjLodOffset-根据给定的Mipmap层级和偏移量对投影纹理进行采样textureProjOffset-对投影纹理进行采样,包括偏移量textureSize-获取纹理的尺寸transpose-矩阵转置trunc-向零舍入取整uintBitsToFloat-将32位无符号整数解释为浮点数unpackHalf2x16-解压缩单精度浮点数unpackSnorm2x16-解压缩单精度浮点数unpackUnorm2x16-解压缩单精度浮点数

GLSL mod()

The mod() function is a built-in function in the GLSL shading language that computes the remainder of the division \a / \b. It returns the value a - b * trunc(a / b).

The mod() function takes two arguments, both of which must be the same data type. The function returns a value with the same data type as the input arguments.

Syntax

The syntax for the mod() function is as follows:

T mod(T a, T b)

Where:

  • T is any valid GLSL data type, such as float, vec2, vec3, vec4, int, ivec2, ivec3, ivec4, bool, bvec2, bvec3, bvec4, mat2, mat3, mat4, and so on.
  • a is the dividend, the numerator of the division.
  • b is the divisor, the denominator of the division.

The mod() function can also be called with a single argument, in which case it returns the same value as the input argument, but with a positive sign. This is equivalent to calling mod(a, a).

Example

float a = 16.0;
float b = 3.0;
float result = mod(a, b); // result = 1.0

In this example, the mod() function is used to compute the remainder of the division 16 / 3, which gives a remainder of 1.

Restrictions

The mod() function has some restrictions in GLSL:

  • The divisor must be non-zero. If the divisor is zero, the behavior of the function is undefined.
  • The dividend and divisor must be of the same data type.
  • For floating-point types, the behavior of mod() is undefined if the divisor or dividend is NaN.

See Also