Skip to content

Instantly share code, notes, and snippets.

@PranavSK
Created July 11, 2022 21:51
Show Gist options
  • Save PranavSK/e205641e9e858406696ada959ef3e19d to your computer and use it in GitHub Desktop.
Save PranavSK/e205641e9e858406696ada959ef3e19d to your computer and use it in GitHub Desktop.
// Those snippets are in vec4 type but you can change to another types like:
// vec3, vec2, float, int ..........
vec4 when_eq(vec4 x, vec4 y) {
return 1.0 - abs(sign(x - y));
}
vec4 when_neq(vec4 x, vec4 y) {
return abs(sign(x - y));
}
vec4 when_gt(vec4 x, vec4 y) {
return max(sign(x - y), 0.0);
}
vec4 when_lt(vec4 x, vec4 y) {
return max(sign(y - x), 0.0);
}
vec4 when_ge(vec4 x, vec4 y) {
return 1.0 - when_lt(x, y);
}
vec4 when_le(vec4 x, vec4 y) {
return 1.0 - when_gt(x, y);
}
//Here are some logical operators to use with the results from above:
vec4 and(vec4 a, vec4 b) {
return a * b;
}
vec4 or(vec4 a, vec4 b) {
return min(a + b, 1.0);
}
vec4 xor(vec4 a, vec4 b) {
return (a + b) % 2.0;
}
vec4 not(vec4 a) {
return 1.0 - a;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment