cheryglsljs 1.1.2 → 1.1.4
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,
|
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 r in t)e.o(t,r)&&!e.o(n,r)&&Object.defineProperty(n,r,{enumerable:!0,get:t[r]})},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:()=>r});function t(e=400,n=400){const t=new THREE.Scene,r=new THREE.PerspectiveCamera(75,window.innerWidth/window.innerHeight,.1,1e3),o=new THREE.WebGLRenderer({alpha:!0});return o.setSize(e,n),{Scene:t,camera:r,renderer:o}}const r={CherryWave:({container:e,image:n,speed:r=.05,strength:o=8,hover:i=!1})=>{if(!n)return void console.log("No image provided");(new THREE.TextureLoader).load(n.src,(a=>{const u={uImage:{value:a},uTime:{value:0},uStrength:{value:i?0:o}},c=t(e.clientWidth,e.clientHeight);let s;c.camera.position.z=190;new THREE.Raycaster;const d=new THREE.Vector2;function l(){const t=e.clientWidth,r=e.clientHeight,o=t/r,i=n.naturalWidth/n.naturalHeight;let a,d;o<i?(a=t,d=t/i):(d=r,a=r*i),s&&(c.Scene.remove(s),s.geometry.dispose(),s.material.dispose()),s=function(e,n){const t=new THREE.PlaneGeometry(e,n,100,100),r=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 // Enhanced wave effect: move vertices in all directions\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;\nvarying vec2 vUv;\nuniform sampler2D uImage;\nuniform float uTime;\nuniform float uStrength;\nvoid main() {\n // Create a wave effect by modifying the y coordinate\n vec2 uv = vUv;\n \n \n uv.y += uStrength/400.0 * sin(10.0 * uv.x + uTime * 2.0);\n uv.x += uStrength/400.0 * sin(10.0 * uv.y + uTime * 2.0);\n \n vec4 color = texture2D(uImage, uv);\n gl_FragColor = color;\n}",uniforms:u});return new THREE.Mesh(t,r)}(a,d),c.mesh=s,c.Scene.add(s)}return i&&(e.addEventListener("mousemove",(function(n){const t=e.getBoundingClientRect();d.x=(n.clientX-t.left)/t.width*2-1,d.y=-(n.clientY-t.top)/t.height*2+1})),e.addEventListener("mouseenter",(()=>{gsap.to(u.uStrength,{value:o,duration:.5,ease:"power2.out"})})),e.addEventListener("mouseleave",(()=>{gsap.to(u.uStrength,{value:0,duration:.5,ease:"power2.out"})}))),e.innerHTML="",e.appendChild(c.renderer.domElement),window.addEventListener("resize",(function(){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(),l()})),l(),function e(){u.uTime.value+=r,c.renderer.render(c.Scene,c.camera),requestAnimationFrame(e)}(),{mesh:c.mesh,geometry:c.geometry,renderer:c.renderer,Scene:c.Scene}}))}};return n})()));
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
import createWaveAssets from '../../utils/init.js';
|
2
|
-
import fragmentShader from './FragementShader.glsl
|
3
|
-
import vertexShader from './Vertexshader.glsl
|
2
|
+
import fragmentShader from './FragementShader.glsl';
|
3
|
+
import vertexShader from './Vertexshader.glsl';
|
4
4
|
|
5
5
|
const CherryWave = ({ container, image, speed = 0.05, strength = 8, hover = false }) => {
|
6
6
|
if (!image) {
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
export default /* glsl */`
|
2
2
|
precision highp float;
|
3
3
|
varying vec2 vUv;
|
4
4
|
uniform sampler2D uImage;
|
@@ -14,6 +14,5 @@ void main() {
|
|
14
14
|
|
15
15
|
vec4 color = texture2D(uImage, uv);
|
16
16
|
gl_FragColor = color;
|
17
|
-
}
|
18
|
-
|
19
|
-
export default fragmentShader;
|
17
|
+
}`
|
18
|
+
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
export default /* glsl */`
|
2
2
|
precision highp float;
|
3
3
|
varying vec2 vUv;
|
4
4
|
varying vec3 pos;
|
@@ -23,8 +23,7 @@ precision highp float;
|
|
23
23
|
|
24
24
|
pos = (modelViewMatrix * vec4(newPosition, 1.0)).xyz;
|
25
25
|
gl_Position = projectionMatrix * modelViewMatrix * vec4(newPosition, 1.0);
|
26
|
-
}
|
27
|
-
|
26
|
+
}`
|
27
|
+
|
28
28
|
|
29
29
|
|
30
|
-
export default vertexShader;
|