Video i made of this code below sped up 2x to some kind of space-like song:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Ethereal Quantum Skybox</title>
<link rel="icon" href="data:,"> <!-- Favicon 404 fix -->
<style>
body { margin: 0; overflow: hidden; background: #000; }
canvas { display: block; }
</style>
<script src="
cdnjs.cloudflare.com/ajax/li…"></script>
<script src="
unpkg.com/three@0.134.0/exam…"></script>
<script src="
unpkg.com/three@0.134.0/exam…"></script>
<script src="
unpkg.com/three@0.134.0/exam…"></script>
<script src="
unpkg.com/three@0.134.0/exam…"></script>
<script src="
unpkg.com/three@0.134.0/exam…"></script>
<script src="
unpkg.com/three@0.134.0/exam…"></script>
</head>
<body oncontextmenu="return false;"> <!-- Disable right-click pop-ups -->
<script>
// Ensure Three.js is loaded
if (typeof THREE === 'undefined' || typeof THREE.EffectComposer === 'undefined') {
console.error('Three.js or post-processing libraries failed to load. Check your internet connection or CDN.');
alert('Three.js or post-processing libraries not loaded. Please check your connection or contact support.');
} else {
// Main scene setup
const mainScene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
// Environment map scene setup
const envScene = new THREE.Scene();
const cubeRenderTarget = new THREE.WebGLCubeRenderTarget(512, { format: THREE.RGBFormat, generateMipmaps: true, minFilter: THREE.LinearMipmapLinearFilter });
const cubeCamera = new THREE.CubeCamera(1, 1000, cubeRenderTarget);
cubeCamera.position.copy(camera.position);
// Add lighting for cosmic ambiance
const pointLight = new THREE.PointLight(0x00ffff, 0.8, 100); // Cyan light
pointLight.position.set(0, 5, 0);
envScene.add(pointLight);
const ambientLight = new THREE.AmbientLight(0x100010, 0.2); // Subtle purple ambient
mainScene.add(ambientLight);
// Dynamic skybox with enhanced GLSL nebula shader
const skyboxGeometry = new THREE.BoxGeometry(100, 100, 100);
const skyboxMaterial = new THREE.ShaderMaterial({
uniforms: {
time: { value: 0.0 },
resolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) }
},
vertexShader: `
varying vec2 vUv;
varying vec3 vNormal;
void main() {
vUv = uv;
vNormal = normalize(position);
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
`,
fragmentShader: `
uniform float time;
uniform vec2 resolution;
varying vec2 vUv;
varying vec3 vNormal;
// Simple noise function
float noise(vec3 p) {
return fract(sin(dot(p, vec3(127.1, 311.7, 74.7))) * 43758.5453);
}
// Perlin noise (3D)
float perlin(vec3 p) {
vec3 i = floor(p);
vec3 f = fract(p);
vec3 u = f * f * (3.0 - 2.0 * f);
return mix(mix(mix(noise(i vec3(0.0, 0.0, 0.0)), noise(i vec3(1.0, 0.0, 0.0)), u.x),
mix(noise(i vec3(0.0, 1.0, 0.0)), noise(i vec3(1.0, 1.0, 0.0)), u.x), u.y),
mix(mix(noise(i vec3(0.0, 0.0, 1.0)), noise(i vec3(1.0, 0.0, 1.0)), u.x),
mix(noise(i vec3(0.0, 1.0, 1.0)), noise(i vec3(1.0, 1.0, 1.0)), u.x), u.y), u.z);
}
// Layered noise for nebula depth
float fbm(vec3 p) {
float v = 0.0;
float a = 0.5;
vec3 shift = vec3(100.0);
for (int i = 0; i < 6; i) {
v = a * perlin(p);
p = p * 2.0 shift;
a *= 0.5;
}
return v;
}
// Twinkling stars
float twinklingStars(vec3 dir) {
float density = (abs(dir.y) > 0.9) ? 0.005 : 0.001; // More on ceiling/floor
float star = noise(dir * 200.0);
star = smoothstep(0.99, 1.0, star);
star *= sin(time * 3.0 noise(dir * 10.0) * 6.28) * 0.5 0.5;
return star * density * 100.0;
}
// Comet effect
vec3 cometColor = vec3(1.0, 0.8, 0.4); // Warm comet tail
float comet(vec3 dir) {
float t = mod(time * 0.5, 6.28);
vec3 cometPos = sin(t) * vec3(1.0, 0.0, 0.0) cos(t) * vec3(0.0, 1.0, 0.0) sin(t * 0.5) * vec3(0.0, 0.0, 1.0);
cometPos = normalize(cometPos) * 50.0;
vec3 cometDir = normalize(cometPos);
float dist = length(cross(dir, cometDir));
float length = 0.3;
float brightness = smoothstep(0.05, 0.0, dist) * (1.0 - smoothstep(0.0, length, dot(dir, cometDir - dir)));
return brightness;
}
// Enhanced nebula with ray marching hint
vec3 nebula(vec3 dir) {
float density = 0.0;
vec3 p = dir * 10.0 time * 0.03; // Simulate depth
density = fbm(p) * 0.6;
density = fbm(p * 2.0 vec3(1.0, 1.0, 1.0)) * 0.3; // Layered detail
vec3 color = mix(vec3(0.0, 0.1, 0.2), vec3(0.3, 0.1, 0.5), density); // Blue to purple gradient
color = vec3(0.2, 0.0, 0.3) * smoothstep(0.4, 0.7, fbm(p * 4.0)); // Deeper hues
return color * 0.4;
}
void main() {
vec3 dir = normalize(vNormal);
vec3 color = nebula(dir); // Primary nebula effect
color = twinklingStars(dir) * vec3(1.0, 0.9, 0.7); // Warm stars
color = comet(dir) * cometColor; // Glowing comet
gl_FragColor = vec4(color, 1.0);
}
`,
side: THREE.BackSide,
transparent: true
});
const envSkybox = new THREE.Mesh(skyboxGeometry, skyboxMaterial);
envScene.add(envSkybox); // Add to envScene for reflections
const mainSkybox = new THREE.Mesh(skyboxGeometry, skyboxMaterial.clone()); // Clone for mainScene
mainScene.add(mainSkybox); // Add to mainScene for visible background
// Reflective mirror squares
const mirrorCount = 200;
const mirrorGroup = new
THREE.Group();
const mirrorGeometry = new THREE.PlaneGeometry(0.5, 0.5);
let mirrorMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
envMap: null, // Applied later
side: THREE.DoubleSide,
transparent: true,
opacity: 0.9
});
for (let i = 0; i < mirrorCount; i ) {
const mirror = new THREE.Mesh(mirrorGeometry, mirrorMaterial);
mirror.position.set((Math.random() - 0.5) * 20, (Math.random() - 0.5) * 20, (Math.random() - 0.5) * 20);
mirror.userData.velocity = new THREE.Vector3((Math.random() - 0.5) * 0.02, (Math.random() - 0.5) * 0.02, (Math.random() - 0.5) * 0.02);
mirrorGroup.add(mirror);
}
mainScene.add(mirrorGroup); // Add to mainScene
// Cosmic particle dust
const particleCount = 1000;
const particleGeometry = new THREE.BufferGeometry();
const particlePositions = new Float32Array(particleCount * 3);
for (let i = 0; i < particleCount; i ) {
particlePositions[i * 3] = (Math.random() - 0.5) * 100;
particlePositions[i * 3 1] = (Math.random() - 0.5) * 100;
particlePositions[i * 3 2] = (Math.random() - 0.5) * 100;
}
particleGeometry.setAttribute('position', new THREE.BufferAttribute(particlePositions, 3));
const particleMaterial = new THREE.PointsMaterial({
color: 0x00ffff, // Cyan for cosmic glow
size: 0.15,
transparent: true,
blending: THREE.AdditiveBlending,
opacity: 0.7
});
const particles = new THREE.Points(particleGeometry, particleMaterial);
mainScene.add(particles);
// Post-processing for bloom/glow
const composer = new THREE.EffectComposer(renderer);
const renderPass = new THREE.RenderPass(mainScene, camera);
composer.addPass(renderPass);
const bloomPass = new THREE.UnrealBloomPass(new THREE.Vector2(window.innerWidth, window.innerHeight), 1.8, 0.4, 0.9);
bloomPass.threshold = 0.2;
bloomPass.strength = 1.5;
bloomPass.radius = 0.6;
composer.addPass(bloomPass);
// Candelabras with candles on skybox walls
const candelabraCount = 6;
const candelabraGroup = new
THREE.Group();
const candleGeometry = new THREE.CylinderGeometry(0.1, 0.1, 0.5, 8);
const flameGeometry = new THREE.ConeGeometry(0.2, 0.4, 8);
for (let i = 0; i < candelabraCount; i ) {
const angle = (i / candelabraCount) * Math.PI * 2;
const x = Math.sin(angle) * 45;
const z = Math.cos(angle) * 45;
const candelabra = new
THREE.Group();
const base = new THREE.Mesh(new THREE.CylinderGeometry(0.3, 0.3, 1, 8), new THREE.MeshStandardMaterial({ color: 0x8B4513 }));
base.position.y = 0.5;
candelabra.add(base);
for (let j = 0; j < 3; j ) {
const armAngle = (j - 1) * Math.PI / 6;
const arm = new THREE.Mesh(new THREE.CylinderGeometry(0.05, 0.05, 1, 8), new THREE.MeshStandardMaterial({ color: 0xDAA520 }));
arm.position.set(Math.sin(armAngle), 0.8, Math.cos(armAngle));
const candle = new THREE.Mesh(candleGeometry, new THREE.MeshStandardMaterial({ color: 0xF5F5DC }));
candle.position.y = 0.5;
const flame = new THREE.Mesh(flameGeometry, new THREE.MeshBasicMaterial({ color: 0xFFA500, transparent: true, opacity: 0.8 }));
flame.position.y = 0.7;
arm.add(candle, flame);
candelabra.add(arm);
}
candelabra.position.set(x, 0, z);
candelabraGroup.add(candelabra);
}
mainScene.add(candelabraGroup);
camera.position.z = 10;
// Euclidean rhythm simulation (3 hits in 8 steps)
let beatTime = 0;
const euclid = (n, k) => {
let pattern = [];
for (let i = 0; i < n; i ) pattern.push(i < k ? 1 : 0);
return pattern;
};
const rhythm = euclid(8, 3); // [1,0,1,0,1,0,0,0]
// Intuitive camera controls (non-inverted)
let moveForward = false, moveBackward = false, moveLeft = false, moveRight = false;
document.addEventListener('keydown', (e) => {
if (e.key === 'w') moveForward = true;
if (e.key === 's') moveBackward = true;
if (e.key === 'a') moveLeft = true;
if (e.key === 'd') moveRight = true;
});
document.addEventListener('keyup', (e) => {
if (e.key === 'w') moveForward = false;
if (e.key === 's') moveBackward = false;
if (e.key === 'a') moveLeft = false;
if (e.key === 'd') moveRight = false;
});
document.addEventListener('mousemove', (e) => {
const moveX = (e.movementX / window.innerWidth) * 2;
const moveY = (e.movementY / window.innerHeight) * 2;
camera.rotation.y -= moveX * 0.1; // Right mouse -> right yaw
camera.rotation.x -= moveY * 0.1; // Up mouse -> up pitch
camera.rotation.x = Math.max(-Math.PI / 2, Math.min(Math.PI / 2, camera.rotation.x));
});
function animate(time) {
requestAnimationFrame(animate);
// First pass: Update environment map with separate scene
skyboxMaterial.uniforms.time.value = time * 0.001;
cubeCamera.position.copy(camera.position);
cubeCamera.update(renderer, envScene); // Render envScene into cubeRenderTarget
// Apply envMap to mirrors after first render
if (!mirrorMaterial.envMap && cubeRenderTarget.texture) {
mirrorMaterial.envMap = cubeRenderTarget.texture;
mirrorMaterial.needsUpdate = true;
console.log('Environment map applied to mirrors');
} else if (!cubeRenderTarget.texture) {
console.warn('Cube render target texture is not available yet');
}
// Update mirrors with rhythm-based scaling
beatTime = 0.016;
const beat = rhythm[Math.floor(beatTime % 8)];
mirrorGroup.children.forEach((mirror, i) => {
mirror.position.x = mirror.userData.velocity.x;
mirror.position.y = mirror.userData.velocity.y;
mirror.position.z = mirror.userData.velocity.z;
if (Math.abs(mirror.position.x) > 10) mirror.userData.velocity.x *= -1;
if (Math.abs(mirror.position.y) > 10) mirror.userData.velocity.y *= -1;
if (Math.abs(mirror.position.z) > 10) mirror.userData.velocity.z *= -1;
mirror.scale.set(1 0.1 * beat, 1 0.1 * beat, 1 0.1 * beat);
});
// Animate candle flames
candelabraGroup.traverse(child => {
if (child.isMesh && child.geometry.type === 'ConeGeometry') {
child.material.opacity = 0.6 0.2 * Math.sin(time * 0.05);
}
});
// Update particle dust
const positions = particleGeometry.attributes.position.array;
for (let i = 0; i < particleCount; i ) {
positions[i * 3 1] -= 0.01; // Slow drift downward
if (positions[i * 3 1] < -50) positions[i * 3 1] = 50; // Reset to top
}
particleGeometry.attributes.position.needsUpdate = true;
// Camera movement
const speed = 0.1;
const direction = camera.getWorldDirection(new THREE.Vector3());
const side = new THREE.Vector3().crossVectors(direction, new THREE.Vector3(0, 1, 0)).normalize();
if (moveForward) camera.position.add(direction.multiplyScalar(speed));
if (moveBackward) camera.position.add(direction.multiplyScalar(-speed));
if (moveLeft) camera.position.add(side.multiplyScalar(-speed));
if (moveRight) camera.position.add(side.multiplyScalar(speed));
// Render with post-processing
composer.render();
}
animate(0);
// Handle window resize
window.addEventListener('resize', () => {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize(window.innerWidth, window.innerHeight);
composer.setSize(window.innerWidth, window.innerHeight);
});
}
</script>
</body>
</html>