Published
Edited
Dec 17, 2020
8 stars
Insert cell
Insert cell
bnbShader(await raymarch({
antiAliasing: 3,
background: `vec3(22./255.)`,
eye: `vec3(-2., 0.5 + cos(u_time * TAU) * 1.5, 2.0)`,
// eye: `vec3(0, 0, 10)`,
sceneSDF: `
#define PI ${Math.PI}
#define TAU ${Math.PI * 2}

${sdBox()}
${sdTorus()}
${opRepLim()}
${opUnion()}
${opSubtraction()}
${opIntersection()}
${rotateX()}
${rotate3D()}
${await easeCubicInOut()}

float glow = 0.;

vec2 sceneSDF(vec3 p) {
vec3 pp = p * rotate3D(u_time * TAU * 2., vec3(0, 0, 1));
pp *= rotate3D(-u_time * TAU, vec3(1, 0, 0));

float t1 = sdTorus(pp, vec2(.9, .4));
float t2 = sdTorus(pp, vec2(.9, .399999 - (sin(u_time * TAU) *.5 + .5) * .1));
float t3 = opSubtraction(t2, t1);


pp = opRepLim(p, vec3(0., 0.15 + sin(u_time * TAU) * .05, 0.), vec3(0, 15, 0));
float b = sdBox(pp, vec3(1.5, 0.01, 1.5));

float d1 = opIntersection(t2, sdBox(pp, vec3(1.5, 0.01, 1.5)));
float d2 = opIntersection(t3, sdBox(pp, vec3(1.5, 0.00001, 1.5)));
glow += 0.005 / (0.02 + d2 * d2 * 100.) / (float(AA) * 4.);

float d = opUnion(d1, d2);
return vec2(d, 60.);
}`,
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.);

// lighting
float occ = calcAO(pos, nor); // ambient occlusion
col *= occ;

return col;
}`,
effect: `
vec3 effect(vec3 col) {
col += glow * mix(vec3(0.3, 1.0, 0.8), vec3(1., .3, .8), sin(u_time * TAU) * .5 + .5);
return col;
}`,
logShader: true,
}), {
w: 540, h: 540,
numFrames: 120,
fps: 20,
record: true,
video: 'mp4',
shutterAngle: .8,
samplesPerFrame: 8
})
Insert cell
Insert cell
Insert cell
Insert cell
import {sdBox, sdTorus, opIntersection, opSubtraction, opUnion, opRepLim, rotateX} from '@makio135/iq-sdf'
Insert cell
import {easeCubicOut, easeCubicInOut, rotate3D} from '@makio135/glsl-snippets'
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