Skip to content

Instantly share code, notes, and snippets.

@noizfactory
Forked from Taremin/zigzag.osl
Created December 5, 2020 17:37
Show Gist options
  • Save noizfactory/2c18bedc4c5549b6f4e84d75725f1e5f to your computer and use it in GitHub Desktop.
Save noizfactory/2c18bedc4c5549b6f4e84d75725f1e5f to your computer and use it in GitHub Desktop.
float fract(float a) {
return a - floor(a);
}
point fract(point p) {
return point(fract(p[0]), fract(p[1]), fract(p[2]));
}
float lerp(float a, float b, float t) {
return (1 - t) * a + t * b;
}
float hash21(point p) {
p = fract(p*point(123.34, 456.21, 0.));
p += dot(p, p+45.32);
return fract(p[0] * p[1]);
}
shader zigzag(
point p = P,
float scale = 1.,
float scale_y = 1.,
float add_y = 1.,
output color Color = (0.0),
) {
int id_x = int(p[0] * scale);
float x = fract(p[0] * scale);
float y = (p[1] + add_y) * scale_y;
float z = p[2];
int up_or_down = id_x % 2;
point cur;
point prev;
if (up_or_down) {
cur = hash21(point(id_x, id_x, id_x)) * -1;
prev = hash21(point(id_x-1, id_x-1, id_x-1));
} else {
cur = hash21(point(id_x, id_x, id_x));
prev = hash21(point(id_x-1 , id_x-1, id_x-1)) * -1;
}
y += lerp(prev[0]-.5, cur[0]-.5, x);
Color = y;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment