-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwow.js
More file actions
366 lines (305 loc) · 12.3 KB
/
Copy pathwow.js
File metadata and controls
366 lines (305 loc) · 12.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
document.addEventListener('DOMContentLoaded', () => {
// --- 1. Custom Cursor ---
const cursor = document.getElementById('custom-cursor');
const supportsCustomCursor = window.matchMedia('(hover: hover) and (pointer: fine)').matches;
const heroVideo = document.getElementById('hero-video');
if (cursor && supportsCustomCursor) {
document.body.classList.add('custom-cursor-active');
const cursorText = cursor.querySelector('.cursor-text');
let mouse = { x: 0, y: 0 };
let cursorObj = { x: 0, y: 0 };
window.addEventListener('mousemove', (e) => {
mouse.x = e.clientX;
mouse.y = e.clientY;
if (!cursor.classList.contains('visible')) {
cursor.classList.add('visible');
}
});
// The small amount of lag is intentional, but the cursor remains compact on controls.
gsap.ticker.add(() => {
cursorObj.x += (mouse.x - cursorObj.x) * 0.15;
cursorObj.y += (mouse.y - cursorObj.y) * 0.15;
cursor.style.transform = `translate(${cursorObj.x}px, ${cursorObj.y}px) translate(-50%, -50%)`;
});
const interactiveElements = document.querySelectorAll('a, button, .btn, .work-item');
interactiveElements.forEach(el => {
el.addEventListener('mouseenter', () => {
cursor.classList.add('hovered');
cursorText.textContent = el.classList.contains('work-item') ? 'VIEW' : '';
});
el.addEventListener('mouseleave', () => {
cursor.classList.remove('hovered');
cursorText.textContent = '';
});
});
if (heroVideo) {
heroVideo.addEventListener('mouseenter', () => {
cursor.classList.add('hovered');
cursorText.textContent = 'WATCH';
});
heroVideo.addEventListener('mouseleave', () => {
cursor.classList.remove('hovered');
cursorText.textContent = '';
});
}
}
// --- 2. Magnetic Buttons ---
const magneticElements = document.querySelectorAll('.btn, .nav-link, .logo a');
magneticElements.forEach(el => {
el.addEventListener('mousemove', (e) => {
const rect = el.getBoundingClientRect();
// Calculate mouse position relative to the center of the element
const x = (e.clientX - rect.left) - rect.width / 2;
const y = (e.clientY - rect.top) - rect.height / 2;
// Move element towards mouse (damping factor 0.3)
gsap.to(el, {
x: x * 0.3,
y: y * 0.3,
duration: 0.4,
ease: 'power2.out'
});
});
el.addEventListener('mouseleave', () => {
// Return to original position
gsap.to(el, {
x: 0,
y: 0,
duration: 0.7,
ease: 'elastic.out(1, 0.3)'
});
});
});
// --- 3. GSAP Scroll Logic & Typography Zoom ---
gsap.registerPlugin(ScrollTrigger);
const heroSection = document.getElementById('hero');
const zoomContainer = document.getElementById('hero-zoom-container');
const zoomText = document.getElementById('hero-zoom-text');
let videoEnded = false;
let zoomScrollTrigger = null;
if (heroVideo && heroSection && zoomContainer) {
// Pause video if scrolled away before it ends
ScrollTrigger.create({
trigger: heroSection,
start: "top top",
end: "bottom center",
onLeave: () => {
if (!videoEnded) {
heroVideo.pause();
}
},
onEnterBack: () => {
if (!videoEnded) {
heroVideo.play();
}
}
});
// When video ends, show the text and enable zoom effect
heroVideo.addEventListener('ended', () => {
videoEnded = true;
zoomContainer.classList.add('active');
// Animate text appearance
gsap.fromTo(zoomText,
{ scale: 0.8, opacity: 0 },
{ scale: 1, opacity: 1, duration: 1.5, ease: 'power3.out' }
);
// Create pinning and zooming ScrollTrigger
zoomScrollTrigger = ScrollTrigger.create({
trigger: heroSection,
start: "top top",
end: "+=2000", // 2000px of scrolling for the zoom
pin: true,
animation: gsap.to(zoomText, {
scale: 150, // Scale up infinitely
opacity: 0, // Fade out as we pass through
ease: "power2.in",
duration: 1
}),
scrub: 1
});
});
}
// --- 4. WebGL Shaders (Three.js) ---
const initWebGL = () => {
if (typeof THREE === 'undefined') return;
// Background Noise Shader
const bgContainer = document.getElementById('webgl-container');
if (bgContainer) {
const scene = new THREE.Scene();
const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1);
const renderer = new THREE.WebGLRenderer({ alpha: true, antialias: false });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
bgContainer.appendChild(renderer.domElement);
const geometry = new THREE.PlaneGeometry(2, 2);
const uniforms = {
u_time: { value: 0.0 },
u_mouse: { value: new THREE.Vector2() },
u_resolution: { value: new THREE.Vector2(window.innerWidth, window.innerHeight) }
};
const material = new THREE.ShaderMaterial({
uniforms: uniforms,
transparent: true,
vertexShader: `
varying vec2 vUv;
void main() {
vUv = uv;
gl_Position = vec4(position, 1.0);
}
`,
fragmentShader: `
uniform float u_time;
uniform vec2 u_mouse;
uniform vec2 u_resolution;
varying vec2 vUv;
// Simple random function for noise
float random(vec2 st) {
return fract(sin(dot(st.xy, vec2(12.9898,78.233))) * 43758.5453123);
}
void main() {
vec2 st = gl_FragCoord.xy / u_resolution.xy;
// Mouse interaction distance
float dist = distance(st, u_mouse);
// Generate animated grain
vec2 noisePos = st * vec2(u_resolution.x/10.0, u_resolution.y/10.0) + u_time * 0.5;
float noise = random(noisePos) * 0.06;
// Glow around mouse
float glow = smoothstep(0.5, 0.0, dist) * 0.08;
// Base dark blueish tint (matching site bg)
vec3 color = vec3(0.03, 0.035, 0.04) + glow + noise;
gl_FragColor = vec4(color, 1.0);
}
`
});
const plane = new THREE.Mesh(geometry, material);
scene.add(plane);
let targetMouse = new THREE.Vector2();
window.addEventListener('mousemove', (e) => {
targetMouse.x = e.clientX / window.innerWidth;
targetMouse.y = 1.0 - (e.clientY / window.innerHeight);
});
const renderBg = (time) => {
uniforms.u_time.value = time * 0.001;
// Smoothly follow mouse
uniforms.u_mouse.value.lerp(targetMouse, 0.05);
renderer.render(scene, camera);
requestAnimationFrame(renderBg);
};
requestAnimationFrame(renderBg);
window.addEventListener('resize', () => {
renderer.setSize(window.innerWidth, window.innerHeight);
uniforms.u_resolution.value.set(window.innerWidth, window.innerHeight);
});
}
// Hero Video Distortion Shader
const heroVideoContainer = document.querySelector('.hero-video-container');
if (heroVideoContainer && heroVideo) {
// Prepare video texture
heroVideo.crossOrigin = "anonymous";
const videoTexture = new THREE.VideoTexture(heroVideo);
videoTexture.minFilter = THREE.LinearFilter;
videoTexture.magFilter = THREE.LinearFilter;
videoTexture.format = THREE.RGBFormat;
const vScene = new THREE.Scene();
// Create a camera that exactly matches the container size
const vCamera = new THREE.OrthographicCamera(
heroVideoContainer.clientWidth / -2,
heroVideoContainer.clientWidth / 2,
heroVideoContainer.clientHeight / 2,
heroVideoContainer.clientHeight / -2,
1, 1000
);
vCamera.position.z = 10;
const vRenderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
vRenderer.setSize(heroVideoContainer.clientWidth, heroVideoContainer.clientHeight);
vRenderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
// Add canvas absolute to container
vRenderer.domElement.style.position = 'absolute';
vRenderer.domElement.style.top = '0';
vRenderer.domElement.style.left = '0';
vRenderer.domElement.style.width = '100%';
vRenderer.domElement.style.height = '100%';
vRenderer.domElement.style.zIndex = '5'; // Below overlay but above original video
heroVideoContainer.appendChild(vRenderer.domElement);
document.body.classList.add('video-webgl-active');
const vGeometry = new THREE.PlaneGeometry(heroVideoContainer.clientWidth, heroVideoContainer.clientHeight, 32, 32);
const vUniforms = {
u_texture: { value: videoTexture },
u_mouse: { value: new THREE.Vector2(0.5, 0.5) },
u_time: { value: 0.0 },
u_resolution: { value: new THREE.Vector2(heroVideoContainer.clientWidth, heroVideoContainer.clientHeight) }
};
const vMaterial = new THREE.ShaderMaterial({
uniforms: vUniforms,
vertexShader: `
varying vec2 vUv;
uniform vec2 u_mouse;
uniform float u_time;
void main() {
vUv = uv;
vec3 pos = position;
// Calculate distance to mouse for bulge effect
// Normalize position to 0.0-1.0 to match mouse coordinates
vec2 normPos = vec2(pos.x / ${heroVideoContainer.clientWidth}.0 + 0.5, pos.y / ${heroVideoContainer.clientHeight}.0 + 0.5);
float dist = distance(normPos, u_mouse);
// Create a ripple/bulge effect around the mouse
float bulge = exp(-dist * 5.0) * 20.0;
pos.z += bulge * sin(u_time * 2.0 - dist * 10.0);
gl_Position = projectionMatrix * modelViewMatrix * vec4(pos, 1.0);
}
`,
fragmentShader: `
uniform sampler2D u_texture;
uniform vec2 u_mouse;
varying vec2 vUv;
void main() {
vec2 uv = vUv;
// Slight RGB split based on mouse distance
float dist = distance(uv, u_mouse);
float rgbSplit = exp(-dist * 8.0) * 0.01;
vec4 colorR = texture2D(u_texture, vec2(uv.x + rgbSplit, uv.y));
vec4 colorG = texture2D(u_texture, vec2(uv.x, uv.y));
vec4 colorB = texture2D(u_texture, vec2(uv.x - rgbSplit, uv.y));
gl_FragColor = vec4(colorR.r, colorG.g, colorB.b, 1.0);
}
`
});
const vPlane = new THREE.Mesh(vGeometry, vMaterial);
vScene.add(vPlane);
let vTargetMouse = new THREE.Vector2(0.5, 0.5);
heroVideoContainer.addEventListener('mousemove', (e) => {
const rect = heroVideoContainer.getBoundingClientRect();
// Mouse coordinates normalized 0-1 relative to the container
vTargetMouse.x = (e.clientX - rect.left) / rect.width;
vTargetMouse.y = 1.0 - ((e.clientY - rect.top) / rect.height);
});
heroVideoContainer.addEventListener('mouseleave', () => {
// Return to center
vTargetMouse.x = 0.5;
vTargetMouse.y = 0.5;
});
const renderVideo = (time) => {
vUniforms.u_time.value = time * 0.001;
vUniforms.u_mouse.value.lerp(vTargetMouse, 0.1);
vRenderer.render(vScene, vCamera);
requestAnimationFrame(renderVideo);
};
requestAnimationFrame(renderVideo);
window.addEventListener('resize', () => {
const w = heroVideoContainer.clientWidth;
const h = heroVideoContainer.clientHeight;
vRenderer.setSize(w, h);
vUniforms.u_resolution.value.set(w, h);
vCamera.left = w / -2;
vCamera.right = w / 2;
vCamera.top = h / 2;
vCamera.bottom = h / -2;
vCamera.updateProjectionMatrix();
// Re-generate geometry on resize to keep proportions
vPlane.geometry.dispose();
vPlane.geometry = new THREE.PlaneGeometry(w, h, 32, 32);
});
}
};
// Give DOM a moment to settle, then initialize WebGL
setTimeout(initWebGL, 100);
});