fuckingtech/public/assets/glsl/lygia/math/mirror.msl
Elias Rhouzlane bf76c6b086 fix: code
2025-04-06 17:23:52 +02:00

24 lines
685 B
Text

/*
contributors: Ian Heisters
description: Transforms the input signal into a triangle wave. For instance, if x goes between 0 and 2, the returned value will go from 0 to 1, and then 1 to 0 a triangle shape.
use: <float|float2> mirror(<float|float2> x)
examples:
- https://raw.githubusercontent.com/patriciogonzalezvivo/lygia_examples/main/math_functions.frag
*/
#ifndef FNC_MIRROR
#define FNC_MIRROR
float mirror(float x) {
float f = fract(x);
float m = floor(mod(x, 2.));
float fm = f * m;
return f + m - fm * 2.;
}
float2 mirror(float2 v) {
float2 f = fract(v);
float2 m = floor(mod(v, 2.));
float2 fm = f * m;
return f + m - fm * 2.;
}
#endif