Last active
March 28, 2019 16:56
-
-
Save NiklasRosenstein/ee1f1b5786f94e17995361c63dafeb3f to your computer and use it in GitHub Desktop.
Functions for complex numbers in GLSL. https://www.shadertoy.com/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
vec2 cmpxcjg(in vec2 c) { | |
return vec2(c.x, -c.y); | |
} | |
vec2 cmpxmul(in vec2 a, in vec2 b) { | |
return vec2(a.x * b.x - a.y * b.y, a.y * b.x + a.x * b.y); | |
} | |
vec2 cmpxpow(in vec2 c, int p) { | |
for (int i = 0; i < p; ++i) { | |
c = cmpxmul(c, c); | |
} | |
return c; | |
} | |
vec2 cmpxdiv(in vec2 a, in vec2 b) { | |
return cmpxmul(a, cmpxcjg(b)); | |
} | |
float cmpxmag(in vec2 c) { | |
return sqrt(c.x * c.x + c.y * c.y); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
the cmpxpow function is rong, is should read something like:
vec2 cmpxpow(in vec2 c, int p) {
vec2 tmp = vec2(1.0,0.0) ;
for (int i = 0; i < p; ++i) {
c = cmpxmul(tmp, c);
}
return c;
}
Cheers,
Paulo