+[{"ver":"0.1","info":{"id":"tfVXz1","date":"1749827724","viewed":230,"name":"Varying sharpness","username":"hamoid","description":"Experiment using complex numbers. Based on https:\/\/hturan.com\/writing\/complex-numbers-glsl","likes":2,"published":3,"flags":0,"usePreview":0,"tags":[]},"renderpass":[{"inputs":[],"outputs":[{"id":"4dfGRr","channel":0}],"code":"#define PI 3.1415926535897932384626433832795\n\n#define cx_mul(a, b) vec2(a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x)\n#define cx_div(a, b) vec2(((a.x*b.x + a.y*b.y)\/(b.x*b.x + b.y*b.y)),((a.y*b.x - a.x*b.y)\/(b.x*b.x + b.y*b.y)))\n#define cx_sin(a) vec2(sin(a.x) * cosh(a.y), cos(a.x) * sinh(a.y))\n#define cx_cos(a) vec2(cos(a.x) * cosh(a.y), -sin(a.x) * sinh(a.y))\n\nvec2 cx_tan(vec2 a) {return cx_div(cx_sin(a), cx_cos(a)); }\nvec2 cx_log(vec2 a) {\n float rpart = sqrt((a.x*a.x)+(a.y*a.y));\n float ipart = atan(a.y,a.x);\n if (ipart > PI) ipart=ipart-(2.0*PI);\n return vec2(log(rpart),ipart);\n}\n\nvec2 as_polar(vec2 z) {\n return vec2(length(z), atan(z.y, z.x));\n}\nvec2 cx_pow(vec2 v, float p) {\n vec2 z = as_polar(v);\n return pow(z.x, p) * vec2(cos(z.y * p), sin(z.y * p));\n}\n\nfloat im(vec2 z) {\n return ((atan(z.y, z.x) \/ PI) + 1.0) * 0.5;\n}\n\nvec3 pal( in float t, in vec3 a, in vec3 b, in vec3 c, in vec3 d ) {\n return a + b*cos(2.*PI*(c*t+d));\n}\n\nvoid mainImage( out vec4 fragColor, in vec2 fragCoord ) { \n float t = iTime * 0.1;\n \/\/ Define our points\n vec2 p[8];\n for(int i=0; i<8; i++) {\n p[i] = vec2(cos(float(i) * 0.1 + t), sin(float(i) * 2.3 + t));\n }\n \n \/\/ Set up our imaginary plane\n vec2 uv = (fragCoord.xy - 0.5 * iResolution.xy) \/ min(iResolution.y, iResolution.x);\n vec2 z = uv * 4.;\n\n \/\/ Calculate the sum of our first polynomial\n vec2 polyA = p[0]\n + cx_mul(p[1], z)\n + cx_mul(p[2], cx_pow(z, 2.0))\n + cx_mul(p[3], cx_pow(z, 3.0));\n\n \/\/ Calculate the sum of our second polynomial\n vec2 polyB = p[4]\n + cx_mul(p[5], z)\n + cx_mul(p[6], cx_pow(z, 2.0))\n + cx_mul(p[7], cx_pow(z, 3.0));\n\n \/\/ Calculate the ratio of our complex polynomials\n vec2 result = cx_div(polyA, polyB);\n\n float imaginary = cx_log(result).y;\n float col = (imaginary \/ PI);\n fragColor = vec4(pal(col, vec3(.52,.45,.21),vec3(.40,.40,.31),vec3(.26,.30,.75),vec3(.15,.4,.2)), 1.0);\n}","name":"Image","description":"","type":"image"}]}]
0 commit comments