body {
margin: 0;
overflow: hidden;
background-color: #87ceeb;
font-family: sans-serif;
}
canvas {
display: block;
}
#hint {
position: absolute;
bottom: 18px;
left: 50%;
transform: translateX(-50%);
color: rgba(255, 255, 255, 0.9);
background: rgba(0, 0, 0, 0.45);
padding: 8px 16px;
border-radius: 20px;
font-size: 13px;
pointer-events: none;
backdrop-filter: blur(4px);
}
// =========================================================================
// 1. ГЛАВНАЯ СЦЕНА, КАМЕРА И РЕНДЕРЕР (Пальмовый пляж и телефон)
// =========================================================================
const scene = new THREE.Scene();
scene.fog = new THREE.FogExp2(0xffe9c5, 0.012);
const camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.1, 200);
camera.position.set(0, 1.6, 4.2);
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
renderer.shadowMap.enabled = true;
renderer.toneMapping = THREE.ACESFilmicToneMapping;
renderer.toneMappingExposure = 1.1;
document.body.appendChild(renderer.domElement);
// =========================================================================
// 2. ОКРУЖЕНИЕ ПАЛЬМОВОГО ПЛЯЖА (Небо, солнце, океан, песок, пальмы)
// =========================================================================
// Купол неба
const skyGeo = new THREE.SphereGeometry(120, 32, 32);
const skyMat = new THREE.ShaderMaterial({
side: THREE.BackSide,
uniforms: {
uSunPos: { value: new THREE.Vector3(25, 18, -50) }
},
vertexShader: `
varying vec3 vWorldPos;
void main() {
vec4 wp = modelMatrix * vec4(position, 1.0);
vWorldPos = wp.xyz;
gl_Position = projectionMatrix * viewMatrix * wp;
}
`,
fragmentShader: `
varying vec3 vWorldPos;
uniform vec3 uSunPos;
void main() {
vec3 dir = normalize(vWorldPos);
float y = clamp(dir.y, 0.0, 1.0);
vec3 horizon = vec3(1.0, 0.85, 0.65);
vec3 zenith = vec3(0.18, 0.58, 0.88);
vec3 col = mix(horizon, zenith, pow(y, 0.55));
vec3 sunDir = normalize(uSunPos);
float sunAmt = max(dot(dir, sunDir), 0.0);
col += vec3(1.0, 0.7, 0.3) * pow(sunAmt, 24.0) * 0.5;
col += vec3(1.0, 0.95, 0.8) * smoothstep(0.997, 0.9995, sunAmt);
gl_FragColor = vec4(col, 1.0);
}
`
});
scene.add(new THREE.Mesh(skyGeo, skyMat));// Освещение
const ambientLight = new THREE.AmbientLight(0xfff3e0, 0.75);
scene.add(ambientLight);
const sunLight = new THREE.DirectionalLight(0xfffaed, 1.3);
sunLight.position.set(15, 20, -20);
sunLight.castShadow = true;
scene.add(sunLight);
const fillLight = new THREE.DirectionalLight(0x88ccff, 0.5);
fillLight.position.set(-5, 6, 10);
scene.add(fillLight);
// Анимированный океан
const oceanGeo = new THREE.PlaneGeometry(160, 120, 80, 80);
oceanGeo.rotateX(-Math.PI / 2);
const oceanMat = new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 }
},
vertexShader: `
uniform float uTime;
varying vec3 vPos;
varying float vWave;
void main() {
vec3 p = position;
float w = sin(p.x * 0.6 + uTime * 1.8) * 0.12
+ cos(p.z * 0.8 + uTime * 1.5) * 0.12
+ sin((p.x + p.z) * 1.2 + uTime * 2.4) * 0.05;
p.y += w;
vWave = w;
vPos = p;
gl_Position = projectionMatrix * modelViewMatrix * vec4(p, 1.0);
}
`,
fragmentShader: `
varying vec3 vPos;
varying float vWave;
void main() {
vec3 deep = vec3(0.02, 0.35, 0.55);
vec3 shallow = vec3(0.1, 0.78, 0.75);
float shoreFactor = clamp((vPos.z + 25.0) / 30.0, 0.0, 1.0);
vec3 waterCol = mix(deep, shallow, shoreFactor);
waterCol += vec3(0.95, 0.9, 0.8) * smoothstep(0.12, 0.24, vWave) * 0.45;
gl_FragColor = vec4(waterCol, 1.0);
}
`
});
const ocean = new THREE.Mesh(oceanGeo, oceanMat);
ocean.position.set(0, -0.8, -45);
scene.add(ocean);
// Песчаный пляж на переднем плане
const sandGeo = new THREE.PlaneGeometry(80, 35, 48, 48);
sandGeo.rotateX(-Math.PI / 2);
const sandPos = sandGeo.attributes.position;
for (let i = 0; i < sandPos.count; i++) {
const z = sandPos.getZ(i);
const x = sandPos.getX(i);
sandPos.setY(i, Math.sin(x * 0.2) * 0.15 — (z < -5 ? (z + 5) * 0.08 : 0));
}
sandGeo.computeVertexNormals();
const sandMat = new THREE.MeshStandardMaterial({
color: 0xf4d7a8,
roughness: 0.9,
metalness: 0.05
});
const sand = new THREE.Mesh(sandGeo, sandMat);
sand.position.set(0, -0.65, 2);
sand.receiveShadow = true;
scene.add(sand);
// Вспомогательная функция для создания тропических пальм
function createPalmTree(x, z, scale, leanAngle) {
const palmGroup = new THREE.Group();
palmGroup.position.set(x, -0.7, z);
palmGroup.scale.setScalar(scale);
const trunkMat = new THREE.MeshStandardMaterial({ color: 0x7c5836, roughness: 0.9 });
const segments = 9;
let prevY = 0;
let prevX = 0;for (let i = 0; i < segments; i++) {
const segGeo = new THREE.CylinderGeometry(
0.18 * (1 — i * 0.05),
0.22 * (1 — i * 0.05),
0.75,
10
);
const seg = new THREE.Mesh(segGeo, trunkMat);
const angle = (i / segments) * leanAngle;
seg.position.set(prevX + Math.sin(angle) * 0.35, prevY + 0.35, 0);
seg.rotation.z = -angle;
palmGroup.add(seg);
prevX += Math.sin(angle) * 0.68;
prevY += Math.cos(angle) * 0.68;
}
// Крона листьев
const crown = new THREE.Group();
crown.position.set(prevX, prevY, 0);
const leafMat = new THREE.MeshStandardMaterial({
color: 0x2e7d32,
roughness: 0.6,
side: THREE.DoubleSide
});
const frondCount = 9;
for (let i = 0; i < frondCount; i++) {
const frondGeo = new THREE.PlaneGeometry(0.65, 3.2, 4, 12);
const pos = frondGeo.attributes.position;
for (let j = 0; j < pos.count; j++) {
const fy = pos.getY(j) + 1.6; // от 0 до 3.2
const fx = pos.getX(j);
const taper = Math.sin((fy / 3.2) * Math.PI);
pos.setX(j, fx * taper);
pos.setZ(j, -Math.pow(fy * 0.45, 2) * 0.45 — Math.abs(fx) * 0.25);
pos.setY(j, fy);
}
frondGeo.computeVertexNormals();
const frond = new THREE.Mesh(frondGeo, leafMat);
const yaw = (i / frondCount) * Math.PI * 2;
frond.rotation.y = yaw;
frond.rotation.x = 0.55 + (i % 2) * 0.15;
crown.add(frond);
}
palmGroup.add(crown);
scene.add(palmGroup);
return crown;
}
const palmCrowns = [
createPalmTree(-4.2, -3.5, 1.15, 0.45),
createPalmTree(4.6, -4.8, 1.25, -0.4),
createPalmTree(-7.5, -8.0, 1.0, 0.3),
createPalmTree(7.0, -7.2, 0.95, -0.35)
];
// =========================================================================
// 3. ШЕЙДЕР ГРАВИТАЦИОННОГО ЛИНЗИРОВАНИЯ ЧЁРНОЙ ДЫРЫ (отображается на экране телефона)
// =========================================================================
const blackHoleMaterial = new THREE.ShaderMaterial({
uniforms: {
uTime: { value: 0 },
uAspect: { value: 9.0 / 19.5 },
uTilt: { value: new THREE.Vector2(0, 0) }
},
vertexShader: `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
precision highp float;
varying vec2 vUv;
uniform float uTime;
uniform float uAspect;
uniform vec2 uTilt;
// Псевдослучайный и 3D-шум для закручивающейся релятивистской плазмы и звёздного поля
float hash(vec3 p) {
p = fract(p * vec3(443.897, 441.423, 437.195));
p += dot(p, p.yzx + 19.19);
return fract((p.x + p.y) * p.z);
}float noise(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
f = f * f * (3.0 — 2.0 * f);
return mix(
mix(mix(hash(i), hash(i + vec3(1,0,0)), f.x),
mix(hash(i + vec3(0,1,0)), hash(i + vec3(1,1,0)), f.x), f.y),
mix(mix(hash(i + vec3(0,0,1)), hash(i + vec3(1,0,1)), f.x),
mix(hash(i + vec3(0,1,1)), hash(i + vec3(1,1,1)), f.x), f.y),
f.z
);
}
float fbm(vec3 p) {
float v = 0.0;
float a = 0.5;
for (int i = 0; i < 4; i++) {
v += a * noise(p);
p *= 2.05;
a *= 0.5;
}
return v;
}
// Фоновая линзированная галактика и звезды
vec3 sampleStarfield(vec3 dir) {
float stars = pow(hash(floor(dir * 260.0)), 26.0) * 2.5;
float nebula = fbm(dir * 3.5 + vec3(0.0, 0.0, uTime * 0.03));
vec3 galaxy = mix(vec3(0.01, 0.02, 0.06), vec3(0.18, 0.08, 0.28), smoothstep(0.35, 0.75, nebula));
galaxy += vec3(0.6, 0.75, 1.0) * stars;
return galaxy;
}
mat3 rotateX(float a) {
float s = sin(a), c = cos(a);
return mat3(1, 0, 0, 0, c, -s, 0, s, c);
}
mat3 rotateY(float a) {
float s = sin(a), c = cos(a);
return mat3(c, 0, s, 0, 1, 0, -s, 0, c);
}
void main() {
// Нормализованные экранные координаты, соответствующие соотношению сторон телефона
vec2 uv = (vUv — 0.5) * 2.0;
uv.x *= uAspect;
// Настройка камеры внутри виртуальной вселенной
float camPitch = 0.22 + uTilt.y * 0.25;
float camYaw = uTilt.x * 0.4 + sin(uTime * 0.25) * 0.15;
mat3 camRot = rotateY(camYaw) * rotateX(camPitch);
vec3 ro = camRot * vec3(0.0, 0.0, 5.2);
vec3 rd = normalize(camRot * normalize(vec3(uv, -1.65)));
// Реймаршинг геодезических линий Шварцшильда
float rs = 0.55; // Радиус горизонта событий
vec3 pos = ro;
vec3 dir = rd;
vec3 accumDisk = vec3(0.0);
float alphaDisk = 0.0;
bool swallowed = false;
float minR = 100.0;
float dt = 0.075;
for (int i = 0; i < 110; i++) {
float r = length(pos);
minR = min(minR, r);
if (r < rs) {
swallowed = true;
break;
}
// Гравитационное отклонение (аппроксимация искривления траектории фотонов в ОТО)
vec3 accel = -1.65 * rs * pos / pow(r, 4.0);
vec3 nextDir = normalize(dir + accel * dt);
vec3 nextPos = pos + nextDir * dt * clamp(r * 0.55, 0.25, 1.6);
// Проверка пересечения с плоскостью экваториального аккреционного диска (y = 0)
if (pos.y * nextPos.y rs * 1.45 && diskR 9.0 && dot(pos, dir) > 0.0) break;
}
vec3 finalColor = vec3(0.0);
if (!swallowed) {
finalColor = sampleStarfield(dir) * (1.0 — alphaDisk * 0.65);
}
// Свечение релятивистского фотонного кольца прямо у края тени
float photonRing = exp(-pow((minR — rs * 1.28) * 14.0, 2.0));
finalColor += vec3(1.0, 0.78, 0.45) * photonRing * 0.95;
finalColor += accumDisk;
// Едва заметное отражение на стеклянном экране телефона
float glassGlare = smoothstep(0.65, -0.5, vUv.x * 0.8 — vUv.y) * 0.05;
finalColor += vec3(0.8, 0.9, 1.0) * glassGlare;
// Тональная компрессия и гамма-коррекция внутри шейдера
finalColor = finalColor / (1.0 + finalColor * 0.35);
finalColor = pow(finalColor, vec3(0.85));
gl_FragColor = vec4(finalColor, 1.0);
}
`
});
// =========================================================================
// 4. 3D-СМАРТФОН И РУКА, ДЕРЖАЩАЯ ЕГО НА ПЕРЕДНЕМ ПЛАНЕ
// =========================================================================
const phoneRig = new THREE.Group();
phoneRig.position.set(0, 1.48, 2.35);
scene.add(phoneRig);
const phoneWidth = 0.88;
const phoneHeight = 1.82;
const phoneDepth = 0.07;
// Металлический корпус телефона
const bodyGeo = new THREE.BoxGeometry(phoneWidth, phoneHeight, phoneDepth);
const bodyMat = new THREE.MeshStandardMaterial({
color: 0x1e2229,
metalness: 0.85,
roughness: 0.22
});
const phoneBody = new THREE.Mesh(bodyGeo, bodyMat);
phoneBody.castShadow = true;
phoneRig.add(phoneBody);// Металлическая рамка корпуса
const bezelGeo = new THREE.BoxGeometry(phoneWidth + 0.02, phoneHeight + 0.02, phoneDepth * 0.85);
const bezelMat = new THREE.MeshStandardMaterial({
color: 0xcfd8dc,
metalness: 0.9,
roughness: 0.2
});
const bezel = new THREE.Mesh(bezelGeo, bezelMat);
phoneRig.add(bezel);
// Экран телефона с шейдером черной дыры
const screenGeo = new THREE.PlaneGeometry(phoneWidth * 0.93, phoneHeight * 0.95);
const screenMesh = new THREE.Mesh(screenGeo, blackHoleMaterial);
screenMesh.position.z = phoneDepth * 0.5 + 0.002;
phoneRig.add(screenMesh);
// Верхний динамик / вырез под камеру
const islandGeo = new THREE.BoxGeometry(0.24, 0.055, 0.01);
const islandMat = new THREE.MeshBasicMaterial({ color: 0x050505 });
const dynamicIsland = new THREE.Mesh(islandGeo, islandMat);
dynamicIsland.position.set(0, phoneHeight * 0.43, phoneDepth * 0.5 + 0.004);
phoneRig.add(dynamicIsland);
// Стилизованная 3D-рука, удерживающая телефон
const skinMat = new THREE.MeshStandardMaterial({
color: 0xe0a382,
roughness: 0.65,
metalness: 0.05
});
function createCapsule(radius, length) {
const group = new THREE.Group();
const cyl = new THREE.Mesh(new THREE.CylinderGeometry(radius, radius, length, 16), skinMat);
const top = new THREE.Mesh(new THREE.SphereGeometry(radius, 16, 16), skinMat);
const bot = new THREE.Mesh(new THREE.SphereGeometry(radius, 16, 16), skinMat);
top.position.y = length / 2;
bot.position.y = -length / 2;
group.add(cyl, top, bot);
return group;
}
const handGroup = new THREE.Group();
phoneRig.add(handGroup);
// Ладонь и запястье позади/снизу телефона
const palm = createCapsule(0.34, 0.75);
palm.position.set(0.22, -0.78, -0.22);
palm.rotation.z = 0.28;
palm.rotation.x = 0.35;
handGroup.add(palm);
// Большой палец, обхватывающий правую/нижнюю рамку
const thumb = createCapsule(0.095, 0.44);
thumb.position.set(phoneWidth * 0.52, -0.35, 0.04);
thumb.rotation.z = 0.55;
thumb.rotation.x = -0.3;
handGroup.add(thumb);
// Четыре пальца, обхватывающие левый край телефона
const fingerY = [0.35, 0.1, -0.15, -0.4];
fingerY.forEach((yPos, idx) => {
const fingerTip = createCapsule(0.072 — idx * 0.003, 0.25);
fingerTip.position.set(-phoneWidth * 0.53, yPos, -0.01);
fingerTip.rotation.z = -0.25;
fingerTip.rotation.y = 0.4;
handGroup.add(fingerTip);
});
// =========================================================================
// 5. ИНТЕРАКТИВНОСТЬ И ЦИКЛ АНИМАЦИИ
// =========================================================================
const mouse = new THREE.Vector2(0, 0);
const targetMouse = new THREE.Vector2(0, 0);
window.addEventListener(‘mousemove’, (e) => {
targetMouse.x = (e.clientX / window.innerWidth) * 2 — 1;
targetMouse.y = -(e.clientY / window.innerHeight) * 2 + 1;
});
window.addEventListener(‘wheel’, (e) => {
camera.position.z = Math.min(Math.max(camera.position.z + e.deltaY * 0.002, 3.1), 5.6);
});
const clock = new THREE.Clock();function animate() {
requestAnimationFrame(animate);
const elapsed = clock.getElapsedTime();
// Плавная интерполяция движения мыши
mouse.lerp(targetMouse, 0.06);
// Обновление шейдеров
oceanMat.uniforms.uTime.value = elapsed;
blackHoleMaterial.uniforms.uTime.value = elapsed;
blackHoleMaterial.uniforms.uTilt.value.copy(mouse);
// Лёгкий бриз, шевелящий ветви пальм
palmCrowns.forEach((crown, i) => {
crown.rotation.z = Math.sin(elapsed * 1.4 + i) * 0.045;
crown.rotation.x = Math.cos(elapsed * 1.1 + i) * 0.03;
});
// Естественное «дыхание» руки и наклон телефона
phoneRig.position.y = 1.48 + Math.sin(elapsed * 1.7) * 0.025;
phoneRig.rotation.y = mouse.x * 0.35 + Math.cos(elapsed * 0.9) * 0.02;
phoneRig.rotation.x = -mouse.y * 0.22 + Math.sin(elapsed * 1.2) * 0.015;
phoneRig.rotation.z = -mouse.x * 0.08;
renderer.render(scene, camera);
}
animate();
// Адаптивное изменение размера окна
window.addEventListener(‘resize’, () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
});
