Skip to content

Instantly share code, notes, and snippets.

@NiklasRosenstein
Last active March 28, 2019 16:56
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save NiklasRosenstein/ee1f1b5786f94e17995361c63dafeb3f to your computer and use it in GitHub Desktop.
Save NiklasRosenstein/ee1f1b5786f94e17995361c63dafeb3f to your computer and use it in GitHub Desktop.
Functions for complex numbers in GLSL. https://www.shadertoy.com/
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);
}
@pjmartel
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment