cheryglsljs 1.1.5 → 1.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cherry.js CHANGED
@@ -1 +1 @@
1
- !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("Cherryglsl",[],n):"object"==typeof exports?exports.Cherryglsl=n():e.Cherryglsl=n()}(this,(()=>(()=>{"use strict";var e={d:(n,t)=>{for(var o in t)e.o(t,o)&&!e.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:t[o]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{default:()=>o});function t(e=400,n=400){const t=new THREE.Scene,o=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,1e3),r=new THREE.WebGLRenderer({alpha:!1});return r.setSize(e,n),{Scene:t,camera:o,renderer:r}}const o={CherryWave:({container:e,image:n,speed:o=.05,strength:r=.02,hover:i=!1,light:a})=>{if(!n)return void console.log("No image provided");(new THREE.TextureLoader).load(n.src,(n=>{const u={uImage:{value:n},uTime:{value:0},uStrength:{value:i?0:r},uLight:{value:a}},s=t(e.clientWidth,e.clientHeight);let l;function v(){l&&(s.Scene.remove(l),l.geometry.dispose(),l.material.dispose()),l=function(){const n=e.clientWidth/e.clientHeight*2.3,t=new THREE.PlaneGeometry(n,2.3,100,100),o=new THREE.ShaderMaterial({vertexShader:"\nprecision highp float;\n varying vec2 vUv;\n varying vec3 pos;\n uniform float uTime;\n uniform float uStrength;\n\n void main() {\n \n vUv = uv;\n \n vec3 newPosition = position;\n\n \n float waveX = uStrength * sin(10.0 * uv.y + uTime * 2.0);\n float waveY = uStrength * cos(12.0 * uv.x + uTime * 1.5);\n \n float waveZ = uStrength * sin(10.0 * uv.x + uTime * 2.5);\n\n newPosition.x += waveX;\n newPosition.y += waveY;\n newPosition.z += waveZ;\n\n pos = (modelViewMatrix * vec4(newPosition, 1.0)).xyz;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);\n }",fragmentShader:"\nprecision highp float;\n\nvarying vec2 vUv;\nuniform sampler2D uImage;\nuniform float uTime;\n\nuniform float uStrength;\nuniform bool uLight;\n\n\nvoid main() {\n vec2 uv = vUv;\n \n\n \n \n\n // Apply wave distortion\n float waveX = sin(10.0 * uv.y + uTime * 2.0);\n float waveY = cos(10.0 * uv.x + uTime * 2.0);\n uv.x += (uStrength * 0.05) * waveX;\n uv.y += (uStrength * 0.05) * waveY;\n\n \n\n vec4 color = texture2D(uImage, uv);\n if(!uLight){\n color.x+=smoothstep(0.001,0.6,sin(2.0*uTime));\n color.y+=smoothstep(0.2,0.6,sin(0.2*uTime));\n }\n \n gl_FragColor = color;\n}\n",uniforms:u,transparent:!0});return new THREE.Mesh(t,o)}(),s.mesh=l,s.Scene.add(l)}function c(){const n=e.clientWidth,t=e.clientHeight;s.renderer.setSize(n,t),s.renderer.setPixelRatio(window.devicePixelRatio),s.camera.aspect=n/t,s.camera.updateProjectionMatrix(),v()}return s.camera.fov=2*Math.atan(e.clientHeight/2/600)*(180/Math.PI),s.camera.position.z=2.8,i&&(e.addEventListener("mouseenter",(()=>{gsap.to(u.uStrength,{value:r,duration:.5,ease:"power2.out"})})),e.addEventListener("mouseleave",(()=>{gsap.to(u.uStrength,{value:0,duration:.5,ease:"power2.out"})}))),e.innerHTML="",e.appendChild(s.renderer.domElement),window.addEventListener("resize",c),c(),function e(){u.uTime.value+=o,s.renderer.render(s.Scene,s.camera),requestAnimationFrame(e)}(),{mesh:s.mesh,geometry:s.geometry,renderer:s.renderer,Scene:s.Scene}}))}};return n})()));
1
+ !function(e,n){"object"==typeof exports&&"object"==typeof module?module.exports=n():"function"==typeof define&&define.amd?define("Cherryglsl",[],n):"object"==typeof exports?exports.Cherryglsl=n():e.Cherryglsl=n()}(this,(()=>(()=>{"use strict";var e={d:(n,t)=>{for(var o in t)e.o(t,o)&&!e.o(n,o)&&Object.defineProperty(n,o,{enumerable:!0,get:t[o]})},o:(e,n)=>Object.prototype.hasOwnProperty.call(e,n),r:e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})}},n={};e.r(n),e.d(n,{default:()=>o});function t(e=400,n=400){const t=new THREE.Scene,o=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,1e3),r=new THREE.WebGLRenderer({alpha:!1});return r.setSize(e,n),{Scene:t,camera:o,renderer:r}}const o={CherryWave:({container:e,image:n,speed:o=.05,strength:r=.02,hover:i=!1,light:a})=>{if(!n)return void console.log("No image provided");(new THREE.TextureLoader).load(n.src,(n=>{const u={uImage:{value:n},uTime:{value:0},uStrength:{value:i?0:r},uLight:{value:a}},l=t(e.clientWidth,e.clientHeight);let s;function v(){s&&(l.Scene.remove(s),s.geometry.dispose(),s.material.dispose()),s=function(){const n=e.clientWidth/e.clientHeight*2.3,t=new THREE.PlaneGeometry(n,2.3,100,100),o=new THREE.ShaderMaterial({vertexShader:"\nprecision highp float;\n varying vec2 vUv;\n varying vec3 pos;\n uniform float uTime;\n uniform float uStrength;\n\n void main() {\n \n vUv = uv;\n \n vec3 newPosition = position;\n\n \n float waveX = uStrength * sin(10.0 * uv.y + uTime * 2.0);\n float waveY = uStrength * cos(12.0 * uv.x + uTime * 1.5);\n \n float waveZ = uStrength * sin(10.0 * uv.x + uTime * 2.5);\n\n newPosition.x += waveX;\n newPosition.y += waveY;\n newPosition.z += waveZ;\n\n pos = (modelViewMatrix * vec4(newPosition, 1.0)).xyz;\n gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);\n }",fragmentShader:"\nprecision highp float;\n\nvarying vec2 vUv;\nuniform sampler2D uImage;\nuniform float uTime;\n\nuniform float uStrength;\nuniform bool uLight;\n\n\nvoid main() {\n vec2 uv = vUv;\n \n\n \n \n\n // Apply wave distortion\n float waveX = sin(10.0 * uv.y + uTime * 2.0);\n float waveY = cos(10.0 * uv.x + uTime * 2.0);\n uv.x += (uStrength * 0.05) * waveX;\n uv.y += (uStrength * 0.05) * waveY;\n\n \n\n vec4 color = texture2D(uImage, uv);\n if(uLight){\n color.x+=smoothstep(0.001,0.6,sin(2.0*uTime));\n color.y+=smoothstep(0.2,0.6,sin(0.2*uTime));\n }\n \n gl_FragColor = color;\n}\n",uniforms:u,transparent:!0});return new THREE.Mesh(t,o)}(),l.mesh=s,l.Scene.add(s)}function d(){const n=e.clientWidth,t=e.clientHeight;l.renderer.setSize(n,t),l.renderer.setPixelRatio(window.devicePixelRatio),l.camera.aspect=n/t,l.camera.updateProjectionMatrix(),v()}return l.camera.fov=2*Math.atan(e.clientHeight/2/600)*(180/Math.PI),l.camera.position.z=2.8,i&&(e.addEventListener("mouseenter",(()=>{gsap.to(u.uStrength,{value:r,duration:.5,ease:"power2.out"})})),e.addEventListener("mouseleave",(()=>{gsap.to(u.uStrength,{value:0,duration:.5,ease:"power2.out"})}))),e.innerHTML="",e.appendChild(l.renderer.domElement),window.addEventListener("resize",d),d(),function e(){u.uTime.value+=o,l.renderer.render(l.Scene,l.camera),requestAnimationFrame(e)}(),{mesh:l.mesh,geometry:l.geometry,renderer:l.renderer,Scene:l.Scene}}))},ImageTransition:function(e,{speed:n=.02,strength:o=.02,radius:r=.02,hover:i=!1,noise:a=.4}={}){let u=Array.from(e.querySelectorAll("img"));if(!u.length)return void console.log("No image provided");const l={uImage:{value:null},uImage2:{value:null},uTime:{value:0},uStrength:{value:i?0:o},uNoise:{value:a},uMouse:{value:new THREE.Vector2(-10,-10)},uRadius:{value:r}},s=new THREE.TextureLoader;let v,d=[];u.map(((e,n)=>{s.load(e.src,(e=>{v=0,1==n&&(l.uImage2.value=e),0==n&&(l.uImage.value=e),d.push(e)}))}));const c=t(e.clientWidth,e.clientHeight);let m;function g(){m&&(c.Scene.remove(m),m.geometry.dispose(),m.material.dispose()),m=function(){const n=e.clientWidth/e.clientHeight*2.3,t=new THREE.PlaneGeometry(n,2.3,100,100),o=new THREE.ShaderMaterial({vertexShader:"\nprecision highp float;\nvarying vec2 vUv; \n\n void main() { \n vUv = uv; \n gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);\n }",fragmentShader:"\nprecision highp float;\nuniform vec2 uMouse;\nvarying vec2 vUv;\nuniform sampler2D uImage;\nuniform float uTime;\nuniform float uRadius;\nuniform float uStrength;\nuniform float uNoise;\nuniform bool uLight;\nuniform sampler2D uImage2;\nfloat rand(float n){return fract(sin(n) * 43758.5453123);}\nfloat rand(vec2 n){return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453123);}\n\nfloat noise(float p){\n float fl = floor(p);\n float fc = fract(p);\n return mix(rand(fl), rand(fl + 1.0), fc);\n}\n \nfloat noise(vec2 n) {\n const vec2 d = vec2(0.0, 1.0);\n vec2 b = floor(n), f = smoothstep(vec2(0.0), vec2(1.0), fract(n));\n return mix(mix(rand(b), rand(b + d.yx), f.x), mix(rand(b + d.xy), rand(b + d.yy), f.x), f.y);\n}\n\nvoid main() {\n vec2 uv = vUv;\n vec2 guv = vUv;\n guv.x -= 0.5;\n guv.y -= 0.5;\n\n // Calculate distance from mouse\n float dist = length(guv - uMouse);\n\n \n float edgeNoise = noise(guv * 10.0 + uTime * 2.0 ) * uNoise;\n\n // Create mask for area following mouse, with wobbly edge\n float inside = step(dist, uRadius *edgeNoise);\n\n // Apply noise only inside the circle\n float n = noise(guv * 0.2);\n\n vec3 circle = mix(vec3(1.0), vec3(n), inside);\n\n // Apply wave distortion\n float waveX = sin(10.0 * uv.y + uTime * 2.0);\n float waveY = cos(10.0 * uv.x + uTime * 2.0);\n uv.x += (uStrength * 0.05) * waveX;\n uv.y += (uStrength * 0.05) * waveY;\n\n \n\n vec4 color = texture2D(uImage, uv);\n \n vec4 color2 = texture2D(uImage2,uv);\n gl_FragColor = mix(color,(vec4(n)+color2),inside);\n}\n",uniforms:l,transparent:!0});return new THREE.Mesh(t,o)}(),c.mesh=m,c.Scene.add(m)}function f(){const n=e.clientWidth,t=e.clientHeight;c.renderer.setSize(n,t),c.renderer.setPixelRatio(window.devicePixelRatio),c.camera.aspect=n/t,c.camera.updateProjectionMatrix(),g()}return c.camera.fov=2*Math.atan(e.clientHeight/2/600)*(180/Math.PI),c.camera.position.z=2.8,e.addEventListener("mousemove",(function(n){const t=e.getBoundingClientRect(),o=(n.clientX-t.left)/t.width-.5,r=-(n.clientY-t.top)/t.height+.5;gsap.to(l.uMouse.value,{x:o,y:r,duration:.2})})),i&&(e.addEventListener("mouseenter",(()=>{gsap.to(l.uStrength,{value:o,duration:.5,ease:"power2.out"}),gsap.to(l.uRadius,{value:r,duration:.2})})),e.addEventListener("mouseleave",(()=>{gsap.to(l.uStrength,{value:0,duration:.5,ease:"power2.out"}),gsap.to(l.uRadius,{value:-100,duration:.6})}))),e.innerHTML="",e.appendChild(c.renderer.domElement),window.addEventListener("resize",f),f(),function e(){l.uTime.value+=n,c.renderer.render(c.Scene,c.camera),requestAnimationFrame(e)}(),e.addEventListener("click",(()=>{const e=(v+1)%d.length,n=(v+2)%d.length;gsap.to(l.uRadius,{value:2,duration:2,ease:"power2.inOut",onComplete:()=>{l.uImage.value=d[e],l.uImage2.value=d[n],gsap.fromTo(l.uRadius,{value:0},{value:r,duration:2,ease:"power2.inOut"}),v=e}})})),{mesh:c.mesh,geometry:c.geometry,renderer:c.renderer,Scene:c.Scene,currntimageIndex:v}}};return n})()));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cheryglsljs",
3
- "version": "1.1.5",
3
+ "version": "1.1.7",
4
4
  "description": "A Three.js + GLSL-based wave effect library.",
5
5
  "main": "dist/cherry.js",
6
6
  "module": "dist/cherry.js",
package/src/cherry.js CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
2
  import CherryWave from "./effects/waveEffect/Effect";
3
-
3
+ import { ImageTransition } from "./effects/TransitionEffect/Effect";
4
4
  export default {
5
- CherryWave
5
+ CherryWave,
6
+ ImageTransition
6
7
  };
@@ -1,161 +1,182 @@
1
-
2
- import createWaveAssets from '../../utils/init.js';
3
- import fragmentShader from './FragementShader.glsl.js';
4
- import vertexShader from './Vertexshader.glsl.js';
5
-
6
- const CherryWave = ({ container, image, speed = 0.05, strength = 0.02, hover = false,light=false }) => {
7
- if (!image) {
1
+ import createWaveAssets from "../../utils/init.js";
2
+ import fragmentShader from "./FragementShader.glsl.js";
3
+ import vertexShader from "./VertexShader.glsl.js";
4
+ // Make sure the file 'FragmentShader.glsl.js' exists in the same directory as this file.
5
+ // If the file is named differently or located elsewhere, update the import path accordingly.
6
+ // Example: import fragmentShader from '../../shaders/FragmentShader.glsl.js';
7
+
8
+ export function ImageTransition(
9
+ container,
10
+ { speed = 0.02, strength = 0.02, radius = 0.02, hover = false,noise=0.4 } = {}
11
+ ) {
12
+ let image = Array.from(container.querySelectorAll("img"));
13
+ if (!image.length) {
8
14
  console.log("No image provided");
9
15
  return;
10
16
  }
11
- const uniforms={
17
+ const uniforms = {
12
18
  uImage: { value: null },
13
- uImage2: { value: null },
14
- uTime: { value: 0.0 },
15
- uStrength: { value: hover ? 0 : strength },
16
- uLight:light,
17
- uMouse: { value: new THREE.Vector2(-10, -10) },
18
- uRadius:{value:-4.0}
19
- };
19
+ uImage2: { value: null },
20
+ uTime: { value: 0.0 },
21
+ uStrength: { value: hover ? 0 : strength },
22
+ uNoise:{value:noise},
23
+ uMouse: { value: new THREE.Vector2(-10, -10) },
24
+ uRadius: { value: radius },
25
+ };
20
26
  const textureLoader = new THREE.TextureLoader();
21
- const images = ["i3.jpg","testimage.jpeg"];
22
- let textures=[];
27
+
28
+ let textures = [];
23
29
  let index;
24
- images.map((img,i)=>{
25
- textureLoader.load(img, (texture) => {
26
- index =0;
27
- if(i==1) uniforms.uImage2.value=texture;
28
- if(i==0) uniforms.uImage.value=texture;
29
- textures.push(texture)
30
- });
31
- })
32
-
33
- const waveassets = createWaveAssets(container.clientWidth, container.clientHeight);
34
-
35
- // Set camera to frame a 2x2 unit square
36
- waveassets.camera.fov = 2 * Math.atan(container.clientHeight / 2 / 600) * (180 / Math.PI);
37
- waveassets.camera.position.z = 2.8;
38
-
39
- let mesh;
40
-
41
- function createMesh() {
42
- const width = container.clientWidth;
43
- const height = container.clientHeight;
44
-
45
-
46
- const aspect = width / height;
47
- const worldHeight = 2.3;
48
- const worldWidth = worldHeight * aspect;
49
-
50
- const geometry = new THREE.PlaneGeometry(worldWidth, worldHeight, 100, 100);
51
- const material = new THREE.ShaderMaterial({
52
- vertexShader,
53
- fragmentShader,
54
- uniforms,
55
- transparent: true
56
- });
30
+ image.map((img, i) => {
31
+ textureLoader.load(img.src, (texture) => {
32
+ index = 0;
33
+ if (i == 1) uniforms.uImage2.value = texture;
34
+ if (i == 0) uniforms.uImage.value = texture;
35
+ textures.push(texture);
36
+ });
37
+ });
38
+
39
+ const waveassets = createWaveAssets(
40
+ container.clientWidth,
41
+ container.clientHeight
42
+ );
43
+
44
+ // Set camera to frame a 2x2 unit square
45
+ waveassets.camera.fov =
46
+ 2 * Math.atan(container.clientHeight / 2 / 600) * (180 / Math.PI);
47
+ waveassets.camera.position.z = 2.8;
48
+
49
+ let mesh;
50
+
51
+ function createMesh() {
52
+ const width = container.clientWidth;
53
+ const height = container.clientHeight;
54
+
55
+ const aspect = width / height;
56
+ const worldHeight = 2.3;
57
+ const worldWidth = worldHeight * aspect;
58
+
59
+ const geometry = new THREE.PlaneGeometry(worldWidth, worldHeight, 100, 100);
60
+ const material = new THREE.ShaderMaterial({
61
+ vertexShader,
62
+ fragmentShader,
63
+ uniforms,
64
+ transparent: true,
65
+ });
66
+
67
+ return new THREE.Mesh(geometry, material);
68
+ }
57
69
 
58
- return new THREE.Mesh(geometry, material);
70
+ function addMesh() {
71
+ if (mesh) {
72
+ waveassets.Scene.remove(mesh);
73
+ mesh.geometry.dispose();
74
+ mesh.material.dispose();
59
75
  }
60
76
 
61
- function addMesh() {
62
- if (mesh) {
63
- waveassets.Scene.remove(mesh);
64
- mesh.geometry.dispose();
65
- mesh.material.dispose();
66
- }
77
+ mesh = createMesh();
78
+ waveassets.mesh = mesh;
79
+ waveassets.Scene.add(mesh);
80
+ }
67
81
 
68
- mesh = createMesh();
69
- waveassets.mesh = mesh;
70
- waveassets.Scene.add(mesh);
71
- }
82
+ function onResize() {
83
+ const width = container.clientWidth;
84
+ const height = container.clientHeight;
72
85
 
73
- function onResize() {
74
- const width = container.clientWidth;
75
- const height = container.clientHeight;
86
+ waveassets.renderer.setSize(width, height);
87
+ waveassets.renderer.setPixelRatio(window.devicePixelRatio);
76
88
 
77
- waveassets.renderer.setSize(width, height);
78
- waveassets.renderer.setPixelRatio(window.devicePixelRatio);
89
+ waveassets.camera.aspect = width / height;
90
+ waveassets.camera.updateProjectionMatrix();
79
91
 
80
- waveassets.camera.aspect = width / height;
81
- waveassets.camera.updateProjectionMatrix();
92
+ addMesh();
93
+ }
82
94
 
83
- addMesh();
84
- }
95
+ function onMouseMove(event) {
96
+ const bounds = container.getBoundingClientRect();
97
+ const x = (event.clientX - bounds.left) / bounds.width - 0.5;
98
+ const y = -((event.clientY - bounds.top) / bounds.height) + 0.5;
85
99
 
86
- function onMouseMove(event) {
87
- const bounds = container.getBoundingClientRect();
88
- const x = ((event.clientX - bounds.left) / bounds.width) - 0.5;
89
- const y = -((event.clientY - bounds.top) / bounds.height) + 0.5;
90
-
91
- gsap.to(uniforms.uMouse.value, {
92
- x: x,
93
- y: y,
94
- duration: 0.2
95
- });
96
- // TransitionAssets.renderer.render(TransitionAssets.Scene, TransitionAssets.camera);
97
- }
98
-
99
- container.addEventListener('mousemove', onMouseMove);
100
- if (hover) {
101
-
102
- container.addEventListener('mouseenter', () => {
103
- gsap.to(uniforms.uStrength, {
104
- value: strength,
105
- duration: 0.5,
106
- ease: 'power2.out'
107
- });
108
- gsap.to(uniforms.uRadius, {
109
- value:0.02,
110
- duration: 0.2
111
- });
100
+ gsap.to(uniforms.uMouse.value, {
101
+ x: x,
102
+ y: y,
103
+ duration: 0.2,
104
+ });
105
+ }
106
+
107
+ container.addEventListener("mousemove", onMouseMove);
108
+ if (hover) {
109
+ container.addEventListener("mouseenter", () => {
110
+ gsap.to(uniforms.uStrength, {
111
+ value: strength,
112
+ duration: 0.5,
113
+ ease: "power2.out",
114
+ });
115
+ gsap.to(uniforms.uRadius, {
116
+ value: radius,
117
+ duration: 0.2,
112
118
  });
119
+ });
113
120
 
114
- container.addEventListener('mouseleave', () => {
115
- gsap.to(uniforms.uStrength, {
116
- value: 0,
117
- duration: 0.5,
118
- ease: 'power2.out'
119
- });
120
- gsap.to(uniforms.uRadius, {
121
- value:-100,
122
- duration: 0.6
123
- });
121
+ container.addEventListener("mouseleave", () => {
122
+ gsap.to(uniforms.uStrength, {
123
+ value: 0,
124
+ duration: 0.5,
125
+ ease: "power2.out",
124
126
  });
125
- }
127
+ gsap.to(uniforms.uRadius, {
128
+ value: -100,
129
+ duration: 0.6,
130
+ });
131
+ });
132
+ }
126
133
 
127
- container.innerHTML = '';
128
- container.appendChild(waveassets.renderer.domElement);
134
+ container.innerHTML = "";
135
+ container.appendChild(waveassets.renderer.domElement);
129
136
 
130
- window.addEventListener('resize', onResize);
131
- onResize();
137
+ window.addEventListener("resize", onResize);
138
+ onResize();
132
139
 
133
- function animate() {
134
- uniforms.uTime.value += speed;
135
- waveassets.renderer.render(waveassets.Scene, waveassets.camera);
136
- requestAnimationFrame(animate);
137
- }
138
-
139
- animate();
140
- container.addEventListener('click',()=>{
141
- gsap.to(uniforms.uRadius,{
142
- value:20,
143
- duration:3,
144
- onComplete:()=>{
145
- uniforms.uRadius.value=0.01
146
- uniforms.uImage.value=textures[(index+1)%textures.length]
147
- uniforms.uImage2.value=textures[(index+2)%textures.length]
148
- index++;
149
- }
150
- })
151
- })
152
-
153
- return {
154
- mesh: waveassets.mesh,
155
- geometry: waveassets.geometry,
156
- renderer: waveassets.renderer,
157
- Scene: waveassets.Scene
158
- };
159
- };
160
-
161
- export default CherryWave;
140
+ function animate() {
141
+ uniforms.uTime.value += speed;
142
+ waveassets.renderer.render(waveassets.Scene, waveassets.camera);
143
+ requestAnimationFrame(animate);
144
+ }
145
+
146
+ animate();
147
+ // let isTransitioning = false; // Removed unused variable
148
+
149
+ container.addEventListener("click", () => {
150
+ const nextIndex = (index + 1) % textures.length;
151
+ const nextNextIndex = (index + 2) % textures.length;
152
+
153
+ gsap.to(uniforms.uRadius, {
154
+ value: 2,
155
+ duration: 2,
156
+ ease: "power2.inOut",
157
+
158
+ onComplete: () => {
159
+ uniforms.uImage.value = textures[nextIndex];
160
+ uniforms.uImage2.value = textures[nextNextIndex];
161
+ gsap.fromTo(
162
+ uniforms.uRadius,
163
+ { value: 0.0 },
164
+ {
165
+ value: radius,
166
+ duration: 2,
167
+ ease: "power2.inOut",
168
+ }
169
+ );
170
+ index = nextIndex;
171
+ },
172
+ });
173
+ });
174
+
175
+ return {
176
+ mesh: waveassets.mesh,
177
+ geometry: waveassets.geometry,
178
+ renderer: waveassets.renderer,
179
+ Scene: waveassets.Scene,
180
+ currntimageIndex: index,
181
+ };
182
+ }
@@ -6,6 +6,7 @@ uniform sampler2D uImage;
6
6
  uniform float uTime;
7
7
  uniform float uRadius;
8
8
  uniform float uStrength;
9
+ uniform float uNoise;
9
10
  uniform bool uLight;
10
11
  uniform sampler2D uImage2;
11
12
  float rand(float n){return fract(sin(n) * 43758.5453123);}
@@ -33,10 +34,10 @@ void main() {
33
34
  float dist = length(guv - uMouse);
34
35
 
35
36
 
36
- float edgeNoise = noise(guv * 10.0 + uTime * 2.0 ) * 0.2;
37
+ float edgeNoise = noise(guv * 10.0 + uTime * 2.0 ) * uNoise;
37
38
 
38
39
  // Create mask for area following mouse, with wobbly edge
39
- float inside = step(dist, uRadius + edgeNoise);
40
+ float inside = step(dist, uRadius *edgeNoise);
40
41
 
41
42
  // Apply noise only inside the circle
42
43
  float n = noise(guv * 0.2);
@@ -52,11 +53,8 @@ void main() {
52
53
 
53
54
 
54
55
  vec4 color = texture2D(uImage, uv);
55
- if(uLight){
56
- color.x-=smoothstep(0.001,0.6,sin(2.0*uTime));
57
- color.y-=smoothstep(0.2,0.6,sin(0.2*uTime));
58
- }
56
+
59
57
  vec4 color2 = texture2D(uImage2,uv);
60
58
  gl_FragColor = mix(color,(vec4(n)+color2),inside);
61
59
  }
62
- `;
60
+ `
@@ -18,6 +18,7 @@ const CherryWave = ({ container, image, speed = 0.05, strength = 0.02, hover = f
18
18
  uLight:{value:light}
19
19
 
20
20
  };
21
+
21
22
 
22
23
 
23
24
  const waveassets = createWaveAssets(container.clientWidth, container.clientHeight);
@@ -25,7 +25,7 @@ void main() {
25
25
 
26
26
 
27
27
  vec4 color = texture2D(uImage, uv);
28
- if(!uLight){
28
+ if(uLight){
29
29
  color.x+=smoothstep(0.001,0.6,sin(2.0*uTime));
30
30
  color.y+=smoothstep(0.2,0.6,sin(0.2*uTime));
31
31
  }