Published
Edited
Jan 31, 2021
1 star
Insert cell
Insert cell
Insert cell
Insert cell
sh = async () => raymarch({
antiAliasing: 3,
eye: `vec3(.3, .1, .7) * 1.2 * rotate3D(sin(u_time * TAU) * .7, vec3(1, 0, 0))`,
sceneSDF: `
#define PI ${Math.PI}
#define TAU ${Math.PI * 2}

uniform sampler2D u_texture;

${iqSDF.sdBox()}
${iqSDF.sdSphere()}
${iqSDF.sdTorus()}
${iqSDF.opUnion()}
${iqSDF.opSmoothUnion()}
${glslSnippets.rotate3D()}
${glslSnippets.random()}
${await glslSnippets.matcap()}

vec2 sceneSDF(vec3 p) {
vec3 pp = p;
float t = u_time * TAU;
float sinT = sin(t);
float cosT = cos(t);
float d = sdTorus(p.xzy * rotate3D(-t, vec3(1, 0, 1)), vec2(.3, .05));
d = opSmoothUnion(d, sdTorus(p.xzy * rotate3D(t, vec3(0, 1, 1)), vec2(.12, .02)), .1);
d = opSmoothUnion(d, sdTorus(p * rotate3D(t * 2., vec3(1, 1, 0)), vec2(.48, .06)), .1);
float dd = 10e5;
const float N = 60.;
for(float i = 0.; i < N; i++) {
float angle = TAU / N * i;
vec3 pp = p * rotate3D(angle, vec3(0,0,1));
pp *= rotate3D(random(i * 2.654823) * TAU, vec3(0,1,0));
pp.x += .4 + .3 * sin((u_time + i/N * 4. + i * 2.1332) * TAU * 2.);
dd = opSmoothUnion(dd, sdSphere(pp, .02 + random(i) * .02), .1);
}
d = opSmoothUnion(d, dd, .1);

return vec2(d, 2.);
}`,
computeColor: `
vec3 computeColor(vec3 ro, vec3 rd, vec3 pos, float d, float m) {
vec3 color = vec3(0.);
vec3 nor = calcNormal(pos);
//color = nor;

vec2 matcapUV = matcap(rd, nor);
color = texture2D(u_texture, matcapUV).rgb;

//float fre = pow(clamp(1.0 + dot(nor, rd), 0.0, 1.0), 2.0); // fresnel
float fre = pow(1.0 + dot(nor, rd), 2.); // fresnel
//color = vec3(fre);
vec3 bg = vec3(0.6 - length((gl_FragCoord.xy - u_resolution / 2.) / u_resolution.x));
color = mix(color, bg, fre);
return color;
}`,
logShader: true
})
Insert cell
Insert cell
matcapURL = `https://makio135.com/matcaps/512/${shuffle(matcapIds)[0]}-512px.png`
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more