Math Mix Combine Functions
This is the equivalent GLSL code for the functions on the Combine page of the Math Mix POP and Math Combine POP.
copya: float(A); abs: abs(A); sign: float(sign(A)); sqrt: float(sqrt(abs(A))); square: float(A * A); inverse: A != 0 ? 1/A : A; floor: float(floor(A)); round: float(round(A)); ceil: float(ceil(A)); int: float(int(A)); fract: float(fract(A)); normalize: normalize(A); exp10: float(pow(10, A)); exp2: float(exp2(A)); exp: float(exp(A)); log10: (A > 0) ? float(log(A) / log(10.0f)) : float(A); log2: (A > 0) ? float(log2(A)) : float(A); ln: (A > 0) ? float(log(A)) : float(A); sin: float(sin(radians(A))); cos: float(cos(radians(A))); tan: float(tan(radians(A))); asin: (A >= -1.0f && A <= 1.0f) ? float(degrees(asin(A))) : float(A); acos: (A >= -1.0f && A <= 1.0f) ? float(degrees(acos(A))) : float(A); atan: float(degrees(atan(A))); degrees: float(degrees(A)); radians: float(radians(A)); length: float(length(A)); compadd: result = A[0]; result += A[1]; result += A[2]; compsub: result = A[0]; result -= A[1]; result -= A[2]; compmult: result = A[0]; result *= A[1]; result *= A[2]; compdiv: result = A[0]; if(A[1] != 0) result /= A[1]; else result = 0; if(A[2] != 0) result /= A[2]; else result = 0; compavg: result = A[0]; result += A[1]; result += A[2]; result /= 3; compmin: result = A[0]; result = min(result, A[1]); result = min(result, A[2]); bsuba: float(B - A); mult: float(A * B); adivb: float(A / B); bdiva: float(B / A); apowerb: float(pow(A, B)); logba: float(B != 0 && B != 1 && A != 0 ? log(A) / log(B) : 0); avg: float(0.5 * (A + B)); min: float(min(A, B)); max: float(max(A, B)); mod: float(mod(A, B)); intadivb: float(int(A / B)); gt: float(A > B); gte: float(A >= B); lt: float(A < B); lte: float(A <= B); eq: float(A == B); ne: float(A != B); atan2: float(degrees(atan(A, B))); dot: = dot(A, B); angle: degrees(acos(dot(A, B) / (length(A)) * length(B)))); cross: cross(A, B); reflect: reflect(A, B); aaddbmultc: float(A + B * float(C)); amultbaddc: float(A * B + float(C)); aaddbaddc: float(A + B + C); amultbmultc: float(A * B * C); rangefrom: float((B != C) ? (A - B) / (C - B) : A); rangeto: float(A * (C - B) + B); mix: float(mix(A, B, C)); ifelse: float(mix(B, A, float(C > 0 ))); loop: TDLoop(A, B, C) zigzag: TDZigZag(A, B, C) clamp: float(clamp(A, B, C)); smoothstep: float(smoothstep(A, B, float(C))); bltealtc: float((B <= A && A < C)); bltaltec: float((B < A && A <= C)); bltaltec: float((B < A && A < C)); bltaltec: float((B <= A && A <= C)); refract: refract(A, B, C);
float TDLoop(float val, float low, float high)
{
float v = (val - low) / (high - low);
return mix(low, high, fract(v));
}
float TDZigZag(float val, float low, float high)
{
float v = (val - low) / (high - low);
bool flip = int(floor(v)) % 2 == 1 ? true : false;
v = fract(v);
if (flip)
v = 1.0 - v;
return mix(low, high, v);
}