xxxxxxxxxx
55
// More info here -> https://moloxe.io/tina
const lib = document.createElement("script");
lib.src = "https://moloxeio.pages.dev/tina/lib.js";
document.head.appendChild(lib);
let lights = [];
function setup() {
createCanvas(windowWidth, windowHeight);
scene = new Tina(width, height);
postProc = new Tina(width, height);
scene.shape({
sdFunc: `(sin(pos.y) - (cos(pos.x) + cos(pos.y) + cos(pos.z))) / 2.`,
shininess: 1024,
});
lights[0] = scene.pointLight({
color: [1, 0, 0],
computeShadows: true,
});
lights[1] = scene.pointLight({
color: [0, 0, 1],
computeShadows: true,
});
scene.build();
scene.fov = 140;
scene.pos = [2.5, 2.5, 1.5];
scene.spherical[1] = 1.2;
postProc.build(`
uniform sampler2D graphics;
---
vec3 color = texture(graphics, uv).rgb;
color = pow(color, vec3(.4));
color += snoise(vec3(uv * width / 4., time * 2.)) * 0.05;
fragColor = vec4(color, 1.);
`);
noSmooth();
}
function draw() {
const t = performance.now() / 1000;
lights[0].pos = [3.5 * cos(t / 2), 2.5, 3.5 * sin(t / 2)];
lights[1].pos = [3.5 * cos(t / 2 + PI), 2.5, 3.5 * sin(t / 2 + PI)];
let graphics = scene.update();
graphics = postProc.update({ graphics });
image(graphics, 0, 0, width, height);
}