shaders-oneshot 0.0.81-shared.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 +201 -0
- package/NOTICE +5 -0
- package/README.md +7 -0
- package/dist/empty-pixel.d.ts +1 -0
- package/dist/empty-pixel.js +10 -0
- package/dist/empty-pixel.js.map +7 -0
- package/dist/get-shader-color-from-string.d.ts +3 -0
- package/dist/get-shader-color-from-string.js +101 -0
- package/dist/get-shader-color-from-string.js.map +7 -0
- package/dist/get-shader-color-from-string.test.d.ts +1 -0
- package/dist/get-shader-color-from-string.test.js +69 -0
- package/dist/get-shader-noise-texture.d.ts +1 -0
- package/dist/get-shader-noise-texture.js +18 -0
- package/dist/get-shader-noise-texture.js.map +7 -0
- package/dist/index.d.ts +68 -0
- package/dist/index.js +194 -0
- package/dist/index.js.map +7 -0
- package/dist/shader-color-spaces.d.ts +6 -0
- package/dist/shader-color-spaces.js +96 -0
- package/dist/shader-color-spaces.js.map +7 -0
- package/dist/shader-mount.d.ts +199 -0
- package/dist/shader-mount.js +735 -0
- package/dist/shader-mount.js.map +7 -0
- package/dist/shader-sizing.d.ts +30 -0
- package/dist/shader-sizing.js +38 -0
- package/dist/shader-sizing.js.map +7 -0
- package/dist/shader-utils.d.ts +10 -0
- package/dist/shader-utils.js +131 -0
- package/dist/shader-utils.js.map +7 -0
- package/dist/shaders/color-panels.d.ts +70 -0
- package/dist/shaders/color-panels.js +224 -0
- package/dist/shaders/color-panels.js.map +7 -0
- package/dist/shaders/dithering.d.ts +62 -0
- package/dist/shaders/dithering.js +271 -0
- package/dist/shaders/dithering.js.map +7 -0
- package/dist/shaders/dot-grid.d.ts +65 -0
- package/dist/shaders/dot-grid.js +110 -0
- package/dist/shaders/dot-grid.js.map +7 -0
- package/dist/shaders/dot-orbit.d.ts +57 -0
- package/dist/shaders/dot-orbit.js +123 -0
- package/dist/shaders/dot-orbit.js.map +7 -0
- package/dist/shaders/fluted-glass.d.ts +112 -0
- package/dist/shaders/fluted-glass.js +361 -0
- package/dist/shaders/fluted-glass.js.map +7 -0
- package/dist/shaders/gem-smoke.d.ts +96 -0
- package/dist/shaders/gem-smoke.js +573 -0
- package/dist/shaders/gem-smoke.js.map +7 -0
- package/dist/shaders/god-rays.d.ts +67 -0
- package/dist/shaders/god-rays.js +133 -0
- package/dist/shaders/god-rays.js.map +7 -0
- package/dist/shaders/grain-gradient.d.ts +80 -0
- package/dist/shaders/grain-gradient.js +301 -0
- package/dist/shaders/grain-gradient.js.map +7 -0
- package/dist/shaders/halftone-cmyk.d.ts +104 -0
- package/dist/shaders/halftone-cmyk.js +295 -0
- package/dist/shaders/halftone-cmyk.js.map +7 -0
- package/dist/shaders/halftone-dots.d.ts +80 -0
- package/dist/shaders/halftone-dots.js +321 -0
- package/dist/shaders/halftone-dots.js.map +7 -0
- package/dist/shaders/heatmap.d.ts +66 -0
- package/dist/shaders/heatmap.js +384 -0
- package/dist/shaders/heatmap.js.map +7 -0
- package/dist/shaders/image-dithering.d.ts +64 -0
- package/dist/shaders/image-dithering.js +199 -0
- package/dist/shaders/image-dithering.js.map +7 -0
- package/dist/shaders/lens-distortion.d.ts +97 -0
- package/dist/shaders/lens-distortion.js +276 -0
- package/dist/shaders/lens-distortion.js.map +7 -0
- package/dist/shaders/liquid-metal.d.ts +89 -0
- package/dist/shaders/liquid-metal.js +633 -0
- package/dist/shaders/liquid-metal.js.map +7 -0
- package/dist/shaders/mesh-gradient.d.ts +52 -0
- package/dist/shaders/mesh-gradient.js +131 -0
- package/dist/shaders/mesh-gradient.js.map +7 -0
- package/dist/shaders/metaballs.d.ts +51 -0
- package/dist/shaders/metaballs.js +111 -0
- package/dist/shaders/metaballs.js.map +7 -0
- package/dist/shaders/neuro-noise.d.ts +47 -0
- package/dist/shaders/neuro-noise.js +77 -0
- package/dist/shaders/neuro-noise.js.map +7 -0
- package/dist/shaders/paper-texture.d.ts +109 -0
- package/dist/shaders/paper-texture.js +527 -0
- package/dist/shaders/paper-texture.js.map +7 -0
- package/dist/shaders/perlin-noise.d.ts +52 -0
- package/dist/shaders/perlin-noise.js +167 -0
- package/dist/shaders/perlin-noise.js.map +7 -0
- package/dist/shaders/pulsing-border.d.ts +98 -0
- package/dist/shaders/pulsing-border.js +239 -0
- package/dist/shaders/pulsing-border.js.map +7 -0
- package/dist/shaders/simplex-noise.d.ts +45 -0
- package/dist/shaders/simplex-noise.js +92 -0
- package/dist/shaders/simplex-noise.js.map +7 -0
- package/dist/shaders/smoke-ring.d.ts +61 -0
- package/dist/shaders/smoke-ring.js +133 -0
- package/dist/shaders/smoke-ring.js.map +7 -0
- package/dist/shaders/spiral.d.ts +61 -0
- package/dist/shaders/spiral.js +83 -0
- package/dist/shaders/spiral.js.map +7 -0
- package/dist/shaders/static-mesh-gradient.d.ts +63 -0
- package/dist/shaders/static-mesh-gradient.js +131 -0
- package/dist/shaders/static-mesh-gradient.js.map +7 -0
- package/dist/shaders/static-radial-gradient.d.ts +72 -0
- package/dist/shaders/static-radial-gradient.js +188 -0
- package/dist/shaders/static-radial-gradient.js.map +7 -0
- package/dist/shaders/swirl.d.ts +63 -0
- package/dist/shaders/swirl.js +104 -0
- package/dist/shaders/swirl.js.map +7 -0
- package/dist/shaders/voronoi.d.ts +65 -0
- package/dist/shaders/voronoi.js +139 -0
- package/dist/shaders/voronoi.js.map +7 -0
- package/dist/shaders/warp.d.ts +70 -0
- package/dist/shaders/warp.js +130 -0
- package/dist/shaders/warp.js.map +7 -0
- package/dist/shaders/water.d.ts +59 -0
- package/dist/shaders/water.js +122 -0
- package/dist/shaders/water.js.map +7 -0
- package/dist/shaders/waves.d.ts +53 -0
- package/dist/shaders/waves.js +66 -0
- package/dist/shaders/waves.js.map +7 -0
- package/dist/shared-webgl-renderer.d.ts +63 -0
- package/dist/shared-webgl-renderer.js +262 -0
- package/dist/shared-webgl-renderer.js.map +7 -0
- package/dist/types.d.ts +3 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +7 -0
- package/dist/vertex-shader.d.ts +2 -0
- package/dist/vertex-shader.js +160 -0
- package/dist/vertex-shader.js.map +7 -0
- package/package.json +29 -0
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import type { ShaderMotionParams } from '../shader-mount.js';
|
|
2
|
+
import { type ShaderSizingParams, type ShaderSizingUniforms } from '../shader-sizing.js';
|
|
3
|
+
export declare const paperTextureMeta: {
|
|
4
|
+
readonly maxCrumpleCount: 15;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* Static paper-like texture built from a combination of grain, noise and multiple fold patterns.
|
|
8
|
+
* Works as an image filter or as a standalone texture.
|
|
9
|
+
*
|
|
10
|
+
* Fragment shader uniforms:
|
|
11
|
+
* - u_image (sampler2D): Optional source image texture
|
|
12
|
+
* - u_isImage (bool): Whether a source image was provided
|
|
13
|
+
* - u_imageAspectRatio (float): Aspect ratio of the source image
|
|
14
|
+
* - u_colorBack (vec4): Color behind the paper sheet in RGBA
|
|
15
|
+
* - u_colorPaper (vec4): Color of the paper sheet in RGBA
|
|
16
|
+
* - u_colorShadow (vec4): Color of the patterns over the paper sheet in RGBA
|
|
17
|
+
* - u_blending (float): Amount of image-to-paper blending, needs image (0 to 1)
|
|
18
|
+
* - u_distortion (float): How much the image bends with the paper surface, needs image (-1 to 1)
|
|
19
|
+
* - u_clip (bool): Cuts the paper sheet to the image frame, needs image
|
|
20
|
+
* - u_angle (float): Direction the surface is lit from in degrees, also the roughness rows direction, needs crumples, wrinkles, folds, roughnessRows or drops > 0 (0 to 360)
|
|
21
|
+
* - u_seed (float): Seed applied to every pattern (0 to 1000)
|
|
22
|
+
* - u_roughness (float): Fine grain covering the surface evenly (0 to 1)
|
|
23
|
+
* - u_roughnessSize (float): Scale of the roughness grain, needs roughness > 0 (0 to 1)
|
|
24
|
+
* - u_roughnessRows (float): Lines the roughness up into stripes, 0 = even scatter, 1 = laid-paper rows, needs roughness > 0 (0 to 1)
|
|
25
|
+
* - u_fiber (float): Curly thread-like noise covering the surface evenly (0 to 1)
|
|
26
|
+
* - u_fiberSize (float): Scale of the fiber noise, needs fiber > 0 (0 to 1)
|
|
27
|
+
* - u_folds (float): Straight vertical and horizontal fold lines producing ridges and valleys (0 to 1)
|
|
28
|
+
* - u_foldSizeX (float): Size of the vertical folds, needs folds > 0 (0 to 1)
|
|
29
|
+
* - u_foldSizeY (float): Size of the horizontal folds, needs folds > 0 (0 to 1)
|
|
30
|
+
* - u_foldOffsetX (float): Shifts the vertical folds across the surface, needs folds > 0 (0 to 1)
|
|
31
|
+
* - u_foldOffsetY (float): Shifts the horizontal folds across the surface, needs folds > 0 (0 to 1)
|
|
32
|
+
* - u_wrinkles (float): Crumple-like facets repeating across the surface (0 to 1)
|
|
33
|
+
* - u_wrinkleSize (float): Scale of the wrinkle facets, needs wrinkles > 0 (0 to 1)
|
|
34
|
+
* - u_crumples (float): A set of irregular folding lines (0 to 1)
|
|
35
|
+
* - u_crumpleCount (float): Number of facets in the crumple field, needs crumples > 0 (2 to 15)
|
|
36
|
+
* - u_drops (float): Visibility of the speckle pattern, darkens the image instead of coloring it (0 to 1)
|
|
37
|
+
* - u_noiseTexture (sampler2D): Pre-computed randomizer source texture
|
|
38
|
+
*
|
|
39
|
+
* Vertex shader outputs (used in fragment shader):
|
|
40
|
+
* - v_imageUV (vec2): UV coordinates for sampling the source image, with fit, scale, rotation, and offset applied
|
|
41
|
+
*
|
|
42
|
+
* Vertex shader uniforms:
|
|
43
|
+
* - u_resolution (vec2): Canvas resolution in pixels
|
|
44
|
+
* - u_pixelRatio (float): Device pixel ratio
|
|
45
|
+
* - u_originX (float): Reference point for positioning world width in the canvas (0 to 1)
|
|
46
|
+
* - u_originY (float): Reference point for positioning world height in the canvas (0 to 1)
|
|
47
|
+
* - u_fit (float): How to fit the rendered shader into the canvas dimensions (0 = none, 1 = contain, 2 = cover)
|
|
48
|
+
* - u_scale (float): Overall zoom level of the graphics (0.01 to 4)
|
|
49
|
+
* - u_rotation (float): Overall rotation angle of the graphics in degrees (0 to 360)
|
|
50
|
+
* - u_offsetX (float): Horizontal offset of the graphics center (-1 to 1)
|
|
51
|
+
* - u_offsetY (float): Vertical offset of the graphics center (-1 to 1)
|
|
52
|
+
* - u_imageAspectRatio (float): Aspect ratio of the source image
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
export declare const paperTextureFragmentShader: string;
|
|
56
|
+
export interface PaperTextureUniforms extends ShaderSizingUniforms {
|
|
57
|
+
u_image: HTMLImageElement | string | undefined;
|
|
58
|
+
u_isImage: boolean;
|
|
59
|
+
u_colorBack: [number, number, number, number];
|
|
60
|
+
u_colorPaper: [number, number, number, number];
|
|
61
|
+
u_colorShadow: [number, number, number, number];
|
|
62
|
+
u_blending: number;
|
|
63
|
+
u_distortion: number;
|
|
64
|
+
u_clip: boolean;
|
|
65
|
+
u_angle: number;
|
|
66
|
+
u_seed: number;
|
|
67
|
+
u_roughness: number;
|
|
68
|
+
u_roughnessSize: number;
|
|
69
|
+
u_roughnessRows: number;
|
|
70
|
+
u_fiber: number;
|
|
71
|
+
u_fiberSize: number;
|
|
72
|
+
u_folds: number;
|
|
73
|
+
u_foldSizeX: number;
|
|
74
|
+
u_foldSizeY: number;
|
|
75
|
+
u_foldOffsetX: number;
|
|
76
|
+
u_foldOffsetY: number;
|
|
77
|
+
u_wrinkles: number;
|
|
78
|
+
u_wrinkleSize: number;
|
|
79
|
+
u_crumples: number;
|
|
80
|
+
u_crumpleCount: number;
|
|
81
|
+
u_drops: number;
|
|
82
|
+
u_noiseTexture?: HTMLImageElement;
|
|
83
|
+
}
|
|
84
|
+
export interface PaperTextureParams extends ShaderSizingParams, ShaderMotionParams {
|
|
85
|
+
image?: HTMLImageElement | string;
|
|
86
|
+
colorBack?: string;
|
|
87
|
+
colorPaper?: string;
|
|
88
|
+
colorShadow?: string;
|
|
89
|
+
blending?: number;
|
|
90
|
+
distortion?: number;
|
|
91
|
+
clip?: boolean;
|
|
92
|
+
angle?: number;
|
|
93
|
+
seed?: number;
|
|
94
|
+
roughness?: number;
|
|
95
|
+
roughnessSize?: number;
|
|
96
|
+
roughnessRows?: number;
|
|
97
|
+
fiber?: number;
|
|
98
|
+
fiberSize?: number;
|
|
99
|
+
folds?: number;
|
|
100
|
+
foldSizeX?: number;
|
|
101
|
+
foldSizeY?: number;
|
|
102
|
+
foldOffsetX?: number;
|
|
103
|
+
foldOffsetY?: number;
|
|
104
|
+
wrinkles?: number;
|
|
105
|
+
wrinkleSize?: number;
|
|
106
|
+
crumples?: number;
|
|
107
|
+
crumpleCount?: number;
|
|
108
|
+
drops?: number;
|
|
109
|
+
}
|
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
|
2
|
+
* Paper Shaders *
|
|
3
|
+
* https://github.com/paper-design/shaders *
|
|
4
|
+
* * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
5
|
+
|
|
6
|
+
import {} from "../shader-sizing.js";
|
|
7
|
+
import { declarePI, proceduralHash21, proceduralHash22 } from "../shader-utils.js";
|
|
8
|
+
const paperTextureMeta = {
|
|
9
|
+
maxCrumpleCount: 15
|
|
10
|
+
};
|
|
11
|
+
const paperTextureFragmentShader = `#version 300 es
|
|
12
|
+
precision mediump float;
|
|
13
|
+
|
|
14
|
+
uniform sampler2D u_image;
|
|
15
|
+
uniform bool u_isImage;
|
|
16
|
+
uniform float u_imageAspectRatio;
|
|
17
|
+
|
|
18
|
+
uniform vec4 u_colorBack;
|
|
19
|
+
uniform vec4 u_colorPaper;
|
|
20
|
+
uniform vec4 u_colorShadow;
|
|
21
|
+
|
|
22
|
+
uniform float u_blending;
|
|
23
|
+
uniform float u_distortion;
|
|
24
|
+
uniform bool u_clip;
|
|
25
|
+
uniform float u_angle;
|
|
26
|
+
uniform float u_seed;
|
|
27
|
+
|
|
28
|
+
uniform float u_roughness;
|
|
29
|
+
uniform float u_roughnessSize;
|
|
30
|
+
uniform float u_roughnessRows;
|
|
31
|
+
uniform float u_fiber;
|
|
32
|
+
uniform float u_fiberSize;
|
|
33
|
+
uniform float u_folds;
|
|
34
|
+
uniform float u_foldSizeX;
|
|
35
|
+
uniform float u_foldSizeY;
|
|
36
|
+
uniform float u_foldOffsetX;
|
|
37
|
+
uniform float u_foldOffsetY;
|
|
38
|
+
uniform float u_wrinkles;
|
|
39
|
+
uniform float u_wrinkleSize;
|
|
40
|
+
uniform float u_crumples;
|
|
41
|
+
uniform float u_crumpleCount;
|
|
42
|
+
uniform float u_drops;
|
|
43
|
+
|
|
44
|
+
uniform sampler2D u_noiseTexture;
|
|
45
|
+
|
|
46
|
+
in vec2 v_imageUV;
|
|
47
|
+
out vec4 fragColor;
|
|
48
|
+
|
|
49
|
+
float getUvFrame(vec2 uv) {
|
|
50
|
+
vec2 invAA = .5 / clamp(fwidth(uv), 1e-5, .02);
|
|
51
|
+
vec2 lo = clamp(uv * invAA + .5, 0., 1.);
|
|
52
|
+
vec2 hi = clamp((1. - uv) * invAA + .5, 0., 1.);
|
|
53
|
+
return lo.x * hi.x * lo.y * hi.y;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
float lst(float edge0, float edge1, float x) {
|
|
57
|
+
return clamp((x - edge0) / (edge1 - edge0), 0.0, 1.0);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
${declarePI}
|
|
61
|
+
${proceduralHash21}
|
|
62
|
+
${proceduralHash22}
|
|
63
|
+
|
|
64
|
+
float getRoughness(vec2 p, vec2 lightDir, vec2 seedShift, float basePixel) {
|
|
65
|
+
vec2 u = p / vec2(2, 4);
|
|
66
|
+
float w = 100. * basePixel;
|
|
67
|
+
float eps = 4. * w;
|
|
68
|
+
|
|
69
|
+
float size = mix(3.2, .8, u_roughnessSize);
|
|
70
|
+
float logLac = log2(2.1);
|
|
71
|
+
float level = -log2(w + 1e-8) / logLac;
|
|
72
|
+
float baseLevel = floor(level) - 2.;
|
|
73
|
+
float fade = fract(level);
|
|
74
|
+
|
|
75
|
+
vec2 px = (u.x + vec2(eps, -eps)) * .1;
|
|
76
|
+
float py = u.y * .1;
|
|
77
|
+
|
|
78
|
+
vec2 sum = vec2(0.);
|
|
79
|
+
float norm = 0., amp = .5;
|
|
80
|
+
float freq = exp2(baseLevel * logLac);
|
|
81
|
+
for (int i = 0; i < 4; i++) {
|
|
82
|
+
float absIdx = baseLevel + float(i);
|
|
83
|
+
vec2 qx = size * px * freq;
|
|
84
|
+
float qy = size * py * freq;
|
|
85
|
+
|
|
86
|
+
float wi = 1.;
|
|
87
|
+
if (i == 0) wi = 1. - fade;
|
|
88
|
+
if (i == 3) wi = fade;
|
|
89
|
+
|
|
90
|
+
vec2 fx = fract(qx);
|
|
91
|
+
float fy = fract(qy);
|
|
92
|
+
vec2 shift = .5 + absIdx * .3 + seedShift;
|
|
93
|
+
float uvY = floor(qy) / 50. + shift.y;
|
|
94
|
+
vec2 s0a = textureLod(u_noiseTexture, fract(vec2(floor(qx.x) / 50. + shift.x, uvY)), 0.).rg;
|
|
95
|
+
vec2 s1a = textureLod(u_noiseTexture, fract(vec2( ceil(qx.x) / 50. + shift.x, uvY)), 0.).rg;
|
|
96
|
+
vec2 s0b = textureLod(u_noiseTexture, fract(vec2(floor(qx.y) / 50. + shift.x, uvY)), 0.).rg;
|
|
97
|
+
vec2 s1b = textureLod(u_noiseTexture, fract(vec2( ceil(qx.y) / 50. + shift.x, uvY)), 0.).rg;
|
|
98
|
+
vec2 ny0 = mix(vec2(s0a.r, s0b.r), vec2(s0a.g, s0b.g), fy);
|
|
99
|
+
vec2 ny1 = mix(vec2(s1a.r, s1b.r), vec2(s1a.g, s1b.g), fy);
|
|
100
|
+
vec2 n = mix(ny0, ny1, fx);
|
|
101
|
+
|
|
102
|
+
sum += amp * wi * n;
|
|
103
|
+
norm += amp * wi;
|
|
104
|
+
amp *= .8;
|
|
105
|
+
freq *= 2.1;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
vec2 r = sum / norm;
|
|
109
|
+
float dx = .5 + r.x - r.y;
|
|
110
|
+
float grain = 3. * dx * dx - .7;
|
|
111
|
+
|
|
112
|
+
float rowBand = fract(dot(p, lightDir) * .05 * size);
|
|
113
|
+
return grain + .6 * u_roughnessRows * (rowBand - .5);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
float getFiber(vec2 p, vec2 seedShift, float basePixel) {
|
|
117
|
+
float size = mix(4., 1., u_fiberSize);
|
|
118
|
+
float w = 50. * basePixel;
|
|
119
|
+
float level = -log2(w + 1e-8);
|
|
120
|
+
float baseLevel = floor(level) - 3.;
|
|
121
|
+
float fade = fract(level);
|
|
122
|
+
|
|
123
|
+
vec2 grad = vec2(0.);
|
|
124
|
+
float scale = 1.;
|
|
125
|
+
float amp = 1.;
|
|
126
|
+
float freq = pow(1.7, baseLevel);
|
|
127
|
+
for (int i = 0; i < 5; i++) {
|
|
128
|
+
float absIdx = baseLevel + float(i);
|
|
129
|
+
vec2 q = size * p * freq;
|
|
130
|
+
|
|
131
|
+
float an = absIdx * .8;
|
|
132
|
+
float rc = cos(an), rs = sin(an);
|
|
133
|
+
q = vec2(rc * q.x - rs * q.y, rs * q.x + rc * q.y);
|
|
134
|
+
|
|
135
|
+
float wi = 1.;
|
|
136
|
+
if (i == 0) wi = 1. - fade;
|
|
137
|
+
if (i == 4) wi = fade;
|
|
138
|
+
|
|
139
|
+
vec2 iq = floor(q);
|
|
140
|
+
vec2 fq = fract(q);
|
|
141
|
+
float shift = absIdx * .3;
|
|
142
|
+
vec4 uv = fract(vec4(iq, iq + 1.) / 50. + .5 + shift + seedShift.xyxy);
|
|
143
|
+
float aF = textureLod(u_noiseTexture, uv.xy, 0.).b;
|
|
144
|
+
float bF = textureLod(u_noiseTexture, uv.zy, 0.).b;
|
|
145
|
+
float cF = textureLod(u_noiseTexture, uv.xw, 0.).b;
|
|
146
|
+
float dF = textureLod(u_noiseTexture, uv.zw, 0.).b;
|
|
147
|
+
vec2 u = fq * fq * (3. - 2. * fq);
|
|
148
|
+
vec2 du = 8. * fq * (1. - fq);
|
|
149
|
+
float dx = du.x * mix(bF - aF, dF - cF, u.y);
|
|
150
|
+
float dy = du.y * mix(cF - aF, dF - bF, u.x);
|
|
151
|
+
grad += wi * amp * scale * vec2(rc * dx + rs * dy, -rs * dx + rc * dy);
|
|
152
|
+
scale *= 1.7;
|
|
153
|
+
amp *= .5;
|
|
154
|
+
freq *= 1.7;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return clamp(.333 * length(grad), 0., 1.);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
vec2 smoothNoise(vec2 p) {
|
|
161
|
+
vec2 t = p * 50. - .5;
|
|
162
|
+
vec2 i = floor(t);
|
|
163
|
+
vec2 f = fract(t);
|
|
164
|
+
f = f * f * (3. - 2. * f);
|
|
165
|
+
return textureLod(u_noiseTexture, fract((i + f + .5) / vec2(50.)), 0.).rg;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
float getDrops(vec2 uv, vec2 seedShift) {
|
|
169
|
+
vec2 iDropsUV = floor(uv);
|
|
170
|
+
vec2 fDropsUV = fract(uv);
|
|
171
|
+
float dropsMinDist = 1.;
|
|
172
|
+
for (int y = -1; y < 2; y += 1) {
|
|
173
|
+
for (int x = -1; x < 2; x += 1) {
|
|
174
|
+
vec2 neighbor = vec2(float(y), float(x));
|
|
175
|
+
vec2 offset = hash22(iDropsUV + neighbor + 50. * seedShift);
|
|
176
|
+
vec2 pos = neighbor + offset - fDropsUV;
|
|
177
|
+
dropsMinDist *= min(1., dot(pos, pos));
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
return .5 * lst(.09, .08, sqrt(sqrt(dropsMinDist)));
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
vec2 getCellTilt(float idx, float radius) {
|
|
184
|
+
vec2 rand = hash22(vec2(idx + 31., idx * u_seed + 17.));
|
|
185
|
+
float an = rand.x * TWO_PI;
|
|
186
|
+
return vec2(cos(an), sin(an)) * mix(.3, 1.7, rand.y * rand.y) * mix(.7, 1., radius);
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
vec2 getCrumpleDetail(vec2 uv, float freq, float shift, float basePixel, out float depth) {
|
|
190
|
+
depth = 0.;
|
|
191
|
+
vec2 v = uv * freq;
|
|
192
|
+
float pixel = .9 * freq * basePixel;
|
|
193
|
+
vec2 base = floor(v);
|
|
194
|
+
float n1 = 9., n2 = 9.;
|
|
195
|
+
vec2 s1 = vec2(0.), s2 = vec2(0.), q1 = vec2(0.), q2 = vec2(0.);
|
|
196
|
+
|
|
197
|
+
for (int y = -1; y <= 1; y++) {
|
|
198
|
+
for (int x = -1; x <= 1; x++) {
|
|
199
|
+
vec2 cell = base + vec2(float(x), float(y));
|
|
200
|
+
vec2 q = hash22(vec2(cell.y * 1.9 + 3.1 + shift, cell.x * 1.3 + .11 * u_seed));
|
|
201
|
+
float keep = .8;
|
|
202
|
+
if (q.y > keep) continue;
|
|
203
|
+
|
|
204
|
+
vec2 r = hash22(vec2(cell.x + .37 * u_seed + shift + 11.1, cell.y - .21 * u_seed + 5.7));
|
|
205
|
+
vec2 s = cell + .06 + .88 * r;
|
|
206
|
+
|
|
207
|
+
vec2 d = v - s;
|
|
208
|
+
float dsq = dot(d, d);
|
|
209
|
+
if (dsq < n1) {
|
|
210
|
+
n2 = n1;
|
|
211
|
+
s2 = s1;
|
|
212
|
+
q2 = q1;
|
|
213
|
+
n1 = dsq;
|
|
214
|
+
s1 = s;
|
|
215
|
+
q1 = q;
|
|
216
|
+
} else if (dsq < n2) {
|
|
217
|
+
n2 = dsq;
|
|
218
|
+
s2 = s;
|
|
219
|
+
q2 = q;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
if (n1 > 8.) return vec2(0.);
|
|
225
|
+
|
|
226
|
+
float an1 = q1.x * TWO_PI, mag1 = q1.y / .8;
|
|
227
|
+
vec2 t1 = vec2(cos(an1), sin(an1)) * mix(.3, 1.7, mag1 * mag1);
|
|
228
|
+
float an2 = q2.x * TWO_PI, mag2 = q2.y / .8;
|
|
229
|
+
vec2 t2 = vec2(cos(an2), sin(an2)) * mix(.3, 1.7, mag2 * mag2);
|
|
230
|
+
|
|
231
|
+
vec2 span = s1 - s2;
|
|
232
|
+
float spanLen = max(length(span), 1e-4);
|
|
233
|
+
float toEdge = (n2 - n1) / (2. * spanLen);
|
|
234
|
+
|
|
235
|
+
float pair = hash21(s1 + s2 + 1.7 * abs(s1 - s2));
|
|
236
|
+
float pairSoft = .05 + .1 * step(pair, .4);
|
|
237
|
+
float b = clamp(toEdge / max(1.5 * pixel, .5 * pairSoft), 0., 1.);
|
|
238
|
+
b = b * b * (3. - 2. * b);
|
|
239
|
+
float d1 = max(sqrt(n1), 1e-4);
|
|
240
|
+
depth = .2 * d1;
|
|
241
|
+
float shoulderAmt = max(0., 1. - toEdge / .42) * b;
|
|
242
|
+
vec2 shoulder = vec2(0.);
|
|
243
|
+
if (shoulderAmt > 0.) {
|
|
244
|
+
float d2 = max(sqrt(n2), 1e-4);
|
|
245
|
+
shoulder = shoulderAmt * ((v - s2) / d2 - (v - s1) / d1);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
vec2 mid = .5 * (t1 + t2);
|
|
249
|
+
return mid + (t1 - mid) * b + .9 * shoulder;
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
vec4 getCrumples(vec2 uv) {
|
|
253
|
+
float crumpleN = max(2., floor(u_crumpleCount + .5));
|
|
254
|
+
float near = 60000., nearB = 60000.;
|
|
255
|
+
float idx = 0., rad = 0.;
|
|
256
|
+
vec2 nearP = vec2(0.), nearPb = vec2(0.);
|
|
257
|
+
vec4 seeds[${paperTextureMeta.maxCrumpleCount}];
|
|
258
|
+
for (int i = 0; i < ${paperTextureMeta.maxCrumpleCount}; i++) {
|
|
259
|
+
if (float(i) >= crumpleN) break;
|
|
260
|
+
vec2 rand = hash22(vec2(float(i), float(i) * u_seed));
|
|
261
|
+
float an = rand.x * TWO_PI;
|
|
262
|
+
vec2 p = vec2(cos(an), sin(an)) * rand.y;
|
|
263
|
+
seeds[i] = vec4(p, rand);
|
|
264
|
+
|
|
265
|
+
vec2 d = uv - p;
|
|
266
|
+
float dsq = dot(d, d);
|
|
267
|
+
if (dsq < near) {
|
|
268
|
+
nearB = near;
|
|
269
|
+
nearPb = nearP;
|
|
270
|
+
near = dsq;
|
|
271
|
+
idx = float(i);
|
|
272
|
+
rad = rand.y;
|
|
273
|
+
nearP = p;
|
|
274
|
+
} else if (dsq < nearB) {
|
|
275
|
+
nearB = dsq;
|
|
276
|
+
nearPb = p;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
float l = sqrt(near), lb = sqrt(nearB);
|
|
280
|
+
vec2 dir = (uv - nearP) / max(l, 1e-4);
|
|
281
|
+
float edge = lst(0., .5, lb - l);
|
|
282
|
+
|
|
283
|
+
float shoulderLimit = l + .5;
|
|
284
|
+
|
|
285
|
+
vec2 tilt = getCellTilt(idx, rad);
|
|
286
|
+
float tiltSum = 1.;
|
|
287
|
+
vec2 wide = vec2(0.);
|
|
288
|
+
float wideSum = 0.;
|
|
289
|
+
float toEdge = 9., edgeSoft = 0.;
|
|
290
|
+
|
|
291
|
+
for (int i = 0; i < ${paperTextureMeta.maxCrumpleCount}; i++) {
|
|
292
|
+
if (float(i) >= crumpleN) break;
|
|
293
|
+
if (float(i) == idx) continue;
|
|
294
|
+
vec4 seed = seeds[i];
|
|
295
|
+
vec2 p = seed.xy;
|
|
296
|
+
vec2 rand = seed.zw;
|
|
297
|
+
|
|
298
|
+
vec2 d = uv - p;
|
|
299
|
+
float dsq = dot(d, d);
|
|
300
|
+
|
|
301
|
+
if (dsq < shoulderLimit * shoulderLimit) {
|
|
302
|
+
float di = sqrt(dsq);
|
|
303
|
+
float shoulder = lst(.5, 0., di - l);
|
|
304
|
+
wide += shoulder * (d / max(di, 1e-4) - dir);
|
|
305
|
+
wideSum += shoulder;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
float pairSoft = .01 + .05 * step(.2, rand.x) + .3 * rand.y;
|
|
309
|
+
float toBisector = (dsq - near) / (.2 * max(length(p - nearP), 1e-4));
|
|
310
|
+
if (toBisector < toEdge) {
|
|
311
|
+
toEdge = toBisector;
|
|
312
|
+
edgeSoft = pairSoft;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
float w = 1. - toBisector / pairSoft;
|
|
316
|
+
if (w > 0.) {
|
|
317
|
+
w *= w;
|
|
318
|
+
tilt += w * getCellTilt(float(i), rand.y);
|
|
319
|
+
tiltSum += w;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
float blend = clamp(toEdge / edgeSoft, 0., 1.);
|
|
324
|
+
vec2 sharp = (1. - edge) * ((uv - nearPb) / max(lb, 1e-4) - dir);
|
|
325
|
+
vec2 rounding = mix(sharp, wide / max(wideSum, 1.), min(2. * edgeSoft, 1.));
|
|
326
|
+
float radial = l / max(l + toEdge, 1e-4);
|
|
327
|
+
|
|
328
|
+
return vec4(tilt / tiltSum + rounding * blend * radial, .2 * l, edge);
|
|
329
|
+
}
|
|
330
|
+
|
|
331
|
+
void getFolds(vec2 coord, vec2 offset, vec2 count, vec2 noise, vec2 baseFwidth, out vec2 slope, out vec2 dark, out vec2 lift) {
|
|
332
|
+
vec2 g = coord * count + .5 * offset + noise;
|
|
333
|
+
vec2 dx = fract(g) - .5;
|
|
334
|
+
vec2 adx = abs(dx);
|
|
335
|
+
float foldRadius = .3;
|
|
336
|
+
vec2 t = clamp(adx / foldRadius, 0., 1.);
|
|
337
|
+
dark = t * t * (3. - 2. * t);
|
|
338
|
+
lift = 1. - t;
|
|
339
|
+
lift *= lift;
|
|
340
|
+
|
|
341
|
+
vec2 crease = clamp(dx / max(count * baseFwidth, 1e-5), -1., 1.);
|
|
342
|
+
slope = crease * (1. - dark);
|
|
343
|
+
|
|
344
|
+
vec2 lineWidth = .02 * count * mix(vec2(2.5), vec2(.8), dark.yx) + .1 * noise;
|
|
345
|
+
slope -= 1. - smoothstep(vec2(0.), lineWidth, adx);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
void main() {
|
|
349
|
+
|
|
350
|
+
vec2 patternUV = (v_imageUV - .5) * vec2(u_imageAspectRatio, 1.);
|
|
351
|
+
float basePixel = max(length(dFdx(patternUV)), length(dFdy(patternUV)));
|
|
352
|
+
vec2 baseFwidth = fwidth(patternUV);
|
|
353
|
+
|
|
354
|
+
float pattern = 0.;
|
|
355
|
+
|
|
356
|
+
float crumpleDepth = 0.;
|
|
357
|
+
float wrinkleDepth = 0.;
|
|
358
|
+
float foldDepth = 0.;
|
|
359
|
+
float roughness = 0.;
|
|
360
|
+
float fiber = 0.;
|
|
361
|
+
float drops = 0.;
|
|
362
|
+
|
|
363
|
+
float grazing = 0.7;
|
|
364
|
+
float lightRad = radians(u_angle);
|
|
365
|
+
vec2 lightDir = vec2(sin(lightRad), -cos(lightRad));
|
|
366
|
+
float foldAngleInSector = mod(u_angle, 90.);
|
|
367
|
+
float foldLightRad = radians(u_angle - foldAngleInSector + mix(12., 78., foldAngleInSector / 90.));
|
|
368
|
+
vec2 foldLightDir = vec2(sin(foldLightRad), -cos(foldLightRad));
|
|
369
|
+
vec2 relief = vec2(0.);
|
|
370
|
+
vec2 foldSlope = vec2(0.);
|
|
371
|
+
float reliefAmount = 0.;
|
|
372
|
+
float foldInk = 1.;
|
|
373
|
+
vec2 crumpleFlow = vec2(0.);
|
|
374
|
+
|
|
375
|
+
vec2 warpNoise = vec2(0.);
|
|
376
|
+
if (u_crumples > 0. || u_folds > 0. || u_wrinkles > 0.) {
|
|
377
|
+
warpNoise = smoothNoise(patternUV * .1 + .2 + .6 * fract(.017 * u_seed)) - .5;
|
|
378
|
+
}
|
|
379
|
+
vec2 crumplesUV = (patternUV * .9) + .012 * warpNoise;
|
|
380
|
+
|
|
381
|
+
if (u_crumples > 0.) {
|
|
382
|
+
vec4 crumples = getCrumples(crumplesUV);
|
|
383
|
+
|
|
384
|
+
vec2 crumpleTilt = .5 * u_crumples * crumples.xy;
|
|
385
|
+
crumpleTilt -= .1 * max(dot(crumpleTilt, lightDir), 0.) * lightDir;
|
|
386
|
+
relief += crumpleTilt;
|
|
387
|
+
reliefAmount += .6 * u_crumples;
|
|
388
|
+
crumpleFlow = crumples.w * crumpleTilt;
|
|
389
|
+
|
|
390
|
+
crumpleDepth = clamp(5. * crumples.z, 0., 1.);
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
if (u_wrinkles > 0.) {
|
|
394
|
+
float detailFreq = mix(10., 1., u_wrinkleSize);
|
|
395
|
+
float detailAmp = .2;
|
|
396
|
+
vec2 detailGrad = vec2(0.);
|
|
397
|
+
float detailDepth = 0., depthSum = 0.;
|
|
398
|
+
for (int i = 0; i < 3; i++) {
|
|
399
|
+
float layerDepth;
|
|
400
|
+
detailGrad += detailAmp * getCrumpleDetail(crumplesUV, detailFreq, 31. * float(i), basePixel, layerDepth);
|
|
401
|
+
detailDepth += detailAmp * layerDepth;
|
|
402
|
+
depthSum += detailAmp;
|
|
403
|
+
detailAmp *= (.5 + .2 * detailGrad.x);
|
|
404
|
+
detailFreq *= 2.1;
|
|
405
|
+
}
|
|
406
|
+
|
|
407
|
+
vec2 detailTilt = 1.5 * u_wrinkles * detailGrad;
|
|
408
|
+
detailTilt -= .65 * max(dot(detailTilt, lightDir), 0.) * lightDir;
|
|
409
|
+
relief += detailTilt;
|
|
410
|
+
reliefAmount += .6 * u_wrinkles;
|
|
411
|
+
|
|
412
|
+
wrinkleDepth = clamp(5. * detailDepth / max(depthSum, 1e-4), 0., 1.);
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (u_folds > 0.) {
|
|
416
|
+
vec2 foldOffset = vec2(1. - 2. * u_foldOffsetX, 1. - 2. * u_foldOffsetY);
|
|
417
|
+
vec2 foldCount = vec2(mix(3., .5, u_foldSizeX), mix(3., .5, u_foldSizeY));
|
|
418
|
+
vec2 foldNoise = .005 * warpNoise * foldCount;
|
|
419
|
+
vec2 uv = patternUV + .03 * crumpleFlow;
|
|
420
|
+
|
|
421
|
+
vec2 slope, dark, lift;
|
|
422
|
+
getFolds(uv, foldOffset, foldCount, foldNoise, baseFwidth, slope, dark, lift);
|
|
423
|
+
|
|
424
|
+
foldSlope = u_folds * slope;
|
|
425
|
+
reliefAmount += 1. * u_folds;
|
|
426
|
+
vec2 ink = mix(vec2(.96), vec2(1.), dark);
|
|
427
|
+
float flatness = dark.x * dark.y;
|
|
428
|
+
foldInk *= mix(1., ink.x * ink.y * mix(.5, .3, flatness), u_folds);
|
|
429
|
+
|
|
430
|
+
foldDepth = u_folds * (lift.y * foldLightDir.y - lift.x * foldLightDir.x);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
float unlit = cos(grazing);
|
|
434
|
+
float lit = unlit;
|
|
435
|
+
|
|
436
|
+
if (reliefAmount > 0.) {
|
|
437
|
+
float lightFalloff = clamp(.5 + dot(v_imageUV - .5, lightDir), 0., 1.);
|
|
438
|
+
float lightPower = mix(.5, 1., lightFalloff);
|
|
439
|
+
float slope = clamp(dot(relief, lightDir) + dot(foldSlope, foldLightDir), -1.2, 1.2);
|
|
440
|
+
lit = max(cos(slope + grazing), 0.);
|
|
441
|
+
|
|
442
|
+
pattern += (clamp(reliefAmount, 0., 1.) * unlit + (lit - unlit)) * foldInk * lightPower;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
patternUV += .04 * crumpleFlow;
|
|
446
|
+
|
|
447
|
+
vec2 seedShift = floor(fract(u_seed * vec2(.7548776662, .5698402909)) * 50.) / 50.;
|
|
448
|
+
|
|
449
|
+
if (u_roughness > 0.) {
|
|
450
|
+
roughness = u_roughness * getRoughness(1000. * patternUV, lightDir, seedShift, basePixel);
|
|
451
|
+
pattern += roughness;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
if (u_fiber > 0.) {
|
|
455
|
+
fiber = u_fiber * getFiber(50. * patternUV, seedShift, basePixel);
|
|
456
|
+
pattern += fiber;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
if (u_drops > 0.) {
|
|
460
|
+
drops = u_drops * getDrops(patternUV * 10., seedShift);
|
|
461
|
+
}
|
|
462
|
+
|
|
463
|
+
pattern = clamp(pattern, 0., 1.);
|
|
464
|
+
|
|
465
|
+
vec3 backColor = u_colorBack.rgb * u_colorBack.a;
|
|
466
|
+
float backOpacity = u_colorBack.a;
|
|
467
|
+
vec3 baseColor = u_colorPaper.rgb * u_colorPaper.a;
|
|
468
|
+
float baseOpacity = u_colorPaper.a;
|
|
469
|
+
vec3 shadowColor = u_colorShadow.rgb * u_colorShadow.a;
|
|
470
|
+
float shadowOpacity = u_colorShadow.a;
|
|
471
|
+
|
|
472
|
+
float notClipped = u_clip ? .1 : 1.;
|
|
473
|
+
vec2 imageCenteredUV = v_imageUV - .5;
|
|
474
|
+
float edgeDist = 2. * max(abs(imageCenteredUV.x), abs(imageCenteredUV.y));
|
|
475
|
+
float wrinkleDistortion = mix(.38, .0175, smoothstep(0., 1., edgeDist));
|
|
476
|
+
float scaleDistortion = .15 * u_crumples * (crumpleDepth - .5) + wrinkleDistortion * u_wrinkles * (wrinkleDepth - .5) + .05 * foldDepth;
|
|
477
|
+
vec2 linearDistortion = notClipped * .002 * lightDir * drops;
|
|
478
|
+
float radialDistortion = notClipped * .02 * (roughness + fiber);
|
|
479
|
+
vec2 centeredUV = imageCenteredUV * (1. - u_distortion * scaleDistortion);
|
|
480
|
+
centeredUV -= u_distortion * linearDistortion;
|
|
481
|
+
vec2 imageUV = .5 + centeredUV * (1. - abs(u_distortion) * radialDistortion * dot(centeredUV, centeredUV));
|
|
482
|
+
|
|
483
|
+
vec3 color = shadowColor * pattern;
|
|
484
|
+
float opacity = shadowOpacity * pattern;
|
|
485
|
+
color += baseColor * (1. - opacity);
|
|
486
|
+
opacity += baseOpacity * (1. - opacity);
|
|
487
|
+
|
|
488
|
+
if (u_isImage) {
|
|
489
|
+
float frame = getUvFrame(imageUV);
|
|
490
|
+
vec4 image = texture(u_image, imageUV);
|
|
491
|
+
frame *= image.a;
|
|
492
|
+
|
|
493
|
+
float maxC = max(max(image.r, image.g), image.b);
|
|
494
|
+
float minC = min(min(image.r, image.g), image.b);
|
|
495
|
+
float sat = maxC > 0. ? (maxC - minC) / maxC : 0.;
|
|
496
|
+
float midC = image.r + image.g + image.b - maxC - minC;
|
|
497
|
+
float secondaryness = maxC > minC ? (midC - minC) / (maxC - minC) : 0.;
|
|
498
|
+
float satDampen = sat * (1. - .5 * secondaryness);
|
|
499
|
+
float darkDampen = 1. - dot(vec3(.2126, .7152, .0722), image.rgb);
|
|
500
|
+
float dampen = mix(0., .7, u_blending) * max(satDampen, darkDampen);
|
|
501
|
+
|
|
502
|
+
vec3 paper = vec3(1.) - opacity + color;
|
|
503
|
+
vec3 pic = image.rgb * paper * u_blending + image.rgb * (1. - u_blending);
|
|
504
|
+
pic = mix(pic, vec3(1.), .6 * pow(dampen, 2. + 3. * pattern));
|
|
505
|
+
|
|
506
|
+
color = mix(color, pic, frame);
|
|
507
|
+
opacity = frame + opacity * (1. - frame);
|
|
508
|
+
|
|
509
|
+
if (u_clip) {
|
|
510
|
+
color *= frame;
|
|
511
|
+
opacity *= frame;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
color *= mix(vec3(1.), .5 * u_colorShadow.rgb, drops * shadowOpacity);
|
|
516
|
+
|
|
517
|
+
color += backColor * (1. - opacity);
|
|
518
|
+
opacity += backOpacity * (1. - opacity);
|
|
519
|
+
|
|
520
|
+
fragColor = vec4(color, opacity);
|
|
521
|
+
}
|
|
522
|
+
`;
|
|
523
|
+
export {
|
|
524
|
+
paperTextureFragmentShader,
|
|
525
|
+
paperTextureMeta
|
|
526
|
+
};
|
|
527
|
+
//# sourceMappingURL=paper-texture.js.map
|