sh = () => raymarch({
antiAliasing: 3,
eye: `vec3(3, 2, 3)`,
background: `vec3(${hexToRgb(palette[0]).join(',')})/255.`,
sceneSDF: `
#define PI ${Math.PI}
#define TAU ${Math.PI * 2}
#define NUM_COLORS ${palette.length}.
uniform sampler2D u_texture;
${iqSDF.opUnion()}
${iqSDF.opSubtraction()}
${iqSDF.sdCappedCylinder()}
${glslSnippets.rotate3D()}
float glow = 0.;
vec2 sceneSDF(vec3 p) {
//p *= rotate3D(u_time * TAU, vec3(1, 1, 0));
float d = 10e5;
const float n = 30.;
for(float i = 0.; i < n; i ++) {
vec3 pp = p * rotate3D(sin(u_time * TAU + (n - i) * .3) * 0.5, vec3(0, 1, 1));
float dd = opSubtraction(sdCappedCylinder(pp, .25, .2 + .15 * i - .08), sdCappedCylinder(pp, .2, .2 + .15 * i));
if(mod(i, 10.) == 1.) glow += 0.001 / (0.001 + dd * dd * 5.) / (float(AA * AA) * 4.);
d = opUnion(d, dd);
}
return vec2(d, 4.);
}`,
computeColor: `
vec3 computeColor(vec3 ro, vec3 rd, vec3 pos, float d, float m) {
vec3 nor = calcNormal(pos);
vec3 ref = reflect(rd, nor); // reflected ray
// material
vec3 col = vec3(0., 0., .1);
// lighting
float occ = calcAO(pos, nor); // ambient occlusion
vec3 lig = normalize(vec3(-0.4, 0.7, -0.6)); // sunlight
float amb = clamp(0.5 + 0.5 * nor.y, 0.0, 1.0); // ambient light
float dif = clamp(dot(nor, lig), 0.0, 1.0); // diffuse reflection from sunlight
// backlight
float bac = clamp(dot(nor, normalize(vec3(-lig.x, 0.0, -lig.z))), 0.0, 1.0) * clamp(1.0 - pos.y, 0.0, 1.0);
float dom = smoothstep(-0.1, 0.1, ref.y); // dome light
float fre = pow(clamp(1.0 + dot(nor, rd), 0.0, 1.0), 2.0); // fresnel
float spe = pow(clamp(dot(ref, lig), 0.0, 1.0), 16.0); // specular reflection
dif *= softshadow(pos, lig, 0.02, 2.5);
dom *= softshadow(pos, ref, 0.02, 2.5);
vec3 lin = vec3(0.0);
lin += 1.30 * dif * vec3(1.00, 0.80, 0.55);
lin += 2.00 * spe * vec3(1.00, 0.90, 0.70) * dif;
lin += 0.40 * amb * vec3(0.40, 0.60, 1.00) * occ;
lin += 0.50 * dom * vec3(0.40, 0.60, 1.00) * occ;
lin += 0.50 * bac * vec3(0.25, 0.25, 0.25) * occ;
lin += 0.25 * fre * vec3(1.00, 1.00, 1.00) * occ;
col = col * lin;
// mix in fog?
// col = mix(col, vec3(0.8, 0.9, 1.0), 1.0 - exp(-0.0002 * d * d * d));
col = mix(col, texture2D(u_texture, vec2(0., .5)).rgb, 1.0 - exp(-0.0005 * d * d * d));
// gamma
col = pow(col, vec3(0.4545));
return col;
}`,
effect: `
vec3 effect(vec3 c) {
c += glow * texture2D(u_texture, vec2(1.5 / NUM_COLORS, .5)).rgb;
return c;
}
`,
logShader: true
})