@remotion/effects 4.0.541 → 4.0.543
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/THIRD_PARTY_LICENSES.md +10 -0
- package/dist/esm/lightning.mjs +603 -0
- package/dist/esm/magnify.mjs +403 -0
- package/dist/esm/preview/barrel-distortion.mjs +303 -0
- package/dist/esm/preview/bevel-alpha.mjs +525 -0
- package/dist/esm/preview/blur.mjs +435 -0
- package/dist/esm/preview/brightness.mjs +95 -0
- package/dist/esm/preview/burlap.mjs +481 -0
- package/dist/esm/preview/checkerboard.mjs +8 -0
- package/dist/esm/preview/chromatic-aberration.mjs +308 -0
- package/dist/esm/preview/color-correction.mjs +522 -0
- package/dist/esm/preview/color-key.mjs +440 -0
- package/dist/esm/preview/contour-lines.mjs +608 -0
- package/dist/esm/preview/contrast.mjs +95 -0
- package/dist/esm/preview/corner-pin.mjs +6 -0
- package/dist/esm/preview/curves.mjs +357 -0
- package/dist/esm/preview/cylinder.mjs +273 -0
- package/dist/esm/preview/dot-grid.mjs +333 -0
- package/dist/esm/preview/drop-shadow.mjs +607 -0
- package/dist/esm/preview/duotone.mjs +344 -0
- package/dist/esm/preview/emboss.mjs +479 -0
- package/dist/esm/preview/evolve.mjs +485 -0
- package/dist/esm/preview/exposure.mjs +264 -0
- package/dist/esm/preview/film-burn.mjs +298 -0
- package/dist/esm/preview/fisheye.mjs +422 -0
- package/dist/esm/preview/flannel.mjs +401 -0
- package/dist/esm/preview/fractal-noise.mjs +642 -0
- package/dist/esm/preview/glow.mjs +598 -0
- package/dist/esm/preview/grayscale.mjs +86 -0
- package/dist/esm/preview/gridlines.mjs +8 -0
- package/dist/esm/preview/halftone-linear-gradient.mjs +523 -0
- package/dist/esm/preview/halftone.mjs +552 -0
- package/dist/esm/preview/hue.mjs +83 -0
- package/dist/esm/preview/index-00v3hr66.mjs +299 -0
- package/dist/esm/preview/index-0w4eqht8.mjs +351 -0
- package/dist/esm/preview/index-18y0zcy2.mjs +440 -0
- package/dist/esm/preview/index-1m1b1ad7.mjs +520 -0
- package/dist/esm/preview/index-34fxm3ax.mjs +518 -0
- package/dist/esm/preview/index-4fvp93ps.mjs +32 -0
- package/dist/esm/preview/index-4scpn12x.mjs +224 -0
- package/dist/esm/preview/index-4z6pt3ka.mjs +104 -0
- package/dist/esm/preview/index-618ky75w.mjs +51 -0
- package/dist/esm/preview/index-6agxdrvr.mjs +411 -0
- package/dist/esm/preview/index-6jkps947.mjs +120 -0
- package/dist/esm/preview/index-8agtsbw4.mjs +617 -0
- package/dist/esm/preview/index-8jx11jyn.mjs +29 -0
- package/dist/esm/preview/index-8p04sssx.mjs +123 -0
- package/dist/esm/preview/index-afdtmrh2.mjs +596 -0
- package/dist/esm/preview/index-b86qstcs.mjs +18 -0
- package/dist/esm/preview/index-cb77qg3g.mjs +587 -0
- package/dist/esm/preview/index-cdp7tr8x.mjs +122 -0
- package/dist/esm/preview/index-evy8hyah.mjs +55 -0
- package/dist/esm/preview/index-gnsce796.mjs +6 -0
- package/dist/esm/preview/index-kkvzt8b7.mjs +199 -0
- package/dist/esm/preview/index-r0v18b2n.mjs +425 -0
- package/dist/esm/preview/index-rswpzmm5.mjs +926 -0
- package/dist/esm/preview/index-s9mrx750.mjs +97 -0
- package/dist/esm/preview/index-tvfexb7s.mjs +164 -0
- package/dist/esm/preview/index-vp56k1gj.mjs +215 -0
- package/dist/esm/preview/index-wxhvgv2s.mjs +79 -0
- package/dist/esm/preview/index-wy95a41r.mjs +407 -0
- package/dist/esm/preview/index-ysnwfc4t.mjs +306 -0
- package/dist/esm/preview/index.mjs +51 -0
- package/dist/esm/preview/invert.mjs +84 -0
- package/dist/esm/preview/iris-wipe.mjs +315 -0
- package/dist/esm/preview/lens-blur.mjs +563 -0
- package/dist/esm/preview/levels.mjs +400 -0
- package/dist/esm/preview/light-leak.mjs +8 -0
- package/dist/esm/preview/light-trail.mjs +516 -0
- package/dist/esm/preview/lightning.mjs +603 -0
- package/dist/esm/preview/linear-gradient-tint.mjs +6 -0
- package/dist/esm/preview/linear-gradient.mjs +6 -0
- package/dist/esm/preview/linear-progressive-blur.mjs +516 -0
- package/dist/esm/preview/linear-progressive-pixelate.mjs +176 -0
- package/dist/esm/preview/lines.mjs +536 -0
- package/dist/esm/preview/liquid-contours.mjs +512 -0
- package/dist/esm/preview/long-shadows.mjs +437 -0
- package/dist/esm/preview/lut.mjs +601 -0
- package/dist/esm/preview/magnify.mjs +403 -0
- package/dist/esm/preview/mirror.mjs +341 -0
- package/dist/esm/preview/noise-displacement.mjs +584 -0
- package/dist/esm/preview/noise.mjs +318 -0
- package/dist/esm/preview/outline.mjs +725 -0
- package/dist/esm/preview/page-turn.mjs +302 -0
- package/dist/esm/preview/paper.mjs +1249 -0
- package/dist/esm/preview/pattern.mjs +6 -0
- package/dist/esm/preview/pixel-dissolve.mjs +360 -0
- package/dist/esm/preview/pixelate.mjs +249 -0
- package/dist/esm/preview/radial-progressive-blur.mjs +582 -0
- package/dist/esm/preview/radial-progressive-pixelate.mjs +220 -0
- package/dist/esm/preview/radial-wipe.mjs +224 -0
- package/dist/esm/preview/rain-fall.mjs +114 -0
- package/dist/esm/preview/region-blur.mjs +500 -0
- package/dist/esm/preview/rings.mjs +8 -0
- package/dist/esm/preview/roughen-edges.mjs +590 -0
- package/dist/esm/preview/saturation.mjs +86 -0
- package/dist/esm/preview/scale.mjs +109 -0
- package/dist/esm/preview/scanlines.mjs +362 -0
- package/dist/esm/preview/shadows-highlights.mjs +284 -0
- package/dist/esm/preview/shatter.mjs +868 -0
- package/dist/esm/preview/shine.mjs +368 -0
- package/dist/esm/preview/shrinkwrap.mjs +769 -0
- package/dist/esm/preview/skew.mjs +300 -0
- package/dist/esm/preview/snow-fall.mjs +170 -0
- package/dist/esm/preview/speckle.mjs +356 -0
- package/dist/esm/preview/sphere.mjs +252 -0
- package/dist/esm/preview/starburst.mjs +8 -0
- package/dist/esm/preview/tear.mjs +375 -0
- package/dist/esm/preview/thermal-vision.mjs +387 -0
- package/dist/esm/preview/tile.mjs +7 -0
- package/dist/esm/preview/tint.mjs +125 -0
- package/dist/esm/preview/translate.mjs +151 -0
- package/dist/esm/preview/turbulent-displace.mjs +613 -0
- package/dist/esm/preview/tv-signal-off.mjs +308 -0
- package/dist/esm/preview/venetian-blinds.mjs +341 -0
- package/dist/esm/preview/vibrance.mjs +254 -0
- package/dist/esm/preview/vignette.mjs +458 -0
- package/dist/esm/preview/wave.mjs +384 -0
- package/dist/esm/preview/waves.mjs +599 -0
- package/dist/esm/preview/white-balance.mjs +280 -0
- package/dist/esm/preview/white-noise.mjs +244 -0
- package/dist/esm/preview/zigzag.mjs +8 -0
- package/dist/esm/preview/zoom-blur.mjs +389 -0
- package/dist/lightning/geometry.d.ts +10 -0
- package/dist/lightning/index.d.ts +4 -0
- package/dist/lightning/mask.d.ts +2 -0
- package/dist/lightning/params.d.ts +259 -0
- package/dist/lightning/shaders.d.ts +2 -0
- package/dist/lightning.d.ts +2 -0
- package/dist/magnify/shader.d.ts +1 -0
- package/dist/magnify/webgpu-shader.d.ts +1 -0
- package/dist/magnify.d.ts +28 -0
- package/package.json +30 -6
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
import {
|
|
2
|
+
setupSinglePass,
|
|
3
|
+
prepareSinglePassSource,
|
|
4
|
+
drawSinglePass,
|
|
5
|
+
cleanupSinglePass
|
|
6
|
+
} from "./index-8p04sssx.mjs";
|
|
7
|
+
import {
|
|
8
|
+
WEBGPU_SINGLE_PASS_VERTEX,
|
|
9
|
+
setupWebGpuSinglePass,
|
|
10
|
+
cleanupWebGpuSinglePass,
|
|
11
|
+
applyWebGpuSinglePass
|
|
12
|
+
} from "./index-tvfexb7s.mjs";
|
|
13
|
+
|
|
14
|
+
// src/color-matrix-runtime.ts
|
|
15
|
+
import { Internals } from "remotion";
|
|
16
|
+
var FRAGMENT_SHADER = `#version 300 es
|
|
17
|
+
precision highp float;
|
|
18
|
+
in vec2 vUv;
|
|
19
|
+
out vec4 fragColor;
|
|
20
|
+
uniform sampler2D uSource;
|
|
21
|
+
uniform vec4 uRed;
|
|
22
|
+
uniform vec4 uGreen;
|
|
23
|
+
uniform vec4 uBlue;
|
|
24
|
+
uniform vec4 uFlags;
|
|
25
|
+
void main() {
|
|
26
|
+
vec4 source = texture(uSource, vUv);
|
|
27
|
+
if (uFlags.z > 0.0 || source.a == 0.0) { fragColor = source; return; }
|
|
28
|
+
vec3 rgb = source.rgb / source.a;
|
|
29
|
+
if (uFlags.x > 0.0) {
|
|
30
|
+
vec3 bytes = floor(rgb * 255.0 + 0.5);
|
|
31
|
+
bytes = uFlags.x == 1.0 ? bytes + uRed.w : (bytes - 128.0) * uRed.x + 128.0;
|
|
32
|
+
rgb = roundEven(clamp(bytes, 0.0, 255.0)) / 255.0;
|
|
33
|
+
} else {
|
|
34
|
+
vec4 color = vec4(rgb, 1.0);
|
|
35
|
+
rgb = clamp(vec3(dot(uRed, color), dot(uGreen, color), dot(uBlue, color)), 0.0, 1.0);
|
|
36
|
+
}
|
|
37
|
+
fragColor = vec4(rgb * source.a, source.a);
|
|
38
|
+
}
|
|
39
|
+
`;
|
|
40
|
+
var WEBGPU_SHADER = `
|
|
41
|
+
${WEBGPU_SINGLE_PASS_VERTEX}
|
|
42
|
+
struct Params {
|
|
43
|
+
red: vec4f,
|
|
44
|
+
green: vec4f,
|
|
45
|
+
blue: vec4f,
|
|
46
|
+
flags: vec4f,
|
|
47
|
+
}
|
|
48
|
+
@group(0) @binding(0) var source: texture_2d<f32>;
|
|
49
|
+
@group(0) @binding(1) var sourceSampler: sampler;
|
|
50
|
+
@group(0) @binding(2) var<uniform> params: Params;
|
|
51
|
+
@fragment fn fragment(input: VertexOutput) -> @location(0) vec4f {
|
|
52
|
+
let sampled = textureSample(source, sourceSampler, input.uv);
|
|
53
|
+
if (params.flags.z > 0.0 || sampled.a == 0.0) { return sampled; }
|
|
54
|
+
var rgb = sampled.rgb / sampled.a;
|
|
55
|
+
if (params.flags.x > 0.0) {
|
|
56
|
+
var bytes = floor(rgb * 255.0 + vec3f(0.5));
|
|
57
|
+
if (params.flags.x == 1.0) {
|
|
58
|
+
bytes += vec3f(params.red.w);
|
|
59
|
+
} else {
|
|
60
|
+
bytes = (bytes - vec3f(128.0)) * params.red.x + vec3f(128.0);
|
|
61
|
+
}
|
|
62
|
+
bytes = clamp(bytes, vec3f(0.0), vec3f(255.0));
|
|
63
|
+
let lower = floor(bytes);
|
|
64
|
+
let fraction = bytes - lower;
|
|
65
|
+
let odd = lower - floor(lower * 0.5) * 2.0 == vec3f(1.0);
|
|
66
|
+
let aboveHalf = fraction > vec3f(0.5);
|
|
67
|
+
let halfway = fraction == vec3f(0.5);
|
|
68
|
+
rgb = (lower + select(vec3f(0.0), vec3f(1.0), aboveHalf | (halfway & odd))) / 255.0;
|
|
69
|
+
} else {
|
|
70
|
+
let color = vec4f(rgb, 1.0);
|
|
71
|
+
rgb = clamp(vec3f(dot(params.red, color), dot(params.green, color), dot(params.blue, color)), vec3f(0.0), vec3f(1.0));
|
|
72
|
+
}
|
|
73
|
+
return vec4f(rgb * sampled.a, sampled.a);
|
|
74
|
+
}
|
|
75
|
+
`;
|
|
76
|
+
var createColorMatrixImplementations = (label, getUniformData) => ({
|
|
77
|
+
webgl2: Internals.createEffectImplementation({
|
|
78
|
+
setup: (target) => setupSinglePass(target, FRAGMENT_SHADER, label, [
|
|
79
|
+
"uRed",
|
|
80
|
+
"uGreen",
|
|
81
|
+
"uBlue",
|
|
82
|
+
"uFlags"
|
|
83
|
+
]),
|
|
84
|
+
apply: ({ source, width, height, params, state, flipSourceY }) => {
|
|
85
|
+
prepareSinglePassSource({
|
|
86
|
+
state,
|
|
87
|
+
source,
|
|
88
|
+
width,
|
|
89
|
+
height,
|
|
90
|
+
flipSourceY
|
|
91
|
+
});
|
|
92
|
+
const data = getUniformData(params);
|
|
93
|
+
const { gl, uniforms } = state;
|
|
94
|
+
gl.uniform4fv(uniforms.uRed, data.subarray(0, 4));
|
|
95
|
+
gl.uniform4fv(uniforms.uGreen, data.subarray(4, 8));
|
|
96
|
+
gl.uniform4fv(uniforms.uBlue, data.subarray(8, 12));
|
|
97
|
+
gl.uniform4fv(uniforms.uFlags, data.subarray(12, 16));
|
|
98
|
+
drawSinglePass(state);
|
|
99
|
+
},
|
|
100
|
+
cleanup: cleanupSinglePass
|
|
101
|
+
}),
|
|
102
|
+
webgpu: Internals.createEffectImplementation({
|
|
103
|
+
setup: (target) => setupWebGpuSinglePass(target, label),
|
|
104
|
+
apply: ({ source, width, height, params, state, gpuDevice }) => {
|
|
105
|
+
if (!gpuDevice) {
|
|
106
|
+
throw new Error(`A WebGPU device is required for the ${label} effect`);
|
|
107
|
+
}
|
|
108
|
+
applyWebGpuSinglePass({
|
|
109
|
+
state,
|
|
110
|
+
source,
|
|
111
|
+
width,
|
|
112
|
+
height,
|
|
113
|
+
device: gpuDevice,
|
|
114
|
+
shader: WEBGPU_SHADER,
|
|
115
|
+
uniformData: getUniformData(params)
|
|
116
|
+
});
|
|
117
|
+
},
|
|
118
|
+
cleanup: cleanupWebGpuSinglePass
|
|
119
|
+
})
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export { createColorMatrixImplementations };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
// src/gaussian-blur-shader.ts
|
|
2
|
+
var buildGaussianBlurFs = (direction) => {
|
|
3
|
+
const dirVec = direction === "horizontal" ? "vec2(1.0, 0.0)" : "vec2(0.0, 1.0)";
|
|
4
|
+
return `#version 300 es
|
|
5
|
+
precision highp float;
|
|
6
|
+
|
|
7
|
+
in vec2 vUv;
|
|
8
|
+
out vec4 fragColor;
|
|
9
|
+
|
|
10
|
+
uniform sampler2D uSource;
|
|
11
|
+
uniform float uRadius;
|
|
12
|
+
uniform vec2 uTexelSize;
|
|
13
|
+
|
|
14
|
+
const int MIN_KERNEL_HALF = 4;
|
|
15
|
+
const int MAX_KERNEL_HALF = 32;
|
|
16
|
+
const float TARGET_SAMPLE_DISTANCE_PX = 2.0;
|
|
17
|
+
const vec2 DIRECTION = ${dirVec};
|
|
18
|
+
|
|
19
|
+
void main() {
|
|
20
|
+
if (uRadius <= 0.0) {
|
|
21
|
+
fragColor = texture(uSource, vUv);
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
int kernelHalf = int(
|
|
26
|
+
min(
|
|
27
|
+
float(MAX_KERNEL_HALF),
|
|
28
|
+
max(float(MIN_KERNEL_HALF), ceil(uRadius / TARGET_SAMPLE_DISTANCE_PX))
|
|
29
|
+
)
|
|
30
|
+
);
|
|
31
|
+
float pixelStride = uRadius / float(kernelHalf);
|
|
32
|
+
float sigma = uRadius / 3.0;
|
|
33
|
+
float twoSigmaSq = 2.0 * sigma * sigma;
|
|
34
|
+
|
|
35
|
+
vec4 sum = vec4(0.0);
|
|
36
|
+
float weightSum = 0.0;
|
|
37
|
+
|
|
38
|
+
for (int i = -MAX_KERNEL_HALF; i <= MAX_KERNEL_HALF; ++i) {
|
|
39
|
+
if (abs(i) > kernelHalf) {
|
|
40
|
+
continue;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
float offsetPx = float(i) * pixelStride;
|
|
44
|
+
float w = exp(-(offsetPx * offsetPx) / twoSigmaSq);
|
|
45
|
+
vec2 uv = vUv + DIRECTION * uTexelSize * offsetPx;
|
|
46
|
+
sum += texture(uSource, uv) * w;
|
|
47
|
+
weightSum += w;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
fragColor = sum / weightSum;
|
|
51
|
+
}
|
|
52
|
+
`;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export { buildGaussianBlurFs };
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import {
|
|
2
|
+
WEBGPU_SINGLE_PASS_VERTEX
|
|
3
|
+
} from "./index-tvfexb7s.mjs";
|
|
4
|
+
|
|
5
|
+
// src/webgpu-multipass-runtime.ts
|
|
6
|
+
var WEBGPU_MULTIPASS_BINDINGS = `
|
|
7
|
+
${WEBGPU_SINGLE_PASS_VERTEX}
|
|
8
|
+
@group(0) @binding(0) var source: texture_2d<f32>;
|
|
9
|
+
@group(0) @binding(1) var sourceSampler: sampler;
|
|
10
|
+
@group(0) @binding(2) var<uniform> params: Params;
|
|
11
|
+
@group(0) @binding(3) var secondary: texture_2d<f32>;
|
|
12
|
+
`;
|
|
13
|
+
var setupWebGpuMultipass = (target, label) => {
|
|
14
|
+
const context = target.getContext("webgpu");
|
|
15
|
+
if (!context)
|
|
16
|
+
throw new Error(`WebGPU is not available for the ${label} effect`);
|
|
17
|
+
return { context, label, resources: null };
|
|
18
|
+
};
|
|
19
|
+
var cleanupWebGpuMultipass = (state) => {
|
|
20
|
+
state.resources?.source?.texture.destroy();
|
|
21
|
+
state.resources?.auxiliary?.texture.destroy();
|
|
22
|
+
state.resources?.textures.forEach((texture) => texture.destroy());
|
|
23
|
+
state.resources?.passes.forEach((pass) => pass.uniforms.destroy());
|
|
24
|
+
state.resources = null;
|
|
25
|
+
state.context.unconfigure();
|
|
26
|
+
};
|
|
27
|
+
var applyWebGpuMultipass = ({
|
|
28
|
+
state,
|
|
29
|
+
source,
|
|
30
|
+
width,
|
|
31
|
+
height,
|
|
32
|
+
device,
|
|
33
|
+
passes,
|
|
34
|
+
auxiliarySource
|
|
35
|
+
}) => {
|
|
36
|
+
if (state.resources && state.resources.device !== device)
|
|
37
|
+
cleanupWebGpuMultipass(state);
|
|
38
|
+
if (!state.resources) {
|
|
39
|
+
const format = navigator.gpu.getPreferredCanvasFormat();
|
|
40
|
+
state.context.configure({ device, format, alphaMode: "premultiplied" });
|
|
41
|
+
const layout = device.createBindGroupLayout({
|
|
42
|
+
entries: [
|
|
43
|
+
{ binding: 0, visibility: GPUShaderStage.FRAGMENT, texture: {} },
|
|
44
|
+
{ binding: 1, visibility: GPUShaderStage.FRAGMENT, sampler: {} },
|
|
45
|
+
{
|
|
46
|
+
binding: 2,
|
|
47
|
+
visibility: GPUShaderStage.FRAGMENT,
|
|
48
|
+
buffer: { type: "uniform" }
|
|
49
|
+
},
|
|
50
|
+
{ binding: 3, visibility: GPUShaderStage.FRAGMENT, texture: {} }
|
|
51
|
+
]
|
|
52
|
+
});
|
|
53
|
+
state.resources = {
|
|
54
|
+
device,
|
|
55
|
+
format,
|
|
56
|
+
layout,
|
|
57
|
+
sampler: device.createSampler({ magFilter: "linear", minFilter: "linear" }),
|
|
58
|
+
passes: [],
|
|
59
|
+
textures: [],
|
|
60
|
+
source: null,
|
|
61
|
+
auxiliary: null,
|
|
62
|
+
width,
|
|
63
|
+
height
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
const r = state.resources;
|
|
67
|
+
const sourceWidth = "displayWidth" in source ? source.displayWidth : ("videoWidth" in source) ? source.videoWidth : ("naturalWidth" in source) ? source.naturalWidth : typeof source.width === "number" ? source.width : source.width.baseVal.value;
|
|
68
|
+
const sourceHeight = "displayHeight" in source ? source.displayHeight : ("videoHeight" in source) ? source.videoHeight : ("naturalHeight" in source) ? source.naturalHeight : typeof source.height === "number" ? source.height : source.height.baseVal.value;
|
|
69
|
+
if (r.source && (r.source.width !== sourceWidth || r.source.height !== sourceHeight)) {
|
|
70
|
+
r.source.texture.destroy();
|
|
71
|
+
r.source = null;
|
|
72
|
+
}
|
|
73
|
+
if (!r.source) {
|
|
74
|
+
r.source = {
|
|
75
|
+
width: sourceWidth,
|
|
76
|
+
height: sourceHeight,
|
|
77
|
+
texture: device.createTexture({
|
|
78
|
+
size: [sourceWidth, sourceHeight],
|
|
79
|
+
format: "rgba8unorm",
|
|
80
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
|
|
81
|
+
})
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
device.queue.copyExternalImageToTexture({ source }, { texture: r.source.texture, premultipliedAlpha: true }, [sourceWidth, sourceHeight]);
|
|
85
|
+
if (r.auxiliary && (!auxiliarySource || r.auxiliary.width !== auxiliarySource.width || r.auxiliary.height !== auxiliarySource.height)) {
|
|
86
|
+
r.auxiliary.texture.destroy();
|
|
87
|
+
r.auxiliary = null;
|
|
88
|
+
}
|
|
89
|
+
if (auxiliarySource) {
|
|
90
|
+
if (!r.auxiliary)
|
|
91
|
+
r.auxiliary = {
|
|
92
|
+
width: auxiliarySource.width,
|
|
93
|
+
height: auxiliarySource.height,
|
|
94
|
+
texture: device.createTexture({
|
|
95
|
+
size: [auxiliarySource.width, auxiliarySource.height],
|
|
96
|
+
format: "rgba8unorm",
|
|
97
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.COPY_DST | GPUTextureUsage.RENDER_ATTACHMENT
|
|
98
|
+
})
|
|
99
|
+
};
|
|
100
|
+
device.queue.copyExternalImageToTexture({ source: auxiliarySource }, { texture: r.auxiliary.texture, premultipliedAlpha: true }, [auxiliarySource.width, auxiliarySource.height]);
|
|
101
|
+
}
|
|
102
|
+
if (r.width !== width || r.height !== height) {
|
|
103
|
+
r.textures.forEach((texture) => texture.destroy());
|
|
104
|
+
r.textures.length = 0;
|
|
105
|
+
r.width = width;
|
|
106
|
+
r.height = height;
|
|
107
|
+
}
|
|
108
|
+
const lastReaders = passes.map((_, index) => index);
|
|
109
|
+
for (let index = 0;index < passes.length; index++) {
|
|
110
|
+
for (const input of [passes[index].source, passes[index].secondary]) {
|
|
111
|
+
if (input >= 0)
|
|
112
|
+
lastReaders[input] = index;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
const outputSlots = [];
|
|
116
|
+
const freeAfter = [];
|
|
117
|
+
for (let index = 0;index < passes.length - 1; index++) {
|
|
118
|
+
let slot = freeAfter.findIndex((lastReader) => lastReader < index);
|
|
119
|
+
if (slot === -1)
|
|
120
|
+
slot = freeAfter.length;
|
|
121
|
+
freeAfter[slot] = lastReaders[index];
|
|
122
|
+
outputSlots.push(slot);
|
|
123
|
+
}
|
|
124
|
+
while (r.textures.length < freeAfter.length) {
|
|
125
|
+
r.textures.push(device.createTexture({
|
|
126
|
+
size: [width, height],
|
|
127
|
+
format: "rgba8unorm",
|
|
128
|
+
usage: GPUTextureUsage.TEXTURE_BINDING | GPUTextureUsage.RENDER_ATTACHMENT
|
|
129
|
+
}));
|
|
130
|
+
}
|
|
131
|
+
while (r.textures.length > freeAfter.length)
|
|
132
|
+
r.textures.pop()?.destroy();
|
|
133
|
+
while (r.passes.length > passes.length)
|
|
134
|
+
r.passes.pop()?.uniforms.destroy();
|
|
135
|
+
const encoder = device.createCommandEncoder();
|
|
136
|
+
for (let index = 0;index < passes.length; index++) {
|
|
137
|
+
const pass = passes[index];
|
|
138
|
+
const format = index === passes.length - 1 ? r.format : "rgba8unorm";
|
|
139
|
+
const size = Math.max(16, Math.ceil(pass.uniforms.byteLength / 16) * 16);
|
|
140
|
+
let resources = r.passes[index];
|
|
141
|
+
if (!resources || resources.shader !== pass.shader || resources.size !== size || resources.format !== format) {
|
|
142
|
+
resources?.uniforms.destroy();
|
|
143
|
+
const module = device.createShaderModule({
|
|
144
|
+
code: pass.shader,
|
|
145
|
+
label: state.label
|
|
146
|
+
});
|
|
147
|
+
resources = {
|
|
148
|
+
shader: pass.shader,
|
|
149
|
+
size,
|
|
150
|
+
format,
|
|
151
|
+
pipeline: device.createRenderPipeline({
|
|
152
|
+
label: state.label,
|
|
153
|
+
layout: device.createPipelineLayout({ bindGroupLayouts: [r.layout] }),
|
|
154
|
+
vertex: { module, entryPoint: "vertex" },
|
|
155
|
+
fragment: { module, entryPoint: "fragment", targets: [{ format }] },
|
|
156
|
+
primitive: { topology: "triangle-list" }
|
|
157
|
+
}),
|
|
158
|
+
uniforms: device.createBuffer({
|
|
159
|
+
size,
|
|
160
|
+
usage: GPUBufferUsage.UNIFORM | GPUBufferUsage.COPY_DST
|
|
161
|
+
})
|
|
162
|
+
};
|
|
163
|
+
r.passes[index] = resources;
|
|
164
|
+
}
|
|
165
|
+
device.queue.writeBuffer(resources.uniforms, 0, pass.uniforms);
|
|
166
|
+
const bindGroup = device.createBindGroup({
|
|
167
|
+
layout: r.layout,
|
|
168
|
+
entries: [
|
|
169
|
+
{
|
|
170
|
+
binding: 0,
|
|
171
|
+
resource: (pass.source === -1 ? r.source.texture : r.textures[outputSlots[pass.source]]).createView()
|
|
172
|
+
},
|
|
173
|
+
{ binding: 1, resource: r.sampler },
|
|
174
|
+
{ binding: 2, resource: { buffer: resources.uniforms } },
|
|
175
|
+
{
|
|
176
|
+
binding: 3,
|
|
177
|
+
resource: (pass.secondary === -2 && r.auxiliary ? r.auxiliary.texture : pass.secondary === -1 ? r.source.texture : r.textures[outputSlots[pass.secondary]]).createView()
|
|
178
|
+
}
|
|
179
|
+
]
|
|
180
|
+
});
|
|
181
|
+
const renderPass = encoder.beginRenderPass({
|
|
182
|
+
colorAttachments: [
|
|
183
|
+
{
|
|
184
|
+
view: (index === passes.length - 1 ? state.context.getCurrentTexture() : r.textures[outputSlots[index]]).createView(),
|
|
185
|
+
clearValue: { r: 0, g: 0, b: 0, a: 0 },
|
|
186
|
+
loadOp: "clear",
|
|
187
|
+
storeOp: "store"
|
|
188
|
+
}
|
|
189
|
+
]
|
|
190
|
+
});
|
|
191
|
+
renderPass.setPipeline(resources.pipeline);
|
|
192
|
+
renderPass.setBindGroup(0, bindGroup);
|
|
193
|
+
renderPass.draw(3);
|
|
194
|
+
renderPass.end();
|
|
195
|
+
}
|
|
196
|
+
device.queue.submit([encoder.finish()]);
|
|
197
|
+
};
|
|
198
|
+
|
|
199
|
+
export { WEBGPU_MULTIPASS_BINDINGS, setupWebGpuMultipass, cleanupWebGpuMultipass, applyWebGpuMultipass };
|