Fractal Glass
vault-hyperiux/fractal-glassFreeComponent
WebGL glass-strip refraction effect with fractal distortion, edge blending, and pointer-reactive parallax.
Install it
npx shadcn@latest add https://vault.hyperiux.com/r/fractal-glass.jsonSource
1// Built using Hyperiux Vault: https://vault.hyperiux.com23'use client';45import { useEffect, useRef, useState } from "react";6import * as THREE from "three";7import { createSuspendedRaf } from "./createSuspendedRaf";89const DEFAULT_IMAGE_SRC = "https://pub-8abee449136941f5b0a1cd2c014534e9.r2.dev/vault-listing-images/assets-images/h-13.jpg";1011function usePrefersReducedMotion() {12 const [prefersReducedMotion, setPrefersReducedMotion] = useState(false);1314 useEffect(() => {15 const mediaQuery = window.matchMedia("(prefers-reduced-motion: reduce)");16 const update = () => setPrefersReducedMotion(mediaQuery.matches);17 update();18 mediaQuery.addEventListener("change", update);19 return () => mediaQuery.removeEventListener("change", update);20 }, []);2122 return prefersReducedMotion;23}2425const vertexShader = `26 varying vec2 vUv;27 void main() {28 vUv = uv;29 gl_Position = projectionMatrix * modelViewMatrix * vec4(position, 1.0);30 }31`;3233const fragmentShader = `34 uniform sampler2D uTexture;35 uniform vec2 uResolution;36 uniform vec2 uTextureSize;37 uniform vec2 uMouse;38 uniform float uParallaxStrength;39 uniform float uDistortionMultiplier;40 uniform float uGlassStrength;41 uniform float uStripesFrequency;42 uniform float uGlassSmoothness;43 uniform float uEdgePadding;4445 varying vec2 vUv;4647 vec2 getCoverUV(vec2 uv, vec2 textureSize) {48 if (textureSize.x < 1.0 || textureSize.y < 1.0) return uv;4950 vec2 s = uResolution / textureSize;51 float scale = max(s.x, s.y);5253 vec2 scaledSize = textureSize * scale;54 vec2 offset = (uResolution - scaledSize) * 0.5;5556 return (uv * uResolution - offset) / scaledSize;57 }5859 float displacement(float x, float num_stripes, float strength) {60 float modulus = 1.0 / num_stripes;61 return mod(x, modulus) * strength;62 }6364 float fractalGlass(float x) {65 float stripeWidth = 1.0 / uStripesFrequency;66 float sampleStep = uGlassSmoothness * stripeWidth;67 float d = 0.0;68 for (int i = -5; i <= 5; i++) {69 d += displacement(x + float(i) * sampleStep, uStripesFrequency, uGlassStrength);70 }71 d = d / 11.0;72 return x + d;73 }7475 float smoothEdge(float x, float padding) {76 float edge = padding;77 if (x < edge) {78 return smoothstep(0.0, edge, x);79 } else if (x > 1.0 - edge) {80 return smoothstep(1.0, 1.0 - edge, x);81 }82 return 1.0;83 }8485 void main() {86 vec2 uv = vUv;8788 float originalX = uv.x;8990 float edgeFactor = smoothEdge(originalX, uEdgePadding);9192 float distortedX = fractalGlass(originalX);9394 uv.x = mix(originalX, distortedX, edgeFactor);9596// … truncated
What it pulls in
npm packages
More from vault-hyperiux
All 120 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| 3D Portfolio Slider3d-portfolio-slider | vault-hyperiux | Components | Free | 3 deps | |
| Animated FAQanimated-faq | vault-hyperiux | Components | Free | 2 deps | |
| Animated Formanimated-form | vault-hyperiux | Components | Free | 1 dep | |
| Animated Modalanimated-modal | vault-hyperiux | Components | Free | 1 dep | |
| Tabsanimated-tabs | vault-hyperiux | Components | Free | 1 dep | |
| Animated Toggleanimated-toggle | vault-hyperiux | Components | Free | no deps | |
| Aperture Transitionaperture-transition | vault-hyperiux | Components | Free | 2 deps | |
| Arrow Fill Buttonarrow-fill-button | vault-hyperiux | Components | Free | 1 dep |
