周一到周五,每天一篇,北京时间早上7点准时更新~
跟着我们一起一天天进步,一步一步变成业界大佬。当别人在炫技术的时候,我们来手把手教你那些技术怎么实现。
GLSL supports many built-in functions to perform mathematical operations and to manipulate data in variables. The common math functions include abs(), sign(), ceil(), floor(), trunc(), round(), roundEven(), fract(), mod(), modf(), min(), and max(). For the most part, these functions operate on vectors as well as scalars, but otherwise behave like their counter parts in the C standard libraries. The roundEven() function doesn’t have a direct equivalent in C—this function rounds its argument to the nearest integer, but breaks ties when there is a fractional part of 0.5 by rounding to the nearest even number. That is, 7.5 and 8.5 will both round to 8, 42.5 will round to 42 and 43.5 will round to 44.
GLSL支持很多内置的执行数学操作的函数。这些就包括常用的abs(), sign(),ceil(), floor(), trunc(), round(), roundEven(), fract(), mod(),modf(), min(), 以及 max()。大部分时候,这些函数都可以用来操作 向量以及标量,但是他们计算的时候会表现得跟C语言的库很相似。
Two implicit declarations of the clamp() function are
两个隐式申明的clamp函数如下所示:
vec4 clamp(vec4 x, float minVal, float maxVal);
vec4 clamp(vec4 x, vec4 minVal, vec4 maxVal);
This function clamps the incoming vector x to the range specified by minVal and maxVal (which may be scal