mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-16 06:19:21 +00:00
style: format new shader compositions with oxfmt
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
d1605e9b8e
commit
436680bc65
+255
-176
@@ -4,30 +4,73 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=1920, height=1080" />
|
||||
<title>Cinematic Camera</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/three@0.147.0/build/three.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/three@0.147.0/examples/js/loaders/GLTFLoader.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/three@0.147.0/examples/js/loaders/RGBELoader.js"></script>
|
||||
<style>
|
||||
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { background: #050510; overflow: hidden; font-family: "Inter", system-ui, sans-serif; }
|
||||
#root { position: relative; width: 1920px; height: 1080px; overflow: hidden; background: #050510; }
|
||||
#three-canvas { position: absolute; top: 0; left: 0; width: 1920px; height: 1080px; }
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
background: #050510;
|
||||
overflow: hidden;
|
||||
font-family: "Inter", system-ui, sans-serif;
|
||||
}
|
||||
#root {
|
||||
position: relative;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
overflow: hidden;
|
||||
background: #050510;
|
||||
}
|
||||
#three-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
}
|
||||
.move-label {
|
||||
position: absolute; bottom: 40px; left: 60px;
|
||||
font-family: "Inter", sans-serif; font-size: 14px; font-weight: 600;
|
||||
letter-spacing: 0.15em; text-transform: uppercase; color: rgba(255,255,255,0.25);
|
||||
z-index: 100; pointer-events: none;
|
||||
position: absolute;
|
||||
bottom: 40px;
|
||||
left: 60px;
|
||||
font-family: "Inter", sans-serif;
|
||||
font-size: 14px;
|
||||
font-weight: 600;
|
||||
letter-spacing: 0.15em;
|
||||
text-transform: uppercase;
|
||||
color: rgba(255, 255, 255, 0.25);
|
||||
z-index: 100;
|
||||
pointer-events: none;
|
||||
}
|
||||
.move-label .name {
|
||||
font-size: 28px; font-weight: 700; letter-spacing: 0.02em;
|
||||
text-transform: none; color: rgba(255,255,255,0.6); margin-top: 4px;
|
||||
font-size: 28px;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.02em;
|
||||
text-transform: none;
|
||||
color: rgba(255, 255, 255, 0.6);
|
||||
margin-top: 4px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="16" data-width="1920" data-height="1080">
|
||||
<div
|
||||
id="root"
|
||||
data-composition-id="main"
|
||||
data-start="0"
|
||||
data-duration="16"
|
||||
data-width="1920"
|
||||
data-height="1080"
|
||||
>
|
||||
<canvas id="three-canvas" width="1920" height="1080"></canvas>
|
||||
|
||||
<div id="move-label" class="move-label" style="opacity: 0">
|
||||
@@ -35,189 +78,225 @@
|
||||
<div id="move-name" class="name">Dolly Zoom</div>
|
||||
</div>
|
||||
|
||||
<div id="driver" data-start="0" data-duration="16" data-track-index="0"
|
||||
style="position:absolute;width:1px;height:1px;opacity:0;pointer-events:none"></div>
|
||||
<div
|
||||
id="driver"
|
||||
data-start="0"
|
||||
data-duration="16"
|
||||
data-track-index="0"
|
||||
style="position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
|
||||
var W = 1920, H = 1080;
|
||||
var canvas = document.getElementById("three-canvas");
|
||||
var W = 1920,
|
||||
H = 1080;
|
||||
var canvas = document.getElementById("three-canvas");
|
||||
|
||||
var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true, alpha: true });
|
||||
renderer.setSize(W, H);
|
||||
renderer.setPixelRatio(1);
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1.3;
|
||||
renderer.outputEncoding = THREE.sRGBEncoding;
|
||||
var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true, alpha: true });
|
||||
renderer.setSize(W, H);
|
||||
renderer.setPixelRatio(1);
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1.3;
|
||||
renderer.outputEncoding = THREE.sRGBEncoding;
|
||||
|
||||
var scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x050510);
|
||||
scene.fog = new THREE.FogExp2(0x050510, 0.06);
|
||||
var scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x050510);
|
||||
scene.fog = new THREE.FogExp2(0x050510, 0.06);
|
||||
|
||||
var camera = new THREE.PerspectiveCamera(50, W / H, 0.1, 100);
|
||||
camera.position.set(0, 0, 4);
|
||||
var camera = new THREE.PerspectiveCamera(50, W / H, 0.1, 100);
|
||||
camera.position.set(0, 0, 4);
|
||||
|
||||
// ── Environment lighting ──────────────────────────────
|
||||
var ambient = new THREE.AmbientLight(0x1a1a3a, 0.3);
|
||||
scene.add(ambient);
|
||||
// ── Environment lighting ──────────────────────────────
|
||||
var ambient = new THREE.AmbientLight(0x1a1a3a, 0.3);
|
||||
scene.add(ambient);
|
||||
|
||||
var keyLight = new THREE.DirectionalLight(0xffeedd, 1.2);
|
||||
keyLight.position.set(3, 4, 5);
|
||||
scene.add(keyLight);
|
||||
var keyLight = new THREE.DirectionalLight(0xffeedd, 1.2);
|
||||
keyLight.position.set(3, 4, 5);
|
||||
scene.add(keyLight);
|
||||
|
||||
var fillLight = new THREE.DirectionalLight(0x4488ff, 0.4);
|
||||
fillLight.position.set(-3, 1, 3);
|
||||
scene.add(fillLight);
|
||||
var fillLight = new THREE.DirectionalLight(0x4488ff, 0.4);
|
||||
fillLight.position.set(-3, 1, 3);
|
||||
scene.add(fillLight);
|
||||
|
||||
var rimLight = new THREE.PointLight(0xff0080, 0.6, 15);
|
||||
rimLight.position.set(-3, 2, -3);
|
||||
scene.add(rimLight);
|
||||
var rimLight = new THREE.PointLight(0xff0080, 0.6, 15);
|
||||
rimLight.position.set(-3, 2, -3);
|
||||
scene.add(rimLight);
|
||||
|
||||
var topLight = new THREE.PointLight(0x00d4ff, 0.4, 15);
|
||||
topLight.position.set(0, 5, 0);
|
||||
scene.add(topLight);
|
||||
var topLight = new THREE.PointLight(0x00d4ff, 0.4, 15);
|
||||
topLight.position.set(0, 5, 0);
|
||||
scene.add(topLight);
|
||||
|
||||
// ── Ground grid ───────────────────────────────────────
|
||||
var gridHelper = new THREE.GridHelper(20, 40, 0x1a1a3a, 0x0a0a1a);
|
||||
gridHelper.position.y = -2;
|
||||
gridHelper.material.transparent = true;
|
||||
gridHelper.material.opacity = 0.25;
|
||||
scene.add(gridHelper);
|
||||
// ── Ground grid ───────────────────────────────────────
|
||||
var gridHelper = new THREE.GridHelper(20, 40, 0x1a1a3a, 0x0a0a1a);
|
||||
gridHelper.position.y = -2;
|
||||
gridHelper.material.transparent = true;
|
||||
gridHelper.material.opacity = 0.25;
|
||||
scene.add(gridHelper);
|
||||
|
||||
// ── Floating particles ────────────────────────────────
|
||||
var particleCount = 300;
|
||||
var particleGeo = new THREE.BufferGeometry();
|
||||
var positions = new Float32Array(particleCount * 3);
|
||||
for (var i = 0; i < particleCount; i++) {
|
||||
positions[i * 3] = (Math.random() - 0.5) * 16;
|
||||
positions[i * 3 + 1] = (Math.random() - 0.5) * 10;
|
||||
positions[i * 3 + 2] = (Math.random() - 0.5) * 12 - 2;
|
||||
}
|
||||
particleGeo.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
var particleMat = new THREE.PointsMaterial({
|
||||
color: 0x00d4ff, size: 0.03, transparent: true, opacity: 0.25
|
||||
});
|
||||
var particles = new THREE.Points(particleGeo, particleMat);
|
||||
scene.add(particles);
|
||||
|
||||
// ── Load DamagedHelmet GLB ────────────────────────────
|
||||
var helmetGroup = new THREE.Group();
|
||||
scene.add(helmetGroup);
|
||||
|
||||
var loader = new THREE.GLTFLoader();
|
||||
var modelReady = false;
|
||||
|
||||
loader.load("models/DamagedHelmet.glb", function (gltf) {
|
||||
var model = gltf.scene;
|
||||
var box = new THREE.Box3().setFromObject(model);
|
||||
var size = box.getSize(new THREE.Vector3());
|
||||
var scale = 2.2 / Math.max(size.x, size.y, size.z);
|
||||
model.scale.setScalar(scale);
|
||||
box.setFromObject(model);
|
||||
model.position.sub(box.getCenter(new THREE.Vector3()));
|
||||
|
||||
model.traverse(function (child) {
|
||||
if (child.isMesh) {
|
||||
child.material.envMapIntensity = 1.5;
|
||||
}
|
||||
});
|
||||
|
||||
helmetGroup.add(model);
|
||||
modelReady = true;
|
||||
renderer.render(scene, camera);
|
||||
}, undefined, function (err) {
|
||||
// Fallback: show a reflective sphere if model fails to load
|
||||
var fallbackGeo = new THREE.IcosahedronGeometry(1.2, 4);
|
||||
var fallbackMat = new THREE.MeshPhysicalMaterial({
|
||||
color: 0x222244, metalness: 0.9, roughness: 0.1,
|
||||
clearcoat: 1, clearcoatRoughness: 0.05,
|
||||
});
|
||||
helmetGroup.add(new THREE.Mesh(fallbackGeo, fallbackMat));
|
||||
modelReady = true;
|
||||
renderer.render(scene, camera);
|
||||
});
|
||||
|
||||
// ── Camera state ──────────────────────────────────────
|
||||
var camState = { x: 0, y: 0, z: 4, lookX: 0, lookY: 0, lookZ: 0, fov: 50 };
|
||||
|
||||
function updateCamera() {
|
||||
camera.position.set(camState.x, camState.y, camState.z);
|
||||
camera.lookAt(camState.lookX, camState.lookY, camState.lookZ);
|
||||
camera.fov = camState.fov;
|
||||
camera.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
// ── Camera moves ──────────────────────────────────────
|
||||
|
||||
function dollyZoomKeyframes(tl, startT) {
|
||||
tl.to(camState, { z: 2.8, fov: 30, duration: 1.5, ease: "power2.inOut" }, startT);
|
||||
tl.to(camState, { z: 7, fov: 75, duration: 2, ease: "power2.inOut" }, startT + 1.5);
|
||||
tl.to(camState, { z: 4, fov: 50, duration: 0.5, ease: "power2.out" }, startT + 3.5);
|
||||
}
|
||||
|
||||
function craneShotKeyframes(tl, startT) {
|
||||
tl.set(camState, { y: -2, z: 3.5, lookY: 0 }, startT);
|
||||
tl.to(camState, { y: 2.5, z: 4.5, lookY: 0, duration: 3, ease: "power1.inOut" }, startT);
|
||||
tl.to(camState, { z: 3.8, duration: 1, ease: "power2.out" }, startT + 3);
|
||||
}
|
||||
|
||||
function orbitKeyframes(tl, startT) {
|
||||
var orbitState = { angle: 0 };
|
||||
tl.set(camState, { x: 0, y: 0.3, z: 4 }, startT);
|
||||
tl.to(orbitState, {
|
||||
angle: Math.PI * 1.2,
|
||||
duration: 4, ease: "power1.inOut",
|
||||
onUpdate: function () {
|
||||
camState.x = Math.sin(orbitState.angle) * 4;
|
||||
camState.z = Math.cos(orbitState.angle) * 4;
|
||||
camState.y = 0.3 + Math.sin(orbitState.angle * 0.7) * 0.8;
|
||||
}
|
||||
}, startT);
|
||||
}
|
||||
|
||||
function rackFocusKeyframes(tl, startT) {
|
||||
tl.set(camState, { x: 0, y: 0, z: 4, fov: 50 }, startT);
|
||||
tl.to(camState, { z: 2, fov: 25, y: 0.2, x: 0.5, duration: 1.5, ease: "power3.inOut" }, startT);
|
||||
tl.to(camState, { x: -0.3, duration: 1, ease: "sine.inOut" }, startT + 1.5);
|
||||
tl.to(camState, { z: 5, fov: 55, x: 0, y: -0.3, duration: 1.5, ease: "power2.in" }, startT + 2.5);
|
||||
}
|
||||
|
||||
// ── Build timeline ────────────────────────────────────
|
||||
var tl = gsap.timeline({
|
||||
paused: true,
|
||||
onUpdate: function () {
|
||||
updateCamera();
|
||||
helmetGroup.rotation.y += 0.003;
|
||||
particles.rotation.y += 0.001;
|
||||
renderer.render(scene, camera);
|
||||
// ── Floating particles ────────────────────────────────
|
||||
var particleCount = 300;
|
||||
var particleGeo = new THREE.BufferGeometry();
|
||||
var positions = new Float32Array(particleCount * 3);
|
||||
for (var i = 0; i < particleCount; i++) {
|
||||
positions[i * 3] = (Math.random() - 0.5) * 16;
|
||||
positions[i * 3 + 1] = (Math.random() - 0.5) * 10;
|
||||
positions[i * 3 + 2] = (Math.random() - 0.5) * 12 - 2;
|
||||
}
|
||||
});
|
||||
particleGeo.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
var particleMat = new THREE.PointsMaterial({
|
||||
color: 0x00d4ff,
|
||||
size: 0.03,
|
||||
transparent: true,
|
||||
opacity: 0.25,
|
||||
});
|
||||
var particles = new THREE.Points(particleGeo, particleMat);
|
||||
scene.add(particles);
|
||||
|
||||
var moveNames = ["Dolly Zoom", "Crane Shot", "Orbit", "Rack Focus"];
|
||||
var labelEl = document.getElementById("move-label");
|
||||
var nameEl = document.getElementById("move-name");
|
||||
// ── Load DamagedHelmet GLB ────────────────────────────
|
||||
var helmetGroup = new THREE.Group();
|
||||
scene.add(helmetGroup);
|
||||
|
||||
dollyZoomKeyframes(tl, 0);
|
||||
craneShotKeyframes(tl, 4);
|
||||
orbitKeyframes(tl, 8);
|
||||
rackFocusKeyframes(tl, 12);
|
||||
var loader = new THREE.GLTFLoader();
|
||||
var modelReady = false;
|
||||
|
||||
for (var m = 0; m < 4; m++) {
|
||||
(function (idx) {
|
||||
var s = idx * 4;
|
||||
tl.call(function () { nameEl.textContent = moveNames[idx]; }, null, s + 0.1);
|
||||
tl.fromTo(labelEl, { opacity: 0 }, { opacity: 1, duration: 0.3 }, s + 0.1);
|
||||
tl.to(labelEl, { opacity: 0, duration: 0.3 }, s + 3.4);
|
||||
})(m);
|
||||
}
|
||||
loader.load(
|
||||
"models/DamagedHelmet.glb",
|
||||
function (gltf) {
|
||||
var model = gltf.scene;
|
||||
var box = new THREE.Box3().setFromObject(model);
|
||||
var size = box.getSize(new THREE.Vector3());
|
||||
var scale = 2.2 / Math.max(size.x, size.y, size.z);
|
||||
model.scale.setScalar(scale);
|
||||
box.setFromObject(model);
|
||||
model.position.sub(box.getCenter(new THREE.Vector3()));
|
||||
|
||||
tl.to({}, { duration: 16, ease: "none" }, 0);
|
||||
renderer.render(scene, camera);
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
model.traverse(function (child) {
|
||||
if (child.isMesh) {
|
||||
child.material.envMapIntensity = 1.5;
|
||||
}
|
||||
});
|
||||
|
||||
helmetGroup.add(model);
|
||||
modelReady = true;
|
||||
renderer.render(scene, camera);
|
||||
},
|
||||
undefined,
|
||||
function (err) {
|
||||
// Fallback: show a reflective sphere if model fails to load
|
||||
var fallbackGeo = new THREE.IcosahedronGeometry(1.2, 4);
|
||||
var fallbackMat = new THREE.MeshPhysicalMaterial({
|
||||
color: 0x222244,
|
||||
metalness: 0.9,
|
||||
roughness: 0.1,
|
||||
clearcoat: 1,
|
||||
clearcoatRoughness: 0.05,
|
||||
});
|
||||
helmetGroup.add(new THREE.Mesh(fallbackGeo, fallbackMat));
|
||||
modelReady = true;
|
||||
renderer.render(scene, camera);
|
||||
},
|
||||
);
|
||||
|
||||
// ── Camera state ──────────────────────────────────────
|
||||
var camState = { x: 0, y: 0, z: 4, lookX: 0, lookY: 0, lookZ: 0, fov: 50 };
|
||||
|
||||
function updateCamera() {
|
||||
camera.position.set(camState.x, camState.y, camState.z);
|
||||
camera.lookAt(camState.lookX, camState.lookY, camState.lookZ);
|
||||
camera.fov = camState.fov;
|
||||
camera.updateProjectionMatrix();
|
||||
}
|
||||
|
||||
// ── Camera moves ──────────────────────────────────────
|
||||
|
||||
function dollyZoomKeyframes(tl, startT) {
|
||||
tl.to(camState, { z: 2.8, fov: 30, duration: 1.5, ease: "power2.inOut" }, startT);
|
||||
tl.to(camState, { z: 7, fov: 75, duration: 2, ease: "power2.inOut" }, startT + 1.5);
|
||||
tl.to(camState, { z: 4, fov: 50, duration: 0.5, ease: "power2.out" }, startT + 3.5);
|
||||
}
|
||||
|
||||
function craneShotKeyframes(tl, startT) {
|
||||
tl.set(camState, { y: -2, z: 3.5, lookY: 0 }, startT);
|
||||
tl.to(camState, { y: 2.5, z: 4.5, lookY: 0, duration: 3, ease: "power1.inOut" }, startT);
|
||||
tl.to(camState, { z: 3.8, duration: 1, ease: "power2.out" }, startT + 3);
|
||||
}
|
||||
|
||||
function orbitKeyframes(tl, startT) {
|
||||
var orbitState = { angle: 0 };
|
||||
tl.set(camState, { x: 0, y: 0.3, z: 4 }, startT);
|
||||
tl.to(
|
||||
orbitState,
|
||||
{
|
||||
angle: Math.PI * 1.2,
|
||||
duration: 4,
|
||||
ease: "power1.inOut",
|
||||
onUpdate: function () {
|
||||
camState.x = Math.sin(orbitState.angle) * 4;
|
||||
camState.z = Math.cos(orbitState.angle) * 4;
|
||||
camState.y = 0.3 + Math.sin(orbitState.angle * 0.7) * 0.8;
|
||||
},
|
||||
},
|
||||
startT,
|
||||
);
|
||||
}
|
||||
|
||||
function rackFocusKeyframes(tl, startT) {
|
||||
tl.set(camState, { x: 0, y: 0, z: 4, fov: 50 }, startT);
|
||||
tl.to(
|
||||
camState,
|
||||
{ z: 2, fov: 25, y: 0.2, x: 0.5, duration: 1.5, ease: "power3.inOut" },
|
||||
startT,
|
||||
);
|
||||
tl.to(camState, { x: -0.3, duration: 1, ease: "sine.inOut" }, startT + 1.5);
|
||||
tl.to(
|
||||
camState,
|
||||
{ z: 5, fov: 55, x: 0, y: -0.3, duration: 1.5, ease: "power2.in" },
|
||||
startT + 2.5,
|
||||
);
|
||||
}
|
||||
|
||||
// ── Build timeline ────────────────────────────────────
|
||||
var tl = gsap.timeline({
|
||||
paused: true,
|
||||
onUpdate: function () {
|
||||
updateCamera();
|
||||
helmetGroup.rotation.y += 0.003;
|
||||
particles.rotation.y += 0.001;
|
||||
renderer.render(scene, camera);
|
||||
},
|
||||
});
|
||||
|
||||
var moveNames = ["Dolly Zoom", "Crane Shot", "Orbit", "Rack Focus"];
|
||||
var labelEl = document.getElementById("move-label");
|
||||
var nameEl = document.getElementById("move-name");
|
||||
|
||||
dollyZoomKeyframes(tl, 0);
|
||||
craneShotKeyframes(tl, 4);
|
||||
orbitKeyframes(tl, 8);
|
||||
rackFocusKeyframes(tl, 12);
|
||||
|
||||
for (var m = 0; m < 4; m++) {
|
||||
(function (idx) {
|
||||
var s = idx * 4;
|
||||
tl.call(
|
||||
function () {
|
||||
nameEl.textContent = moveNames[idx];
|
||||
},
|
||||
null,
|
||||
s + 0.1,
|
||||
);
|
||||
tl.fromTo(labelEl, { opacity: 0 }, { opacity: 1, duration: 0.3 }, s + 0.1);
|
||||
tl.to(labelEl, { opacity: 0, duration: 0.3 }, s + 3.4);
|
||||
})(m);
|
||||
}
|
||||
|
||||
tl.to({}, { duration: 16, ease: "none" }, 0);
|
||||
renderer.render(scene, camera);
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+302
-248
@@ -4,288 +4,342 @@
|
||||
<meta charset="utf-8" />
|
||||
<meta name="viewport" content="width=1920, height=1080" />
|
||||
<title>Volumetric Light Rays</title>
|
||||
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap" rel="stylesheet" />
|
||||
<link
|
||||
href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800;900&display=swap"
|
||||
rel="stylesheet"
|
||||
/>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/three@0.147.0/build/three.min.js"></script>
|
||||
<style>
|
||||
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { background: #000; overflow: hidden; }
|
||||
#root { position: relative; width: 1920px; height: 1080px; overflow: hidden; background: #000; }
|
||||
#three-canvas { position: absolute; top: 0; left: 0; width: 1920px; height: 1080px; }
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
}
|
||||
#root {
|
||||
position: relative;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
overflow: hidden;
|
||||
background: #000;
|
||||
}
|
||||
#three-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="8" data-width="1920" data-height="1080">
|
||||
<div
|
||||
id="root"
|
||||
data-composition-id="main"
|
||||
data-start="0"
|
||||
data-duration="8"
|
||||
data-width="1920"
|
||||
data-height="1080"
|
||||
>
|
||||
<canvas id="three-canvas" width="1920" height="1080"></canvas>
|
||||
<div id="driver" data-start="0" data-duration="8" data-track-index="0"
|
||||
style="position:absolute;width:1px;height:1px;opacity:0;pointer-events:none"></div>
|
||||
<div
|
||||
id="driver"
|
||||
data-start="0"
|
||||
data-duration="8"
|
||||
data-track-index="0"
|
||||
style="position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
|
||||
var W = 1920, H = 1080;
|
||||
var canvas = document.getElementById("three-canvas");
|
||||
var W = 1920,
|
||||
H = 1080;
|
||||
var canvas = document.getElementById("three-canvas");
|
||||
|
||||
// ── Renderer ──────────────────────────────────────────
|
||||
var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true });
|
||||
renderer.setSize(W, H);
|
||||
renderer.setPixelRatio(1);
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1.0;
|
||||
// ── Renderer ──────────────────────────────────────────
|
||||
var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true });
|
||||
renderer.setSize(W, H);
|
||||
renderer.setPixelRatio(1);
|
||||
renderer.toneMapping = THREE.ACESFilmicToneMapping;
|
||||
renderer.toneMappingExposure = 1.0;
|
||||
|
||||
// ── Scene ─────────────────────────────────────────────
|
||||
var scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x020208);
|
||||
scene.fog = new THREE.FogExp2(0x020208, 0.04);
|
||||
// ── Scene ─────────────────────────────────────────────
|
||||
var scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x020208);
|
||||
scene.fog = new THREE.FogExp2(0x020208, 0.04);
|
||||
|
||||
var camera = new THREE.PerspectiveCamera(60, W / H, 0.1, 100);
|
||||
camera.position.set(0, 2, 8);
|
||||
camera.lookAt(0, 1, 0);
|
||||
var camera = new THREE.PerspectiveCamera(60, W / H, 0.1, 100);
|
||||
camera.position.set(0, 2, 8);
|
||||
camera.lookAt(0, 1, 0);
|
||||
|
||||
// ── Light source (the "sun") ──────────────────────────
|
||||
var sunPos = new THREE.Vector3(0, 6, -8);
|
||||
var sunLight = new THREE.PointLight(0xffeedd, 2, 50);
|
||||
sunLight.position.copy(sunPos);
|
||||
scene.add(sunLight);
|
||||
// ── Light source (the "sun") ──────────────────────────
|
||||
var sunPos = new THREE.Vector3(0, 6, -8);
|
||||
var sunLight = new THREE.PointLight(0xffeedd, 2, 50);
|
||||
sunLight.position.copy(sunPos);
|
||||
scene.add(sunLight);
|
||||
|
||||
var ambient = new THREE.AmbientLight(0x0a0a20, 0.3);
|
||||
scene.add(ambient);
|
||||
var ambient = new THREE.AmbientLight(0x0a0a20, 0.3);
|
||||
scene.add(ambient);
|
||||
|
||||
// Sun glow sphere
|
||||
var sunGeo = new THREE.SphereGeometry(0.8, 32, 32);
|
||||
var sunMat = new THREE.MeshBasicMaterial({ color: 0xffeedd });
|
||||
var sunMesh = new THREE.Mesh(sunGeo, sunMat);
|
||||
sunMesh.position.copy(sunPos);
|
||||
scene.add(sunMesh);
|
||||
// Sun glow sphere
|
||||
var sunGeo = new THREE.SphereGeometry(0.8, 32, 32);
|
||||
var sunMat = new THREE.MeshBasicMaterial({ color: 0xffeedd });
|
||||
var sunMesh = new THREE.Mesh(sunGeo, sunMat);
|
||||
sunMesh.position.copy(sunPos);
|
||||
scene.add(sunMesh);
|
||||
|
||||
// ── Occluding pillars (create god ray shadows) ────────
|
||||
var pillarMat = new THREE.MeshStandardMaterial({
|
||||
color: 0x080818, roughness: 0.8, metalness: 0.2,
|
||||
});
|
||||
var pillarPositions = [
|
||||
[-3, 0, -2], [-1.2, 0, -3], [1.2, 0, -3], [3, 0, -2],
|
||||
[-2, 0, -5], [0, 0, -5.5], [2, 0, -5],
|
||||
];
|
||||
pillarPositions.forEach(function (p) {
|
||||
var h = 4 + Math.random() * 4;
|
||||
var r = 0.15 + Math.random() * 0.2;
|
||||
var geo = new THREE.CylinderGeometry(r, r, h, 8);
|
||||
var mesh = new THREE.Mesh(geo, pillarMat);
|
||||
mesh.position.set(p[0], h / 2, p[2]);
|
||||
scene.add(mesh);
|
||||
});
|
||||
// ── Occluding pillars (create god ray shadows) ────────
|
||||
var pillarMat = new THREE.MeshStandardMaterial({
|
||||
color: 0x080818,
|
||||
roughness: 0.8,
|
||||
metalness: 0.2,
|
||||
});
|
||||
var pillarPositions = [
|
||||
[-3, 0, -2],
|
||||
[-1.2, 0, -3],
|
||||
[1.2, 0, -3],
|
||||
[3, 0, -2],
|
||||
[-2, 0, -5],
|
||||
[0, 0, -5.5],
|
||||
[2, 0, -5],
|
||||
];
|
||||
pillarPositions.forEach(function (p) {
|
||||
var h = 4 + Math.random() * 4;
|
||||
var r = 0.15 + Math.random() * 0.2;
|
||||
var geo = new THREE.CylinderGeometry(r, r, h, 8);
|
||||
var mesh = new THREE.Mesh(geo, pillarMat);
|
||||
mesh.position.set(p[0], h / 2, p[2]);
|
||||
scene.add(mesh);
|
||||
});
|
||||
|
||||
// ── Ground plane ──────────────────────────────────────
|
||||
var groundGeo = new THREE.PlaneGeometry(40, 40);
|
||||
var groundMat = new THREE.MeshStandardMaterial({
|
||||
color: 0x0a0a18, roughness: 0.9, metalness: 0,
|
||||
});
|
||||
var ground = new THREE.Mesh(groundGeo, groundMat);
|
||||
ground.rotation.x = -Math.PI / 2;
|
||||
scene.add(ground);
|
||||
// ── Ground plane ──────────────────────────────────────
|
||||
var groundGeo = new THREE.PlaneGeometry(40, 40);
|
||||
var groundMat = new THREE.MeshStandardMaterial({
|
||||
color: 0x0a0a18,
|
||||
roughness: 0.9,
|
||||
metalness: 0,
|
||||
});
|
||||
var ground = new THREE.Mesh(groundGeo, groundMat);
|
||||
ground.rotation.x = -Math.PI / 2;
|
||||
scene.add(ground);
|
||||
|
||||
// ── Dust particles ────────────────────────────────────
|
||||
var dustCount = 500;
|
||||
var dustGeo = new THREE.BufferGeometry();
|
||||
var dustPos = new Float32Array(dustCount * 3);
|
||||
for (var i = 0; i < dustCount; i++) {
|
||||
dustPos[i * 3] = (Math.random() - 0.5) * 12;
|
||||
dustPos[i * 3 + 1] = Math.random() * 8;
|
||||
dustPos[i * 3 + 2] = (Math.random() - 0.5) * 12 - 2;
|
||||
}
|
||||
dustGeo.setAttribute("position", new THREE.BufferAttribute(dustPos, 3));
|
||||
var dustMat = new THREE.PointsMaterial({
|
||||
color: 0xffeedd, size: 0.04, transparent: true, opacity: 0.4,
|
||||
});
|
||||
var dust = new THREE.Points(dustGeo, dustMat);
|
||||
scene.add(dust);
|
||||
|
||||
// ── God rays post-process (screen-space radial blur) ──
|
||||
var godRayScene = new THREE.Scene();
|
||||
var godRayCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
||||
|
||||
var occlusionRT = new THREE.WebGLRenderTarget(W / 2, H / 2);
|
||||
var godRayRT = new THREE.WebGLRenderTarget(W / 2, H / 2);
|
||||
|
||||
var godRayMaterial = new THREE.ShaderMaterial({
|
||||
uniforms: {
|
||||
tDiffuse: { value: null },
|
||||
lightPos: { value: new THREE.Vector2(0.5, 0.7) },
|
||||
exposure: { value: 0.25 },
|
||||
decay: { value: 0.96 },
|
||||
density: { value: 0.8 },
|
||||
weight: { value: 0.5 },
|
||||
samples: { value: 60 },
|
||||
},
|
||||
vertexShader: [
|
||||
"varying vec2 vUv;",
|
||||
"void main() {",
|
||||
" vUv = uv;",
|
||||
" gl_Position = vec4(position, 1.0);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
fragmentShader: [
|
||||
"precision highp float;",
|
||||
"varying vec2 vUv;",
|
||||
"uniform sampler2D tDiffuse;",
|
||||
"uniform vec2 lightPos;",
|
||||
"uniform float exposure;",
|
||||
"uniform float decay;",
|
||||
"uniform float density;",
|
||||
"uniform float weight;",
|
||||
"uniform float samples;",
|
||||
"",
|
||||
"void main() {",
|
||||
" vec2 texCoord = vUv;",
|
||||
" vec2 deltaTexCoord = (texCoord - lightPos) * (1.0 / samples) * density;",
|
||||
" vec3 color = texture2D(tDiffuse, texCoord).rgb;",
|
||||
" float illuminationDecay = 1.0;",
|
||||
" for (int i = 0; i < 60; i++) {",
|
||||
" texCoord -= deltaTexCoord;",
|
||||
" vec3 samp = texture2D(tDiffuse, texCoord).rgb;",
|
||||
" samp *= illuminationDecay * weight;",
|
||||
" color += samp;",
|
||||
" illuminationDecay *= decay;",
|
||||
" }",
|
||||
" gl_FragColor = vec4(color * exposure, 1.0);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
});
|
||||
|
||||
var compositeMaterial = new THREE.ShaderMaterial({
|
||||
uniforms: {
|
||||
tScene: { value: null },
|
||||
tGodRays: { value: null },
|
||||
godRayIntensity: { value: 1.0 },
|
||||
},
|
||||
vertexShader: [
|
||||
"varying vec2 vUv;",
|
||||
"void main() { vUv = uv; gl_Position = vec4(position, 1.0); }",
|
||||
].join("\n"),
|
||||
fragmentShader: [
|
||||
"precision highp float;",
|
||||
"varying vec2 vUv;",
|
||||
"uniform sampler2D tScene;",
|
||||
"uniform sampler2D tGodRays;",
|
||||
"uniform float godRayIntensity;",
|
||||
"void main() {",
|
||||
" vec3 scene = texture2D(tScene, vUv).rgb;",
|
||||
" vec3 rays = texture2D(tGodRays, vUv).rgb;",
|
||||
" // Warm tint on the rays",
|
||||
" rays *= vec3(1.0, 0.85, 0.6);",
|
||||
" gl_FragColor = vec4(scene + rays * godRayIntensity, 1.0);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
});
|
||||
|
||||
var fullscreenQuad = new THREE.Mesh(
|
||||
new THREE.PlaneGeometry(2, 2),
|
||||
godRayMaterial
|
||||
);
|
||||
godRayScene.add(fullscreenQuad);
|
||||
|
||||
var sceneRT = new THREE.WebGLRenderTarget(W, H);
|
||||
|
||||
// Occlusion scene — black occluders, white sun
|
||||
var occScene = new THREE.Scene();
|
||||
occScene.background = new THREE.Color(0x000000);
|
||||
var occSun = new THREE.Mesh(sunGeo.clone(), new THREE.MeshBasicMaterial({ color: 0xffffff }));
|
||||
occSun.position.copy(sunPos);
|
||||
occScene.add(occSun);
|
||||
|
||||
// Black versions of pillars for occlusion
|
||||
var occMat = new THREE.MeshBasicMaterial({ color: 0x000000 });
|
||||
pillarPositions.forEach(function (p) {
|
||||
var h = 4 + Math.random() * 4;
|
||||
var r = 0.15 + Math.random() * 0.2;
|
||||
var geo = new THREE.CylinderGeometry(r, r, h, 8);
|
||||
var mesh = new THREE.Mesh(geo, occMat);
|
||||
mesh.position.set(p[0], h / 2, p[2]);
|
||||
occScene.add(mesh);
|
||||
});
|
||||
|
||||
// ── Animation state ───────────────────────────────────
|
||||
var state = { camAngle: 0, rayIntensity: 0, sunY: 6 };
|
||||
|
||||
function projectSunToScreen() {
|
||||
var v = sunPos.clone().project(camera);
|
||||
return new THREE.Vector2(v.x * 0.5 + 0.5, v.y * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
function renderFrame() {
|
||||
// Update sun position
|
||||
sunPos.y = state.sunY;
|
||||
sunMesh.position.y = state.sunY;
|
||||
sunLight.position.y = state.sunY;
|
||||
occSun.position.y = state.sunY;
|
||||
|
||||
// Camera orbit
|
||||
camera.position.x = Math.sin(state.camAngle) * 8;
|
||||
camera.position.z = Math.cos(state.camAngle) * 8;
|
||||
camera.position.y = 2 + Math.sin(state.camAngle * 0.5) * 0.5;
|
||||
camera.lookAt(0, 1.5, -2);
|
||||
|
||||
// Dust drift
|
||||
dust.rotation.y += 0.002;
|
||||
var arr = dustGeo.attributes.position.array;
|
||||
for (var i = 1; i < dustCount * 3; i += 3) {
|
||||
arr[i] += 0.002;
|
||||
if (arr[i] > 8) arr[i] = 0;
|
||||
// ── Dust particles ────────────────────────────────────
|
||||
var dustCount = 500;
|
||||
var dustGeo = new THREE.BufferGeometry();
|
||||
var dustPos = new Float32Array(dustCount * 3);
|
||||
for (var i = 0; i < dustCount; i++) {
|
||||
dustPos[i * 3] = (Math.random() - 0.5) * 12;
|
||||
dustPos[i * 3 + 1] = Math.random() * 8;
|
||||
dustPos[i * 3 + 2] = (Math.random() - 0.5) * 12 - 2;
|
||||
}
|
||||
dustGeo.attributes.position.needsUpdate = true;
|
||||
dustGeo.setAttribute("position", new THREE.BufferAttribute(dustPos, 3));
|
||||
var dustMat = new THREE.PointsMaterial({
|
||||
color: 0xffeedd,
|
||||
size: 0.04,
|
||||
transparent: true,
|
||||
opacity: 0.4,
|
||||
});
|
||||
var dust = new THREE.Points(dustGeo, dustMat);
|
||||
scene.add(dust);
|
||||
|
||||
// 1. Render main scene to RT
|
||||
renderer.setRenderTarget(sceneRT);
|
||||
renderer.render(scene, camera);
|
||||
// ── God rays post-process (screen-space radial blur) ──
|
||||
var godRayScene = new THREE.Scene();
|
||||
var godRayCamera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
|
||||
|
||||
// 2. Render occlusion map
|
||||
renderer.setRenderTarget(occlusionRT);
|
||||
renderer.render(occScene, camera);
|
||||
var occlusionRT = new THREE.WebGLRenderTarget(W / 2, H / 2);
|
||||
var godRayRT = new THREE.WebGLRenderTarget(W / 2, H / 2);
|
||||
|
||||
// 3. God rays pass
|
||||
var sp = projectSunToScreen();
|
||||
godRayMaterial.uniforms.tDiffuse.value = occlusionRT.texture;
|
||||
godRayMaterial.uniforms.lightPos.value.copy(sp);
|
||||
fullscreenQuad.material = godRayMaterial;
|
||||
var godRayMaterial = new THREE.ShaderMaterial({
|
||||
uniforms: {
|
||||
tDiffuse: { value: null },
|
||||
lightPos: { value: new THREE.Vector2(0.5, 0.7) },
|
||||
exposure: { value: 0.25 },
|
||||
decay: { value: 0.96 },
|
||||
density: { value: 0.8 },
|
||||
weight: { value: 0.5 },
|
||||
samples: { value: 60 },
|
||||
},
|
||||
vertexShader: [
|
||||
"varying vec2 vUv;",
|
||||
"void main() {",
|
||||
" vUv = uv;",
|
||||
" gl_Position = vec4(position, 1.0);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
fragmentShader: [
|
||||
"precision highp float;",
|
||||
"varying vec2 vUv;",
|
||||
"uniform sampler2D tDiffuse;",
|
||||
"uniform vec2 lightPos;",
|
||||
"uniform float exposure;",
|
||||
"uniform float decay;",
|
||||
"uniform float density;",
|
||||
"uniform float weight;",
|
||||
"uniform float samples;",
|
||||
"",
|
||||
"void main() {",
|
||||
" vec2 texCoord = vUv;",
|
||||
" vec2 deltaTexCoord = (texCoord - lightPos) * (1.0 / samples) * density;",
|
||||
" vec3 color = texture2D(tDiffuse, texCoord).rgb;",
|
||||
" float illuminationDecay = 1.0;",
|
||||
" for (int i = 0; i < 60; i++) {",
|
||||
" texCoord -= deltaTexCoord;",
|
||||
" vec3 samp = texture2D(tDiffuse, texCoord).rgb;",
|
||||
" samp *= illuminationDecay * weight;",
|
||||
" color += samp;",
|
||||
" illuminationDecay *= decay;",
|
||||
" }",
|
||||
" gl_FragColor = vec4(color * exposure, 1.0);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
});
|
||||
|
||||
renderer.setRenderTarget(godRayRT);
|
||||
renderer.render(godRayScene, godRayCamera);
|
||||
var compositeMaterial = new THREE.ShaderMaterial({
|
||||
uniforms: {
|
||||
tScene: { value: null },
|
||||
tGodRays: { value: null },
|
||||
godRayIntensity: { value: 1.0 },
|
||||
},
|
||||
vertexShader: [
|
||||
"varying vec2 vUv;",
|
||||
"void main() { vUv = uv; gl_Position = vec4(position, 1.0); }",
|
||||
].join("\n"),
|
||||
fragmentShader: [
|
||||
"precision highp float;",
|
||||
"varying vec2 vUv;",
|
||||
"uniform sampler2D tScene;",
|
||||
"uniform sampler2D tGodRays;",
|
||||
"uniform float godRayIntensity;",
|
||||
"void main() {",
|
||||
" vec3 scene = texture2D(tScene, vUv).rgb;",
|
||||
" vec3 rays = texture2D(tGodRays, vUv).rgb;",
|
||||
" // Warm tint on the rays",
|
||||
" rays *= vec3(1.0, 0.85, 0.6);",
|
||||
" gl_FragColor = vec4(scene + rays * godRayIntensity, 1.0);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
});
|
||||
|
||||
// 4. Composite
|
||||
compositeMaterial.uniforms.tScene.value = sceneRT.texture;
|
||||
compositeMaterial.uniforms.tGodRays.value = godRayRT.texture;
|
||||
compositeMaterial.uniforms.godRayIntensity.value = state.rayIntensity;
|
||||
fullscreenQuad.material = compositeMaterial;
|
||||
var fullscreenQuad = new THREE.Mesh(new THREE.PlaneGeometry(2, 2), godRayMaterial);
|
||||
godRayScene.add(fullscreenQuad);
|
||||
|
||||
renderer.setRenderTarget(null);
|
||||
renderer.render(godRayScene, godRayCamera);
|
||||
}
|
||||
var sceneRT = new THREE.WebGLRenderTarget(W, H);
|
||||
|
||||
// ── Timeline ──────────────────────────────────────────
|
||||
var tl = gsap.timeline({ paused: true, onUpdate: renderFrame });
|
||||
// Occlusion scene — black occluders, white sun
|
||||
var occScene = new THREE.Scene();
|
||||
occScene.background = new THREE.Color(0x000000);
|
||||
var occSun = new THREE.Mesh(
|
||||
sunGeo.clone(),
|
||||
new THREE.MeshBasicMaterial({ color: 0xffffff }),
|
||||
);
|
||||
occSun.position.copy(sunPos);
|
||||
occScene.add(occSun);
|
||||
|
||||
// Fade in god rays
|
||||
tl.fromTo(state, { rayIntensity: 0 }, { rayIntensity: 1.2, duration: 2, ease: "power2.out" }, 0);
|
||||
// Black versions of pillars for occlusion
|
||||
var occMat = new THREE.MeshBasicMaterial({ color: 0x000000 });
|
||||
pillarPositions.forEach(function (p) {
|
||||
var h = 4 + Math.random() * 4;
|
||||
var r = 0.15 + Math.random() * 0.2;
|
||||
var geo = new THREE.CylinderGeometry(r, r, h, 8);
|
||||
var mesh = new THREE.Mesh(geo, occMat);
|
||||
mesh.position.set(p[0], h / 2, p[2]);
|
||||
occScene.add(mesh);
|
||||
});
|
||||
|
||||
// Slow camera orbit
|
||||
tl.to(state, { camAngle: Math.PI * 0.4, duration: 8, ease: "none" }, 0);
|
||||
// ── Animation state ───────────────────────────────────
|
||||
var state = { camAngle: 0, rayIntensity: 0, sunY: 6 };
|
||||
|
||||
// Sun rises then descends
|
||||
tl.to(state, { sunY: 8, duration: 4, ease: "sine.inOut" }, 0);
|
||||
tl.to(state, { sunY: 4, duration: 4, ease: "sine.inOut" }, 4);
|
||||
function projectSunToScreen() {
|
||||
var v = sunPos.clone().project(camera);
|
||||
return new THREE.Vector2(v.x * 0.5 + 0.5, v.y * 0.5 + 0.5);
|
||||
}
|
||||
|
||||
// Intensity pulse
|
||||
tl.to(state, { rayIntensity: 1.8, duration: 2, ease: "sine.inOut" }, 3);
|
||||
tl.to(state, { rayIntensity: 0.8, duration: 2, ease: "sine.inOut" }, 5);
|
||||
tl.to(state, { rayIntensity: 0, duration: 1, ease: "power2.in" }, 7);
|
||||
function renderFrame() {
|
||||
// Update sun position
|
||||
sunPos.y = state.sunY;
|
||||
sunMesh.position.y = state.sunY;
|
||||
sunLight.position.y = state.sunY;
|
||||
occSun.position.y = state.sunY;
|
||||
|
||||
tl.to({}, { duration: 8, ease: "none" }, 0);
|
||||
// Camera orbit
|
||||
camera.position.x = Math.sin(state.camAngle) * 8;
|
||||
camera.position.z = Math.cos(state.camAngle) * 8;
|
||||
camera.position.y = 2 + Math.sin(state.camAngle * 0.5) * 0.5;
|
||||
camera.lookAt(0, 1.5, -2);
|
||||
|
||||
renderFrame();
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
// Dust drift
|
||||
dust.rotation.y += 0.002;
|
||||
var arr = dustGeo.attributes.position.array;
|
||||
for (var i = 1; i < dustCount * 3; i += 3) {
|
||||
arr[i] += 0.002;
|
||||
if (arr[i] > 8) arr[i] = 0;
|
||||
}
|
||||
dustGeo.attributes.position.needsUpdate = true;
|
||||
|
||||
// 1. Render main scene to RT
|
||||
renderer.setRenderTarget(sceneRT);
|
||||
renderer.render(scene, camera);
|
||||
|
||||
// 2. Render occlusion map
|
||||
renderer.setRenderTarget(occlusionRT);
|
||||
renderer.render(occScene, camera);
|
||||
|
||||
// 3. God rays pass
|
||||
var sp = projectSunToScreen();
|
||||
godRayMaterial.uniforms.tDiffuse.value = occlusionRT.texture;
|
||||
godRayMaterial.uniforms.lightPos.value.copy(sp);
|
||||
fullscreenQuad.material = godRayMaterial;
|
||||
|
||||
renderer.setRenderTarget(godRayRT);
|
||||
renderer.render(godRayScene, godRayCamera);
|
||||
|
||||
// 4. Composite
|
||||
compositeMaterial.uniforms.tScene.value = sceneRT.texture;
|
||||
compositeMaterial.uniforms.tGodRays.value = godRayRT.texture;
|
||||
compositeMaterial.uniforms.godRayIntensity.value = state.rayIntensity;
|
||||
fullscreenQuad.material = compositeMaterial;
|
||||
|
||||
renderer.setRenderTarget(null);
|
||||
renderer.render(godRayScene, godRayCamera);
|
||||
}
|
||||
|
||||
// ── Timeline ──────────────────────────────────────────
|
||||
var tl = gsap.timeline({ paused: true, onUpdate: renderFrame });
|
||||
|
||||
// Fade in god rays
|
||||
tl.fromTo(
|
||||
state,
|
||||
{ rayIntensity: 0 },
|
||||
{ rayIntensity: 1.2, duration: 2, ease: "power2.out" },
|
||||
0,
|
||||
);
|
||||
|
||||
// Slow camera orbit
|
||||
tl.to(state, { camAngle: Math.PI * 0.4, duration: 8, ease: "none" }, 0);
|
||||
|
||||
// Sun rises then descends
|
||||
tl.to(state, { sunY: 8, duration: 4, ease: "sine.inOut" }, 0);
|
||||
tl.to(state, { sunY: 4, duration: 4, ease: "sine.inOut" }, 4);
|
||||
|
||||
// Intensity pulse
|
||||
tl.to(state, { rayIntensity: 1.8, duration: 2, ease: "sine.inOut" }, 3);
|
||||
tl.to(state, { rayIntensity: 0.8, duration: 2, ease: "sine.inOut" }, 5);
|
||||
tl.to(state, { rayIntensity: 0, duration: 1, ease: "power2.in" }, 7);
|
||||
|
||||
tl.to({}, { duration: 8, ease: "none" }, 0);
|
||||
|
||||
renderFrame();
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+267
-216
@@ -7,244 +7,295 @@
|
||||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/npm/three@0.147.0/build/three.min.js"></script>
|
||||
<style>
|
||||
*, *::before, *::after { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { background: #030308; overflow: hidden; }
|
||||
#root { position: relative; width: 1920px; height: 1080px; overflow: hidden; background: #030308; }
|
||||
#three-canvas { position: absolute; top: 0; left: 0; width: 1920px; height: 1080px; }
|
||||
*,
|
||||
*::before,
|
||||
*::after {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
background: #030308;
|
||||
overflow: hidden;
|
||||
}
|
||||
#root {
|
||||
position: relative;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
overflow: hidden;
|
||||
background: #030308;
|
||||
}
|
||||
#three-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="10" data-width="1920" data-height="1080">
|
||||
<div
|
||||
id="root"
|
||||
data-composition-id="main"
|
||||
data-start="0"
|
||||
data-duration="10"
|
||||
data-width="1920"
|
||||
data-height="1080"
|
||||
>
|
||||
<canvas id="three-canvas" width="1920" height="1080"></canvas>
|
||||
<div id="driver" data-start="0" data-duration="10" data-track-index="0"
|
||||
style="position:absolute;width:1px;height:1px;opacity:0;pointer-events:none"></div>
|
||||
<div
|
||||
id="driver"
|
||||
data-start="0"
|
||||
data-duration="10"
|
||||
data-track-index="0"
|
||||
style="position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
|
||||
var W = 1920, H = 1080;
|
||||
var canvas = document.getElementById("three-canvas");
|
||||
var COUNT = 8000;
|
||||
var W = 1920,
|
||||
H = 1080;
|
||||
var canvas = document.getElementById("three-canvas");
|
||||
var COUNT = 8000;
|
||||
|
||||
var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true });
|
||||
renderer.setSize(W, H);
|
||||
renderer.setPixelRatio(1);
|
||||
var renderer = new THREE.WebGLRenderer({ canvas: canvas, antialias: true });
|
||||
renderer.setSize(W, H);
|
||||
renderer.setPixelRatio(1);
|
||||
|
||||
var scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x030308);
|
||||
var scene = new THREE.Scene();
|
||||
scene.background = new THREE.Color(0x030308);
|
||||
|
||||
var camera = new THREE.PerspectiveCamera(50, W / H, 0.1, 100);
|
||||
camera.position.set(0, 0, 12);
|
||||
var camera = new THREE.PerspectiveCamera(50, W / H, 0.1, 100);
|
||||
camera.position.set(0, 0, 12);
|
||||
|
||||
// ── Generate target shapes ────────────────────────────
|
||||
function textToPositions(text, scale) {
|
||||
var c = document.createElement("canvas");
|
||||
c.width = 512; c.height = 128;
|
||||
var ctx = c.getContext("2d");
|
||||
ctx.fillStyle = "#000";
|
||||
ctx.fillRect(0, 0, 512, 128);
|
||||
ctx.font = "bold 90px Inter, Arial, sans-serif";
|
||||
ctx.fillStyle = "#fff";
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillText(text, 256, 68);
|
||||
// ── Generate target shapes ────────────────────────────
|
||||
function textToPositions(text, scale) {
|
||||
var c = document.createElement("canvas");
|
||||
c.width = 512;
|
||||
c.height = 128;
|
||||
var ctx = c.getContext("2d");
|
||||
ctx.fillStyle = "#000";
|
||||
ctx.fillRect(0, 0, 512, 128);
|
||||
ctx.font = "bold 90px Inter, Arial, sans-serif";
|
||||
ctx.fillStyle = "#fff";
|
||||
ctx.textAlign = "center";
|
||||
ctx.textBaseline = "middle";
|
||||
ctx.fillText(text, 256, 68);
|
||||
|
||||
var data = ctx.getImageData(0, 0, 512, 128).data;
|
||||
var pts = [];
|
||||
for (var y = 0; y < 128; y += 2) {
|
||||
for (var x = 0; x < 512; x += 2) {
|
||||
if (data[(y * 512 + x) * 4] > 128) {
|
||||
pts.push(new THREE.Vector3(
|
||||
(x - 256) * scale * 0.018,
|
||||
(64 - y) * scale * 0.018,
|
||||
(Math.random() - 0.5) * 0.3
|
||||
));
|
||||
var data = ctx.getImageData(0, 0, 512, 128).data;
|
||||
var pts = [];
|
||||
for (var y = 0; y < 128; y += 2) {
|
||||
for (var x = 0; x < 512; x += 2) {
|
||||
if (data[(y * 512 + x) * 4] > 128) {
|
||||
pts.push(
|
||||
new THREE.Vector3(
|
||||
(x - 256) * scale * 0.018,
|
||||
(64 - y) * scale * 0.018,
|
||||
(Math.random() - 0.5) * 0.3,
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
function spherePositions(radius, count) {
|
||||
var pts = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
var phi = Math.acos(2 * Math.random() - 1);
|
||||
var theta = Math.random() * Math.PI * 2;
|
||||
pts.push(new THREE.Vector3(
|
||||
radius * Math.sin(phi) * Math.cos(theta),
|
||||
radius * Math.sin(phi) * Math.sin(theta),
|
||||
radius * Math.cos(phi)
|
||||
));
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
function torusPositions(R, r, count) {
|
||||
var pts = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
var u = Math.random() * Math.PI * 2;
|
||||
var v = Math.random() * Math.PI * 2;
|
||||
pts.push(new THREE.Vector3(
|
||||
(R + r * Math.cos(v)) * Math.cos(u),
|
||||
(R + r * Math.cos(v)) * Math.sin(u),
|
||||
r * Math.sin(v)
|
||||
));
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
function noisePositions(spread, count) {
|
||||
var pts = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
pts.push(new THREE.Vector3(
|
||||
(Math.random() - 0.5) * spread,
|
||||
(Math.random() - 0.5) * spread * 0.6,
|
||||
(Math.random() - 0.5) * spread
|
||||
));
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
// Pad/trim arrays to exactly COUNT
|
||||
function padPositions(arr) {
|
||||
while (arr.length < COUNT) {
|
||||
arr.push(arr[Math.floor(Math.random() * arr.length)].clone().add(
|
||||
new THREE.Vector3((Math.random()-0.5)*0.1, (Math.random()-0.5)*0.1, (Math.random()-0.5)*0.1)
|
||||
));
|
||||
}
|
||||
return arr.slice(0, COUNT);
|
||||
}
|
||||
|
||||
var shapes = [
|
||||
padPositions(textToPositions("HYPERFRAMES", 1.0)),
|
||||
padPositions(noisePositions(10, COUNT)),
|
||||
padPositions(spherePositions(3.5, COUNT)),
|
||||
padPositions(noisePositions(12, COUNT)),
|
||||
padPositions(torusPositions(3, 1.2, COUNT)),
|
||||
];
|
||||
|
||||
// ── Particles ─────────────────────────────────────────
|
||||
var geo = new THREE.BufferGeometry();
|
||||
var positions = new Float32Array(COUNT * 3);
|
||||
var colors = new Float32Array(COUNT * 3);
|
||||
var sizes = new Float32Array(COUNT);
|
||||
|
||||
// Start at shape 0
|
||||
for (var i = 0; i < COUNT; i++) {
|
||||
var p = shapes[0][i];
|
||||
positions[i * 3] = p.x;
|
||||
positions[i * 3 + 1] = p.y;
|
||||
positions[i * 3 + 2] = p.z;
|
||||
|
||||
// Color palette: cyan → purple → pink
|
||||
var t = i / COUNT;
|
||||
colors[i * 3] = 0.0 + t * 0.5;
|
||||
colors[i * 3 + 1] = 0.7 - t * 0.4;
|
||||
colors[i * 3 + 2] = 1.0;
|
||||
sizes[i] = 2.0 + Math.random() * 2.0;
|
||||
}
|
||||
|
||||
geo.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
geo.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
||||
geo.setAttribute("size", new THREE.BufferAttribute(sizes, 1));
|
||||
|
||||
var mat = new THREE.ShaderMaterial({
|
||||
uniforms: {
|
||||
uPixelRatio: { value: 1 },
|
||||
uOpacity: { value: 1.0 },
|
||||
},
|
||||
vertexShader: [
|
||||
"attribute float size;",
|
||||
"attribute vec3 color;",
|
||||
"varying vec3 vColor;",
|
||||
"uniform float uPixelRatio;",
|
||||
"void main() {",
|
||||
" vColor = color;",
|
||||
" vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);",
|
||||
" gl_PointSize = size * uPixelRatio * (300.0 / -mvPosition.z);",
|
||||
" gl_Position = projectionMatrix * mvPosition;",
|
||||
"}",
|
||||
].join("\n"),
|
||||
fragmentShader: [
|
||||
"precision highp float;",
|
||||
"varying vec3 vColor;",
|
||||
"uniform float uOpacity;",
|
||||
"void main() {",
|
||||
" float d = length(gl_PointCoord - vec2(0.5));",
|
||||
" if (d > 0.5) discard;",
|
||||
" float alpha = smoothstep(0.5, 0.1, d) * uOpacity;",
|
||||
" gl_FragColor = vec4(vColor, alpha);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
transparent: true,
|
||||
depthWrite: false,
|
||||
blending: THREE.AdditiveBlending,
|
||||
});
|
||||
|
||||
var points = new THREE.Points(geo, mat);
|
||||
scene.add(points);
|
||||
|
||||
// ── Morph state ───────────────────────────────────────
|
||||
var morphState = { progress: 0, shapeIndex: 0, rotation: 0, opacity: 1.0 };
|
||||
|
||||
function lerpToShape(targetIdx, t) {
|
||||
var target = shapes[targetIdx];
|
||||
var pos = geo.attributes.position.array;
|
||||
for (var i = 0; i < COUNT; i++) {
|
||||
var idx = i * 3;
|
||||
pos[idx] += (target[i].x - pos[idx]) * t;
|
||||
pos[idx + 1] += (target[i].y - pos[idx + 1]) * t;
|
||||
pos[idx + 2] += (target[i].z - pos[idx + 2]) * t;
|
||||
}
|
||||
geo.attributes.position.needsUpdate = true;
|
||||
}
|
||||
|
||||
function renderFrame() {
|
||||
points.rotation.y = morphState.rotation;
|
||||
mat.uniforms.uOpacity.value = morphState.opacity;
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
|
||||
// ── Timeline ──────────────────────────────────────────
|
||||
// 10s total: text(2s) → dissolve(1s) → sphere(1.5s) → dissolve(1s) → torus(1.5s) → dissolve(1s) → text(2s)
|
||||
var tl = gsap.timeline({
|
||||
paused: true,
|
||||
onUpdate: function () {
|
||||
var t = tl.time();
|
||||
// Morph between shapes based on time
|
||||
if (t < 2) {
|
||||
lerpToShape(0, 0.15); // Hold text
|
||||
} else if (t < 3) {
|
||||
lerpToShape(1, 0.08); // Dissolve to noise
|
||||
} else if (t < 4.5) {
|
||||
lerpToShape(2, 0.1); // Form sphere
|
||||
} else if (t < 5.5) {
|
||||
lerpToShape(3, 0.08); // Dissolve to noise
|
||||
} else if (t < 7) {
|
||||
lerpToShape(4, 0.1); // Form torus
|
||||
} else if (t < 8) {
|
||||
lerpToShape(3, 0.08); // Dissolve
|
||||
} else {
|
||||
lerpToShape(0, 0.12); // Reform text
|
||||
function spherePositions(radius, count) {
|
||||
var pts = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
var phi = Math.acos(2 * Math.random() - 1);
|
||||
var theta = Math.random() * Math.PI * 2;
|
||||
pts.push(
|
||||
new THREE.Vector3(
|
||||
radius * Math.sin(phi) * Math.cos(theta),
|
||||
radius * Math.sin(phi) * Math.sin(theta),
|
||||
radius * Math.cos(phi),
|
||||
),
|
||||
);
|
||||
}
|
||||
renderFrame();
|
||||
},
|
||||
});
|
||||
return pts;
|
||||
}
|
||||
|
||||
// Slow rotation
|
||||
tl.to(morphState, { rotation: Math.PI * 0.6, duration: 10, ease: "none" }, 0);
|
||||
function torusPositions(R, r, count) {
|
||||
var pts = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
var u = Math.random() * Math.PI * 2;
|
||||
var v = Math.random() * Math.PI * 2;
|
||||
pts.push(
|
||||
new THREE.Vector3(
|
||||
(R + r * Math.cos(v)) * Math.cos(u),
|
||||
(R + r * Math.cos(v)) * Math.sin(u),
|
||||
r * Math.sin(v),
|
||||
),
|
||||
);
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
// Fade in/out
|
||||
tl.fromTo(morphState, { opacity: 0 }, { opacity: 1, duration: 0.5 }, 0);
|
||||
tl.to(morphState, { opacity: 0, duration: 0.5 }, 9.5);
|
||||
function noisePositions(spread, count) {
|
||||
var pts = [];
|
||||
for (var i = 0; i < count; i++) {
|
||||
pts.push(
|
||||
new THREE.Vector3(
|
||||
(Math.random() - 0.5) * spread,
|
||||
(Math.random() - 0.5) * spread * 0.6,
|
||||
(Math.random() - 0.5) * spread,
|
||||
),
|
||||
);
|
||||
}
|
||||
return pts;
|
||||
}
|
||||
|
||||
tl.to({}, { duration: 10, ease: "none" }, 0);
|
||||
// Pad/trim arrays to exactly COUNT
|
||||
function padPositions(arr) {
|
||||
while (arr.length < COUNT) {
|
||||
arr.push(
|
||||
arr[Math.floor(Math.random() * arr.length)]
|
||||
.clone()
|
||||
.add(
|
||||
new THREE.Vector3(
|
||||
(Math.random() - 0.5) * 0.1,
|
||||
(Math.random() - 0.5) * 0.1,
|
||||
(Math.random() - 0.5) * 0.1,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
return arr.slice(0, COUNT);
|
||||
}
|
||||
|
||||
renderFrame();
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
var shapes = [
|
||||
padPositions(textToPositions("HYPERFRAMES", 1.0)),
|
||||
padPositions(noisePositions(10, COUNT)),
|
||||
padPositions(spherePositions(3.5, COUNT)),
|
||||
padPositions(noisePositions(12, COUNT)),
|
||||
padPositions(torusPositions(3, 1.2, COUNT)),
|
||||
];
|
||||
|
||||
// ── Particles ─────────────────────────────────────────
|
||||
var geo = new THREE.BufferGeometry();
|
||||
var positions = new Float32Array(COUNT * 3);
|
||||
var colors = new Float32Array(COUNT * 3);
|
||||
var sizes = new Float32Array(COUNT);
|
||||
|
||||
// Start at shape 0
|
||||
for (var i = 0; i < COUNT; i++) {
|
||||
var p = shapes[0][i];
|
||||
positions[i * 3] = p.x;
|
||||
positions[i * 3 + 1] = p.y;
|
||||
positions[i * 3 + 2] = p.z;
|
||||
|
||||
// Color palette: cyan → purple → pink
|
||||
var t = i / COUNT;
|
||||
colors[i * 3] = 0.0 + t * 0.5;
|
||||
colors[i * 3 + 1] = 0.7 - t * 0.4;
|
||||
colors[i * 3 + 2] = 1.0;
|
||||
sizes[i] = 2.0 + Math.random() * 2.0;
|
||||
}
|
||||
|
||||
geo.setAttribute("position", new THREE.BufferAttribute(positions, 3));
|
||||
geo.setAttribute("color", new THREE.BufferAttribute(colors, 3));
|
||||
geo.setAttribute("size", new THREE.BufferAttribute(sizes, 1));
|
||||
|
||||
var mat = new THREE.ShaderMaterial({
|
||||
uniforms: {
|
||||
uPixelRatio: { value: 1 },
|
||||
uOpacity: { value: 1.0 },
|
||||
},
|
||||
vertexShader: [
|
||||
"attribute float size;",
|
||||
"attribute vec3 color;",
|
||||
"varying vec3 vColor;",
|
||||
"uniform float uPixelRatio;",
|
||||
"void main() {",
|
||||
" vColor = color;",
|
||||
" vec4 mvPosition = modelViewMatrix * vec4(position, 1.0);",
|
||||
" gl_PointSize = size * uPixelRatio * (300.0 / -mvPosition.z);",
|
||||
" gl_Position = projectionMatrix * mvPosition;",
|
||||
"}",
|
||||
].join("\n"),
|
||||
fragmentShader: [
|
||||
"precision highp float;",
|
||||
"varying vec3 vColor;",
|
||||
"uniform float uOpacity;",
|
||||
"void main() {",
|
||||
" float d = length(gl_PointCoord - vec2(0.5));",
|
||||
" if (d > 0.5) discard;",
|
||||
" float alpha = smoothstep(0.5, 0.1, d) * uOpacity;",
|
||||
" gl_FragColor = vec4(vColor, alpha);",
|
||||
"}",
|
||||
].join("\n"),
|
||||
transparent: true,
|
||||
depthWrite: false,
|
||||
blending: THREE.AdditiveBlending,
|
||||
});
|
||||
|
||||
var points = new THREE.Points(geo, mat);
|
||||
scene.add(points);
|
||||
|
||||
// ── Morph state ───────────────────────────────────────
|
||||
var morphState = { progress: 0, shapeIndex: 0, rotation: 0, opacity: 1.0 };
|
||||
|
||||
function lerpToShape(targetIdx, t) {
|
||||
var target = shapes[targetIdx];
|
||||
var pos = geo.attributes.position.array;
|
||||
for (var i = 0; i < COUNT; i++) {
|
||||
var idx = i * 3;
|
||||
pos[idx] += (target[i].x - pos[idx]) * t;
|
||||
pos[idx + 1] += (target[i].y - pos[idx + 1]) * t;
|
||||
pos[idx + 2] += (target[i].z - pos[idx + 2]) * t;
|
||||
}
|
||||
geo.attributes.position.needsUpdate = true;
|
||||
}
|
||||
|
||||
function renderFrame() {
|
||||
points.rotation.y = morphState.rotation;
|
||||
mat.uniforms.uOpacity.value = morphState.opacity;
|
||||
renderer.render(scene, camera);
|
||||
}
|
||||
|
||||
// ── Timeline ──────────────────────────────────────────
|
||||
// 10s total: text(2s) → dissolve(1s) → sphere(1.5s) → dissolve(1s) → torus(1.5s) → dissolve(1s) → text(2s)
|
||||
var tl = gsap.timeline({
|
||||
paused: true,
|
||||
onUpdate: function () {
|
||||
var t = tl.time();
|
||||
// Morph between shapes based on time
|
||||
if (t < 2) {
|
||||
lerpToShape(0, 0.15); // Hold text
|
||||
} else if (t < 3) {
|
||||
lerpToShape(1, 0.08); // Dissolve to noise
|
||||
} else if (t < 4.5) {
|
||||
lerpToShape(2, 0.1); // Form sphere
|
||||
} else if (t < 5.5) {
|
||||
lerpToShape(3, 0.08); // Dissolve to noise
|
||||
} else if (t < 7) {
|
||||
lerpToShape(4, 0.1); // Form torus
|
||||
} else if (t < 8) {
|
||||
lerpToShape(3, 0.08); // Dissolve
|
||||
} else {
|
||||
lerpToShape(0, 0.12); // Reform text
|
||||
}
|
||||
renderFrame();
|
||||
},
|
||||
});
|
||||
|
||||
// Slow rotation
|
||||
tl.to(morphState, { rotation: Math.PI * 0.6, duration: 10, ease: "none" }, 0);
|
||||
|
||||
// Fade in/out
|
||||
tl.fromTo(morphState, { opacity: 0 }, { opacity: 1, duration: 0.5 }, 0);
|
||||
tl.to(morphState, { opacity: 0, duration: 0.5 }, 9.5);
|
||||
|
||||
tl.to({}, { duration: 10, ease: "none" }, 0);
|
||||
|
||||
renderFrame();
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
+198
-157
@@ -6,177 +6,218 @@
|
||||
<title>SDF Ray March</title>
|
||||
<script src="https://cdn.jsdelivr.net/npm/gsap@3.14.2/dist/gsap.min.js"></script>
|
||||
<style>
|
||||
* { margin: 0; padding: 0; box-sizing: border-box; }
|
||||
body { background: #000; overflow: hidden; }
|
||||
#root { position: relative; width: 1920px; height: 1080px; overflow: hidden; }
|
||||
#gl-canvas { position: absolute; top: 0; left: 0; width: 1920px; height: 1080px; }
|
||||
* {
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
body {
|
||||
background: #000;
|
||||
overflow: hidden;
|
||||
}
|
||||
#root {
|
||||
position: relative;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
overflow: hidden;
|
||||
}
|
||||
#gl-canvas {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 1920px;
|
||||
height: 1080px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root" data-composition-id="main" data-start="0" data-duration="8" data-width="1920" data-height="1080">
|
||||
<div
|
||||
id="root"
|
||||
data-composition-id="main"
|
||||
data-start="0"
|
||||
data-duration="8"
|
||||
data-width="1920"
|
||||
data-height="1080"
|
||||
>
|
||||
<canvas id="gl-canvas" width="1920" height="1080"></canvas>
|
||||
<div id="driver" data-start="0" data-duration="8" data-track-index="0"
|
||||
style="position:absolute;width:1px;height:1px;opacity:0;pointer-events:none"></div>
|
||||
<div
|
||||
id="driver"
|
||||
data-start="0"
|
||||
data-duration="8"
|
||||
data-track-index="0"
|
||||
style="position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none"
|
||||
></div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
(function () {
|
||||
window.__timelines = window.__timelines || {};
|
||||
|
||||
var canvas = document.getElementById("gl-canvas");
|
||||
var gl = canvas.getContext("webgl", { preserveDrawingBuffer: true });
|
||||
if (!gl) { window.__timelines["main"] = gsap.timeline({ paused: true }); return; }
|
||||
var canvas = document.getElementById("gl-canvas");
|
||||
var gl = canvas.getContext("webgl", { preserveDrawingBuffer: true });
|
||||
if (!gl) {
|
||||
window.__timelines["main"] = gsap.timeline({ paused: true });
|
||||
return;
|
||||
}
|
||||
|
||||
gl.viewport(0, 0, 1920, 1080);
|
||||
gl.viewport(0, 0, 1920, 1080);
|
||||
|
||||
// ── Fullscreen quad ───────────────────────────────────
|
||||
var quadBuf = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuf);
|
||||
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 1,-1, -1,1, 1,1]), gl.STATIC_DRAW);
|
||||
|
||||
function compileShader(src, type) {
|
||||
var s = gl.createShader(type);
|
||||
gl.shaderSource(s, src);
|
||||
gl.compileShader(s);
|
||||
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(s));
|
||||
return s;
|
||||
}
|
||||
|
||||
var vertSrc = "attribute vec2 a_pos; varying vec2 v_uv; void main(){ v_uv = a_pos; gl_Position = vec4(a_pos, 0, 1); }";
|
||||
|
||||
var fragSrc = [
|
||||
"precision highp float;",
|
||||
"varying vec2 v_uv;",
|
||||
"uniform float u_time;",
|
||||
"uniform vec2 u_resolution;",
|
||||
"",
|
||||
"// Rotation matrix",
|
||||
"mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }",
|
||||
"",
|
||||
"// Smooth minimum for organic blending",
|
||||
"float smin(float a, float b, float k) {",
|
||||
" float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);",
|
||||
" return mix(b, a, h) - k * h * (1.0 - h);",
|
||||
"}",
|
||||
"",
|
||||
"// SDF scene — morphing infinite tunnel with fractal pillars",
|
||||
"float map(vec3 p) {",
|
||||
" // Infinite repeat along Z",
|
||||
" float cell = 4.0;",
|
||||
" vec3 q = p;",
|
||||
" q.z = mod(q.z + cell * 0.5, cell) - cell * 0.5;",
|
||||
"",
|
||||
" // Morphing octahedron pillars",
|
||||
" vec3 r = q;",
|
||||
" r.xz *= rot(u_time * 0.3 + floor((p.z + cell * 0.5) / cell) * 1.57);",
|
||||
" float octa = dot(abs(r), normalize(vec3(1.0))) - 0.8 - sin(u_time * 0.5) * 0.2;",
|
||||
"",
|
||||
" // Tunnel (subtracted cylinder)",
|
||||
" float tunnel = -(length(p.xy) - 2.5 + sin(p.z * 0.3 + u_time) * 0.3);",
|
||||
"",
|
||||
" // Fractal folds",
|
||||
" vec3 f = abs(q) - 1.2;",
|
||||
" f = abs(f + 0.5) - 0.5;",
|
||||
" float fractal = length(f.xy) - 0.08;",
|
||||
"",
|
||||
" return smin(max(octa, tunnel), fractal, 0.3);",
|
||||
"}",
|
||||
"",
|
||||
"// Normal from SDF gradient",
|
||||
"vec3 calcNormal(vec3 p) {",
|
||||
" vec2 e = vec2(0.001, 0.0);",
|
||||
" return normalize(vec3(",
|
||||
" map(p + e.xyy) - map(p - e.xyy),",
|
||||
" map(p + e.yxy) - map(p - e.yxy),",
|
||||
" map(p + e.yyx) - map(p - e.yyx)",
|
||||
" ));",
|
||||
"}",
|
||||
"",
|
||||
"void main() {",
|
||||
" vec2 uv = (v_uv * vec2(u_resolution.x / u_resolution.y, 1.0));",
|
||||
"",
|
||||
" // Camera — fly through tunnel",
|
||||
" vec3 ro = vec3(0.0, 0.0, u_time * 3.0);",
|
||||
" ro.xy += vec2(sin(u_time * 0.7) * 0.5, cos(u_time * 0.5) * 0.3);",
|
||||
" vec3 rd = normalize(vec3(uv, 1.5));",
|
||||
" rd.xz *= rot(sin(u_time * 0.3) * 0.2);",
|
||||
" rd.yz *= rot(cos(u_time * 0.4) * 0.15);",
|
||||
"",
|
||||
" // Ray march",
|
||||
" float t = 0.0;",
|
||||
" float d;",
|
||||
" for (int i = 0; i < 80; i++) {",
|
||||
" d = map(ro + rd * t);",
|
||||
" if (d < 0.001 || t > 30.0) break;",
|
||||
" t += d * 0.8;",
|
||||
" }",
|
||||
"",
|
||||
" vec3 col = vec3(0.02, 0.01, 0.04);",
|
||||
"",
|
||||
" if (d < 0.01) {",
|
||||
" vec3 p = ro + rd * t;",
|
||||
" vec3 n = calcNormal(p);",
|
||||
"",
|
||||
" // Lighting",
|
||||
" vec3 lightDir = normalize(vec3(0.0, 1.0, 1.0));",
|
||||
" float diff = max(dot(n, lightDir), 0.0);",
|
||||
" float spec = pow(max(dot(reflect(-lightDir, n), -rd), 0.0), 32.0);",
|
||||
"",
|
||||
" // Color based on position and normal",
|
||||
" vec3 baseCol = vec3(0.0, 0.6, 1.0) + n * 0.3;",
|
||||
" float stripe = sin(p.z * 2.0 + u_time * 2.0) * 0.5 + 0.5;",
|
||||
" baseCol = mix(baseCol, vec3(0.8, 0.0, 0.5), stripe * 0.4);",
|
||||
"",
|
||||
" col = baseCol * (diff * 0.7 + 0.15) + vec3(0.8, 0.9, 1.0) * spec * 0.5;",
|
||||
"",
|
||||
" // Fog",
|
||||
" float fog = exp(-t * 0.08);",
|
||||
" col = mix(vec3(0.02, 0.01, 0.04), col, fog);",
|
||||
" }",
|
||||
"",
|
||||
" // Vignette",
|
||||
" float vig = 1.0 - dot(v_uv * 0.7, v_uv * 0.7);",
|
||||
" col *= vig;",
|
||||
"",
|
||||
" // Tone mapping",
|
||||
" col = col / (col + 1.0);",
|
||||
" col = pow(col, vec3(0.85));",
|
||||
"",
|
||||
" gl_FragColor = vec4(col, 1.0);",
|
||||
"}",
|
||||
].join("\n");
|
||||
|
||||
var prog = gl.createProgram();
|
||||
gl.attachShader(prog, compileShader(vertSrc, gl.VERTEX_SHADER));
|
||||
gl.attachShader(prog, compileShader(fragSrc, gl.FRAGMENT_SHADER));
|
||||
gl.linkProgram(prog);
|
||||
if (!gl.getProgramParameter(prog, gl.LINK_STATUS)) console.error(gl.getProgramInfoLog(prog));
|
||||
|
||||
var uTime = gl.getUniformLocation(prog, "u_time");
|
||||
var uRes = gl.getUniformLocation(prog, "u_resolution");
|
||||
var aPos = gl.getAttribLocation(prog, "a_pos");
|
||||
|
||||
function renderFrame(time) {
|
||||
gl.useProgram(prog);
|
||||
gl.uniform1f(uTime, time);
|
||||
gl.uniform2f(uRes, 1920, 1080);
|
||||
// ── Fullscreen quad ───────────────────────────────────
|
||||
var quadBuf = gl.createBuffer();
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuf);
|
||||
gl.enableVertexAttribArray(aPos);
|
||||
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
gl.bufferData(
|
||||
gl.ARRAY_BUFFER,
|
||||
new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]),
|
||||
gl.STATIC_DRAW,
|
||||
);
|
||||
|
||||
var state = { time: 0 };
|
||||
var tl = gsap.timeline({
|
||||
paused: true,
|
||||
onUpdate: function () { renderFrame(state.time); }
|
||||
});
|
||||
function compileShader(src, type) {
|
||||
var s = gl.createShader(type);
|
||||
gl.shaderSource(s, src);
|
||||
gl.compileShader(s);
|
||||
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) console.error(gl.getShaderInfoLog(s));
|
||||
return s;
|
||||
}
|
||||
|
||||
tl.to(state, { time: 8, duration: 8, ease: "none" }, 0);
|
||||
var vertSrc =
|
||||
"attribute vec2 a_pos; varying vec2 v_uv; void main(){ v_uv = a_pos; gl_Position = vec4(a_pos, 0, 1); }";
|
||||
|
||||
renderFrame(0);
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
var fragSrc = [
|
||||
"precision highp float;",
|
||||
"varying vec2 v_uv;",
|
||||
"uniform float u_time;",
|
||||
"uniform vec2 u_resolution;",
|
||||
"",
|
||||
"// Rotation matrix",
|
||||
"mat2 rot(float a) { float c = cos(a), s = sin(a); return mat2(c, -s, s, c); }",
|
||||
"",
|
||||
"// Smooth minimum for organic blending",
|
||||
"float smin(float a, float b, float k) {",
|
||||
" float h = clamp(0.5 + 0.5 * (b - a) / k, 0.0, 1.0);",
|
||||
" return mix(b, a, h) - k * h * (1.0 - h);",
|
||||
"}",
|
||||
"",
|
||||
"// SDF scene — morphing infinite tunnel with fractal pillars",
|
||||
"float map(vec3 p) {",
|
||||
" // Infinite repeat along Z",
|
||||
" float cell = 4.0;",
|
||||
" vec3 q = p;",
|
||||
" q.z = mod(q.z + cell * 0.5, cell) - cell * 0.5;",
|
||||
"",
|
||||
" // Morphing octahedron pillars",
|
||||
" vec3 r = q;",
|
||||
" r.xz *= rot(u_time * 0.3 + floor((p.z + cell * 0.5) / cell) * 1.57);",
|
||||
" float octa = dot(abs(r), normalize(vec3(1.0))) - 0.8 - sin(u_time * 0.5) * 0.2;",
|
||||
"",
|
||||
" // Tunnel (subtracted cylinder)",
|
||||
" float tunnel = -(length(p.xy) - 2.5 + sin(p.z * 0.3 + u_time) * 0.3);",
|
||||
"",
|
||||
" // Fractal folds",
|
||||
" vec3 f = abs(q) - 1.2;",
|
||||
" f = abs(f + 0.5) - 0.5;",
|
||||
" float fractal = length(f.xy) - 0.08;",
|
||||
"",
|
||||
" return smin(max(octa, tunnel), fractal, 0.3);",
|
||||
"}",
|
||||
"",
|
||||
"// Normal from SDF gradient",
|
||||
"vec3 calcNormal(vec3 p) {",
|
||||
" vec2 e = vec2(0.001, 0.0);",
|
||||
" return normalize(vec3(",
|
||||
" map(p + e.xyy) - map(p - e.xyy),",
|
||||
" map(p + e.yxy) - map(p - e.yxy),",
|
||||
" map(p + e.yyx) - map(p - e.yyx)",
|
||||
" ));",
|
||||
"}",
|
||||
"",
|
||||
"void main() {",
|
||||
" vec2 uv = (v_uv * vec2(u_resolution.x / u_resolution.y, 1.0));",
|
||||
"",
|
||||
" // Camera — fly through tunnel",
|
||||
" vec3 ro = vec3(0.0, 0.0, u_time * 3.0);",
|
||||
" ro.xy += vec2(sin(u_time * 0.7) * 0.5, cos(u_time * 0.5) * 0.3);",
|
||||
" vec3 rd = normalize(vec3(uv, 1.5));",
|
||||
" rd.xz *= rot(sin(u_time * 0.3) * 0.2);",
|
||||
" rd.yz *= rot(cos(u_time * 0.4) * 0.15);",
|
||||
"",
|
||||
" // Ray march",
|
||||
" float t = 0.0;",
|
||||
" float d;",
|
||||
" for (int i = 0; i < 80; i++) {",
|
||||
" d = map(ro + rd * t);",
|
||||
" if (d < 0.001 || t > 30.0) break;",
|
||||
" t += d * 0.8;",
|
||||
" }",
|
||||
"",
|
||||
" vec3 col = vec3(0.02, 0.01, 0.04);",
|
||||
"",
|
||||
" if (d < 0.01) {",
|
||||
" vec3 p = ro + rd * t;",
|
||||
" vec3 n = calcNormal(p);",
|
||||
"",
|
||||
" // Lighting",
|
||||
" vec3 lightDir = normalize(vec3(0.0, 1.0, 1.0));",
|
||||
" float diff = max(dot(n, lightDir), 0.0);",
|
||||
" float spec = pow(max(dot(reflect(-lightDir, n), -rd), 0.0), 32.0);",
|
||||
"",
|
||||
" // Color based on position and normal",
|
||||
" vec3 baseCol = vec3(0.0, 0.6, 1.0) + n * 0.3;",
|
||||
" float stripe = sin(p.z * 2.0 + u_time * 2.0) * 0.5 + 0.5;",
|
||||
" baseCol = mix(baseCol, vec3(0.8, 0.0, 0.5), stripe * 0.4);",
|
||||
"",
|
||||
" col = baseCol * (diff * 0.7 + 0.15) + vec3(0.8, 0.9, 1.0) * spec * 0.5;",
|
||||
"",
|
||||
" // Fog",
|
||||
" float fog = exp(-t * 0.08);",
|
||||
" col = mix(vec3(0.02, 0.01, 0.04), col, fog);",
|
||||
" }",
|
||||
"",
|
||||
" // Vignette",
|
||||
" float vig = 1.0 - dot(v_uv * 0.7, v_uv * 0.7);",
|
||||
" col *= vig;",
|
||||
"",
|
||||
" // Tone mapping",
|
||||
" col = col / (col + 1.0);",
|
||||
" col = pow(col, vec3(0.85));",
|
||||
"",
|
||||
" gl_FragColor = vec4(col, 1.0);",
|
||||
"}",
|
||||
].join("\n");
|
||||
|
||||
var prog = gl.createProgram();
|
||||
gl.attachShader(prog, compileShader(vertSrc, gl.VERTEX_SHADER));
|
||||
gl.attachShader(prog, compileShader(fragSrc, gl.FRAGMENT_SHADER));
|
||||
gl.linkProgram(prog);
|
||||
if (!gl.getProgramParameter(prog, gl.LINK_STATUS))
|
||||
console.error(gl.getProgramInfoLog(prog));
|
||||
|
||||
var uTime = gl.getUniformLocation(prog, "u_time");
|
||||
var uRes = gl.getUniformLocation(prog, "u_resolution");
|
||||
var aPos = gl.getAttribLocation(prog, "a_pos");
|
||||
|
||||
function renderFrame(time) {
|
||||
gl.useProgram(prog);
|
||||
gl.uniform1f(uTime, time);
|
||||
gl.uniform2f(uRes, 1920, 1080);
|
||||
gl.bindBuffer(gl.ARRAY_BUFFER, quadBuf);
|
||||
gl.enableVertexAttribArray(aPos);
|
||||
gl.vertexAttribPointer(aPos, 2, gl.FLOAT, false, 0, 0);
|
||||
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
var state = { time: 0 };
|
||||
var tl = gsap.timeline({
|
||||
paused: true,
|
||||
onUpdate: function () {
|
||||
renderFrame(state.time);
|
||||
},
|
||||
});
|
||||
|
||||
tl.to(state, { time: 8, duration: 8, ease: "none" }, 0);
|
||||
|
||||
renderFrame(0);
|
||||
window.__timelines["main"] = tl;
|
||||
})();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user