<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Cloth Shade</title>
<style>
:root{
--ground:#F3EEE2;--card:#E6E3CE;--card2:#EBE8D7;--ink:#1E1F15;--deep:#0F100A;
--lift:#3D4128;--muted:#5A5E3B;--soft:#C9C8A6;--accent:#86914C;
--font:"Geist",system-ui,-apple-system,sans-serif;
}
@font-face{font-family:"Geist";src:url("/fonts-geist/Geist-Regular-latin.woff2") format("woff2");font-weight:400;font-style:normal;font-display:swap;}
@font-face{font-family:"Geist";src:url("/fonts-geist/Geist-Medium-latin.woff2") format("woff2");font-weight:500;font-style:normal;font-display:swap;}
*{box-sizing:border-box}
html,body{margin:0;height:100%;background:var(--ground);color:var(--ink);font-family:var(--font);-webkit-font-smoothing:antialiased}
button{font:inherit;color:inherit;background:none;border:0;padding:0;cursor:pointer}
.cover{width:100%;height:100%;object-fit:cover;object-position:center;display:block;pointer-events:none;user-select:none}
.hint{position:fixed;left:50%;bottom:5vh;transform:translateX(-50%);margin:0;font-size:10px;font-weight:500;letter-spacing:.22em;text-transform:uppercase;color:var(--muted);pointer-events:none;z-index:5;white-space:nowrap}
@media (prefers-reduced-motion:reduce){ .hint{display:none} }
html,body{overflow:hidden}
.stage{position:fixed;inset:0;background:var(--card2)}
canvas{position:absolute;inset:0;width:100%;height:100%;display:block;touch-action:none}
.fallback{position:absolute;inset:0}
.fallback img{width:100%;height:100%;object-fit:cover}
</style>
</head>
<body>
<div class="stage" id="stage">
<div class="fallback" id="fallback"><img class="cover" src="/images/webp/ix-wool-nap.webp" alt=""></div>
<canvas id="c"></canvas>
</div>
<p class="hint">Move or drag</p>
<script>
(function(){
const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
const srcOf = (f) => "/images/webp/" + f;
const canvas = document.getElementById("c");
const gl = canvas.getContext("webgl", {antialias:true, alpha:false, preserveDrawingBuffer:false});
if (!gl || reduce){
canvas.remove();
return;
}
document.getElementById("fallback").hidden = true;
const vs = `attribute vec2 a; void main(){ gl_Position = vec4(a,0.0,1.0); }`;
const fs = `
precision mediump float;
uniform sampler2D uTex;
uniform vec2 uRes, uImg, uLight;
uniform float uOn, uAmt;
void main(){
vec2 uv = gl_FragCoord.xy / uRes;
uv.y = 1.0 - uv.y;
// object-fit: cover
float ca = uRes.x / uRes.y;
float ia = uImg.x / uImg.y;
vec2 suv = uv;
if (ca > ia){
float s = ia / ca;
suv.y = uv.y * s + (1.0-s)*0.5;
} else {
float s = ca / ia;
suv.x = uv.x * s + (1.0-s)*0.5;
}
vec3 col = texture2D(uTex, suv).rgb;
vec2 p = gl_FragCoord.xy / uRes;
float d = distance(p, uLight);
float light = 0.78 + uAmt * 0.34 * exp(-d * 3.4);
float shade = 1.0 - uAmt * 0.16 * smoothstep(0.25, 1.1, d);
col *= mix(1.0, light * shade, uOn);
gl_FragColor = vec4(col, 1.0);
}
`;
function compile(type, src){
const s = gl.createShader(type);
gl.shaderSource(s, src); gl.compileShader(s);
if (!gl.getShaderParameter(s, gl.COMPILE_STATUS)) throw new Error(gl.getShaderInfoLog(s));
return s;
}
const prog = gl.createProgram();
gl.attachShader(prog, compile(gl.VERTEX_SHADER, vs));
gl.attachShader(prog, compile(gl.FRAGMENT_SHADER, fs));
gl.linkProgram(prog);
gl.useProgram(prog);
const buf = gl.createBuffer();
gl.bindBuffer(gl.ARRAY_BUFFER, buf);
gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1,-1, 1,-1, -1,1, 1,1]), gl.STATIC_DRAW);
const loc = gl.getAttribLocation(prog, "a");
gl.enableVertexAttribArray(loc);
gl.vertexAttribPointer(loc, 2, gl.FLOAT, false, 0, 0);
const uRes = gl.getUniformLocation(prog, "uRes");
const uImg = gl.getUniformLocation(prog, "uImg");
const uLight = gl.getUniformLocation(prog, "uLight");
const uOn = gl.getUniformLocation(prog, "uOn");
const uAmt = gl.getUniformLocation(prog, "uAmt");
const tex = gl.createTexture();
const img = new Image();
let iw=1, ih=1, ready=false;
img.onload = () => {
iw=img.naturalWidth; ih=img.naturalHeight;
gl.bindTexture(gl.TEXTURE_2D, tex);
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR);
gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, img);
ready=true;
};
img.src = srcOf("ix-wool-nap.webp");
let lx=0.5, ly=0.5, tlx=0.5, tly=0.5, amt=0, tamt=0;
function resize(){
const dpr = Math.min(1.5, window.devicePixelRatio||1);
canvas.width = Math.floor(canvas.clientWidth*dpr);
canvas.height = Math.floor(canvas.clientHeight*dpr);
gl.viewport(0,0,canvas.width,canvas.height);
}
resize();
window.addEventListener("resize", resize);
function pointer(e){
const r = canvas.getBoundingClientRect();
tlx = (e.clientX - r.left) / r.width;
tly = 1 - (e.clientY - r.top) / r.height;
tamt = 1;
}
canvas.addEventListener("pointermove", pointer);
canvas.addEventListener("pointerleave", () => { tamt = 0; });
function frame(){
lx += (tlx-lx)*0.08;
ly += (tly-ly)*0.08;
amt += (tamt-amt)*0.08;
if (ready){
gl.uniform2f(uRes, canvas.width, canvas.height);
gl.uniform2f(uImg, iw, ih);
gl.uniform2f(uLight, lx, ly);
gl.uniform1f(uOn, 1);
gl.uniform1f(uAmt, amt);
gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);
}
requestAnimationFrame(frame);
}
requestAnimationFrame(frame);
})();
</script>
</body>
</html>
Build a single self-contained HTML file (vanilla CSS and JavaScript; GSAP 3.13+ from jsDelivr, plus ScrollTrigger or Flip only if required) for “Cloth Shade”.
A soft light travels across the cloth. The photograph never warps.
Use the Olive & Moss palette: ground #F3EEE2, card #E6E3CE, ink #1E1F15, deep #0F100A, lift #3D4128, muted #5A5E3B, soft #C9C8A6, accent #86914C. Amber #FFA51F is not used as type. Images use object-fit: cover (or equivalent cover mapping in a shader) and must be undistorted at rest. Easing: expo.out / power3.inOut, no bounce or elastic. Respect prefers-reduced-motion. One file.