|
| 1 | + console.log("hmoe-proolgue-test loaded"); |
| 2 | + |
| 3 | + if (window.innerWidth > 991) { |
| 4 | + //–– Three.js setup –– |
| 5 | + const canvas = document.getElementById("canvas_prologue"); |
| 6 | + const renderer = new THREE.WebGLRenderer({ |
| 7 | + canvas, |
| 8 | + alpha: true, |
| 9 | + antialias: true, |
| 10 | + }); |
| 11 | + const scene = new THREE.Scene(); |
| 12 | + const camera = new THREE.OrthographicCamera(-1, 1, 1, -1, 0, 1); |
| 13 | + |
| 14 | + //–– Load texture –– |
| 15 | + const loader = new THREE.TextureLoader(); |
| 16 | + const texture = loader.load( |
| 17 | + "https://cdn.prod.website-files.com/683424d3c1de3b2630c7c44a/68407308f41544816614f101_grandfather.avif", |
| 18 | + onResize |
| 19 | + ); |
| 20 | + |
| 21 | + //–– Noise-circle shader –– |
| 22 | + const material = new THREE.ShaderMaterial({ |
| 23 | + transparent: true, |
| 24 | + uniforms: { |
| 25 | + u_image: { value: texture }, |
| 26 | + u_resolution: { value: new THREE.Vector2() }, |
| 27 | + u_radius: { value: 0.5 }, // try 0.5 to start |
| 28 | + }, |
| 29 | + vertexShader: ` |
| 30 | + void main(){ |
| 31 | + gl_Position = vec4(position, 1.0); |
| 32 | + } |
| 33 | + `, |
| 34 | + fragmentShader: ` |
| 35 | + // — noise / fbm functions unchanged — |
| 36 | + float hash(vec2 p){ return fract(sin(dot(p, vec2(12.9898,78.233)))*43758.5453); } |
| 37 | + float noise(vec2 p){ |
| 38 | + vec2 i = floor(p), f = fract(p), u = f*f*(3.0-2.0*f); |
| 39 | + return mix(hash(i),hash(i+vec2(1,0)),u.x) |
| 40 | + + (hash(i+vec2(0,1))-hash(i))*u.y*(1.0-u.x) |
| 41 | + + (hash(i+vec2(1,1))-hash(i+vec2(1,0)))*u.x*u.y; |
| 42 | + } |
| 43 | + float fbm(vec2 p){ |
| 44 | + float v=0., amp=0.5, freq=1.; |
| 45 | + for(int i=0; i<6; i++){ |
| 46 | + v += amp * noise(p*freq); |
| 47 | + freq*= 2.; |
| 48 | + amp *= 0.5; |
| 49 | + } |
| 50 | + return clamp(v, 0.0, 1.0); |
| 51 | + } |
| 52 | +
|
| 53 | + uniform sampler2D u_image; |
| 54 | + uniform vec2 u_resolution; |
| 55 | + uniform float u_radius; |
| 56 | +
|
| 57 | + void main(){ |
| 58 | + // 1) compute standard UV for sampling |
| 59 | + vec2 uv = gl_FragCoord.xy / u_resolution; |
| 60 | +
|
| 61 | + // 2) make a centered, aspect-corrected UV for mask math |
| 62 | + vec2 m = uv - 0.5; |
| 63 | + m.x *= u_resolution.x / u_resolution.y; |
| 64 | +
|
| 65 | + // 3) true circle distance |
| 66 | + float d = length(m); |
| 67 | +
|
| 68 | + // 4) add noise‐jitter on edge |
| 69 | + float n = fbm(uv * -10.0); |
| 70 | + float edge = d + n * 0.1; |
| 71 | +
|
| 72 | + // 5) smoothstep for soft edge |
| 73 | + float mask = smoothstep(u_radius, u_radius - 0.001, edge); |
| 74 | +
|
| 75 | + // 6) sample original image and apply alpha mask |
| 76 | + vec4 col = texture(u_image, uv); |
| 77 | + gl_FragColor = vec4(col.rgb, col.a * mask); |
| 78 | + } |
| 79 | + `, |
| 80 | + }); |
| 81 | + |
| 82 | + scene.add(new THREE.Mesh(new THREE.PlaneGeometry(2, 2), material)); |
| 83 | + |
| 84 | + function onResize() { |
| 85 | + const w = canvas.clientWidth; |
| 86 | + const h = canvas.clientHeight; |
| 87 | + renderer.setSize(w, h, false); |
| 88 | + material.uniforms.u_resolution.value.set(w, h); |
| 89 | + } |
| 90 | + window.addEventListener("resize", onResize); |
| 91 | + onResize(); |
| 92 | + |
| 93 | + function render() { |
| 94 | + renderer.render(scene, camera); |
| 95 | + requestAnimationFrame(render); |
| 96 | + } |
| 97 | + requestAnimationFrame(render); |
| 98 | + |
| 99 | + /* |
| 100 | + |
| 101 | + 🛠️ Tunable Parameters You Can Play With Variable Effect |
| 102 | + |
| 103 | + u_radius Radius of the circular mask |
| 104 | + uv * 5.0 Frequency of noise – higher = more fine detail |
| 105 | + smoothstep 0.1 Strength of noise effect on edge (scale factor) |
| 106 | + amp 0.5, freq in fbm() Controls how fast noise fades out or zooms in |
| 107 | + |
| 108 | + */ |
| 109 | + |
| 110 | + console.log("Home-prologue-test") |
| 111 | + |
| 112 | + // setting all prologue-content to be fixed in one place |
| 113 | + const prologueContents = document.querySelectorAll(".prologue .prologue-content"); |
| 114 | + prologueContents.forEach((el, index) => { |
| 115 | + const offsetY = -(index + 1) * 100; |
| 116 | + |
| 117 | + gsap.set(el, { |
| 118 | + y: `${offsetY}vh` |
| 119 | + }); |
| 120 | + |
| 121 | + ScrollTrigger.create({ |
| 122 | + trigger: ".prologue", |
| 123 | + start: "0% 100%", |
| 124 | + end: "100% 100%", |
| 125 | + pin: el |
| 126 | + }); |
| 127 | + }); |
| 128 | + |
| 129 | + //adding will-change for GPU Accelration |
| 130 | + document.querySelectorAll( |
| 131 | + ".prologue-content, .prologue-content .prologue-text, .prologue-content .prologue-text-small, .prologue-grandfathers-name, .prologue-gi, .prologue-grandfathers-name" |
| 132 | + ).forEach(el => { |
| 133 | + el.style.willChange = "transform, opacity, filter"; |
| 134 | + }); |
| 135 | + |
| 136 | + //change this value to progressively slow down the timeleine scroll speed, min value is 0vh |
| 137 | + gsap.set(".prologue-speed-controller", { height: "300vh" }); |
| 138 | + |
| 139 | + // initializing elements before timeline |
| 140 | + const prologue1text1 = new SplitText(prologueContents[0].querySelectorAll( |
| 141 | + ".prologue-content-block:nth-child(1) .prologue-text"), { type: "chars" }); |
| 142 | + const prologue1text2 = new SplitText(prologueContents[0].querySelectorAll( |
| 143 | + ".prologue-content-block:nth-child(2) .prologue-text"), { type: "chars" }); |
| 144 | + const prologue2text1 = new SplitText(prologueContents[1].querySelectorAll( |
| 145 | + ".prologue-content-block:nth-child(1) .prologue-text"), { type: "chars" }); |
| 146 | + const prologue2text2 = new SplitText(prologueContents[1].querySelectorAll( |
| 147 | + ".prologue-content-block:nth-child(2) .prologue-text"), { type: "chars" }); |
| 148 | + const prologue3text1 = new SplitText(prologueContents[2].querySelectorAll( |
| 149 | + ".prologue-content-block:nth-child(1) .prologue-text-small"), { type: "chars" }); |
| 150 | + const prologue3text2 = new SplitText(prologueContents[2].querySelector( |
| 151 | + ".prologue-grandfather-container .prologue-grandfathers-name:nth-of-type(1)" |
| 152 | + ), { type: "chars" }); |
| 153 | + const prologue3text3 = new SplitText(prologueContents[2].querySelector( |
| 154 | + ".prologue-gi-test .prologue-grandfathers-name" |
| 155 | + ), { type: "chars" }); // splitting internal text so that it aligns with the external |
| 156 | + const prologue3image = prologueContents[2].querySelector(".prologue-gi-mask .noise"); |
| 157 | + const prologue3text4 = new SplitText(prologueContents[2].querySelectorAll( |
| 158 | + ".prologue-content-block:nth-child(2) .prologue-text-small"), { type: "chars" }); |
| 159 | + |
| 160 | + //Prologue Timline Initialization with scrollTrigger |
| 161 | + const prologueTimeline = gsap.timeline({ |
| 162 | + scrollTrigger: { |
| 163 | + trigger: ".prologue", |
| 164 | + start: "0% 20%", |
| 165 | + end: "100% 100%", |
| 166 | + scrub: true, |
| 167 | + } |
| 168 | + }); |
| 169 | + |
| 170 | + //Prologue Timeline Animation Sequence |
| 171 | + prologueTimeline.fromTo(prologue1text1.chars, { |
| 172 | + filter: "blur(10px)", |
| 173 | + scale: 1.5, |
| 174 | + opacity: 0 |
| 175 | + }, { |
| 176 | + filter: "blur(0px)", |
| 177 | + scale: 1, |
| 178 | + opacity: 1, |
| 179 | + stagger: 0.2, |
| 180 | + duration: 4, |
| 181 | + ease: "power1.out" |
| 182 | + }).fromTo(prologue1text2.chars, { |
| 183 | + filter: "blur(10px)", |
| 184 | + scale: 1.5, |
| 185 | + opacity: 0 |
| 186 | + }, { |
| 187 | + filter: "blur(0px)", |
| 188 | + scale: 1, |
| 189 | + opacity: 1, |
| 190 | + stagger: 0.2, |
| 191 | + duration: 4, |
| 192 | + ease: "power1.out" |
| 193 | + }, "+=2").to([prologue1text1.chars, prologue1text2 |
| 194 | + .chars |
| 195 | + ], { filter: "blur(10px)", scale: 1, opacity: 0, duration: 3, stagger: 0.1 }, "+=4").fromTo( |
| 196 | + prologue2text1.chars, { filter: "blur(10px)", scale: 1.5, opacity: 0 }, { |
| 197 | + filter: "blur(0px)", |
| 198 | + scale: 1, |
| 199 | + opacity: 1, |
| 200 | + stagger: 0.2, |
| 201 | + duration: 4, |
| 202 | + ease: "power1.out" |
| 203 | + } |
| 204 | + ).fromTo(prologue2text2.chars, { |
| 205 | + filter: "blur(10px)", |
| 206 | + scale: 1.5, |
| 207 | + opacity: 0 |
| 208 | + }, { |
| 209 | + filter: "blur(0px)", |
| 210 | + scale: 1, |
| 211 | + opacity: 1, |
| 212 | + stagger: 0.2, |
| 213 | + duration: 4, |
| 214 | + ease: "power1.out" |
| 215 | + }, "+=2").to([prologue2text1.chars, prologue2text2 |
| 216 | + .chars |
| 217 | + ], { filter: "blur(10px)", scale: 1, opacity: 0, duration: 3, stagger: 0.1 }, "+=4").fromTo( |
| 218 | + prologue3text1.chars, { opacity: 0 }, { |
| 219 | + opacity: 1, |
| 220 | + stagger: 0.07, |
| 221 | + duration: 3, |
| 222 | + ease: "power1.out" |
| 223 | + } |
| 224 | + ).fromTo(prologue3text2.chars, { |
| 225 | + filter: "blur(10px)", |
| 226 | + y: -60, |
| 227 | + scale: 1.5, |
| 228 | + opacity: 0 |
| 229 | + }, { |
| 230 | + filter: "blur(0px)", |
| 231 | + y: 0, |
| 232 | + scale: 1, |
| 233 | + opacity: 1, |
| 234 | + stagger: 0.3, |
| 235 | + duration: 4, |
| 236 | + ease: "sine.inOut" |
| 237 | + }).fromTo(prologue3text3.chars, { |
| 238 | + filter: "blur(10px)", |
| 239 | + y: -60, |
| 240 | + scale: 1.5, |
| 241 | + opacity: 0 |
| 242 | + }, { |
| 243 | + filter: "blur(0px)", |
| 244 | + y: 0, |
| 245 | + scale: 1, |
| 246 | + opacity: 1, |
| 247 | + stagger: 0.3, |
| 248 | + duration: 4, |
| 249 | + ease: "sine.inOut" |
| 250 | + }, "<").fromTo( |
| 251 | + material.uniforms.u_radius, // target the actual float |
| 252 | + { value: 0 }, |
| 253 | + { |
| 254 | + value: 1, |
| 255 | + ease: "sine.inOut", |
| 256 | + duration: 20, |
| 257 | + }, "-=6").fromTo( |
| 258 | + ["#inner-grandfather-name", ".prologue-gi-frame", |
| 259 | + ".prologue-gi-cta" |
| 260 | + ], { opacity: 0 }, // fully hidden from all sides |
| 261 | + { |
| 262 | + opacity: 1, // full rectangle visible |
| 263 | + ease: "sine.inOut", |
| 264 | + duration: 3, |
| 265 | + }, |
| 266 | + "-=10" |
| 267 | + ).fromTo(prologue3text4.chars, { opacity: 0 }, { |
| 268 | + opacity: 1, |
| 269 | + stagger: 0.07, |
| 270 | + duration: 3, |
| 271 | + ease: "power1.out" |
| 272 | + }, "-=3").fromTo(prologueContents[2] |
| 273 | + .querySelector(".prologue-end-content-wrapper"), { |
| 274 | + filter: "blur(0px), brightness(100)", |
| 275 | + scale: 1, |
| 276 | + opacity: 1, |
| 277 | + }, { |
| 278 | + filter: "blur(20px), brightness(50)", |
| 279 | + scale: 0.95, |
| 280 | + opacity: 0, |
| 281 | + duration: 5, |
| 282 | + ease: "sine.inOut" |
| 283 | + }, "+=3" |
| 284 | + ).fromTo(".prologue-gi-test", { height: "90%" }, { |
| 285 | + height: "75%", |
| 286 | + duration: 5, |
| 287 | + ease: "sine.inOut" |
| 288 | + }, |
| 289 | + "<-=1" |
| 290 | + ); |
| 291 | + /*.to(prologue3image, |
| 292 | + {r: "50%", duration: 5, ease: "sine.inOut"}, "<-=2" |
| 293 | + );*/ |
| 294 | + |
| 295 | + } |
0 commit comments