glsl = ({
useStandardDerivatives: `
#extension GL_OES_standard_derivatives : enable
`,
constants: `
#define PI 3.141592653589793238
#define HALF_PI 1.57079632679
#define HALF_PI_INV 0.15915494309
#define LOG_2 0.69314718056
#define C_ONE (vec2(1.0, 0.0))
#define C_I (vec2(0.0, 1.0))
#define TO_RADIANS 0.01745329251
`,
precision: `
precision highp float;
`,
hsv2rgb: `
vec3 hsv2rgb(vec3 c) {
vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);
vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);
return c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);
}
`,
complex: `
float cosh (float x) {
return 0.5 * (exp(x) + exp(-x));
}
float sinh (float x) {
return 0.5 * (exp(x) - exp(-x));
}
vec2 sinhcosh (float x) {
float ex = exp(x);
float emx = exp(-x);
return 0.5 * vec2(
ex + emx,
ex - emx
);
}
vec2 cmul (vec2 a, vec2 b) {
return vec2(
a.x * b.x - a.y * b.y,
a.y * b.x + a.x * b.y
);
}
vec2 cmul (vec2 a, vec2 b, vec2 c) {
return cmul(cmul(a, b), c);
}
vec2 cdiv (vec2 a, vec2 b) {
return vec2(
a.y * b.y + a.x * b.x,
a.y * b.x - a.x * b.y
) / dot(b, b);
}
vec2 cinv (vec2 z) {
return vec2(z.x, -z.y) / dot(z, z);
}
vec2 cexp (vec2 z) {
return vec2(cos(z.y), sin(z.y)) * exp(z.x);
}
vec2 clog (vec2 z) {
return vec2(
log(hypot(z)),
atan(z.y, z.x)
);
}
vec2 cpolar (vec2 z) {
return vec2(
atan(z.y, z.x),
hypot(z)
);
}
vec2 cpow (vec2 z, float x) {
float r = hypot(z);
float theta = atan(z.y, z.x) * x;
return vec2(cos(theta), sin(theta)) * pow(r, x);
}
vec2 cpow (vec2 a, vec2 b) {
float aarg = atan(a.y, a.x);
float amod = hypot(a);
float theta = log(amod) * b.y + aarg * b.x;
return vec2(cos(theta), sin(theta)) * pow(amod, b.x) * exp(-aarg * b.y);
}
vec2 csqrt (vec2 z) {
vec2 zpolar = cpolar(z);
float theta = zpolar.x * 0.5;
float mod = sqrt(zpolar.y);
return vec2(cos(theta), sin(theta)) * mod;
}
vec2 csqr (vec2 z) {
return vec2(z.x * z.x - z.y * z.y, 2.0 * z.x * z.y);
}
vec2 ccos (vec2 z) {
return sinhcosh(z.y) * vec2(cos(z.x), -sin(z.x));
}
vec2 csin (vec2 z) {
return sinhcosh(z.y).yx * vec2(sin(z.x), cos(z.x));
}
vec2 ctan (vec2 z) {
vec2 e2iz = cexp(2.0 * vec2(-z.y, z.x));
return cdiv(e2iz - C_ONE, cmul(C_I, C_ONE + e2iz));
}
vec2 cacos (vec2 z) {
vec2 t1 = csqrt(vec2(z.y * z.y - z.x * z.x + 1.0, -2.0 * z.x * z.y));
vec2 t2 = clog(vec2(t1.x - z.y, t1.y + z.x));
return vec2(HALF_PI - t2.y, t2.x);
}
vec2 casin (vec2 z) {
vec2 t1 = csqrt(vec2(z.y * z.y - z.x * z.x + 1.0, -2.0 * z.x * z.y));
vec2 t2 = clog(vec2(t1.x - z.y, t1.y + z.x));
return vec2(t2.y, -t2.x);
}
vec2 catan (vec2 z) {
float d = z.x * z.x + (1.0 - z.y) * (1.0 - z.y);
vec2 t1 = clog(vec2(1.0 - z.y * z.y - z.x * z.x, -2.0 * z.x) / d);
return 0.5 * vec2(-t1.y, t1.x);
}
vec2 ccosh (vec2 z) {
return sinhcosh(z.x).yx * vec2(cos(z.y), sin(z.y));
}
vec2 csinh (vec2 z) {
return sinhcosh(z.x) * vec2(cos(z.y), sin(z.y));
}
vec2 ctanh (vec2 z) {
vec2 ez = cexp(z);
vec2 emz = cexp(-z);
return cdiv(ez - emz, ez + emz);
}
`,
hypot: `
float hypot (vec2 z) {
float t;
float x = abs(z.x);
float y = abs(z.y);
t = min(x, y);
x = max(x, y);
t = t / x;
return x * sqrt(1.0 + t * t);
}
`,
wireframe: `
// https://github.com/rreusser/glsl-solid-wireframe
float wireframe (float parameter, float width, float feather) {
float w1 = width - feather * 0.5;
float d = fwidth(parameter);
float looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
return smoothstep(d * w1, d * (w1 + feather), looped);
}
float wireframe (vec2 parameter, float width, float feather) {
float w1 = width - feather * 0.5;
vec2 d = fwidth(parameter);
vec2 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec2 a2 = smoothstep(d * w1, d * (w1 + feather), looped);
return min(a2.x, a2.y);
}
float wireframe (vec3 parameter, float width, float feather) {
float w1 = width - feather * 0.5;
vec3 d = fwidth(parameter);
vec3 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec3 a3 = smoothstep(d * w1, d * (w1 + feather), looped);
return min(min(a3.x, a3.y), a3.z);
}
float wireframe (vec4 parameter, float width, float feather) {
float w1 = width - feather * 0.5;
vec4 d = fwidth(parameter);
vec4 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec4 a4 = smoothstep(d * w1, d * (w1 + feather), looped);
return min(min(min(a4.x, a4.y), a4.z), a4.w);
}
float wireframe (float parameter, float width) {
float d = fwidth(parameter);
float looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
return smoothstep(d * (width - 0.5), d * (width + 0.5), looped);
}
float wireframe (vec2 parameter, float width) {
vec2 d = fwidth(parameter);
vec2 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec2 a2 = smoothstep(d * (width - 0.5), d * (width + 0.5), looped);
return min(a2.x, a2.y);
}
float wireframe (vec3 parameter, float width) {
vec3 d = fwidth(parameter);
vec3 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec3 a3 = smoothstep(d * (width - 0.5), d * (width + 0.5), looped);
return min(min(a3.x, a3.y), a3.z);
}
float wireframe (vec4 parameter, float width) {
vec4 d = fwidth(parameter);
vec4 looped = 0.5 - abs(mod(parameter, 1.0) - 0.5);
vec4 a4 = smoothstep(d * (width - 0.5), d * (width + 0.5), looped);
return min(min(min(a4.x, a4.y), a4.z), a4.z);
}
`
})