Creating a visually appealing website with a chromatic, reflective liquid effect that responds to user clicks involves using WebGL or a high-level library like Three.js, along with shaders (GLSL) to simulate the liquid and chromatic reflection. Below is a complete example using Three.js and custom shaders to achieve this effect.
📌 Features:
Chromatic, reflective liquid surface
Interactive ripples on user clicks
Smooth animation using shaders
Responsive full-screen canvas
🚀 Live Demo (Optional): You can test this code by copying it into an HTML file and opening it in a browser.
✅ Full HTML + JavaScript + Shader Code
html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Chromatic Liquid Interaction</title>
<style>
body, html {
margin: 0;
padding: 0;
overflow: hidden;
background: black;
}
canvas {
display: block;
}
</style>
</head>
<body>
<script src="https://cdn.jsdelivr.net/npm/three@0.155.0/build/three.min.js"></script>
<script id="vertexShader" type="x-shader/x-vertex">
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);
}
</script>
<script id="fragmentShader" type="x-shader/x-fragment">
precision highp float;
uniform float uTime;
uniform vec2 uMouse;
uniform vec2 uResolution;
varying vec2 vUv;
float ripple(vec2 uv, vec2 center, float time) {
float dist = distance(uv, center);
return sin(20.0 * dist - time * 5.0) * exp(-10.0 * dist);
}
void main() {
vec2 uv = vUv;
vec2 center = uMouse;
float r = ripple(uv, center, uTime);
float g = ripple(uv + vec2(0.01, 0.01), center, uTime);
float b = ripple(uv - vec2(0.01, 0.01), center, uTime);
vec3 color = vec3(r, g, b) * 0.5 + 0.5;
// Add chromatic aberration
color.r += 0.05 * sin(uTime + uv.x * 10.0);
color.g += 0.05 * sin(uTime + uv.y * 10.0);
color.b += 0.05 * sin(uTime + (uv.x + uv.y) * 5.0);
gl_FragColor = vec4(color, 1.0);
}
</script>
<script>
let scene, camera, renderer, material, mesh;
let mouse = new THREE.Vector2(0.5, 0.5);
let clock = new THREE.Clock();
init();
animate();
function init() {
scene = new THREE.Scene();
camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const geometry = new THREE.PlaneGeometry(2, 2);
const uniforms = {
uTime: { value: 0.0 },
uMouse: { value: new THREE.Vector2(0.5, 0.5) },
uResolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) }
};
material = new THREE.ShaderMaterial({
vertexShader: document.getElementById('vertexShader').textContent,
fragmentShader: document.getElementById('fragmentShader').textContent,
uniforms: uniforms
});
mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
window.addEventListener('resize', onWindowResize, false);
window.addEventListener('pointermove', onPointerMove, false);
window.addEventListener('click', onClick, false);
}
function onWindowResize() {
renderer.setSize(window.innerWidth, window.innerHeight);
material.uniforms.uResolution.value.set(window.innerWidth, window.innerHeight);
}
function onPointerMove(event) {
mouse.x = event.clientX / window.innerWidth;
mouse.y = 1.0 - event.clientY / window.innerHeight;
}
function onClick(event) {
// On click, update the ripple center
mouse.x = event.clientX / window.innerWidth;
mouse.y = 1.0 - event.clientY / window.innerHeight;
material.uniforms.uMouse.value.set(mouse.x, mouse.y);
}
function animate() {
requestAnimationFrame(animate);
material.uniforms.uTime.value = clock.getElapsedTime();
renderer.render(scene, camera);
}
</script>
</body>
</html>
🧠 How It Works
Three.js renders a full-screen plane with a custom shader.
Vertex Shader passes UV coordinates.
Fragment Shader simulates a ripple effect using sine waves and exponential decay.
Chromatic Aberration is added by offsetting RGB channels slightly.
User Interaction: Clicking updates the ripple center, creating interactive waves.
🛠️ Customization Ideas
Add multiple ripple centers for multiple clicks
Use Perlin noise for more organic liquid motion
Add reflection from an environment map
Use mouse movement for continuous interaction
Let me know if you'd like to turn this into a React component, add sound interaction, or export it as a screensaver!
User
Make it in one file
Assistant
Sure! Below is a complete, single-file HTML document that creates a visually appealing, interactive chromatic liquid effect using Three.js and GLSL shaders. It includes:
✅ Fullscreen canvas
✅ Chromatic ripple effect
✅ Interactive response to mouse clicks
✅ All code (HTML, CSS, JS, shaders) in one file
📄 Copy and paste this into a file (e.g., chromatic-liquid.html) and open it in your browser: