@paper-design/shaders 0.0.78 → 0.0.79
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/index.d.ts
CHANGED
|
@@ -51,6 +51,8 @@ export { waterFragmentShader, type WaterParams, type WaterUniforms } from './sha
|
|
|
51
51
|
export { flutedGlassFragmentShader, GlassDistortionShapes, GlassGridShapes, type GlassDistortionShape, type GlassGridShape, type FlutedGlassParams, type FlutedGlassUniforms, } from './shaders/fluted-glass.js';
|
|
52
52
|
/** A dithering image filter with support for 4 dithering modes and multiple color palettes (2-color, 3-color, and multicolor options, using either predefined colors or ones sampled directly from the original image) */
|
|
53
53
|
export { imageDitheringFragmentShader, type ImageDitheringParams, type ImageDitheringUniforms, } from './shaders/image-dithering.js';
|
|
54
|
+
/** Lens Distortion image filter that separates an image into shifting color layers, recreating the chromatic aberration of a lens, and warps the image geometry with barrel or pincushion curvature */
|
|
55
|
+
export { lensDistortionFragmentShader, lensDistortionMeta, type LensDistortionParams, type LensDistortionUniforms } from './shaders/lens-distortion.js';
|
|
54
56
|
/** A glowing gradient of colors flowing through an input image. The effect creates a smoothly animated wave of intensity across the image */
|
|
55
57
|
export { heatmapMeta, heatmapFragmentShader, toProcessedHeatmap, type HeatmapParams, type HeatmapUniforms, } from './shaders/heatmap.js';
|
|
56
58
|
/** Futuristic liquid metal material applied to uploaded logo or one of pre-defined abstract shape */
|
package/dist/index.js
CHANGED
|
@@ -84,6 +84,7 @@ import {
|
|
|
84
84
|
import {
|
|
85
85
|
imageDitheringFragmentShader
|
|
86
86
|
} from "./shaders/image-dithering.js";
|
|
87
|
+
import { lensDistortionFragmentShader, lensDistortionMeta } from "./shaders/lens-distortion.js";
|
|
87
88
|
import {
|
|
88
89
|
heatmapMeta,
|
|
89
90
|
heatmapFragmentShader,
|
|
@@ -152,6 +153,8 @@ export {
|
|
|
152
153
|
heatmapMeta,
|
|
153
154
|
imageDitheringFragmentShader,
|
|
154
155
|
isPaperShaderElement,
|
|
156
|
+
lensDistortionFragmentShader,
|
|
157
|
+
lensDistortionMeta,
|
|
155
158
|
liquidMetalFragmentShader,
|
|
156
159
|
meshGradientFragmentShader,
|
|
157
160
|
meshGradientMeta,
|
package/dist/index.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/index.ts"],
|
|
4
|
-
"sourcesContent": ["/** The core Shader Mount class. Pass it a parent element and a fragment shader to get started. */\nexport { ShaderMount, isPaperShaderElement } from './shader-mount.js';\nexport type {\n PaperShaderElement,\n ShaderMotionParams,\n ShaderMountUniforms,\n ShaderPreset,\n ImageShaderPreset,\n} from './shader-mount.js';\n\n/** Shader sizing options and uniforms */\nexport {\n defaultObjectSizing,\n defaultPatternSizing,\n ShaderFitOptions,\n type ShaderFit,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from './shader-sizing.js';\n\n/** A flowing interplay of color spots, moving along distinct trajectories and transformed by organic distortion */\nexport {\n meshGradientFragmentShader,\n meshGradientMeta,\n type MeshGradientParams,\n type MeshGradientUniforms,\n} from './shaders/mesh-gradient.js';\n\n/** Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic */\nexport {\n smokeRingMeta,\n smokeRingFragmentShader,\n type SmokeRingParams,\n type SmokeRingUniforms,\n} from './shaders/smoke-ring.js';\n\n/** A glowing, web-like structure of fluid lines and soft intersections. Great for creating atmospheric, organic-yet-futuristic visuals */\nexport { neuroNoiseFragmentShader, type NeuroNoiseParams, type NeuroNoiseUniforms } from './shaders/neuro-noise.js';\n\n/** Animated multi-color dots pattern with each dot orbiting around its cell center. Supports up to 40 colors and various shape and motion controls. Great for playful, dynamic backgrounds and UI textures */\nexport {\n dotOrbitMeta,\n dotOrbitFragmentShader,\n type DotOrbitParams,\n type DotOrbitUniforms,\n} from './shaders/dot-orbit.js';\n\n/** Static grid pattern made of circles, diamonds, squares or triangles */\nexport {\n dotGridFragmentShader,\n DotGridShapes,\n type DotGridShape,\n type DotGridParams,\n type DotGridUniforms,\n} from './shaders/dot-grid.js';\n\n/** A multi-color gradient mapped into smooth, animated curves, delivering a sleek, futuristic visual */\nexport {\n simplexNoiseMeta,\n simplexNoiseFragmentShader,\n type SimplexNoiseParams,\n type SimplexNoiseUniforms,\n} from './shaders/simplex-noise.js';\n\n/** Up to 20 gooey blobs moving around the center and merging into smooth organic shapes */\nexport {\n metaballsMeta,\n metaballsFragmentShader,\n type MetaballsParams,\n type MetaballsUniforms,\n} from './shaders/metaballs.js';\n\n/** Animated 3D Perlin noise with exposed controls */\nexport { perlinNoiseFragmentShader, type PerlinNoiseParams, type PerlinNoiseUniforms } from './shaders/perlin-noise.js';\n\n/** Anti-aliased animated Voronoi pattern with smooth and customizable edges */\nexport { voronoiMeta, voronoiFragmentShader, type VoronoiParams, type VoronoiUniforms } from './shaders/voronoi.js';\n\n/** Static line pattern configurable into textures ranging from sharp zigzags to smooth flowing waves */\nexport { wavesFragmentShader, type WavesParams, type WavesUniforms } from './shaders/waves.js';\n\n/** Animated color fields warped by noise and swirls, applied over base patterns (checks, stripes, or split edge). Blends up to 10 colors with adjustable distribution, softness, distortion, and swirl. Great for fluid, smoky, or marbled effects */\nexport {\n warpMeta,\n warpFragmentShader,\n WarpPatterns,\n type WarpParams,\n type WarpUniforms,\n type WarpPattern,\n} from './shaders/warp.js';\n\n/** Animated rays of light radiating from the center, blended with up to 5 colors. The rays are adjustable by size, density, brightness and center glow. Great for dramatic backgrounds, logo reveals, and VFX like energy bursts or sun shafts */\nexport { godRaysMeta, godRaysFragmentShader, type GodRaysParams, type GodRaysUniforms } from './shaders/god-rays.js';\n\n/** A single-colored animated spiral that morphs across a wide range of shapes - from crisp, thin-lined geometry to flowing whirlpool forms and wavy, abstract rings */\nexport { spiralFragmentShader, type SpiralParams, type SpiralUniforms } from './shaders/spiral.js';\n\n/** Animated bands of color twisting and bending, producing spirals, arcs, and flowing circular patterns */\nexport { swirlMeta, swirlFragmentShader, type SwirlParams, type SwirlUniforms } from './shaders/swirl.js';\n\n/** Animated 2-color dithering over with multiple pattern sources (noise, warp, dots, waves, ripple, swirl, sphere) */\nexport {\n ditheringFragmentShader,\n DitheringShapes,\n DitheringTypes,\n type DitheringParams,\n type DitheringUniforms,\n type DitheringShape,\n type DitheringType,\n} from './shaders/dithering.js';\n\n/** Multi-color gradients with grainy, noise-textured distortion available in 7 animated abstract forms */\nexport {\n grainGradientFragmentShader,\n grainGradientMeta,\n GrainGradientShapes,\n type GrainGradientParams,\n type GrainGradientUniforms,\n type GrainGradientShape,\n} from './shaders/grain-gradient.js';\n\n/** Luminous trails of color merging into a glowing gradient frame */\nexport {\n pulsingBorderMeta,\n pulsingBorderFragmentShader,\n PulsingBorderAspectRatios,\n type PulsingBorderParams,\n type PulsingBorderUniforms,\n type PulsingBorderAspectRatio,\n} from './shaders/pulsing-border.js';\n\n/** Glowing translucent 3D panels rotating around a central axis */\nexport {\n colorPanelsFragmentShader,\n colorPanelsMeta,\n type ColorPanelsParams,\n type ColorPanelsUniforms,\n} from './shaders/color-panels.js';\n\n/** Multi-point mesh gradients with up to 10 color spots, enhanced by two-direction warping, adjustable blend sharpness, and grain controls. Perfect for elegant wallpapers and atmospheric backdrops */\nexport {\n staticMeshGradientFragmentShader,\n staticMeshGradientMeta,\n type StaticMeshGradientParams,\n type StaticMeshGradientUniforms,\n} from './shaders/static-mesh-gradient.js';\n\n/** Radial gradient with up to 10 blended colors, featuring advanced focal point control, shape distortion, and grain effects */\nexport {\n staticRadialGradientFragmentShader,\n staticRadialGradientMeta,\n type StaticRadialGradientParams,\n type StaticRadialGradientUniforms,\n} from './shaders/static-radial-gradient.js';\n\n/** A static texture built from multiple noise layers, usable for a realistic paper and cardboard surfaces or generating abstract patterns. Can be used as a image filter or as a texture */\nexport {\n paperTextureFragmentShader,\n type PaperTextureParams,\n type PaperTextureUniforms,\n} from './shaders/paper-texture.js';\n\n/** Water-like surface distortion with natural caustic realism. Works as an image filter or animated texture without image */\nexport { waterFragmentShader, type WaterParams, type WaterUniforms } from './shaders/water.js';\n\n/** Fluted glass image filter transforms an image into streaked, ribbed distortions, giving a mix of clarity and obscurity */\nexport {\n flutedGlassFragmentShader,\n GlassDistortionShapes,\n GlassGridShapes,\n type GlassDistortionShape,\n type GlassGridShape,\n type FlutedGlassParams,\n type FlutedGlassUniforms,\n} from './shaders/fluted-glass.js';\n\n/** A dithering image filter with support for 4 dithering modes and multiple color palettes (2-color, 3-color, and multicolor options, using either predefined colors or ones sampled directly from the original image) */\nexport {\n imageDitheringFragmentShader,\n type ImageDitheringParams,\n type ImageDitheringUniforms,\n} from './shaders/image-dithering.js';\n\n/** A glowing gradient of colors flowing through an input image. The effect creates a smoothly animated wave of intensity across the image */\nexport {\n heatmapMeta,\n heatmapFragmentShader,\n toProcessedHeatmap,\n type HeatmapParams,\n type HeatmapUniforms,\n} from './shaders/heatmap.js';\n\n/** Futuristic liquid metal material applied to uploaded logo or one of pre-defined abstract shape */\nexport {\n liquidMetalFragmentShader,\n LiquidMetalShapes,\n toProcessedLiquidMetal,\n type LiquidMetalShape,\n type LiquidMetalParams,\n type LiquidMetalUniforms,\n} from './shaders/liquid-metal.js';\n\n/** A halftone-dot image filter featuring customizable grids, color palettes, and dot styles */\nexport {\n HalftoneDotsTypes,\n HalftoneDotsGrids,\n halftoneDotsFragmentShader,\n type HalftoneDotsParams,\n type HalftoneDotsUniforms,\n type HalftoneDotsType,\n type HalftoneDotsGrid,\n} from './shaders/halftone-dots.js';\n\n/** A halftone CMYK classic algo */\nexport {\n HalftoneCmykTypes,\n halftoneCmykFragmentShader,\n type HalftoneCmykParams,\n type HalftoneCmykUniforms,\n type HalftoneCmykType,\n} from './shaders/halftone-cmyk.js';\n\n/** Animated color fields running around a glassy logo shape */\nexport {\n gemSmokeMeta,\n gemSmokeFragmentShader,\n toProcessedGemSmoke,\n GemSmokeShapes,\n type GemSmokeShape,\n type GemSmokeParams,\n type GemSmokeUniforms,\n} from './shaders/gem-smoke.js';\n\n// ----- Utils ----- //\nexport { getShaderColorFromString } from './get-shader-color-from-string.js';\nexport { getShaderNoiseTexture } from './get-shader-noise-texture.js';\nexport { emptyPixel } from './empty-pixel.js';\n"],
|
|
5
|
-
"mappings": ";;;;;AACA,SAAS,aAAa,4BAA4B;AAUlD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,gCAAgF;AAGzF;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,iCAAmF;AAG5F,SAAS,aAAa,6BAAuE;AAG7F,SAAS,2BAAiE;AAG1E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,aAAa,6BAAuE;AAG7F,SAAS,4BAAoE;AAG7E,SAAS,WAAW,2BAAiE;AAGrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,OAGK;AAGP,SAAS,2BAAiE;AAG1E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;",
|
|
4
|
+
"sourcesContent": ["/** The core Shader Mount class. Pass it a parent element and a fragment shader to get started. */\nexport { ShaderMount, isPaperShaderElement } from './shader-mount.js';\nexport type {\n PaperShaderElement,\n ShaderMotionParams,\n ShaderMountUniforms,\n ShaderPreset,\n ImageShaderPreset,\n} from './shader-mount.js';\n\n/** Shader sizing options and uniforms */\nexport {\n defaultObjectSizing,\n defaultPatternSizing,\n ShaderFitOptions,\n type ShaderFit,\n type ShaderSizingParams,\n type ShaderSizingUniforms,\n} from './shader-sizing.js';\n\n/** A flowing interplay of color spots, moving along distinct trajectories and transformed by organic distortion */\nexport {\n meshGradientFragmentShader,\n meshGradientMeta,\n type MeshGradientParams,\n type MeshGradientUniforms,\n} from './shaders/mesh-gradient.js';\n\n/** Radial multi-colored gradient shaped with layered noise for a natural, smoky aesthetic */\nexport {\n smokeRingMeta,\n smokeRingFragmentShader,\n type SmokeRingParams,\n type SmokeRingUniforms,\n} from './shaders/smoke-ring.js';\n\n/** A glowing, web-like structure of fluid lines and soft intersections. Great for creating atmospheric, organic-yet-futuristic visuals */\nexport { neuroNoiseFragmentShader, type NeuroNoiseParams, type NeuroNoiseUniforms } from './shaders/neuro-noise.js';\n\n/** Animated multi-color dots pattern with each dot orbiting around its cell center. Supports up to 40 colors and various shape and motion controls. Great for playful, dynamic backgrounds and UI textures */\nexport {\n dotOrbitMeta,\n dotOrbitFragmentShader,\n type DotOrbitParams,\n type DotOrbitUniforms,\n} from './shaders/dot-orbit.js';\n\n/** Static grid pattern made of circles, diamonds, squares or triangles */\nexport {\n dotGridFragmentShader,\n DotGridShapes,\n type DotGridShape,\n type DotGridParams,\n type DotGridUniforms,\n} from './shaders/dot-grid.js';\n\n/** A multi-color gradient mapped into smooth, animated curves, delivering a sleek, futuristic visual */\nexport {\n simplexNoiseMeta,\n simplexNoiseFragmentShader,\n type SimplexNoiseParams,\n type SimplexNoiseUniforms,\n} from './shaders/simplex-noise.js';\n\n/** Up to 20 gooey blobs moving around the center and merging into smooth organic shapes */\nexport {\n metaballsMeta,\n metaballsFragmentShader,\n type MetaballsParams,\n type MetaballsUniforms,\n} from './shaders/metaballs.js';\n\n/** Animated 3D Perlin noise with exposed controls */\nexport { perlinNoiseFragmentShader, type PerlinNoiseParams, type PerlinNoiseUniforms } from './shaders/perlin-noise.js';\n\n/** Anti-aliased animated Voronoi pattern with smooth and customizable edges */\nexport { voronoiMeta, voronoiFragmentShader, type VoronoiParams, type VoronoiUniforms } from './shaders/voronoi.js';\n\n/** Static line pattern configurable into textures ranging from sharp zigzags to smooth flowing waves */\nexport { wavesFragmentShader, type WavesParams, type WavesUniforms } from './shaders/waves.js';\n\n/** Animated color fields warped by noise and swirls, applied over base patterns (checks, stripes, or split edge). Blends up to 10 colors with adjustable distribution, softness, distortion, and swirl. Great for fluid, smoky, or marbled effects */\nexport {\n warpMeta,\n warpFragmentShader,\n WarpPatterns,\n type WarpParams,\n type WarpUniforms,\n type WarpPattern,\n} from './shaders/warp.js';\n\n/** Animated rays of light radiating from the center, blended with up to 5 colors. The rays are adjustable by size, density, brightness and center glow. Great for dramatic backgrounds, logo reveals, and VFX like energy bursts or sun shafts */\nexport { godRaysMeta, godRaysFragmentShader, type GodRaysParams, type GodRaysUniforms } from './shaders/god-rays.js';\n\n/** A single-colored animated spiral that morphs across a wide range of shapes - from crisp, thin-lined geometry to flowing whirlpool forms and wavy, abstract rings */\nexport { spiralFragmentShader, type SpiralParams, type SpiralUniforms } from './shaders/spiral.js';\n\n/** Animated bands of color twisting and bending, producing spirals, arcs, and flowing circular patterns */\nexport { swirlMeta, swirlFragmentShader, type SwirlParams, type SwirlUniforms } from './shaders/swirl.js';\n\n/** Animated 2-color dithering over with multiple pattern sources (noise, warp, dots, waves, ripple, swirl, sphere) */\nexport {\n ditheringFragmentShader,\n DitheringShapes,\n DitheringTypes,\n type DitheringParams,\n type DitheringUniforms,\n type DitheringShape,\n type DitheringType,\n} from './shaders/dithering.js';\n\n/** Multi-color gradients with grainy, noise-textured distortion available in 7 animated abstract forms */\nexport {\n grainGradientFragmentShader,\n grainGradientMeta,\n GrainGradientShapes,\n type GrainGradientParams,\n type GrainGradientUniforms,\n type GrainGradientShape,\n} from './shaders/grain-gradient.js';\n\n/** Luminous trails of color merging into a glowing gradient frame */\nexport {\n pulsingBorderMeta,\n pulsingBorderFragmentShader,\n PulsingBorderAspectRatios,\n type PulsingBorderParams,\n type PulsingBorderUniforms,\n type PulsingBorderAspectRatio,\n} from './shaders/pulsing-border.js';\n\n/** Glowing translucent 3D panels rotating around a central axis */\nexport {\n colorPanelsFragmentShader,\n colorPanelsMeta,\n type ColorPanelsParams,\n type ColorPanelsUniforms,\n} from './shaders/color-panels.js';\n\n/** Multi-point mesh gradients with up to 10 color spots, enhanced by two-direction warping, adjustable blend sharpness, and grain controls. Perfect for elegant wallpapers and atmospheric backdrops */\nexport {\n staticMeshGradientFragmentShader,\n staticMeshGradientMeta,\n type StaticMeshGradientParams,\n type StaticMeshGradientUniforms,\n} from './shaders/static-mesh-gradient.js';\n\n/** Radial gradient with up to 10 blended colors, featuring advanced focal point control, shape distortion, and grain effects */\nexport {\n staticRadialGradientFragmentShader,\n staticRadialGradientMeta,\n type StaticRadialGradientParams,\n type StaticRadialGradientUniforms,\n} from './shaders/static-radial-gradient.js';\n\n/** A static texture built from multiple noise layers, usable for a realistic paper and cardboard surfaces or generating abstract patterns. Can be used as a image filter or as a texture */\nexport {\n paperTextureFragmentShader,\n type PaperTextureParams,\n type PaperTextureUniforms,\n} from './shaders/paper-texture.js';\n\n/** Water-like surface distortion with natural caustic realism. Works as an image filter or animated texture without image */\nexport { waterFragmentShader, type WaterParams, type WaterUniforms } from './shaders/water.js';\n\n/** Fluted glass image filter transforms an image into streaked, ribbed distortions, giving a mix of clarity and obscurity */\nexport {\n flutedGlassFragmentShader,\n GlassDistortionShapes,\n GlassGridShapes,\n type GlassDistortionShape,\n type GlassGridShape,\n type FlutedGlassParams,\n type FlutedGlassUniforms,\n} from './shaders/fluted-glass.js';\n\n/** A dithering image filter with support for 4 dithering modes and multiple color palettes (2-color, 3-color, and multicolor options, using either predefined colors or ones sampled directly from the original image) */\nexport {\n imageDitheringFragmentShader,\n type ImageDitheringParams,\n type ImageDitheringUniforms,\n} from './shaders/image-dithering.js';\n\n/** Lens Distortion image filter that separates an image into shifting color layers, recreating the chromatic aberration of a lens, and warps the image geometry with barrel or pincushion curvature */\nexport { lensDistortionFragmentShader, lensDistortionMeta, type LensDistortionParams, type LensDistortionUniforms } from './shaders/lens-distortion.js';\n\n/** A glowing gradient of colors flowing through an input image. The effect creates a smoothly animated wave of intensity across the image */\nexport {\n heatmapMeta,\n heatmapFragmentShader,\n toProcessedHeatmap,\n type HeatmapParams,\n type HeatmapUniforms,\n} from './shaders/heatmap.js';\n\n/** Futuristic liquid metal material applied to uploaded logo or one of pre-defined abstract shape */\nexport {\n liquidMetalFragmentShader,\n LiquidMetalShapes,\n toProcessedLiquidMetal,\n type LiquidMetalShape,\n type LiquidMetalParams,\n type LiquidMetalUniforms,\n} from './shaders/liquid-metal.js';\n\n/** A halftone-dot image filter featuring customizable grids, color palettes, and dot styles */\nexport {\n HalftoneDotsTypes,\n HalftoneDotsGrids,\n halftoneDotsFragmentShader,\n type HalftoneDotsParams,\n type HalftoneDotsUniforms,\n type HalftoneDotsType,\n type HalftoneDotsGrid,\n} from './shaders/halftone-dots.js';\n\n/** A halftone CMYK classic algo */\nexport {\n HalftoneCmykTypes,\n halftoneCmykFragmentShader,\n type HalftoneCmykParams,\n type HalftoneCmykUniforms,\n type HalftoneCmykType,\n} from './shaders/halftone-cmyk.js';\n\n/** Animated color fields running around a glassy logo shape */\nexport {\n gemSmokeMeta,\n gemSmokeFragmentShader,\n toProcessedGemSmoke,\n GemSmokeShapes,\n type GemSmokeShape,\n type GemSmokeParams,\n type GemSmokeUniforms,\n} from './shaders/gem-smoke.js';\n\n// ----- Utils ----- //\nexport { getShaderColorFromString } from './get-shader-color-from-string.js';\nexport { getShaderNoiseTexture } from './get-shader-noise-texture.js';\nexport { emptyPixel } from './empty-pixel.js';\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,SAAS,aAAa,4BAA4B;AAUlD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,gCAAgF;AAGzF;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP,SAAS,iCAAmF;AAG5F,SAAS,aAAa,6BAAuE;AAG7F,SAAS,2BAAiE;AAG1E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,aAAa,6BAAuE;AAG7F,SAAS,4BAAoE;AAG7E,SAAS,WAAW,2BAAiE;AAGrF;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,OAGK;AAGP,SAAS,2BAAiE;AAG1E;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,OAGK;AAGP,SAAS,8BAA8B,0BAAkF;AAGzH;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,OAKK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,OAIK;AAGP;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAIK;AAGP,SAAS,gCAAgC;AACzC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
2
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
3
|
+
export declare const lensDistortionMeta: {
|
|
4
|
+
readonly maxSamples: 50;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
*
|
|
8
|
+
* Lens Distortion image filter separates an image into shifting color layers
|
|
9
|
+
* (recreating the chromatic aberration of a lens) and warps the image geometry,
|
|
10
|
+
* curving it outward or inward like barrel and pincushion distortion.
|
|
11
|
+
*
|
|
12
|
+
* Fragment shader uniforms:
|
|
13
|
+
* - u_image (sampler2D): Source image texture
|
|
14
|
+
* - u_spread (float): Strength of the color split; how far the color layers are pushed apart; 0 is off (0 to 1)
|
|
15
|
+
* - u_bias (float): Shifts the colors toward one end of the spread; 0 spaces them evenly (-1 to 1)
|
|
16
|
+
* - u_angle (float): Direction of the spread in degrees (0 to 360)
|
|
17
|
+
* - u_perspective (float): Shapes the spread direction from a straight line (0) to a radial burst out from the centre (1) (0 to 1)
|
|
18
|
+
* - u_count (float): Number of sampled color layers along the spread; higher is smoother and costlier (2 to 50)
|
|
19
|
+
* - u_dispersion (float): Overall amount of color dispersion; 1 gives each layer its own color from the spectrum, 0 keeps the original image color (0 to 1)
|
|
20
|
+
* - u_dispersionShift (float): Balance of the dispersion between a soft circular zone at the centre and the rest of the image; 0 applies it evenly, -1 keeps it in the centre only, 1 keeps it at the edges only (-1 to 1)
|
|
21
|
+
* - u_dispersionColor (float): Rotates the colors around the hue wheel, 0 to 1 for a full turn
|
|
22
|
+
* - u_focusCenter (float): Reduces the spread in a circular zone at the centre; 0 keeps it full to the centre (0 to 1)
|
|
23
|
+
* - u_focusEdges (float): Reduces the spread toward the edges; 0 keeps it full to the edges, 1 restores the original image there (0 to 1)
|
|
24
|
+
* - u_swirl (float): Rotates the color layers around the centre by an angle growing along the spread; 0 is off (-1 to 1)
|
|
25
|
+
* - u_noise (float): Scatters the spread direction with noise; 0 is off (0 to 1)
|
|
26
|
+
* - u_noiseFrequency (float): Frequency of the noise, 0 to 1 mapped internally to 0 to 18; higher is finer (no effect with noise = 0)
|
|
27
|
+
* - u_noiseOffset (float): Offsets the noise pattern for a different seed (no effect with noise = 0)
|
|
28
|
+
* - u_lensBulge (float): Radial lens warp of the image geometry; positive bulges out like a fisheye/barrel, negative pinches in like a pincushion; strong positive values fade out the corners (-1 to 1)
|
|
29
|
+
* - u_lensCircle (float): Squeezes pixels outside the inscribed circle inward so the outline becomes a circle; also turns the spread radial and damps it near the rim; 0 is off, 1 is full (0 to 1)
|
|
30
|
+
* - u_grainMixer (float): Scatters the spread with grain noise, breaking up the edges of the color layers (0 to 1)
|
|
31
|
+
* - u_grainOverlay (float): Post-processing black/white grain overlay (0 to 1)
|
|
32
|
+
* - u_imageX (float): Pans the image horizontally behind the effect; 0 is centred (-1 to 1)
|
|
33
|
+
* - u_imageY (float): Pans the image vertically behind the effect; 0 is centred (-1 to 1)
|
|
34
|
+
*
|
|
35
|
+
* Vertex shader outputs (used in fragment shader):
|
|
36
|
+
* - v_imageUV (vec2): Image UV coordinates with global sizing (rotation, scale, offset, etc) applied
|
|
37
|
+
*
|
|
38
|
+
* Vertex shader uniforms:
|
|
39
|
+
* - u_resolution (vec2): Canvas resolution in pixels
|
|
40
|
+
* - u_pixelRatio (float): Device pixel ratio
|
|
41
|
+
* - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
|
|
42
|
+
* - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
|
|
43
|
+
* - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
|
|
44
|
+
* - u_scale (float): Overall zoom level of the graphics (0.01 to 4)
|
|
45
|
+
* - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
|
|
46
|
+
* - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
|
|
47
|
+
* - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
|
|
48
|
+
* - u_imageAspectRatio (float): Aspect ratio of the source image
|
|
49
|
+
*
|
|
50
|
+
*/
|
|
51
|
+
export declare const lensDistortionFragmentShader: string;
|
|
52
|
+
export interface LensDistortionUniforms extends ShaderSizingUniforms {
|
|
53
|
+
u_image: HTMLImageElement | string | undefined;
|
|
54
|
+
u_spread: number;
|
|
55
|
+
u_bias: number;
|
|
56
|
+
u_angle: number;
|
|
57
|
+
u_perspective: number;
|
|
58
|
+
u_count: number;
|
|
59
|
+
u_dispersion: number;
|
|
60
|
+
u_dispersionShift: number;
|
|
61
|
+
u_dispersionColor: number;
|
|
62
|
+
u_focusCenter: number;
|
|
63
|
+
u_focusEdges: number;
|
|
64
|
+
u_swirl: number;
|
|
65
|
+
u_noise: number;
|
|
66
|
+
u_noiseFrequency: number;
|
|
67
|
+
u_noiseOffset: number;
|
|
68
|
+
u_lensBulge: number;
|
|
69
|
+
u_lensCircle: number;
|
|
70
|
+
u_grainMixer: number;
|
|
71
|
+
u_grainOverlay: number;
|
|
72
|
+
u_imageX: number;
|
|
73
|
+
u_imageY: number;
|
|
74
|
+
}
|
|
75
|
+
export interface LensDistortionParams extends ShaderSizingParams, ShaderMotionParams {
|
|
76
|
+
image?: HTMLImageElement | string;
|
|
77
|
+
spread?: number;
|
|
78
|
+
bias?: number;
|
|
79
|
+
angle?: number;
|
|
80
|
+
perspective?: number;
|
|
81
|
+
count?: number;
|
|
82
|
+
dispersion?: number;
|
|
83
|
+
dispersionShift?: number;
|
|
84
|
+
dispersionColor?: number;
|
|
85
|
+
focusCenter?: number;
|
|
86
|
+
focusEdges?: number;
|
|
87
|
+
swirl?: number;
|
|
88
|
+
noise?: number;
|
|
89
|
+
noiseFrequency?: number;
|
|
90
|
+
noiseOffset?: number;
|
|
91
|
+
lensBulge?: number;
|
|
92
|
+
lensCircle?: number;
|
|
93
|
+
grainMixer?: number;
|
|
94
|
+
grainOverlay?: number;
|
|
95
|
+
imageX?: number;
|
|
96
|
+
imageY?: number;
|
|
97
|
+
}
|
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {} from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, proceduralHash21, rotation2 } from "../shader-utils.js";
|
|
8
|
+
const lensDistortionMeta = {
|
|
9
|
+
maxSamples: 50
|
|
10
|
+
};
|
|
11
|
+
const lensDistortionFragmentShader = `#version 300 es
|
|
12
|
+
precision mediump float;
|
|
13
|
+
|
|
14
|
+
uniform sampler2D u_image;
|
|
15
|
+
uniform float u_imageAspectRatio;
|
|
16
|
+
uniform float u_spread;
|
|
17
|
+
uniform float u_bias;
|
|
18
|
+
uniform float u_angle;
|
|
19
|
+
uniform float u_perspective;
|
|
20
|
+
uniform float u_count;
|
|
21
|
+
uniform float u_dispersion;
|
|
22
|
+
uniform float u_dispersionShift;
|
|
23
|
+
uniform float u_dispersionColor;
|
|
24
|
+
uniform float u_focusCenter;
|
|
25
|
+
uniform float u_focusEdges;
|
|
26
|
+
uniform float u_swirl;
|
|
27
|
+
uniform float u_noise;
|
|
28
|
+
uniform float u_noiseFrequency;
|
|
29
|
+
uniform float u_noiseOffset;
|
|
30
|
+
uniform float u_lensBulge;
|
|
31
|
+
uniform float u_lensCircle;
|
|
32
|
+
uniform float u_grainMixer;
|
|
33
|
+
uniform float u_grainOverlay;
|
|
34
|
+
uniform float u_imageX;
|
|
35
|
+
uniform float u_imageY;
|
|
36
|
+
|
|
37
|
+
in vec2 v_imageUV;
|
|
38
|
+
|
|
39
|
+
out vec4 fragColor;
|
|
40
|
+
|
|
41
|
+
${declarePI}
|
|
42
|
+
${proceduralHash21}
|
|
43
|
+
${rotation2}
|
|
44
|
+
|
|
45
|
+
float valueNoise(vec2 st) {
|
|
46
|
+
vec2 i = floor(st);
|
|
47
|
+
vec2 f = fract(st);
|
|
48
|
+
float a = hash21(i);
|
|
49
|
+
float b = hash21(i + vec2(1., 0.));
|
|
50
|
+
float c = hash21(i + vec2(0., 1.));
|
|
51
|
+
float d = hash21(i + vec2(1., 1.));
|
|
52
|
+
vec2 u = f * f * (3. - 2. * f);
|
|
53
|
+
return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
float getUvFrame(vec2 uv) {
|
|
57
|
+
vec2 invAA = 1. / clamp(fwidth(uv), 1e-5, .02);
|
|
58
|
+
vec2 lo = clamp(uv * invAA + .5, 0., 1.);
|
|
59
|
+
vec2 hi = clamp((1. - uv) * invAA + .5, 0., 1.);
|
|
60
|
+
return lo.x * hi.x * lo.y * hi.y;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
vec4 sampleOverWhite(vec2 uv) {
|
|
64
|
+
vec4 img = texture(u_image, uv);
|
|
65
|
+
float cover = img.a * getUvFrame(uv);
|
|
66
|
+
vec3 colorOverWhite = mix(vec3(1.), img.rgb, cover);
|
|
67
|
+
return vec4(colorOverWhite, cover);
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
vec3 hueColor(float hue) {
|
|
71
|
+
vec3 rgb = clamp(abs(mod(hue * 6. + vec3(0., 4., 2.), 6.) - 3.) - 1., 0., 1.);
|
|
72
|
+
rgb = rgb * rgb * (3. - 2. * rgb);
|
|
73
|
+
return rgb;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
float boxInradius() {
|
|
77
|
+
return .5 * min(u_imageAspectRatio, 1.);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
float boxOutradius() {
|
|
81
|
+
return .5 * length(vec2(u_imageAspectRatio, 1.));
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
float spreadReach() {
|
|
85
|
+
return .7 * pow(u_spread, 1.3 + 2.7 * u_spread);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
float innerCircleMask(float radius, float inradius) {
|
|
89
|
+
return 1. - smoothstep(.5 * inradius, 1.1 * inradius, radius);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
float dispersionCurve(float t, float biasPow) {
|
|
93
|
+
float mirroredT = u_bias < 0. ? 1. - t : t;
|
|
94
|
+
float curved = pow(mirroredT, biasPow);
|
|
95
|
+
return u_bias < 0. ? 1. - curved : curved;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
vec2 getSpread(vec2 fromCenter, float radius, vec2 warpedUV, float edgeAA, float inradius, float outradius, float reach, out float outStrength) {
|
|
99
|
+
float angleRad = radians(u_angle);
|
|
100
|
+
vec2 uniformDir = vec2(cos(angleRad), sin(angleRad));
|
|
101
|
+
|
|
102
|
+
float invInradius = 1. / inradius;
|
|
103
|
+
vec2 radialDir = fromCenter * invInradius;
|
|
104
|
+
float maxLen = (outradius + reach) * invInradius;
|
|
105
|
+
float radialLen = radius * invInradius;
|
|
106
|
+
if (radialLen > maxLen) radialDir *= maxLen / radialLen;
|
|
107
|
+
vec2 spreadDir = mix(uniformDir, radialDir, u_perspective);
|
|
108
|
+
|
|
109
|
+
float bandProximity = smoothstep(inradius * .8, inradius, radius);
|
|
110
|
+
float lensCircleMaxing = bandProximity * u_lensCircle * u_lensCircle * u_lensCircle;
|
|
111
|
+
spreadDir = mix(spreadDir, radialDir, lensCircleMaxing);
|
|
112
|
+
|
|
113
|
+
vec2 warpedAbs = abs(warpedUV - .5);
|
|
114
|
+
float inner = mix(1., smoothstep(0., mix(inradius, outradius, u_focusCenter), radius), u_focusCenter);
|
|
115
|
+
float boxDist = max(warpedAbs.x, warpedAbs.y) * 2.;
|
|
116
|
+
float outer = mix(1., 1. - min(boxDist, 1.), u_focusEdges);
|
|
117
|
+
float strength = inner * outer;
|
|
118
|
+
|
|
119
|
+
strength *= mix(1., mix(.15, .03, max(-u_lensBulge, 0.)), lensCircleMaxing);
|
|
120
|
+
|
|
121
|
+
vec2 outside = max(warpedAbs - .5, 0.);
|
|
122
|
+
float margin = max(reach * length(spreadDir) * (1. - u_lensCircle), edgeAA);
|
|
123
|
+
strength *= 1. - smoothstep(0., margin, length(outside));
|
|
124
|
+
|
|
125
|
+
outStrength = strength;
|
|
126
|
+
vec2 axis = spreadDir * (reach * strength);
|
|
127
|
+
|
|
128
|
+
if (u_noise > 0.) {
|
|
129
|
+
float turn = (valueNoise(fromCenter * u_noiseFrequency * 18. + u_noiseOffset) - .5) * 2. * u_noise;
|
|
130
|
+
float cs = cos(turn), sn = sin(turn);
|
|
131
|
+
axis = mat2(cs, -sn, sn, cs) * axis;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
axis.x /= u_imageAspectRatio;
|
|
135
|
+
return axis;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
vec2 lensWarp(vec2 fromCenter, float radius, float inradius, out float bulgeFade) {
|
|
139
|
+
bulgeFade = 1.;
|
|
140
|
+
if (u_lensBulge == 0. && u_lensCircle <= 0.) return fromCenter;
|
|
141
|
+
if (radius < 1e-5) return fromCenter;
|
|
142
|
+
|
|
143
|
+
float r = radius;
|
|
144
|
+
|
|
145
|
+
if (u_lensBulge != 0.) {
|
|
146
|
+
float rn = radius / inradius;
|
|
147
|
+
float bulge = abs(u_lensBulge) * (u_lensBulge > 0. ? 1.4 : 1.2);
|
|
148
|
+
if (u_lensBulge > 0.) bulgeFade = 1. - smoothstep(1.45, 1.53, rn * bulge);
|
|
149
|
+
float map = u_lensBulge > 0.
|
|
150
|
+
? tan(min(rn * bulge, 1.53)) / tan(bulge)
|
|
151
|
+
: atan(rn * tan(bulge)) / bulge;
|
|
152
|
+
float bulgeScale = map / rn;
|
|
153
|
+
fromCenter *= bulgeScale;
|
|
154
|
+
r *= bulgeScale;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
if (u_lensCircle > 0.) {
|
|
158
|
+
vec2 dir = fromCenter / max(r, 1e-5);
|
|
159
|
+
vec2 halfBox = vec2(u_imageAspectRatio, 1.) * .5;
|
|
160
|
+
float rBox = min(halfBox.x / max(abs(dir.x), 1e-4), halfBox.y / max(abs(dir.y), 1e-4));
|
|
161
|
+
float band = inradius * mix(.03, .2, .5 * (u_lensBulge + 1.));
|
|
162
|
+
float innerEdge = inradius - band;
|
|
163
|
+
float over = smoothstep(0., 1., (r - innerEdge) / band);
|
|
164
|
+
float g = r + (rBox - inradius) * pow(over, 14.);
|
|
165
|
+
fromCenter = dir * mix(r, g, u_lensCircle);
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return fromCenter;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
void main() {
|
|
172
|
+
vec2 uv = v_imageUV;
|
|
173
|
+
|
|
174
|
+
float invAspect = 1. / u_imageAspectRatio;
|
|
175
|
+
float inradius = boxInradius();
|
|
176
|
+
float outradius = boxOutradius();
|
|
177
|
+
float reach = spreadReach();
|
|
178
|
+
|
|
179
|
+
vec2 fromCenter = uv - .5;
|
|
180
|
+
fromCenter.x *= u_imageAspectRatio;
|
|
181
|
+
float radius = length(fromCenter);
|
|
182
|
+
|
|
183
|
+
float bulgeFade;
|
|
184
|
+
vec2 warpedFromCenter = lensWarp(fromCenter, radius, inradius, bulgeFade);
|
|
185
|
+
vec2 baseUV = vec2(warpedFromCenter.x * invAspect, warpedFromCenter.y) + .5;
|
|
186
|
+
|
|
187
|
+
vec2 baseDerivative = fwidth(baseUV);
|
|
188
|
+
float edgeAA = clamp(2. * max(baseDerivative.x, baseDerivative.y), .001, .02);
|
|
189
|
+
|
|
190
|
+
float spreadStrength;
|
|
191
|
+
vec2 spreadAxis = getSpread(fromCenter, radius, baseUV, edgeAA, inradius, outradius, reach, spreadStrength);
|
|
192
|
+
|
|
193
|
+
vec2 grainUV = vec2(0.);
|
|
194
|
+
if (u_grainMixer > 0. || u_grainOverlay > 0.) {
|
|
195
|
+
vec2 dudx = dFdx(v_imageUV);
|
|
196
|
+
vec2 dudy = dFdy(v_imageUV);
|
|
197
|
+
grainUV = (v_imageUV - .5) * (.8 / vec2(length(dudx), length(dudy))) + .5;
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (u_grainMixer > 0.) {
|
|
201
|
+
float grainSeed = valueNoise(grainUV);
|
|
202
|
+
vec2 jit = fract(grainSeed * vec2(157.31, 113.57)) * 2. - 1.;
|
|
203
|
+
spreadAxis += jit * .3 * u_grainMixer * length(spreadAxis);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
float count = floor(u_count);
|
|
207
|
+
int countInteger = int(count);
|
|
208
|
+
|
|
209
|
+
float invCount = 1. / count;
|
|
210
|
+
float invSpan = 1. / max(count - 1., 1.);
|
|
211
|
+
float hueBase = u_dispersionColor + .5;
|
|
212
|
+
float biasPower = 1. + 2. * abs(u_bias);
|
|
213
|
+
vec2 tapBias = .5 - vec2(u_imageX, u_imageY);
|
|
214
|
+
|
|
215
|
+
float centerAmount = clamp(1. - u_dispersionShift, 0., 1.);
|
|
216
|
+
float edgesAmount = clamp(1. + u_dispersionShift, 0., 1.);
|
|
217
|
+
float dispersion = u_dispersion * mix(edgesAmount, centerAmount, innerCircleMask(radius, inradius));
|
|
218
|
+
float dispersionPower = pow(dispersion, .8);
|
|
219
|
+
|
|
220
|
+
float warpedRadius = length(warpedFromCenter);
|
|
221
|
+
float swirlAngle = u_swirl * .4 * PI * spreadStrength * u_spread * min(1., inradius / max(warpedRadius, 1e-4));
|
|
222
|
+
|
|
223
|
+
vec3 colorSum = vec3(0.);
|
|
224
|
+
vec3 weightSum = vec3(0.);
|
|
225
|
+
float coverSum = 0.;
|
|
226
|
+
|
|
227
|
+
for (int i = 0; i < ${lensDistortionMeta.maxSamples}; i++) {
|
|
228
|
+
if (i >= countInteger) break;
|
|
229
|
+
|
|
230
|
+
float layer = float(i);
|
|
231
|
+
float hue = hueBase + layer * invCount;
|
|
232
|
+
|
|
233
|
+
float spread = layer * invSpan;
|
|
234
|
+
if (u_bias != 0.) spread = dispersionCurve(spread, biasPower);
|
|
235
|
+
|
|
236
|
+
// mix(axis, -axis, spread) is axis scaled by the signed position along the fan
|
|
237
|
+
float fanPos = 1. - 2. * spread;
|
|
238
|
+
vec2 tapUV = baseUV + spreadAxis * fanPos - .5;
|
|
239
|
+
|
|
240
|
+
if (u_swirl != 0.) {
|
|
241
|
+
tapUV.x *= u_imageAspectRatio;
|
|
242
|
+
tapUV = rotate(tapUV, swirlAngle * fanPos);
|
|
243
|
+
tapUV.x *= invAspect;
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
vec4 tap = sampleOverWhite(tapUV + tapBias);
|
|
247
|
+
vec3 weight = 1. - dispersionPower * hueColor(hue);
|
|
248
|
+
|
|
249
|
+
colorSum += tap.rgb * weight;
|
|
250
|
+
weightSum += weight;
|
|
251
|
+
coverSum += tap.a;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
vec3 color = colorSum / max(weightSum, 1e-4);
|
|
255
|
+
float coverAvg = coverSum * invCount;
|
|
256
|
+
|
|
257
|
+
float ground = min(color.r, min(color.g, color.b));
|
|
258
|
+
float alpha = max(coverAvg, 1. - ground);
|
|
259
|
+
vec3 premult = max(color - (1. - alpha), 0.);
|
|
260
|
+
fragColor = vec4(premult, alpha) * bulgeFade;
|
|
261
|
+
|
|
262
|
+
if (u_grainOverlay > 0.) {
|
|
263
|
+
float grain = valueNoise(rotate(grainUV, 1.) + vec2(3.));
|
|
264
|
+
grain = mix(grain, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);
|
|
265
|
+
grain = pow(grain, 1.3);
|
|
266
|
+
float grainV = grain * 2. - 1.;
|
|
267
|
+
float grainStrength = pow(u_grainOverlay * abs(grainV), .8) * fragColor.a;
|
|
268
|
+
fragColor.rgb = mix(fragColor.rgb, vec3(step(0., grainV)) * fragColor.a, .35 * grainStrength);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
`;
|
|
272
|
+
export {
|
|
273
|
+
lensDistortionFragmentShader,
|
|
274
|
+
lensDistortionMeta
|
|
275
|
+
};
|
|
276
|
+
//# sourceMappingURL=lens-distortion.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/shaders/lens-distortion.ts"],
|
|
4
|
+
"sourcesContent": ["import type { ShaderMotionParams } from '../shader-mount.js';\nimport { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';\nimport { declarePI, proceduralHash21, rotation2 } from '../shader-utils.js';\n\nexport const lensDistortionMeta = {\n maxSamples: 50,\n} as const;\n\n/**\n *\n * Lens Distortion image filter separates an image into shifting color layers\n * (recreating the chromatic aberration of a lens) and warps the image geometry,\n * curving it outward or inward like barrel and pincushion distortion.\n *\n * Fragment shader uniforms:\n * - u_image (sampler2D): Source image texture\n * - u_spread (float): Strength of the color split; how far the color layers are pushed apart; 0 is off (0 to 1)\n * - u_bias (float): Shifts the colors toward one end of the spread; 0 spaces them evenly (-1 to 1)\n * - u_angle (float): Direction of the spread in degrees (0 to 360)\n * - u_perspective (float): Shapes the spread direction from a straight line (0) to a radial burst out from the centre (1) (0 to 1)\n * - u_count (float): Number of sampled color layers along the spread; higher is smoother and costlier (2 to 50)\n * - u_dispersion (float): Overall amount of color dispersion; 1 gives each layer its own color from the spectrum, 0 keeps the original image color (0 to 1)\n * - u_dispersionShift (float): Balance of the dispersion between a soft circular zone at the centre and the rest of the image; 0 applies it evenly, -1 keeps it in the centre only, 1 keeps it at the edges only (-1 to 1)\n * - u_dispersionColor (float): Rotates the colors around the hue wheel, 0 to 1 for a full turn\n * - u_focusCenter (float): Reduces the spread in a circular zone at the centre; 0 keeps it full to the centre (0 to 1)\n * - u_focusEdges (float): Reduces the spread toward the edges; 0 keeps it full to the edges, 1 restores the original image there (0 to 1)\n * - u_swirl (float): Rotates the color layers around the centre by an angle growing along the spread; 0 is off (-1 to 1)\n * - u_noise (float): Scatters the spread direction with noise; 0 is off (0 to 1)\n * - u_noiseFrequency (float): Frequency of the noise, 0 to 1 mapped internally to 0 to 18; higher is finer (no effect with noise = 0)\n * - u_noiseOffset (float): Offsets the noise pattern for a different seed (no effect with noise = 0)\n * - u_lensBulge (float): Radial lens warp of the image geometry; positive bulges out like a fisheye/barrel, negative pinches in like a pincushion; strong positive values fade out the corners (-1 to 1)\n * - u_lensCircle (float): Squeezes pixels outside the inscribed circle inward so the outline becomes a circle; also turns the spread radial and damps it near the rim; 0 is off, 1 is full (0 to 1)\n * - u_grainMixer (float): Scatters the spread with grain noise, breaking up the edges of the color layers (0 to 1)\n * - u_grainOverlay (float): Post-processing black/white grain overlay (0 to 1)\n * - u_imageX (float): Pans the image horizontally behind the effect; 0 is centred (-1 to 1)\n * - u_imageY (float): Pans the image vertically behind the effect; 0 is centred (-1 to 1)\n *\n * Vertex shader outputs (used in fragment shader):\n * - v_imageUV (vec2): Image UV coordinates with global sizing (rotation, scale, offset, etc) applied\n *\n * Vertex shader uniforms:\n * - u_resolution (vec2): Canvas resolution in pixels\n * - u_pixelRatio (float): Device pixel ratio\n * - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)\n * - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)\n * - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)\n * - u_scale (float): Overall zoom level of the graphics (0.01 to 4)\n * - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)\n * - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)\n * - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)\n * - u_imageAspectRatio (float): Aspect ratio of the source image\n *\n */\n\n// language=GLSL\nexport const lensDistortionFragmentShader: string = `#version 300 es\nprecision mediump float;\n\nuniform sampler2D u_image;\nuniform float u_imageAspectRatio;\nuniform float u_spread;\nuniform float u_bias;\nuniform float u_angle;\nuniform float u_perspective;\nuniform float u_count;\nuniform float u_dispersion;\nuniform float u_dispersionShift;\nuniform float u_dispersionColor;\nuniform float u_focusCenter;\nuniform float u_focusEdges;\nuniform float u_swirl;\nuniform float u_noise;\nuniform float u_noiseFrequency;\nuniform float u_noiseOffset;\nuniform float u_lensBulge;\nuniform float u_lensCircle;\nuniform float u_grainMixer;\nuniform float u_grainOverlay;\nuniform float u_imageX;\nuniform float u_imageY;\n\nin vec2 v_imageUV;\n\nout vec4 fragColor;\n\n${declarePI}\n${proceduralHash21}\n${rotation2}\n\nfloat valueNoise(vec2 st) {\n vec2 i = floor(st);\n vec2 f = fract(st);\n float a = hash21(i);\n float b = hash21(i + vec2(1., 0.));\n float c = hash21(i + vec2(0., 1.));\n float d = hash21(i + vec2(1., 1.));\n vec2 u = f * f * (3. - 2. * f);\n return mix(mix(a, b, u.x), mix(c, d, u.x), u.y);\n}\n\nfloat getUvFrame(vec2 uv) {\n vec2 invAA = 1. / clamp(fwidth(uv), 1e-5, .02);\n vec2 lo = clamp(uv * invAA + .5, 0., 1.);\n vec2 hi = clamp((1. - uv) * invAA + .5, 0., 1.);\n return lo.x * hi.x * lo.y * hi.y;\n}\n\nvec4 sampleOverWhite(vec2 uv) {\n vec4 img = texture(u_image, uv);\n float cover = img.a * getUvFrame(uv);\n vec3 colorOverWhite = mix(vec3(1.), img.rgb, cover);\n return vec4(colorOverWhite, cover);\n}\n\nvec3 hueColor(float hue) {\n vec3 rgb = clamp(abs(mod(hue * 6. + vec3(0., 4., 2.), 6.) - 3.) - 1., 0., 1.);\n rgb = rgb * rgb * (3. - 2. * rgb);\n return rgb;\n}\n \nfloat boxInradius() {\n return .5 * min(u_imageAspectRatio, 1.);\n}\n\nfloat boxOutradius() {\n return .5 * length(vec2(u_imageAspectRatio, 1.));\n}\n\nfloat spreadReach() {\n return .7 * pow(u_spread, 1.3 + 2.7 * u_spread);\n}\n\nfloat innerCircleMask(float radius, float inradius) {\n return 1. - smoothstep(.5 * inradius, 1.1 * inradius, radius);\n}\n\nfloat dispersionCurve(float t, float biasPow) {\n float mirroredT = u_bias < 0. ? 1. - t : t;\n float curved = pow(mirroredT, biasPow);\n return u_bias < 0. ? 1. - curved : curved;\n}\n\nvec2 getSpread(vec2 fromCenter, float radius, vec2 warpedUV, float edgeAA, float inradius, float outradius, float reach, out float outStrength) {\n float angleRad = radians(u_angle);\n vec2 uniformDir = vec2(cos(angleRad), sin(angleRad));\n\n float invInradius = 1. / inradius;\n vec2 radialDir = fromCenter * invInradius;\n float maxLen = (outradius + reach) * invInradius;\n float radialLen = radius * invInradius;\n if (radialLen > maxLen) radialDir *= maxLen / radialLen;\n vec2 spreadDir = mix(uniformDir, radialDir, u_perspective);\n\n float bandProximity = smoothstep(inradius * .8, inradius, radius);\n float lensCircleMaxing = bandProximity * u_lensCircle * u_lensCircle * u_lensCircle;\n spreadDir = mix(spreadDir, radialDir, lensCircleMaxing);\n\n vec2 warpedAbs = abs(warpedUV - .5);\n float inner = mix(1., smoothstep(0., mix(inradius, outradius, u_focusCenter), radius), u_focusCenter);\n float boxDist = max(warpedAbs.x, warpedAbs.y) * 2.;\n float outer = mix(1., 1. - min(boxDist, 1.), u_focusEdges);\n float strength = inner * outer;\n\n strength *= mix(1., mix(.15, .03, max(-u_lensBulge, 0.)), lensCircleMaxing);\n\n vec2 outside = max(warpedAbs - .5, 0.);\n float margin = max(reach * length(spreadDir) * (1. - u_lensCircle), edgeAA);\n strength *= 1. - smoothstep(0., margin, length(outside));\n\n outStrength = strength;\n vec2 axis = spreadDir * (reach * strength);\n\n if (u_noise > 0.) {\n float turn = (valueNoise(fromCenter * u_noiseFrequency * 18. + u_noiseOffset) - .5) * 2. * u_noise;\n float cs = cos(turn), sn = sin(turn);\n axis = mat2(cs, -sn, sn, cs) * axis;\n }\n\n axis.x /= u_imageAspectRatio;\n return axis;\n}\n\nvec2 lensWarp(vec2 fromCenter, float radius, float inradius, out float bulgeFade) {\n bulgeFade = 1.;\n if (u_lensBulge == 0. && u_lensCircle <= 0.) return fromCenter;\n if (radius < 1e-5) return fromCenter;\n \n float r = radius;\n\n if (u_lensBulge != 0.) {\n float rn = radius / inradius;\n float bulge = abs(u_lensBulge) * (u_lensBulge > 0. ? 1.4 : 1.2);\n if (u_lensBulge > 0.) bulgeFade = 1. - smoothstep(1.45, 1.53, rn * bulge);\n float map = u_lensBulge > 0.\n ? tan(min(rn * bulge, 1.53)) / tan(bulge)\n : atan(rn * tan(bulge)) / bulge;\n float bulgeScale = map / rn;\n fromCenter *= bulgeScale;\n r *= bulgeScale;\n }\n\n if (u_lensCircle > 0.) {\n vec2 dir = fromCenter / max(r, 1e-5);\n vec2 halfBox = vec2(u_imageAspectRatio, 1.) * .5;\n float rBox = min(halfBox.x / max(abs(dir.x), 1e-4), halfBox.y / max(abs(dir.y), 1e-4));\n float band = inradius * mix(.03, .2, .5 * (u_lensBulge + 1.));\n float innerEdge = inradius - band;\n float over = smoothstep(0., 1., (r - innerEdge) / band);\n float g = r + (rBox - inradius) * pow(over, 14.);\n fromCenter = dir * mix(r, g, u_lensCircle);\n }\n\n return fromCenter;\n}\n\nvoid main() {\n vec2 uv = v_imageUV;\n\n float invAspect = 1. / u_imageAspectRatio;\n float inradius = boxInradius();\n float outradius = boxOutradius();\n float reach = spreadReach();\n\n vec2 fromCenter = uv - .5;\n fromCenter.x *= u_imageAspectRatio;\n float radius = length(fromCenter);\n\n float bulgeFade;\n vec2 warpedFromCenter = lensWarp(fromCenter, radius, inradius, bulgeFade);\n vec2 baseUV = vec2(warpedFromCenter.x * invAspect, warpedFromCenter.y) + .5;\n\n vec2 baseDerivative = fwidth(baseUV);\n float edgeAA = clamp(2. * max(baseDerivative.x, baseDerivative.y), .001, .02);\n\n float spreadStrength;\n vec2 spreadAxis = getSpread(fromCenter, radius, baseUV, edgeAA, inradius, outradius, reach, spreadStrength);\n\n vec2 grainUV = vec2(0.);\n if (u_grainMixer > 0. || u_grainOverlay > 0.) {\n vec2 dudx = dFdx(v_imageUV);\n vec2 dudy = dFdy(v_imageUV);\n grainUV = (v_imageUV - .5) * (.8 / vec2(length(dudx), length(dudy))) + .5;\n }\n\n if (u_grainMixer > 0.) {\n float grainSeed = valueNoise(grainUV);\n vec2 jit = fract(grainSeed * vec2(157.31, 113.57)) * 2. - 1.;\n spreadAxis += jit * .3 * u_grainMixer * length(spreadAxis);\n }\n\n float count = floor(u_count);\n int countInteger = int(count);\n\n float invCount = 1. / count;\n float invSpan = 1. / max(count - 1., 1.);\n float hueBase = u_dispersionColor + .5;\n float biasPower = 1. + 2. * abs(u_bias);\n vec2 tapBias = .5 - vec2(u_imageX, u_imageY);\n\n float centerAmount = clamp(1. - u_dispersionShift, 0., 1.);\n float edgesAmount = clamp(1. + u_dispersionShift, 0., 1.);\n float dispersion = u_dispersion * mix(edgesAmount, centerAmount, innerCircleMask(radius, inradius));\n float dispersionPower = pow(dispersion, .8);\n\n float warpedRadius = length(warpedFromCenter);\n float swirlAngle = u_swirl * .4 * PI * spreadStrength * u_spread * min(1., inradius / max(warpedRadius, 1e-4));\n\n vec3 colorSum = vec3(0.);\n vec3 weightSum = vec3(0.);\n float coverSum = 0.;\n\n for (int i = 0; i < ${lensDistortionMeta.maxSamples}; i++) {\n if (i >= countInteger) break;\n\n float layer = float(i);\n float hue = hueBase + layer * invCount;\n\n float spread = layer * invSpan;\n if (u_bias != 0.) spread = dispersionCurve(spread, biasPower);\n\n // mix(axis, -axis, spread) is axis scaled by the signed position along the fan\n float fanPos = 1. - 2. * spread;\n vec2 tapUV = baseUV + spreadAxis * fanPos - .5;\n\n if (u_swirl != 0.) {\n tapUV.x *= u_imageAspectRatio;\n tapUV = rotate(tapUV, swirlAngle * fanPos);\n tapUV.x *= invAspect;\n }\n\n vec4 tap = sampleOverWhite(tapUV + tapBias);\n vec3 weight = 1. - dispersionPower * hueColor(hue);\n\n colorSum += tap.rgb * weight;\n weightSum += weight;\n coverSum += tap.a;\n }\n\n vec3 color = colorSum / max(weightSum, 1e-4);\n float coverAvg = coverSum * invCount;\n\n float ground = min(color.r, min(color.g, color.b));\n float alpha = max(coverAvg, 1. - ground);\n vec3 premult = max(color - (1. - alpha), 0.);\n fragColor = vec4(premult, alpha) * bulgeFade;\n\n if (u_grainOverlay > 0.) {\n float grain = valueNoise(rotate(grainUV, 1.) + vec2(3.));\n grain = mix(grain, valueNoise(rotate(grainUV, 2.) + vec2(-1.)), .5);\n grain = pow(grain, 1.3);\n float grainV = grain * 2. - 1.;\n float grainStrength = pow(u_grainOverlay * abs(grainV), .8) * fragColor.a;\n fragColor.rgb = mix(fragColor.rgb, vec3(step(0., grainV)) * fragColor.a, .35 * grainStrength);\n }\n}\n`;\n\nexport interface LensDistortionUniforms extends ShaderSizingUniforms {\n u_image: HTMLImageElement | string | undefined;\n u_spread: number;\n u_bias: number;\n u_angle: number;\n u_perspective: number;\n u_count: number;\n u_dispersion: number;\n u_dispersionShift: number;\n u_dispersionColor: number;\n u_focusCenter: number;\n u_focusEdges: number;\n u_swirl: number;\n u_noise: number;\n u_noiseFrequency: number;\n u_noiseOffset: number;\n u_lensBulge: number;\n u_lensCircle: number;\n u_grainMixer: number;\n u_grainOverlay: number;\n u_imageX: number;\n u_imageY: number;\n}\n\nexport interface LensDistortionParams extends ShaderSizingParams, ShaderMotionParams {\n image?: HTMLImageElement | string;\n spread?: number;\n bias?: number;\n angle?: number;\n perspective?: number;\n count?: number;\n dispersion?: number;\n dispersionShift?: number;\n dispersionColor?: number;\n focusCenter?: number;\n focusEdges?: number;\n swirl?: number;\n noise?: number;\n noiseFrequency?: number;\n noiseOffset?: number;\n lensBulge?: number;\n lensCircle?: number;\n grainMixer?: number;\n grainOverlay?: number;\n imageX?: number;\n imageY?: number;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;AACA,eAAmE;AACnE,SAAS,WAAW,kBAAkB,iBAAiB;AAEhD,MAAM,qBAAqB;AAAA,EAChC,YAAY;AACd;AAiDO,MAAM,+BAAuC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EA8BlD,SAAS;AAAA,EACT,gBAAgB;AAAA,EAChB,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,wBAwLa,mBAAmB,UAAU;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|