@luma.gl/effects 9.3.0-alpha.4 → 9.3.0-alpha.8
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/dist.dev.js +1934 -415
- package/dist/dist.min.js +6 -6
- package/dist/index.cjs +736 -285
- package/dist/index.cjs.map +3 -3
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts +1 -0
- package/dist/passes/postprocessing/fxaa/fxaa.d.ts.map +1 -1
- package/dist/passes/postprocessing/fxaa/fxaa.js +287 -0
- package/dist/passes/postprocessing/fxaa/fxaa.js.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js +5 -6
- package/dist/passes/postprocessing/image-adjust-filters/brightnesscontrast.js.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/denoise.d.ts +2 -2
- package/dist/passes/postprocessing/image-adjust-filters/denoise.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/denoise.js +32 -24
- package/dist/passes/postprocessing/image-adjust-filters/denoise.js.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js +25 -32
- package/dist/passes/postprocessing/image-adjust-filters/huesaturation.js.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/noise.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/noise.js +9 -8
- package/dist/passes/postprocessing/image-adjust-filters/noise.js.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/sepia.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/sepia.js +11 -10
- package/dist/passes/postprocessing/image-adjust-filters/sepia.js.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vibrance.js +9 -9
- package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vignette.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-adjust-filters/vignette.js +10 -14
- package/dist/passes/postprocessing/image-adjust-filters/vignette.js.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.js +35 -17
- package/dist/passes/postprocessing/image-blur-filters/tiltshift.js.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.js +26 -17
- package/dist/passes/postprocessing/image-blur-filters/triangleblur.js.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts +2 -2
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.js +21 -12
- package/dist/passes/postprocessing/image-blur-filters/zoomblur.js.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js +19 -17
- package/dist/passes/postprocessing/image-fun-filters/colorhalftone.js.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/dotscreen.js +11 -11
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts +2 -2
- package/dist/passes/postprocessing/image-fun-filters/edgework.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/edgework.js +84 -13
- package/dist/passes/postprocessing/image-fun-filters/edgework.js.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js +34 -22
- package/dist/passes/postprocessing/image-fun-filters/hexagonalpixelate.js.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/ink.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/ink.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/ink.js +25 -16
- package/dist/passes/postprocessing/image-fun-filters/ink.js.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-fun-filters/magnify.js +22 -12
- package/dist/passes/postprocessing/image-fun-filters/magnify.js.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts +3 -3
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js +27 -13
- package/dist/passes/postprocessing/image-warp-filters/bulgepinch.js.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts +3 -3
- package/dist/passes/postprocessing/image-warp-filters/swirl.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/swirl.js +20 -15
- package/dist/passes/postprocessing/image-warp-filters/swirl.js.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/warp.d.ts +1 -1
- package/dist/passes/postprocessing/image-warp-filters/warp.d.ts.map +1 -1
- package/dist/passes/postprocessing/image-warp-filters/warp.js +9 -4
- package/dist/passes/postprocessing/image-warp-filters/warp.js.map +1 -1
- package/package.json +3 -3
- package/src/passes/postprocessing/fxaa/fxaa.ts +288 -0
- package/src/passes/postprocessing/image-adjust-filters/brightnesscontrast.ts +5 -6
- package/src/passes/postprocessing/image-adjust-filters/denoise.ts +34 -26
- package/src/passes/postprocessing/image-adjust-filters/huesaturation.ts +27 -34
- package/src/passes/postprocessing/image-adjust-filters/noise.ts +9 -8
- package/src/passes/postprocessing/image-adjust-filters/sepia.ts +11 -10
- package/src/passes/postprocessing/image-adjust-filters/vibrance.ts +9 -9
- package/src/passes/postprocessing/image-adjust-filters/vignette.ts +10 -14
- package/src/passes/postprocessing/image-blur-filters/tiltshift.ts +37 -19
- package/src/passes/postprocessing/image-blur-filters/triangleblur.ts +26 -17
- package/src/passes/postprocessing/image-blur-filters/zoomblur.ts +22 -13
- package/src/passes/postprocessing/image-fun-filters/colorhalftone.ts +19 -17
- package/src/passes/postprocessing/image-fun-filters/dotscreen.ts +11 -11
- package/src/passes/postprocessing/image-fun-filters/edgework.ts +85 -14
- package/src/passes/postprocessing/image-fun-filters/hexagonalpixelate.ts +38 -26
- package/src/passes/postprocessing/image-fun-filters/ink.ts +25 -16
- package/src/passes/postprocessing/image-fun-filters/magnify.ts +22 -12
- package/src/passes/postprocessing/image-warp-filters/bulgepinch.ts +27 -13
- package/src/passes/postprocessing/image-warp-filters/swirl.ts +20 -15
- package/src/passes/postprocessing/image-warp-filters/warp.ts +9 -4
|
@@ -8,25 +8,35 @@ import {random} from '@luma.gl/shadertools';
|
|
|
8
8
|
const source = /* wgsl */ `\
|
|
9
9
|
struct edgeWorkUniforms {
|
|
10
10
|
radius: f32,
|
|
11
|
-
|
|
11
|
+
mode: u32,
|
|
12
12
|
};
|
|
13
13
|
|
|
14
|
-
@group(0) @binding(
|
|
14
|
+
@group(0) @binding(auto) var<uniform> edgeWork: edgeWorkUniforms;
|
|
15
15
|
|
|
16
|
-
fn edgeWork_sampleColorRGB(
|
|
17
|
-
|
|
16
|
+
fn edgeWork_sampleColorRGB(
|
|
17
|
+
sourceTexture: texture_2d<f32>,
|
|
18
|
+
sourceTextureSampler: sampler,
|
|
19
|
+
texSize: vec2f,
|
|
20
|
+
texCoord: vec2f,
|
|
21
|
+
delta: vec2f
|
|
22
|
+
) -> vec4f {
|
|
23
|
+
let relativeDelta = edgeWork.radius * delta / texSize;
|
|
18
24
|
|
|
19
|
-
|
|
20
|
-
|
|
25
|
+
var color = vec2f(0.0);
|
|
26
|
+
var total = vec2f(0.0);
|
|
21
27
|
|
|
22
28
|
/* randomize the lookup values to hide the fixed number of samples */
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
for (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
29
|
+
let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
|
|
30
|
+
|
|
31
|
+
for (var t = -30.0; t <= 30.0; t += 1.0) {
|
|
32
|
+
let percent = (t + offset - 0.5) / 30.0;
|
|
33
|
+
var weight = 1.0 - abs(percent);
|
|
34
|
+
let sampleColor = textureSample(
|
|
35
|
+
sourceTexture,
|
|
36
|
+
sourceTextureSampler,
|
|
37
|
+
texCoord + relativeDelta * percent
|
|
38
|
+
).rgb;
|
|
39
|
+
let average = (sampleColor.r + sampleColor.g + sampleColor.b) / 3.0;
|
|
30
40
|
color.x += average * weight;
|
|
31
41
|
total.x += weight;
|
|
32
42
|
if (abs(t) < 15.0) {
|
|
@@ -35,7 +45,68 @@ fn edgeWork_sampleColorRGB(sampler2D source, vec2 texSize, vec2 texCoord, vec2 d
|
|
|
35
45
|
total.y += weight;
|
|
36
46
|
}
|
|
37
47
|
}
|
|
38
|
-
return
|
|
48
|
+
return vec4f(color / total, 0.0, 1.0);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
fn edgeWork_sampleColorXY(
|
|
52
|
+
sourceTexture: texture_2d<f32>,
|
|
53
|
+
sourceTextureSampler: sampler,
|
|
54
|
+
texSize: vec2f,
|
|
55
|
+
texCoord: vec2f,
|
|
56
|
+
delta: vec2f
|
|
57
|
+
) -> vec4f {
|
|
58
|
+
let relativeDelta = edgeWork.radius * delta / texSize;
|
|
59
|
+
|
|
60
|
+
var color = vec2f(0.0);
|
|
61
|
+
var total = vec2f(0.0);
|
|
62
|
+
|
|
63
|
+
/* randomize the lookup values to hide the fixed number of samples */
|
|
64
|
+
let offset = random(vec3f(12.9898, 78.233, 151.7182), 0.0);
|
|
65
|
+
|
|
66
|
+
for (var t = -30.0; t <= 30.0; t += 1.0) {
|
|
67
|
+
let percent = (t + offset - 0.5) / 30.0;
|
|
68
|
+
var weight = 1.0 - abs(percent);
|
|
69
|
+
let sampleColor = textureSample(
|
|
70
|
+
sourceTexture,
|
|
71
|
+
sourceTextureSampler,
|
|
72
|
+
texCoord + relativeDelta * percent
|
|
73
|
+
).xy;
|
|
74
|
+
color.x += sampleColor.x * weight;
|
|
75
|
+
total.x += weight;
|
|
76
|
+
if (abs(t) < 15.0) {
|
|
77
|
+
weight = weight * 2.0 - 1.0;
|
|
78
|
+
color.y += sampleColor.y * weight;
|
|
79
|
+
total.y += weight;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
let c = clamp(10000.0 * (color.y / total.y - color.x / total.x) + 0.5, 0.0, 1.0);
|
|
84
|
+
return vec4f(c, c, c, 1.0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
fn edgeWork_sampleColor(
|
|
88
|
+
sourceTexture: texture_2d<f32>,
|
|
89
|
+
sourceTextureSampler: sampler,
|
|
90
|
+
texSize: vec2f,
|
|
91
|
+
texCoord: vec2f
|
|
92
|
+
) -> vec4f {
|
|
93
|
+
if (edgeWork.mode == 0u) {
|
|
94
|
+
return edgeWork_sampleColorRGB(
|
|
95
|
+
sourceTexture,
|
|
96
|
+
sourceTextureSampler,
|
|
97
|
+
texSize,
|
|
98
|
+
texCoord,
|
|
99
|
+
vec2f(1.0, 0.0)
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return edgeWork_sampleColorXY(
|
|
104
|
+
sourceTexture,
|
|
105
|
+
sourceTextureSampler,
|
|
106
|
+
texSize,
|
|
107
|
+
texCoord,
|
|
108
|
+
vec2f(0.0, 1.0)
|
|
109
|
+
);
|
|
39
110
|
}
|
|
40
111
|
`;
|
|
41
112
|
|
|
@@ -10,44 +10,56 @@ struct hexagonalPixelateUniforms {
|
|
|
10
10
|
scale: f32,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
-
@group(0) @binding(
|
|
14
|
-
|
|
15
|
-
fn hexagonalPixelate_sampleColor(
|
|
16
|
-
|
|
13
|
+
@group(0) @binding(auto) var<uniform> hexagonalPixelate: hexagonalPixelateUniforms;
|
|
14
|
+
|
|
15
|
+
fn hexagonalPixelate_sampleColor(
|
|
16
|
+
sourceTexture: texture_2d<f32>,
|
|
17
|
+
sourceTextureSampler: sampler,
|
|
18
|
+
texSize: vec2f,
|
|
19
|
+
texCoord: vec2f
|
|
20
|
+
) -> vec4f {
|
|
21
|
+
var tex = (texCoord * texSize - hexagonalPixelate.center * texSize) / hexagonalPixelate.scale;
|
|
17
22
|
tex.y /= 0.866025404;
|
|
18
23
|
tex.x -= tex.y * 0.5;
|
|
19
24
|
|
|
20
|
-
|
|
25
|
+
var a = vec2f(0.0);
|
|
21
26
|
if (tex.x + tex.y - floor(tex.x) - floor(tex.y) < 1.0) {
|
|
22
|
-
a =
|
|
27
|
+
a = vec2f(floor(tex.x), floor(tex.y));
|
|
28
|
+
} else {
|
|
29
|
+
a = vec2f(ceil(tex.x), ceil(tex.y));
|
|
23
30
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
else
|
|
31
|
+
let b = vec2f(ceil(tex.x), floor(tex.y));
|
|
32
|
+
let c = vec2f(floor(tex.x), ceil(tex.y));
|
|
33
|
+
|
|
34
|
+
let texBarycentric = vec3f(tex.x, tex.y, 1.0 - tex.x - tex.y);
|
|
35
|
+
let aBarycentric = vec3f(a.x, a.y, 1.0 - a.x - a.y);
|
|
36
|
+
let bBarycentric = vec3f(b.x, b.y, 1.0 - b.x - b.y);
|
|
37
|
+
let cBarycentric = vec3f(c.x, c.y, 1.0 - c.x - c.y);
|
|
38
|
+
|
|
39
|
+
let aLength = length(texBarycentric - aBarycentric);
|
|
40
|
+
let bLength = length(texBarycentric - bBarycentric);
|
|
41
|
+
let cLength = length(texBarycentric - cBarycentric);
|
|
42
|
+
|
|
43
|
+
var choice = vec2f(0.0);
|
|
44
|
+
if (aLength < bLength) {
|
|
45
|
+
if (aLength < cLength) {
|
|
46
|
+
choice = a;
|
|
47
|
+
} else {
|
|
48
|
+
choice = c;
|
|
49
|
+
}
|
|
41
50
|
} else {
|
|
42
|
-
if (
|
|
43
|
-
|
|
51
|
+
if (bLength < cLength) {
|
|
52
|
+
choice = b;
|
|
53
|
+
} else {
|
|
54
|
+
choice = c;
|
|
55
|
+
}
|
|
44
56
|
}
|
|
45
57
|
|
|
46
58
|
choice.x += choice.y * 0.5;
|
|
47
59
|
choice.y *= 0.866025404;
|
|
48
60
|
choice *= hexagonalPixelate.scale / texSize;
|
|
49
61
|
|
|
50
|
-
return
|
|
62
|
+
return textureSample(sourceTexture, sourceTextureSampler, choice + hexagonalPixelate.center);
|
|
51
63
|
}
|
|
52
64
|
`;
|
|
53
65
|
|
|
@@ -5,23 +5,32 @@
|
|
|
5
5
|
import type {ShaderPass} from '@luma.gl/shadertools';
|
|
6
6
|
|
|
7
7
|
const source = /* wgsl */ `\
|
|
8
|
-
|
|
8
|
+
struct inkUniforms {
|
|
9
9
|
strength: f32,
|
|
10
10
|
};
|
|
11
11
|
|
|
12
|
-
@group(0) @binding(
|
|
12
|
+
@group(0) @binding(auto) var<uniform> ink: inkUniforms;
|
|
13
13
|
|
|
14
|
-
fn ink_sampleColor(
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
14
|
+
fn ink_sampleColor(
|
|
15
|
+
sourceTexture: texture_2d<f32>,
|
|
16
|
+
sourceTextureSampler: sampler,
|
|
17
|
+
texSize: vec2f,
|
|
18
|
+
texCoord: vec2f
|
|
19
|
+
) -> vec4f {
|
|
20
|
+
let dx = vec2f(1.0 / texSize.x, 0.0);
|
|
21
|
+
let dy = vec2f(0.0, 1.0 / texSize.y);
|
|
22
|
+
let color = textureSample(sourceTexture, sourceTextureSampler, texCoord);
|
|
23
|
+
var bigTotal = 0.0;
|
|
24
|
+
var smallTotal = 0.0;
|
|
25
|
+
var bigAverage = vec3f(0.0);
|
|
26
|
+
var smallAverage = vec3f(0.0);
|
|
27
|
+
for (var x = -2.0; x <= 2.0; x += 1.0) {
|
|
28
|
+
for (var y = -2.0; y <= 2.0; y += 1.0) {
|
|
29
|
+
let offsetColor = textureSample(
|
|
30
|
+
sourceTexture,
|
|
31
|
+
sourceTextureSampler,
|
|
32
|
+
texCoord + dx * x + dy * y
|
|
33
|
+
).rgb;
|
|
25
34
|
bigAverage += offsetColor;
|
|
26
35
|
bigTotal += 1.0;
|
|
27
36
|
if (abs(x) + abs(y) < 2.0) {
|
|
@@ -30,9 +39,9 @@ fn ink_sampleColor(sampler2D source, vec2 texSize, vec2 texCoord) -> vec4f {
|
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
return
|
|
42
|
+
let edge = max(vec3f(0.0), bigAverage / bigTotal - smallAverage / smallTotal);
|
|
43
|
+
let power = ink.strength * ink.strength * ink.strength * ink.strength * ink.strength;
|
|
44
|
+
return vec4f(color.rgb - vec3f(dot(edge, edge) * power * 100000.0), color.a);
|
|
36
45
|
}
|
|
37
46
|
`;
|
|
38
47
|
|
|
@@ -5,27 +5,37 @@
|
|
|
5
5
|
import type {ShaderPass} from '@luma.gl/shadertools';
|
|
6
6
|
|
|
7
7
|
const source = /* wgsl */ `\
|
|
8
|
-
|
|
9
|
-
screenXY: vec2f
|
|
10
|
-
radiusPixels: f32
|
|
11
|
-
zoom: f32
|
|
12
|
-
borderWidthPixels: f32
|
|
13
|
-
borderColor: vec4f
|
|
8
|
+
struct magnifyUniforms {
|
|
9
|
+
screenXY: vec2f,
|
|
10
|
+
radiusPixels: f32,
|
|
11
|
+
zoom: f32,
|
|
12
|
+
borderWidthPixels: f32,
|
|
13
|
+
borderColor: vec4f,
|
|
14
14
|
};
|
|
15
15
|
|
|
16
|
-
@group(0) @binding(
|
|
16
|
+
@group(0) @binding(auto) var<uniform> magnify: magnifyUniforms;
|
|
17
17
|
|
|
18
|
-
fn magnify_sampleColor(
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
fn magnify_sampleColor(
|
|
19
|
+
sourceTexture: texture_2d<f32>,
|
|
20
|
+
sourceTextureSampler: sampler,
|
|
21
|
+
texSize: vec2f,
|
|
22
|
+
texCoord: vec2f
|
|
23
|
+
) -> vec4f {
|
|
24
|
+
let pos = vec2f(magnify.screenXY.x, 1.0 - magnify.screenXY.y);
|
|
25
|
+
let dist = distance(texCoord * texSize, pos * texSize);
|
|
21
26
|
if (dist < magnify.radiusPixels) {
|
|
22
|
-
return
|
|
27
|
+
return textureSampleLevel(
|
|
28
|
+
sourceTexture,
|
|
29
|
+
sourceTextureSampler,
|
|
30
|
+
(texCoord - pos) / magnify.zoom + pos,
|
|
31
|
+
0.0
|
|
32
|
+
);
|
|
23
33
|
}
|
|
24
34
|
|
|
25
35
|
if (dist <= magnify.radiusPixels + magnify.borderWidthPixels) {
|
|
26
36
|
return magnify.borderColor;
|
|
27
37
|
}
|
|
28
|
-
return
|
|
38
|
+
return textureSampleLevel(sourceTexture, sourceTextureSampler, texCoord, 0.0);
|
|
29
39
|
}
|
|
30
40
|
`;
|
|
31
41
|
|
|
@@ -6,41 +6,55 @@ import type {ShaderPass} from '@luma.gl/shadertools';
|
|
|
6
6
|
import {warp} from './warp';
|
|
7
7
|
|
|
8
8
|
const source = /* wgsl */ `\
|
|
9
|
-
|
|
9
|
+
struct bulgePinchUniforms {
|
|
10
|
+
center: vec2f,
|
|
10
11
|
radius: f32,
|
|
11
12
|
strength: f32,
|
|
12
|
-
center: vec2f,
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
@group(0) @binding(
|
|
15
|
+
@group(0) @binding(auto) var<uniform> bulgePinch: bulgePinchUniforms;
|
|
16
16
|
|
|
17
|
-
fn bulgePinch_warp(
|
|
18
|
-
coord
|
|
19
|
-
|
|
17
|
+
fn bulgePinch_warp(coordIn: vec2f, texCenter: vec2f) -> vec2f {
|
|
18
|
+
var coord = coordIn - texCenter;
|
|
19
|
+
let distance = length(coord);
|
|
20
20
|
if (distance < bulgePinch.radius) {
|
|
21
|
-
|
|
21
|
+
let percent = distance / bulgePinch.radius;
|
|
22
|
+
let safeDistance = max(distance, 0.00001);
|
|
22
23
|
if (bulgePinch.strength > 0.0) {
|
|
23
|
-
coord *= mix(
|
|
24
|
+
coord *= mix(
|
|
25
|
+
1.0,
|
|
26
|
+
smoothstep(0.0, bulgePinch.radius / safeDistance, percent),
|
|
27
|
+
bulgePinch.strength * 0.75
|
|
28
|
+
);
|
|
24
29
|
} else {
|
|
25
|
-
coord *= mix(
|
|
30
|
+
coord *= mix(
|
|
31
|
+
1.0,
|
|
32
|
+
pow(percent, 1.0 + bulgePinch.strength * 0.75) * bulgePinch.radius / safeDistance,
|
|
33
|
+
1.0 - percent
|
|
34
|
+
);
|
|
26
35
|
}
|
|
27
36
|
}
|
|
28
37
|
coord += texCenter;
|
|
29
38
|
return coord;
|
|
30
39
|
}
|
|
31
40
|
|
|
32
|
-
fn bulgePinch_sampleColor(
|
|
33
|
-
|
|
41
|
+
fn bulgePinch_sampleColor(
|
|
42
|
+
sourceTexture: texture_2d<f32>,
|
|
43
|
+
sourceTextureSampler: sampler,
|
|
44
|
+
texSize: vec2f,
|
|
45
|
+
texCoord: vec2f
|
|
46
|
+
) -> vec4f {
|
|
47
|
+
var coord = texCoord * texSize;
|
|
34
48
|
coord = bulgePinch_warp(coord, bulgePinch.center * texSize);
|
|
35
|
-
return warp_sampleColor(
|
|
49
|
+
return warp_sampleColor(sourceTexture, sourceTextureSampler, texSize, coord);
|
|
36
50
|
}
|
|
37
51
|
`;
|
|
38
52
|
|
|
39
53
|
const fs = /* glsl */ `\
|
|
40
54
|
uniform bulgePinchUniforms {
|
|
55
|
+
vec2 center;
|
|
41
56
|
float radius;
|
|
42
57
|
float strength;
|
|
43
|
-
vec2 center;
|
|
44
58
|
} bulgePinch;
|
|
45
59
|
|
|
46
60
|
vec2 bulgePinch_warp(vec2 coord, vec2 texCenter) {
|
|
@@ -6,23 +6,23 @@ import type {ShaderPass} from '@luma.gl/shadertools';
|
|
|
6
6
|
import {warp} from './warp';
|
|
7
7
|
|
|
8
8
|
const source = /* wgsl */ `\
|
|
9
|
-
|
|
9
|
+
struct swirlUniforms {
|
|
10
|
+
center: vec2f,
|
|
10
11
|
radius: f32,
|
|
11
12
|
angle: f32,
|
|
12
|
-
center: vec2f,
|
|
13
13
|
};
|
|
14
14
|
|
|
15
|
-
@group(0) @binding(
|
|
15
|
+
@group(0) @binding(auto) var<uniform> swirl: swirlUniforms;
|
|
16
16
|
|
|
17
|
-
fn swirl_warp(
|
|
18
|
-
coord
|
|
19
|
-
|
|
17
|
+
fn swirl_warp(coordIn: vec2f, texCenter: vec2f) -> vec2f {
|
|
18
|
+
var coord = coordIn - texCenter;
|
|
19
|
+
let distance = length(coord);
|
|
20
20
|
if (distance < swirl.radius) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
coord =
|
|
21
|
+
let percent = (swirl.radius - distance) / swirl.radius;
|
|
22
|
+
let theta = percent * percent * swirl.angle;
|
|
23
|
+
let s = sin(theta);
|
|
24
|
+
let c = cos(theta);
|
|
25
|
+
coord = vec2f(
|
|
26
26
|
coord.x * c - coord.y * s,
|
|
27
27
|
coord.x * s + coord.y * c
|
|
28
28
|
);
|
|
@@ -31,18 +31,23 @@ fn swirl_warp(vec2 coord, vec2 texCenter) -> vec2f {
|
|
|
31
31
|
return coord;
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
fn swirl_sampleColor(
|
|
35
|
-
|
|
34
|
+
fn swirl_sampleColor(
|
|
35
|
+
sourceTexture: texture_2d<f32>,
|
|
36
|
+
sourceTextureSampler: sampler,
|
|
37
|
+
texSize: vec2f,
|
|
38
|
+
texCoord: vec2f
|
|
39
|
+
) -> vec4f {
|
|
40
|
+
var coord = texCoord * texSize;
|
|
36
41
|
coord = swirl_warp(coord, swirl.center * texSize);
|
|
37
|
-
return warp_sampleColor(
|
|
42
|
+
return warp_sampleColor(sourceTexture, sourceTextureSampler, texSize, coord);
|
|
38
43
|
}
|
|
39
44
|
`;
|
|
40
45
|
|
|
41
46
|
const fs = /* glsl */ `\
|
|
42
47
|
uniform swirlUniforms {
|
|
48
|
+
vec2 center;
|
|
43
49
|
float radius;
|
|
44
50
|
float angle;
|
|
45
|
-
vec2 center;
|
|
46
51
|
} swirl;
|
|
47
52
|
|
|
48
53
|
vec2 swirl_warp(vec2 coord, vec2 texCenter) {
|
|
@@ -5,10 +5,15 @@
|
|
|
5
5
|
import type {ShaderPass} from '@luma.gl/shadertools';
|
|
6
6
|
|
|
7
7
|
const source = /* wgsl */ `\
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
fn warp_sampleColor(
|
|
9
|
+
sourceTexture: texture_2d<f32>,
|
|
10
|
+
sourceTextureSampler: sampler,
|
|
11
|
+
texSize: vec2f,
|
|
12
|
+
coord: vec2f
|
|
13
|
+
) -> vec4f {
|
|
14
|
+
var color = textureSample(sourceTexture, sourceTextureSampler, coord / texSize);
|
|
15
|
+
let clampedCoord = clamp(coord, vec2f(0.0), texSize);
|
|
16
|
+
if (any(coord != clampedCoord)) {
|
|
12
17
|
/* fade to transparent if we are outside the image */
|
|
13
18
|
color.a *= max(0.0, 1.0 - length(coord - clampedCoord));
|
|
14
19
|
}
|