Solshine commited on
Commit
78637a0
·
verified ·
1 Parent(s): ef78915

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. DisplacementFilter.js +22 -23
DisplacementFilter.js CHANGED
@@ -2,52 +2,51 @@ export class DisplacementFilter {
2
  constructor(rendererCanvas, videoElement) {
3
  this.canvas = rendererCanvas;
4
  this.video = videoElement;
5
- this.enabled = false;
6
  this.time = 0;
7
  }
8
 
9
  toggle() {
10
  this.enabled = !this.enabled;
11
  if (!this.enabled) {
12
- // Reset transforms
13
  this.canvas.style.transform = '';
14
- this.video.style.transform = 'scaleX(-1)'; // Restore original mirror
15
  }
 
16
  }
17
 
18
- update(amplitude, handPositions) {
19
  if (!this.enabled) return;
20
- this.time += 0.016; // ~60fps
21
 
22
- // Barrel distortion via CSS perspective + scale oscillation
23
- var breathScale = 1.0 + 0.015 * Math.sin(this.time * 1.5);
24
- var ampScale = 1.0 + amplitude * 0.03;
 
 
 
25
  var totalScale = breathScale * ampScale;
26
 
27
- // Chromatic aberration simulation: slight RGB offset via text-shadow-like effect
28
- // (CSS can't do true chromatic aberration, but we can do skew + hue shift)
29
- var skewX = Math.sin(this.time * 0.7) * amplitude * 0.5;
30
- var skewY = Math.cos(this.time * 0.9) * amplitude * 0.3;
31
 
32
- // Wave distortion
33
- var waveX = Math.sin(this.time * 2.0) * amplitude * 2;
34
- var waveY = Math.cos(this.time * 1.7) * amplitude * 1.5;
35
 
36
- // Apply to Three.js canvas (the overlay)
37
  this.canvas.style.transform =
38
  'scale(' + totalScale + ') ' +
39
  'skew(' + skewX + 'deg, ' + skewY + 'deg) ' +
40
  'translate(' + waveX + 'px, ' + waveY + 'px)';
41
 
42
- // Apply matching distortion to video (keeps them aligned)
43
  this.video.style.transform =
44
- 'scaleX(-1) ' + // Keep mirror
45
  'scale(' + totalScale + ') ' +
46
- 'skew(' + (-skewX * 0.5) + 'deg, ' + (-skewY * 0.5) + 'deg) ' +
47
- 'translate(' + (waveX * 0.5) + 'px, ' + (waveY * 0.5) + 'px)';
48
-
49
- // Also modulate the video's hue rotation faster when amplitude is high
50
- // (This enhances the existing psychedelic hue rotation)
51
  }
52
 
53
  dispose() {
 
2
  constructor(rendererCanvas, videoElement) {
3
  this.canvas = rendererCanvas;
4
  this.video = videoElement;
5
+ this.enabled = true; // ON by default — trippy from the start
6
  this.time = 0;
7
  }
8
 
9
  toggle() {
10
  this.enabled = !this.enabled;
11
  if (!this.enabled) {
 
12
  this.canvas.style.transform = '';
13
+ this.video.style.transform = 'scaleX(-1)';
14
  }
15
+ console.log('Displacement filter: ' + (this.enabled ? 'ON' : 'OFF'));
16
  }
17
 
18
+ update(amplitude) {
19
  if (!this.enabled) return;
20
+ this.time += 0.016;
21
 
22
+ // Use a minimum baseline so effects are visible even without loud audio
23
+ var amp = Math.max(0.3, amplitude || 0);
24
+
25
+ // Breathing scale — always visible, boosted by audio
26
+ var breathScale = 1.0 + 0.03 * Math.sin(this.time * 1.2);
27
+ var ampScale = 1.0 + amp * 0.04;
28
  var totalScale = breathScale * ampScale;
29
 
30
+ // Wobble skew trippy warping
31
+ var skewX = Math.sin(this.time * 0.7) * (1.0 + amp * 3.0);
32
+ var skewY = Math.cos(this.time * 0.9) * (0.6 + amp * 2.0);
 
33
 
34
+ // Wave translation — scene drifts
35
+ var waveX = Math.sin(this.time * 1.3) * (2.0 + amp * 6.0);
36
+ var waveY = Math.cos(this.time * 1.0) * (1.5 + amp * 4.0);
37
 
38
+ // Three.js canvas
39
  this.canvas.style.transform =
40
  'scale(' + totalScale + ') ' +
41
  'skew(' + skewX + 'deg, ' + skewY + 'deg) ' +
42
  'translate(' + waveX + 'px, ' + waveY + 'px)';
43
 
44
+ // Video (matching but inverted skew for trippy desync)
45
  this.video.style.transform =
46
+ 'scaleX(-1) ' +
47
  'scale(' + totalScale + ') ' +
48
+ 'skew(' + (-skewX * 0.7) + 'deg, ' + (-skewY * 0.7) + 'deg) ' +
49
+ 'translate(' + (waveX * 0.6) + 'px, ' + (waveY * 0.6) + 'px)';
 
 
 
50
  }
51
 
52
  dispose() {