@ivanalbizu/astro-webgl-hover 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Ivan Alabizu
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,111 @@
1
+ # astro-webgl-hover
2
+
3
+ WebGL image hover effects for Astro with displacement transitions using Curtains.js and GSAP.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install astro-webgl-hover curtainsjs gsap
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ ```astro
14
+ ---
15
+ import { WebglHoverImages, WebglHoverImage } from 'astro-webgl-hover';
16
+ ---
17
+
18
+ <WebglHoverImages>
19
+ <WebglHoverImage
20
+ texture0="/image-default.jpg"
21
+ texture1="/image-hover.jpg"
22
+ map="/displacements/displacement.jpg"
23
+ />
24
+ </WebglHoverImages>
25
+ ```
26
+
27
+ ## Components
28
+
29
+ ### `<WebglHoverImages>`
30
+
31
+ Container component that initializes the WebGL context. Wrap all your `<WebglHoverImage>` components inside this.
32
+
33
+ #### Props
34
+
35
+ | Prop | Type | Default | Description |
36
+ |------|------|---------|-------------|
37
+ | `durationIn` | `number` | `0.8` | Duration of hover-in animation (seconds) |
38
+ | `durationOut` | `number` | `0.8` | Duration of hover-out animation (seconds) |
39
+ | `easeIn` | `string` | `'power2.out'` | GSAP easing for hover-in |
40
+ | `easeOut` | `string` | `'power2.out'` | GSAP easing for hover-out |
41
+ | `intensity` | `number` | `1` | Displacement intensity |
42
+ | `displacementAngle` | `number` | `0` | Displacement direction (degrees) |
43
+ | `zoom` | `number` | `0` | Zoom amount on hover (0-1) |
44
+ | `imageRotation` | `number` | `0` | Image rotation on hover (degrees) |
45
+ | `noiseSpeed` | `number` | `0.5` | Noise animation speed |
46
+ | `noiseScale` | `number` | `6.0` | Noise texture scale |
47
+ | `rgbShiftIntensity` | `number` | `0` | RGB shift/chromatic aberration intensity |
48
+ | `debug` | `boolean` | `false` | Show debug panel (lil-gui) |
49
+
50
+ ### `<WebglHoverImage>`
51
+
52
+ Individual image component with hover effect.
53
+
54
+ #### Props
55
+
56
+ | Prop | Type | Required | Description |
57
+ |------|------|----------|-------------|
58
+ | `texture0` | `string` | Yes | Default image URL |
59
+ | `texture1` | `string` | Yes | Hover image URL |
60
+ | `map` | `string` | Yes | Displacement map URL |
61
+
62
+ All props from `<WebglHoverImages>` can also be passed to individual `<WebglHoverImage>` components to override the global settings.
63
+
64
+ ## Displacement Maps
65
+
66
+ The `map` prop accepts a grayscale image that controls the displacement effect. You can find free displacement maps at:
67
+
68
+ - [Grayscale displacement textures](https://github.com/robin-dela/hover-effect/tree/master/images)
69
+ - Create your own using Photoshop/GIMP noise filters
70
+
71
+ ## Debug Mode
72
+
73
+ Enable `debug={true}` on `<WebglHoverImages>` to show a control panel where you can adjust all parameters in real-time.
74
+
75
+ ```astro
76
+ <WebglHoverImages debug={true}>
77
+ <!-- ... -->
78
+ </WebglHoverImages>
79
+ ```
80
+
81
+ ## Advanced Usage
82
+
83
+ You can also import the library directly for more control:
84
+
85
+ ```typescript
86
+ import { initWebglHover, WebglHover } from 'astro-webgl-hover';
87
+
88
+ // Initialize manually
89
+ const instances = initWebglHover();
90
+
91
+ // Control individual instances
92
+ instances[0].setProgress(0.5);
93
+ instances[0].destroy();
94
+ ```
95
+
96
+ ## Performance
97
+
98
+ The library includes several optimizations:
99
+
100
+ - Fallback for low-performance devices
101
+ - Render loop pauses when not animating
102
+ - Debounced resize handler
103
+ - Optimized mesh segments
104
+
105
+ ## Browser Support
106
+
107
+ Requires WebGL support. Falls back to static images on unsupported devices.
108
+
109
+ ## License
110
+
111
+ MIT
package/index.ts ADDED
@@ -0,0 +1,16 @@
1
+ /**
2
+ * astro-webgl-hover
3
+ *
4
+ * WebGL image hover effects for Astro using Curtains.js and GSAP
5
+ */
6
+
7
+ // Components (for Astro users)
8
+ export { default as WebglHoverImages } from './src/components/WebglHoverImages.astro';
9
+ export { default as WebglHoverImage } from './src/components/WebglHoverImage.astro';
10
+
11
+ // Library exports (for advanced usage)
12
+ export { WebglHover } from './src/lib/webgl-hover/WebglHover';
13
+ export { initWebglHover } from './src/lib/webgl-hover/index';
14
+ export * from './src/lib/webgl-hover/config';
15
+ export * from './src/lib/webgl-hover/utils';
16
+ export * from './src/lib/webgl-hover/performance';
package/package.json ADDED
@@ -0,0 +1,53 @@
1
+ {
2
+ "name": "@ivanalbizu/astro-webgl-hover",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "description": "WebGL image hover effects for Astro with displacement transitions using Curtains.js and GSAP",
6
+ "author": "Ivan Alabizu",
7
+ "license": "MIT",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/ivanalabizu/astro-webgl-hover"
11
+ },
12
+ "keywords": [
13
+ "astro",
14
+ "astro-component",
15
+ "webgl",
16
+ "hover",
17
+ "image",
18
+ "effect",
19
+ "displacement",
20
+ "curtainsjs",
21
+ "gsap",
22
+ "animation"
23
+ ],
24
+ "exports": {
25
+ ".": "./index.ts",
26
+ "./components": {
27
+ "import": "./src/components/index.ts"
28
+ }
29
+ },
30
+ "files": [
31
+ "index.ts",
32
+ "src/components/",
33
+ "src/lib/",
34
+ "src/shaders/"
35
+ ],
36
+ "scripts": {
37
+ "dev": "astro dev",
38
+ "build": "astro build",
39
+ "preview": "astro preview",
40
+ "astro": "astro"
41
+ },
42
+ "peerDependencies": {
43
+ "astro": "^4.0.0 || ^5.0.0",
44
+ "curtainsjs": "^8.0.0",
45
+ "gsap": "^3.0.0"
46
+ },
47
+ "devDependencies": {
48
+ "astro": "^5.16.9",
49
+ "curtainsjs": "^8.1.6",
50
+ "gsap": "^3.12.7",
51
+ "lil-gui": "^0.19.2"
52
+ }
53
+ }
@@ -0,0 +1,61 @@
1
+ ---
2
+ import type { HTMLAttributes } from 'astro/types';
3
+
4
+ interface Props extends HTMLAttributes<'div'> {
5
+ texture0: string;
6
+ texture1: string;
7
+ map: string;
8
+ durationIn?: number;
9
+ durationOut?: number;
10
+ easeIn?: string;
11
+ easeOut?: string;
12
+ displacementAngle?: number; // Ángulo del desplazamiento en grados
13
+ intensity?: number;
14
+ zoom?: number;
15
+ imageRotation?: number; // Rotación de la imagen en grados
16
+ noiseSpeed?: number;
17
+ noiseScale?: number;
18
+ rgbShiftIntensity?: number;
19
+ alt?: string;
20
+ imgAttributes?: HTMLAttributes<'img'>;
21
+ width?: number;
22
+ height?: number;
23
+ width1?: number;
24
+ height1?: number;
25
+ }
26
+
27
+ const { texture0, texture1, map, durationIn, durationOut, easeIn, easeOut, displacementAngle, intensity, zoom, imageRotation, noiseSpeed, noiseScale, rgbShiftIntensity, alt = "", imgAttributes = {}, width = 382, height = 640, width1, height1, ...rest } = Astro.props;
28
+
29
+ const { loading = "lazy", ...restImgAttributes } = imgAttributes;
30
+ const finalWidth1 = width1 || width;
31
+ const finalHeight1 = height1 || height;
32
+ ---
33
+
34
+ <div class:list={["whi-slide", rest.class]} {...rest} data-width={width} data-height={height} data-width1={finalWidth1} data-height1={finalHeight1} data-duration-in={durationIn} data-duration-out={durationOut} data-ease-in={easeIn} data-ease-out={easeOut} data-displacement-angle={displacementAngle} data-intensity={intensity} data-zoom={zoom} data-image-rotation={imageRotation} data-noise-speed={noiseSpeed} data-noise-scale={noiseScale} data-rgb-shift-intensity={rgbShiftIntensity}>
35
+ <div class="whi-plane">
36
+ <img data-sampler="texture0" src={texture0} alt={alt} loading={loading} width={width} height={height} {...restImgAttributes} crossorigin="anonymous" />
37
+ <img data-sampler="texture1" src={texture1} aria-hidden="true" alt="" loading={loading} crossorigin="anonymous" />
38
+ <img data-sampler="map" src={map} aria-hidden="true" alt="" loading={loading} crossorigin="anonymous" />
39
+ </div>
40
+ <slot />
41
+ </div>
42
+
43
+ <style lang="scss" define:vars={{ width, height }}>
44
+ .whi-plane {
45
+ aspect-ratio: var(--width) / var(--height);
46
+ position: relative;
47
+ img {
48
+ position: absolute;
49
+ top: 0;
50
+ left: 0;
51
+ width: 100%;
52
+ height: 100%;
53
+ opacity: 0;
54
+ pointer-events: none;
55
+ }
56
+ img[data-sampler="texture0"] {
57
+ opacity: 1;
58
+ transition: opacity 0.5s ease-out;
59
+ }
60
+ }
61
+ </style>
@@ -0,0 +1,68 @@
1
+ ---
2
+ interface Props {
3
+ durationIn?: number;
4
+ durationOut?: number;
5
+ easeIn?: string;
6
+ easeOut?: string;
7
+ displacementAngle?: number;
8
+ intensity?: number;
9
+ zoom?: number;
10
+ imageRotation?: number;
11
+ noiseSpeed?: number;
12
+ noiseScale?: number;
13
+ rgbShiftIntensity?: number;
14
+ debug?: boolean;
15
+ }
16
+
17
+ const {
18
+ durationIn = 0.8,
19
+ durationOut = 0.8,
20
+ easeIn = 'power2.out',
21
+ easeOut = 'power2.out',
22
+ displacementAngle = 0,
23
+ intensity = 1,
24
+ zoom = 0,
25
+ imageRotation = 0,
26
+ noiseSpeed = 0.5,
27
+ noiseScale = 6.0,
28
+ rgbShiftIntensity = 0,
29
+ debug = false,
30
+ } = Astro.props;
31
+ ---
32
+
33
+ <div
34
+ id="webgl-hover-config"
35
+ data-debug={String(debug)}
36
+ data-duration-in={durationIn}
37
+ data-duration-out={durationOut}
38
+ data-ease-in={easeIn}
39
+ data-ease-out={easeOut}
40
+ data-displacement-angle={displacementAngle}
41
+ data-intensity={intensity}
42
+ data-zoom={zoom}
43
+ data-image-rotation={imageRotation}
44
+ data-noise-speed={noiseSpeed}
45
+ data-noise-scale={noiseScale}
46
+ data-rgb-shift-intensity={rgbShiftIntensity}
47
+ style="display: none;"
48
+ >
49
+ </div>
50
+
51
+ <slot />
52
+
53
+ <script>
54
+ import { initWebglHover } from '@/lib/webgl-hover';
55
+ initWebglHover();
56
+ </script>
57
+
58
+ <style is:global>
59
+ #canvas-container {
60
+ position: fixed;
61
+ top: 0;
62
+ left: 0;
63
+ width: 100%;
64
+ height: 100vh;
65
+ pointer-events: none;
66
+ z-index: -1;
67
+ }
68
+ </style>
@@ -0,0 +1,2 @@
1
+ export { default as WebglHoverImages } from './WebglHoverImages.astro';
2
+ export { default as WebglHoverImage } from './WebglHoverImage.astro';
@@ -0,0 +1,233 @@
1
+ /**
2
+ * Clase principal para manejar efectos WebGL hover con Curtains.js
3
+ */
4
+
5
+ import { Plane } from 'curtainsjs';
6
+ import gsap from 'gsap';
7
+ import type { WebglHoverOptions } from './config';
8
+ import { degreesToRadians, calculateDisplacementVector } from './utils';
9
+ import vertexShader from '@/shaders/vertex.glsl?raw';
10
+ import fragmentShader from '@/shaders/fragment.glsl?raw';
11
+
12
+ export class WebglHover {
13
+ private webGLCurtain: any;
14
+ private planeElement: HTMLElement;
15
+ private plane: any;
16
+ private params: any;
17
+
18
+ private durationIn: number;
19
+ private durationOut: number;
20
+ private easeIn: string;
21
+ private easeOut: string;
22
+ private zoom: number;
23
+ private imageRotation: number;
24
+ private noiseSpeed: number;
25
+ private noiseScale: number;
26
+ private rgbShiftIntensity: number;
27
+ private intensity: number;
28
+ private displacementAngle: number;
29
+
30
+ private hoverEnabled: boolean = true;
31
+ private isAnimating: boolean = false;
32
+
33
+ private boundHandleMouseEnter: () => void;
34
+ private boundHandleMouseOut: () => void;
35
+
36
+ constructor(curtains: any, planeElement: HTMLElement, options: WebglHoverOptions) {
37
+ this.webGLCurtain = curtains;
38
+ this.planeElement = planeElement;
39
+
40
+ // Bind handlers para poder hacer cleanup
41
+ this.boundHandleMouseEnter = this.handleMouseEnter.bind(this);
42
+ this.boundHandleMouseOut = this.handleMouseOut.bind(this);
43
+
44
+ this.durationIn = options.durationIn;
45
+ this.durationOut = options.durationOut;
46
+ this.easeIn = options.easeIn;
47
+ this.easeOut = options.easeOut;
48
+ this.zoom = options.zoom;
49
+ this.imageRotation = degreesToRadians(options.imageRotation);
50
+ this.noiseSpeed = options.noiseSpeed;
51
+ this.noiseScale = options.noiseScale;
52
+ this.rgbShiftIntensity = options.rgbShiftIntensity;
53
+ this.intensity = options.intensity;
54
+ this.displacementAngle = options.displacementAngle;
55
+
56
+ const displacement = calculateDisplacementVector(options.intensity, options.displacementAngle);
57
+
58
+ this.params = {
59
+ vertexShader,
60
+ fragmentShader,
61
+ widthSegments: 20,
62
+ heightSegments: 20,
63
+ uniforms: {
64
+ time: { name: 'uTime', type: '1f', value: 0 },
65
+ mousepos: { name: 'uMouse', type: '2f', value: [0, 0] },
66
+ resolution: { name: 'uReso', type: '2f', value: [innerWidth, innerHeight] },
67
+ progress: { name: 'uProgress', type: '1f', value: 0 },
68
+ displacement: { name: 'uDisplacement', type: '2f', value: displacement },
69
+ zoom: { name: 'uZoom', type: '1f', value: 1 },
70
+ rotation: { name: 'uRotation', type: '1f', value: 0 },
71
+ noiseSpeed: { name: 'uNoiseSpeed', type: '1f', value: this.noiseSpeed },
72
+ noiseScale: { name: 'uNoiseScale', type: '1f', value: this.noiseScale },
73
+ rgbShift: { name: 'uRgbShift', type: '1f', value: 0 },
74
+ tex1Scale: { name: 'uTex1Scale', type: '2f', value: options.tex1Scale },
75
+ },
76
+ };
77
+
78
+ this.initPlane();
79
+ }
80
+
81
+ private initPlane(): void {
82
+ this.plane = new Plane(this.webGLCurtain, this.planeElement, this.params);
83
+
84
+ if (this.plane) {
85
+ this.plane.onReady(() => {
86
+ this.startRenderLoop();
87
+ this.bindEvents();
88
+ this.hideOriginalImage();
89
+ });
90
+ }
91
+ }
92
+
93
+ private startRenderLoop(): void {
94
+ this.plane.onRender(() => {
95
+ if (this.isAnimating) {
96
+ this.plane.uniforms.time.value += 0.01;
97
+ }
98
+ });
99
+ }
100
+
101
+ private hideOriginalImage(): void {
102
+ const img = this.planeElement.querySelector('img[data-sampler="texture0"]') as HTMLElement;
103
+ if (img) {
104
+ img.style.opacity = '0';
105
+ }
106
+ }
107
+
108
+ private bindEvents(): void {
109
+ this.planeElement.addEventListener('mouseenter', this.boundHandleMouseEnter);
110
+ this.planeElement.addEventListener('mouseout', this.boundHandleMouseOut);
111
+ }
112
+
113
+ private unbindEvents(): void {
114
+ this.planeElement.removeEventListener('mouseenter', this.boundHandleMouseEnter);
115
+ this.planeElement.removeEventListener('mouseout', this.boundHandleMouseOut);
116
+ }
117
+
118
+ private handleMouseEnter(): void {
119
+ if (!this.hoverEnabled) return;
120
+
121
+ this.isAnimating = true;
122
+
123
+ const commonIn = {
124
+ duration: this.durationIn,
125
+ ease: this.easeIn,
126
+ overwrite: true,
127
+ };
128
+
129
+ gsap.to(this.plane.uniforms.progress, { ...commonIn, value: 1 });
130
+ gsap.to(this.plane.uniforms.zoom, { ...commonIn, value: 1 + this.zoom });
131
+ gsap.to(this.plane.uniforms.rotation, { ...commonIn, value: this.imageRotation });
132
+ gsap.to(this.plane.uniforms.rgbShift, { ...commonIn, value: this.rgbShiftIntensity });
133
+ }
134
+
135
+ private handleMouseOut(): void {
136
+ if (!this.hoverEnabled) return;
137
+
138
+ const commonOut = {
139
+ duration: this.durationOut,
140
+ ease: this.easeOut,
141
+ overwrite: true,
142
+ onComplete: () => {
143
+ this.isAnimating = false;
144
+ },
145
+ };
146
+
147
+ gsap.to(this.plane.uniforms.progress, { ...commonOut, value: 0 });
148
+ gsap.to(this.plane.uniforms.zoom, { ...commonOut, value: 1 });
149
+ gsap.to(this.plane.uniforms.rotation, { ...commonOut, value: 0 });
150
+ gsap.to(this.plane.uniforms.rgbShift, { ...commonOut, value: 0 });
151
+ }
152
+
153
+ public resize(): void {
154
+ if (this.plane) {
155
+ this.plane.uniforms.resolution.value = [window.innerWidth, window.innerHeight];
156
+ }
157
+ }
158
+
159
+ public setProgress(progress: number): void {
160
+ if (!this.plane) return;
161
+
162
+ this.isAnimating = progress > 0;
163
+
164
+ this.plane.uniforms.progress.value = progress;
165
+ this.plane.uniforms.zoom.value = 1 + this.zoom * progress;
166
+ this.plane.uniforms.rotation.value = this.imageRotation * progress;
167
+ this.plane.uniforms.rgbShift.value = this.rgbShiftIntensity * progress;
168
+ }
169
+
170
+ public setHoverEnabled(enabled: boolean): void {
171
+ this.hoverEnabled = enabled;
172
+ }
173
+
174
+ public destroy(): void {
175
+ this.unbindEvents();
176
+ if (this.plane) {
177
+ this.plane.remove();
178
+ this.plane = null;
179
+ }
180
+ }
181
+
182
+ public setDebugHighlight(enabled: boolean): void {
183
+ if (enabled) {
184
+ this.planeElement.style.outline = '3px solid #00ff00';
185
+ this.planeElement.style.outlineOffset = '-3px';
186
+ } else {
187
+ this.planeElement.style.outline = '';
188
+ this.planeElement.style.outlineOffset = '';
189
+ }
190
+ }
191
+
192
+ public getConfig(): Partial<WebglHoverOptions> {
193
+ return {
194
+ durationIn: this.durationIn,
195
+ durationOut: this.durationOut,
196
+ easeIn: this.easeIn,
197
+ easeOut: this.easeOut,
198
+ zoom: this.zoom,
199
+ imageRotation: this.imageRotation * (180 / Math.PI), // radians to degrees
200
+ noiseSpeed: this.noiseSpeed,
201
+ noiseScale: this.noiseScale,
202
+ rgbShiftIntensity: this.rgbShiftIntensity,
203
+ intensity: this.intensity,
204
+ displacementAngle: this.displacementAngle,
205
+ };
206
+ }
207
+
208
+ public updateConfig(config: Partial<WebglHoverOptions>): void {
209
+ if (config.durationIn !== undefined) this.durationIn = config.durationIn;
210
+ if (config.durationOut !== undefined) this.durationOut = config.durationOut;
211
+ if (config.easeIn !== undefined) this.easeIn = config.easeIn;
212
+ if (config.easeOut !== undefined) this.easeOut = config.easeOut;
213
+ if (config.zoom !== undefined) this.zoom = config.zoom;
214
+ if (config.imageRotation !== undefined) this.imageRotation = degreesToRadians(config.imageRotation);
215
+ if (config.rgbShiftIntensity !== undefined) this.rgbShiftIntensity = config.rgbShiftIntensity;
216
+ if (config.intensity !== undefined) this.intensity = config.intensity;
217
+ if (config.displacementAngle !== undefined) this.displacementAngle = config.displacementAngle;
218
+
219
+ if (this.plane) {
220
+ if (config.noiseSpeed !== undefined) {
221
+ this.noiseSpeed = config.noiseSpeed;
222
+ this.plane.uniforms.noiseSpeed.value = this.noiseSpeed;
223
+ }
224
+ if (config.noiseScale !== undefined) {
225
+ this.noiseScale = config.noiseScale;
226
+ this.plane.uniforms.noiseScale.value = this.noiseScale;
227
+ }
228
+
229
+ const displacement = calculateDisplacementVector(this.intensity, this.displacementAngle);
230
+ this.plane.uniforms.displacement.value = displacement;
231
+ }
232
+ }
233
+ }
@@ -0,0 +1,48 @@
1
+ /**
2
+ * Configuración e interfaces para WebGL Hover
3
+ */
4
+
5
+ export interface WebglHoverOptions {
6
+ durationIn: number;
7
+ durationOut: number;
8
+ easeIn: string;
9
+ easeOut: string;
10
+ intensity: number;
11
+ displacementAngle: number;
12
+ zoom: number;
13
+ imageRotation: number;
14
+ noiseSpeed: number;
15
+ noiseScale: number;
16
+ rgbShiftIntensity: number;
17
+ tex1Scale: [number, number];
18
+ }
19
+
20
+ export interface WebglHoverConfig {
21
+ durationIn: number;
22
+ durationOut: number;
23
+ easeIn: string;
24
+ easeOut: string;
25
+ displacementAngle: number;
26
+ intensity: number;
27
+ zoom: number;
28
+ imageRotation: number;
29
+ noiseSpeed: number;
30
+ noiseScale: number;
31
+ rgbShiftIntensity: number;
32
+ debug: boolean;
33
+ }
34
+
35
+ export const DEFAULT_CONFIG: WebglHoverConfig = {
36
+ durationIn: 0.8,
37
+ durationOut: 0.8,
38
+ easeIn: 'power2.out',
39
+ easeOut: 'power2.out',
40
+ displacementAngle: 0,
41
+ intensity: 1,
42
+ zoom: 0.1,
43
+ imageRotation: 0,
44
+ noiseSpeed: 0.5,
45
+ noiseScale: 6.0,
46
+ rgbShiftIntensity: 0,
47
+ debug: false,
48
+ };
@@ -0,0 +1,293 @@
1
+ /**
2
+ * WebGL Hover - Punto de entrada principal
3
+ *
4
+ * Inicializa efectos WebGL hover con Curtains.js y GSAP
5
+ */
6
+
7
+ import { Curtains } from 'curtainsjs';
8
+ import { WebglHover } from './WebglHover';
9
+ import { DEFAULT_CONFIG, type WebglHoverConfig, type WebglHoverOptions } from './config';
10
+ import { shouldUseFallback, applyFallbackStyles } from './performance';
11
+ import {
12
+ getAttributeAsFloat,
13
+ getAttributeAsString,
14
+ calculateTextureScale,
15
+ } from './utils';
16
+
17
+ export { WebglHover } from './WebglHover';
18
+ export * from './config';
19
+ export * from './performance';
20
+ export * from './utils';
21
+
22
+ function getConfigFromDOM(): WebglHoverConfig {
23
+ const configEl = document.getElementById('webgl-hover-config');
24
+
25
+ if (!configEl) {
26
+ return DEFAULT_CONFIG;
27
+ }
28
+
29
+ return {
30
+ durationIn: parseFloat(configEl.dataset.durationIn || String(DEFAULT_CONFIG.durationIn)),
31
+ durationOut: parseFloat(configEl.dataset.durationOut || String(DEFAULT_CONFIG.durationOut)),
32
+ easeIn: configEl.dataset.easeIn || DEFAULT_CONFIG.easeIn,
33
+ easeOut: configEl.dataset.easeOut || DEFAULT_CONFIG.easeOut,
34
+ intensity: parseFloat(configEl.dataset.intensity || String(DEFAULT_CONFIG.intensity)),
35
+ displacementAngle: parseFloat(configEl.dataset.displacementAngle || String(DEFAULT_CONFIG.displacementAngle)),
36
+ zoom: parseFloat(configEl.dataset.zoom || String(DEFAULT_CONFIG.zoom)),
37
+ imageRotation: parseFloat(configEl.dataset.imageRotation || String(DEFAULT_CONFIG.imageRotation)),
38
+ noiseSpeed: parseFloat(configEl.dataset.noiseSpeed || String(DEFAULT_CONFIG.noiseSpeed)),
39
+ noiseScale: parseFloat(configEl.dataset.noiseScale || String(DEFAULT_CONFIG.noiseScale)),
40
+ rgbShiftIntensity: parseFloat(configEl.dataset.rgbShiftIntensity || String(DEFAULT_CONFIG.rgbShiftIntensity)),
41
+ debug: configEl.dataset.debug === 'true',
42
+ };
43
+ }
44
+
45
+ function getOptionsFromSlide(slide: Element, defaults: WebglHoverConfig): WebglHoverOptions {
46
+ const planeWidth = getAttributeAsFloat(slide, 'data-width', 1);
47
+ const planeHeight = getAttributeAsFloat(slide, 'data-height', 1);
48
+ const tex1Width = getAttributeAsFloat(slide, 'data-width1', planeWidth);
49
+ const tex1Height = getAttributeAsFloat(slide, 'data-height1', planeHeight);
50
+
51
+ const tex1Scale = calculateTextureScale(planeWidth, planeHeight, tex1Width, tex1Height);
52
+
53
+ return {
54
+ durationIn: getAttributeAsFloat(slide, 'data-duration-in', defaults.durationIn),
55
+ durationOut: getAttributeAsFloat(slide, 'data-duration-out', defaults.durationOut),
56
+ easeIn: getAttributeAsString(slide, 'data-ease-in', defaults.easeIn),
57
+ easeOut: getAttributeAsString(slide, 'data-ease-out', defaults.easeOut),
58
+ intensity: getAttributeAsFloat(slide, 'data-intensity', defaults.intensity),
59
+ displacementAngle: getAttributeAsFloat(slide, 'data-displacement-angle', defaults.displacementAngle),
60
+ zoom: getAttributeAsFloat(slide, 'data-zoom', defaults.zoom),
61
+ imageRotation: getAttributeAsFloat(slide, 'data-image-rotation', defaults.imageRotation),
62
+ noiseSpeed: getAttributeAsFloat(slide, 'data-noise-speed', defaults.noiseSpeed),
63
+ noiseScale: getAttributeAsFloat(slide, 'data-noise-scale', defaults.noiseScale),
64
+ rgbShiftIntensity: getAttributeAsFloat(slide, 'data-rgb-shift-intensity', defaults.rgbShiftIntensity),
65
+ tex1Scale,
66
+ };
67
+ }
68
+
69
+ function createCanvasContainer(): HTMLElement {
70
+ let container = document.getElementById('canvas-container');
71
+
72
+ if (!container) {
73
+ container = document.createElement('div');
74
+ container.id = 'canvas-container';
75
+ document.body.appendChild(container);
76
+ }
77
+
78
+ return container;
79
+ }
80
+
81
+ function initDebugMode(instances: WebglHover[], config: WebglHoverConfig): void {
82
+ import('lil-gui').then(({ default: GUI }) => {
83
+ const gui = new GUI({ title: 'WebGL Hover Debug' });
84
+
85
+ // Selector de instancia (sin opción "All")
86
+ const targetOptions: Record<string, number> = {};
87
+ instances.forEach((_, i) => {
88
+ targetOptions[`Image ${i + 1}`] = i;
89
+ });
90
+
91
+ const selectorConfig = { target: 0 };
92
+
93
+ const getTargetInstance = (): WebglHover => {
94
+ return instances[selectorConfig.target];
95
+ };
96
+
97
+ // Cargar config inicial de la primera imagen
98
+ const initialConfig = instances[0].getConfig();
99
+ const debugConfig = {
100
+ intensity: initialConfig.intensity ?? config.intensity,
101
+ displacementAngle: initialConfig.displacementAngle ?? config.displacementAngle,
102
+ zoom: initialConfig.zoom ?? config.zoom,
103
+ imageRotation: initialConfig.imageRotation ?? config.imageRotation,
104
+ noiseSpeed: initialConfig.noiseSpeed ?? config.noiseSpeed,
105
+ noiseScale: initialConfig.noiseScale ?? config.noiseScale,
106
+ rgbShiftIntensity: initialConfig.rgbShiftIntensity ?? config.rgbShiftIntensity,
107
+ durationIn: initialConfig.durationIn ?? config.durationIn,
108
+ durationOut: initialConfig.durationOut ?? config.durationOut,
109
+ easeIn: initialConfig.easeIn ?? config.easeIn,
110
+ easeOut: initialConfig.easeOut ?? config.easeOut,
111
+ };
112
+
113
+ const timelineConfig = {
114
+ progress: 0,
115
+ manualControl: false,
116
+ };
117
+
118
+ // Controllers para actualizar valores al cambiar de imagen
119
+ const controllers: any[] = [];
120
+ // Controllers de animación (se deshabilitan en manual mode)
121
+ const animControllers: any[] = [];
122
+
123
+ const loadConfigFromInstance = (index: number) => {
124
+ const instanceConfig = instances[index].getConfig();
125
+ debugConfig.intensity = instanceConfig.intensity ?? debugConfig.intensity;
126
+ debugConfig.displacementAngle = instanceConfig.displacementAngle ?? debugConfig.displacementAngle;
127
+ debugConfig.zoom = instanceConfig.zoom ?? debugConfig.zoom;
128
+ debugConfig.imageRotation = instanceConfig.imageRotation ?? debugConfig.imageRotation;
129
+ debugConfig.noiseSpeed = instanceConfig.noiseSpeed ?? debugConfig.noiseSpeed;
130
+ debugConfig.noiseScale = instanceConfig.noiseScale ?? debugConfig.noiseScale;
131
+ debugConfig.rgbShiftIntensity = instanceConfig.rgbShiftIntensity ?? debugConfig.rgbShiftIntensity;
132
+ debugConfig.durationIn = instanceConfig.durationIn ?? debugConfig.durationIn;
133
+ debugConfig.durationOut = instanceConfig.durationOut ?? debugConfig.durationOut;
134
+ debugConfig.easeIn = instanceConfig.easeIn ?? debugConfig.easeIn;
135
+ debugConfig.easeOut = instanceConfig.easeOut ?? debugConfig.easeOut;
136
+
137
+ // Actualizar todos los controllers
138
+ controllers.forEach((c) => c.updateDisplay());
139
+ };
140
+
141
+ // Highlight inicial en la primera imagen
142
+ instances[0].setDebugHighlight(true);
143
+
144
+ gui.add(selectorConfig, 'target', targetOptions).name('Target').onChange((index: number) => {
145
+ // Quitar highlight de todas y poner en la seleccionada
146
+ instances.forEach((inst, i) => inst.setDebugHighlight(i === index));
147
+
148
+ loadConfigFromInstance(index);
149
+ // Reset timeline progress al cambiar
150
+ timelineConfig.progress = 0;
151
+ controllers.forEach((c) => c.updateDisplay());
152
+ });
153
+
154
+ const updateTargetInstance = () => {
155
+ getTargetInstance().updateConfig(debugConfig);
156
+ };
157
+
158
+ const setTargetProgress = (value: number) => {
159
+ getTargetInstance().setProgress(value);
160
+ };
161
+
162
+ const setTargetHoverEnabled = (enabled: boolean) => {
163
+ getTargetInstance().setHoverEnabled(enabled);
164
+ };
165
+
166
+ // Timeline folder
167
+ const folderTimeline = gui.addFolder('Timeline');
168
+ controllers.push(
169
+ folderTimeline
170
+ .add(timelineConfig, 'progress', 0, 1, 0.01)
171
+ .name('Progress')
172
+ .onChange((value: number) => {
173
+ if (timelineConfig.manualControl) {
174
+ setTargetProgress(value);
175
+ }
176
+ })
177
+ );
178
+
179
+ controllers.push(
180
+ folderTimeline.add(timelineConfig, 'manualControl').name('Manual Control').onChange((enabled: boolean) => {
181
+ setTargetHoverEnabled(!enabled);
182
+ if (enabled) {
183
+ setTargetProgress(timelineConfig.progress);
184
+ } else {
185
+ // Volver a estado de reposo al desactivar
186
+ setTargetProgress(0);
187
+ timelineConfig.progress = 0;
188
+ controllers.forEach((c) => c.updateDisplay());
189
+ }
190
+ // Deshabilitar/habilitar controles de animación
191
+ animControllers.forEach((c) => c.enable(!enabled));
192
+ })
193
+ );
194
+
195
+ folderTimeline.open();
196
+
197
+ // Parameters folder
198
+ const folderParams = gui.addFolder('Parameters');
199
+ controllers.push(folderParams.add(debugConfig, 'intensity', 0, 2).name('Intensity').onChange(updateTargetInstance));
200
+ controllers.push(folderParams.add(debugConfig, 'displacementAngle', 0, 360).name('Disp. Angle').onChange(updateTargetInstance));
201
+ controllers.push(folderParams.add(debugConfig, 'zoom', 0, 0.5).name('Zoom').onChange(updateTargetInstance));
202
+ controllers.push(folderParams.add(debugConfig, 'imageRotation', -45, 45).name('Rotation (deg)').onChange(updateTargetInstance));
203
+ controllers.push(folderParams.add(debugConfig, 'noiseSpeed', 0, 2).name('Noise Speed').onChange(updateTargetInstance));
204
+ controllers.push(folderParams.add(debugConfig, 'noiseScale', 0, 20).name('Noise Scale').onChange(updateTargetInstance));
205
+ controllers.push(folderParams.add(debugConfig, 'rgbShiftIntensity', 0, 1).name('RGB Shift').onChange(updateTargetInstance));
206
+
207
+ // Animation folder (se deshabilitan en manual mode)
208
+ const folderAnim = gui.addFolder('Animation');
209
+ const durationInCtrl = folderAnim.add(debugConfig, 'durationIn', 0.1, 3).name('Duration In').onChange(updateTargetInstance);
210
+ const durationOutCtrl = folderAnim.add(debugConfig, 'durationOut', 0.1, 3).name('Duration Out').onChange(updateTargetInstance);
211
+ controllers.push(durationInCtrl, durationOutCtrl);
212
+ animControllers.push(durationInCtrl, durationOutCtrl);
213
+
214
+ const easingOptions = [
215
+ 'none',
216
+ 'power1.in',
217
+ 'power1.out',
218
+ 'power1.inOut',
219
+ 'power2.in',
220
+ 'power2.out',
221
+ 'power2.inOut',
222
+ 'power3.in',
223
+ 'power3.out',
224
+ 'power3.inOut',
225
+ 'power4.in',
226
+ 'power4.out',
227
+ 'power4.inOut',
228
+ 'back.in(1.7)',
229
+ 'back.out(1.7)',
230
+ 'back.inOut(1.7)',
231
+ 'elastic.out(1, 0.3)',
232
+ 'elastic.out(1, 0.5)',
233
+ 'elastic.inOut(1, 0.3)',
234
+ 'bounce.out',
235
+ 'bounce.inOut',
236
+ 'circ.in',
237
+ 'circ.out',
238
+ 'circ.inOut',
239
+ 'expo.in',
240
+ 'expo.out',
241
+ 'expo.inOut',
242
+ ];
243
+
244
+ const easeInCtrl = folderAnim.add(debugConfig, 'easeIn', easingOptions).name('Ease In').onChange(updateTargetInstance);
245
+ const easeOutCtrl = folderAnim.add(debugConfig, 'easeOut', easingOptions).name('Ease Out').onChange(updateTargetInstance);
246
+ controllers.push(easeInCtrl, easeOutCtrl);
247
+ animControllers.push(easeInCtrl, easeOutCtrl);
248
+
249
+ folderParams.open();
250
+ });
251
+ }
252
+
253
+ export function initWebglHover(): WebglHover[] {
254
+ const planes = document.querySelectorAll('.whi-plane');
255
+
256
+ if (shouldUseFallback()) {
257
+ applyFallbackStyles(planes);
258
+ return [];
259
+ }
260
+
261
+ const config = getConfigFromDOM();
262
+ const container = createCanvasContainer();
263
+
264
+ const webGLCurtain = new Curtains({
265
+ container,
266
+ pixelRatio: Math.min(1.5, window.devicePixelRatio),
267
+ });
268
+
269
+ const instances: WebglHover[] = [];
270
+
271
+ document.querySelectorAll('.whi-slide').forEach((slide) => {
272
+ const planeElement = slide.querySelector('.whi-plane') as HTMLElement;
273
+
274
+ if (planeElement) {
275
+ const options = getOptionsFromSlide(slide, config);
276
+ instances.push(new WebglHover(webGLCurtain, planeElement, options));
277
+ }
278
+ });
279
+
280
+ let resizeTimeout: ReturnType<typeof setTimeout>;
281
+ window.addEventListener('resize', () => {
282
+ clearTimeout(resizeTimeout);
283
+ resizeTimeout = setTimeout(() => {
284
+ instances.forEach((instance) => instance.resize());
285
+ }, 150);
286
+ });
287
+
288
+ if (config.debug) {
289
+ initDebugMode(instances, config);
290
+ }
291
+
292
+ return instances;
293
+ }
@@ -0,0 +1,57 @@
1
+ /**
2
+ * Detección de rendimiento y fallbacks para WebGL Hover
3
+ */
4
+
5
+ interface NavigatorWithExtensions extends Navigator {
6
+ connection?: {
7
+ saveData?: boolean;
8
+ };
9
+ deviceMemory?: number;
10
+ }
11
+
12
+ export function isLowPerformance(): boolean {
13
+ const nav = navigator as NavigatorWithExtensions;
14
+
15
+ // 1. Detectar modo "Ahorro de datos" del navegador/SO
16
+ if (nav.connection?.saveData) {
17
+ return true;
18
+ }
19
+
20
+ // 2. Heurística de Hardware
21
+ // deviceMemory (RAM en GB) - Solo Chrome/Edge. Valores: 0.25, 0.5, 1, 2, 4, 8...
22
+ const memory = nav.deviceMemory;
23
+ // hardwareConcurrency (Núcleos CPU)
24
+ const cores = navigator.hardwareConcurrency;
25
+
26
+ // Si tiene menos de 4GB de RAM o 2 o menos núcleos, asumimos gama baja.
27
+ return (memory !== undefined && memory < 4) || (cores !== undefined && cores <= 2);
28
+ }
29
+
30
+ export function prefersReducedMotion(): boolean {
31
+ return window.matchMedia('(prefers-reduced-motion: reduce)').matches;
32
+ }
33
+
34
+ export function shouldUseFallback(): boolean {
35
+ return prefersReducedMotion() || isLowPerformance();
36
+ }
37
+
38
+ export function applyFallbackStyles(planes: NodeListOf<Element>): void {
39
+ planes.forEach((plane) => {
40
+ const planeEl = plane as HTMLElement;
41
+ planeEl.style.position = 'relative';
42
+
43
+ const img = planeEl.querySelector('img[data-sampler="texture0"]') as HTMLImageElement;
44
+ if (img) {
45
+ Object.assign(img.style, {
46
+ display: 'block',
47
+ opacity: '1',
48
+ position: 'absolute',
49
+ top: '0',
50
+ left: '0',
51
+ width: '100%',
52
+ height: '100%',
53
+ objectFit: 'cover',
54
+ });
55
+ }
56
+ });
57
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Funciones utilitarias para WebGL Hover
3
+ */
4
+
5
+ export function getAttributeAsFloat(
6
+ element: Element,
7
+ attribute: string,
8
+ defaultValue: number
9
+ ): number {
10
+ const value = element.getAttribute(attribute);
11
+ return value !== null ? parseFloat(value) : defaultValue;
12
+ }
13
+
14
+ export function getAttributeAsString(
15
+ element: Element,
16
+ attribute: string,
17
+ defaultValue: string
18
+ ): string {
19
+ return element.getAttribute(attribute) || defaultValue;
20
+ }
21
+
22
+ export function degreesToRadians(degrees: number): number {
23
+ return degrees * (Math.PI / 180);
24
+ }
25
+
26
+ export function calculateDisplacementVector(
27
+ intensity: number,
28
+ angleInDegrees: number
29
+ ): [number, number] {
30
+ const angleRad = degreesToRadians(angleInDegrees);
31
+ return [intensity * Math.cos(angleRad), intensity * Math.sin(angleRad)];
32
+ }
33
+
34
+ export function calculateTextureScale(
35
+ planeWidth: number,
36
+ planeHeight: number,
37
+ textureWidth: number,
38
+ textureHeight: number
39
+ ): [number, number] {
40
+ const planeRatio = planeWidth / planeHeight;
41
+ const textureRatio = textureWidth / textureHeight;
42
+
43
+ let scaleX = 1.0;
44
+ let scaleY = 1.0;
45
+
46
+ if (planeRatio > textureRatio) {
47
+ scaleX = planeRatio / textureRatio;
48
+ } else {
49
+ scaleY = textureRatio / planeRatio;
50
+ }
51
+
52
+ return [scaleX, scaleY];
53
+ }
@@ -0,0 +1,145 @@
1
+ #ifdef GL_ES
2
+ precision mediump float;
3
+ #endif
4
+
5
+ #define PI2 6.28318530718
6
+ #define PI 3.14159265359
7
+ #define S(a,b,n) smoothstep(a,b,n)
8
+
9
+ uniform float uTime;
10
+ uniform float uProgress;
11
+ uniform vec2 uReso;
12
+ uniform vec2 uMouse;
13
+ uniform vec2 uDisplacement;
14
+ uniform float uZoom;
15
+ uniform float uRotation;
16
+ uniform float uNoiseSpeed;
17
+ uniform float uNoiseScale;
18
+ uniform float uRgbShift;
19
+ uniform vec2 uTex1Scale;
20
+
21
+ // get our varyings
22
+ varying vec3 vVertexPosition;
23
+ varying vec2 vTextureCoord0;
24
+ varying vec2 vTextureCoord1;
25
+ varying vec2 vTextureCoordMap;
26
+
27
+ // the uniform we declared inside our javascript
28
+
29
+ // our texture sampler (default name, to use a different name please refer to the documentation)
30
+ uniform sampler2D texture0;
31
+ uniform sampler2D texture1;
32
+ uniform sampler2D map;
33
+
34
+ //
35
+ // Description : Array and textureless GLSL 2D simplex noise function.
36
+ // Author : Ian McEwan, Ashima Arts.
37
+ // Maintainer : stegu
38
+ // Lastmod : 20110822 (ijm)
39
+ // License : Copyright (C) 2011 Ashima Arts. All rights reserved.
40
+ // Distributed under the MIT License. See LICENSE file.
41
+ // https://github.com/ashima/webgl-noise
42
+ // https://github.com/stegu/webgl-noise
43
+ //
44
+ vec3 mod289(vec3 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
45
+ vec2 mod289(vec2 x) { return x - floor(x * (1.0 / 289.0)) * 289.0; }
46
+ vec3 permute(vec3 x) { return mod289(((x*34.0)+1.0)*x); }
47
+
48
+ float snoise(vec2 v){
49
+ const vec4 C = vec4(0.211324865405187, 0.366025403784439, -0.577350269189626, 0.024390243902439);
50
+ vec2 i = floor(v + dot(v, C.yy));
51
+ vec2 x0 = v - i + dot(i, C.xx);
52
+ vec2 i1 = (x0.x > x0.y) ? vec2(1.0, 0.0) : vec2(0.0, 1.0);
53
+ vec4 x12 = x0.xyxy + C.xxzz;
54
+ x12.xy -= i1;
55
+ i = mod289(i);
56
+ vec3 p = permute(permute(i.y + vec3(0.0, i1.y, 1.0)) + i.x + vec3(0.0, i1.x, 1.0));
57
+ vec3 m = max(0.5 - vec3(dot(x0, x0), dot(x12.xy, x12.xy), dot(x12.zw, x12.zw)), 0.0);
58
+ m = m * m;
59
+ m = m * m;
60
+ vec3 x = 2.0 * fract(p * C.www) - 1.0;
61
+ vec3 h = abs(x) - 0.5;
62
+ vec3 ox = floor(x + 0.5);
63
+ vec3 a0 = x - ox;
64
+ m *= 1.79284291400159 - 0.85373472095314 * (a0 * a0 + h * h);
65
+ vec3 g;
66
+ g.x = a0.x * x0.x + h.x * x0.y;
67
+ g.yz = a0.yz * x12.xz + h.yz * x12.yw;
68
+ return 130.0 * dot(m, g);
69
+ }
70
+
71
+ // http://www.flong.com/texts/code/shapers_exp/
72
+ float exponentialEasing (float x, float a){
73
+
74
+ float epsilon = 0.00001;
75
+ float min_param_a = 0.0 + epsilon;
76
+ float max_param_a = 1.0 - epsilon;
77
+ a = max(min_param_a, min(max_param_a, a));
78
+
79
+ if (a < 0.5){
80
+ // emphasis
81
+ a = 2.0 * a;
82
+ float y = pow(x, a);
83
+ return y;
84
+ } else {
85
+ // de-emphasis
86
+ a = 2.0 * (a-0.5);
87
+ float y = pow(x, 1.0 / (1.-a));
88
+ return y;
89
+ }
90
+ }
91
+
92
+ mat2 rotate(float a) {
93
+ float s = sin(a);
94
+ float c = cos(a);
95
+ return mat2(c, -s, s, c);
96
+ }
97
+
98
+ vec4 blur13(sampler2D image, vec2 uv, vec2 resolution, vec2 direction) {
99
+ vec4 color = vec4(0.0);
100
+ vec2 off1 = vec2(1.411764705882353) * direction;
101
+ vec2 off2 = vec2(3.2941176470588234) * direction;
102
+ vec2 off3 = vec2(5.176470588235294) * direction;
103
+ color += texture2D(image, uv) * 0.1964825501511404;
104
+ color += texture2D(image, uv + (off1 / resolution)) * 0.2969069646728344;
105
+ color += texture2D(image, uv - (off1 / resolution)) * 0.2969069646728344;
106
+ color += texture2D(image, uv + (off2 / resolution)) * 0.09447039785044732;
107
+ color += texture2D(image, uv - (off2 / resolution)) * 0.09447039785044732;
108
+ color += texture2D(image, uv + (off3 / resolution)) * 0.010381362401148057;
109
+ color += texture2D(image, uv - (off3 / resolution)) * 0.010381362401148057;
110
+ return color;
111
+ }
112
+
113
+ void main(){
114
+ vec2 uv0 = vTextureCoord0;
115
+ vec2 uv1 = vTextureCoord1;
116
+
117
+ vec2 center = vec2(0.5);
118
+ uv0 = (uv0 - center) * (1.0 / uZoom) * rotate(uRotation) + center; // texture0 uses the plane's aspect ratio
119
+ uv1 = (uv1 - center) * uTex1Scale * (1.0 / uZoom) * rotate(uRotation) + center; // texture1 is corrected
120
+
121
+ float progress0 = uProgress;
122
+ float progress1 = 1. - uProgress;
123
+
124
+ vec4 map = blur13(map, vTextureCoordMap, uReso, vec2(2.)) + 0.5;
125
+
126
+ float noise = snoise(vTextureCoordMap * uNoiseScale + vec2(uTime * uNoiseSpeed));
127
+ vec2 organicDisplacement = uDisplacement * (1.0 + noise * 0.5);
128
+
129
+ uv0 += progress0 * map.r * organicDisplacement;
130
+ uv1 -= progress1 * map.r * organicDisplacement;
131
+
132
+ vec2 shift = uDisplacement * uRgbShift * 0.01;
133
+
134
+ vec4 c0 = texture2D(texture0, uv0);
135
+ float r0 = texture2D(texture0, uv0 + shift).r;
136
+ float b0 = texture2D(texture0, uv0 - shift).b;
137
+ vec4 color = vec4(r0, c0.g, b0, c0.a);
138
+
139
+ vec4 c1 = texture2D(texture1, uv1);
140
+ float r1 = texture2D(texture1, uv1 + shift).r;
141
+ float b1 = texture2D(texture1, uv1 - shift).b;
142
+ vec4 color1 = vec4(r1, c1.g, b1, c1.a);
143
+
144
+ gl_FragColor = mix(color, color1, progress0 );
145
+ }
@@ -0,0 +1,33 @@
1
+ #ifdef GL_ES
2
+ precision mediump float;
3
+ #endif
4
+
5
+ // those are the mandatory attributes that the lib sets
6
+ attribute vec3 aVertexPosition;
7
+ attribute vec2 aTextureCoord;
8
+
9
+ // those are mandatory uniforms that the lib sets and that contain our model view and projection matrix
10
+ uniform mat4 uMVMatrix;
11
+ uniform mat4 uPMatrix;
12
+
13
+ uniform mat4 texture0Matrix;
14
+ uniform mat4 texture1Matrix;
15
+ uniform mat4 mapMatrix;
16
+
17
+ // if you want to pass your vertex and texture coords to the fragment shader
18
+ varying vec3 vVertexPosition;
19
+ varying vec2 vTextureCoord0;
20
+ varying vec2 vTextureCoord1;
21
+ varying vec2 vTextureCoordMap;
22
+
23
+ void main() {
24
+ vec3 vertexPosition = aVertexPosition;
25
+
26
+ gl_Position = uPMatrix * uMVMatrix * vec4(vertexPosition, 1.0);
27
+
28
+ // set the varyings
29
+ vTextureCoord0 = (texture0Matrix * vec4(aTextureCoord, 0., 1.)).xy;
30
+ vTextureCoord1 = (texture1Matrix * vec4(aTextureCoord, 0., 1.)).xy;
31
+ vTextureCoordMap = (mapMatrix * vec4(aTextureCoord, 0., 1.)).xy;
32
+ vVertexPosition = vertexPosition;
33
+ }