@swf2es/render 0.1.43 → 0.1.45
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/filter-shaders.d.ts +2 -2
- package/dist/filter-shaders.d.ts.map +1 -1
- package/dist/filter-shaders.js +7 -4
- package/dist/filter-shaders.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +12 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +19 -0
- package/dist/registry.js.map +1 -1
- package/dist/rows.d.ts +28 -1
- package/dist/rows.d.ts.map +1 -1
- package/dist/rows.js +32 -1
- package/dist/rows.js.map +1 -1
- package/dist/scene.d.ts +6 -0
- package/dist/scene.d.ts.map +1 -1
- package/dist/scene.js +6 -0
- package/dist/scene.js.map +1 -1
- package/dist/spans.js +2 -2
- package/dist/spans.js.map +1 -1
- package/dist/textures.d.ts +33 -0
- package/dist/textures.d.ts.map +1 -1
- package/dist/textures.js +67 -14
- package/dist/textures.js.map +1 -1
- package/dist/webgl/backend.d.ts +15 -3
- package/dist/webgl/backend.d.ts.map +1 -1
- package/dist/webgl/backend.js +63 -14
- package/dist/webgl/backend.js.map +1 -1
- package/dist/webgl/draws.d.ts +50 -29
- package/dist/webgl/draws.d.ts.map +1 -1
- package/dist/webgl/draws.js +185 -85
- package/dist/webgl/draws.js.map +1 -1
- package/dist/webgl/gpu-textures.d.ts +16 -1
- package/dist/webgl/gpu-textures.d.ts.map +1 -1
- package/dist/webgl/gpu-textures.js +61 -3
- package/dist/webgl/gpu-textures.js.map +1 -1
- package/dist/webgl/programs.d.ts +40 -9
- package/dist/webgl/programs.d.ts.map +1 -1
- package/dist/webgl/programs.js +111 -18
- package/dist/webgl/programs.js.map +1 -1
- package/package.json +2 -2
- package/src/filter-shaders.ts +7 -4
- package/src/index.ts +1 -0
- package/src/registry.ts +21 -0
- package/src/rows.ts +34 -1
- package/src/scene.ts +6 -0
- package/src/spans.ts +2 -2
- package/src/textures.ts +85 -14
- package/src/webgl/backend.ts +73 -15
- package/src/webgl/draws.ts +252 -91
- package/src/webgl/gpu-textures.ts +91 -4
- package/src/webgl/programs.ts +124 -18
package/src/webgl/programs.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TARGET_TEXEL } from "../geometry.js";
|
|
2
|
-
import { ROWS_A_LINE } from "../rows.js";
|
|
2
|
+
import { RADIAL, RADIAL_LEAST_STEP, ROWS_A_LINE } from "../rows.js";
|
|
3
3
|
import {
|
|
4
4
|
ADD,
|
|
5
5
|
ALPHA,
|
|
@@ -109,11 +109,20 @@ if (FILL_TEXTURES >= STAGE_TEXEL) {
|
|
|
109
109
|
* `multi`, a merged fill's vertices carry as aDraw where its packed row is
|
|
110
110
|
* in uMergedRows, which the stream keeps for its copy, so that the row
|
|
111
111
|
* changes from frame to frame where the vertices need not; the atlas leaves
|
|
112
|
-
* that attribute disabled and negative.
|
|
113
|
-
*
|
|
114
|
-
*
|
|
112
|
+
* that attribute disabled and negative. A row's line (Rows.line) puts the
|
|
113
|
+
* texel on that line of its texture. With `radial`, a radial gradient's
|
|
114
|
+
* row (Rows.radial) passes on its focal point and its ramp's line in
|
|
115
|
+
* vRadial, the texel its square's place, which the fragment takes to the
|
|
116
|
+
* ramp (radialFillFragment). With `stage`, the stage fill program's
|
|
117
|
+
* (stageFillFragment), a texel of TARGET_TEXEL or below samples the
|
|
118
|
+
* stage's pixel under the fragment instead.
|
|
115
119
|
*/
|
|
116
|
-
export const fillVertex = (
|
|
120
|
+
export const fillVertex = (
|
|
121
|
+
multi: boolean,
|
|
122
|
+
merged = multi,
|
|
123
|
+
stage = false,
|
|
124
|
+
radial = false,
|
|
125
|
+
) => `#version 300 es
|
|
117
126
|
${multi ? "#extension GL_ANGLE_multi_draw : require" : ""}
|
|
118
127
|
precision highp float;
|
|
119
128
|
layout(location = ${POSITION_AT}) in vec2 aPosition;
|
|
@@ -129,6 +138,7 @@ out vec2 vTexel;
|
|
|
129
138
|
flat out vec4 vMul;
|
|
130
139
|
flat out vec4 vAdd;
|
|
131
140
|
flat out int vSlot;
|
|
141
|
+
${radial ? "flat out vec3 vRadial;" : ""}
|
|
132
142
|
|
|
133
143
|
void main(void) {
|
|
134
144
|
int draw = ${merged ? `aDraw >= 0 ? texelFetch(uMergedRows, ivec2(aDraw & ${MERGED_LINE - 1}, aDraw >> ${Math.log2(MERGED_LINE)}), 0).r : ` : ""}${multi ? `texelFetch(uRunTable, ivec2((uRunBase + gl_DrawID) & ${RUN_MOST - 1}, (uRunBase + gl_DrawID) >> ${Math.log2(RUN_MOST)}), 0).r` : "uRow"};
|
|
@@ -146,13 +156,26 @@ void main(void) {
|
|
|
146
156
|
|
|
147
157
|
gl_Position = vec4(p * uView.xy + uView.zw, 0.0, 1.0);
|
|
148
158
|
vColor = aColor;
|
|
159
|
+
// A ramp kept as a line of a texture of many (Rows.line) is read on that line's centre, a
|
|
160
|
+
// texture of its own on its middle${radial ? "; a radial gradient's, at the place the fragment finds" : ""}.
|
|
161
|
+
${
|
|
162
|
+
radial
|
|
163
|
+
? ` // Its x the least the place is read at, the middle of the row's least entry: above 0, which
|
|
164
|
+
// tells the fragment to take its place to the ramp.
|
|
165
|
+
bool radial = t.w > 0.0;
|
|
166
|
+
float least = floor((t.w - ${(RADIAL - 1).toFixed(1)}) / ${RADIAL_LEAST_STEP.toFixed(1)});
|
|
167
|
+
float focal = t.w - ${RADIAL.toFixed(1)} - least * ${RADIAL_LEAST_STEP.toFixed(1)};
|
|
168
|
+
vRadial = radial ? vec3(least + 0.5, focal, t.z > 0.0 ? t.z : 0.5) : vec3(0.0);
|
|
169
|
+
vec2 texel = !radial && t.z > 0.0 ? vec2(aTexel.x, t.z) : aTexel;`
|
|
170
|
+
: " vec2 texel = t.z > 0.0 ? vec2(aTexel.x, t.z) : aTexel;"
|
|
171
|
+
}
|
|
149
172
|
${
|
|
150
173
|
stage
|
|
151
174
|
? ` // The fragment finds the stage's pixel from its place (STAGE_TEXEL in vSlot).
|
|
152
175
|
bool onStage = aTexel.x <= ${TARGET_TEXEL / 2};
|
|
153
|
-
vTexel = onStage ? p :
|
|
176
|
+
vTexel = onStage ? p : texel;
|
|
154
177
|
vSlot |= onStage ? ${STAGE_TEXEL} : 0;`
|
|
155
|
-
: " vTexel =
|
|
178
|
+
: " vTexel = texel;"
|
|
156
179
|
}
|
|
157
180
|
}
|
|
158
181
|
`;
|
|
@@ -172,20 +195,68 @@ const slotTexel = Array.from(
|
|
|
172
195
|
break;`,
|
|
173
196
|
).join("\n");
|
|
174
197
|
|
|
198
|
+
/** Texels a gradient's ramp has across, its line's (Textures.addLine) or a texture's of its own. */
|
|
199
|
+
const RAMP_TEXELS = 256;
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Where p, in the gradient square's place (a unit its radius), lies out
|
|
203
|
+
* from the focal point (f, 0) to the circle along the ray through it, as
|
|
204
|
+
* display/gradients.ts's radialPlace finds it: 0 at the focus, 1 on the
|
|
205
|
+
* circle; on a focus off the centre 1, the last stop, and on the centre of
|
|
206
|
+
* one centred 0, which the row's least entry raises (Rows.radial: 8 for a
|
|
207
|
+
* padded one). 1 / s where the ray f + s d meets the circle, in whichever
|
|
208
|
+
* of its two forms subtracts nothing, as a float's few digits would lose a
|
|
209
|
+
* focus near the circle's. A point so far out that its square overflows,
|
|
210
|
+
* as a matrix all but collapsed puts one, is as far out as it is across.
|
|
211
|
+
*/
|
|
212
|
+
export const radialPlace = `float radialPlace(vec2 p, float f) {
|
|
213
|
+
vec2 d = vec2(p.x - f, p.y);
|
|
214
|
+
float across = max(abs(d.x), abs(d.y));
|
|
215
|
+
if (across > 1e18) {
|
|
216
|
+
return across;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
float dd = dot(d, d);
|
|
220
|
+
if (dd < 1e-12) {
|
|
221
|
+
return f != 0.0 ? 1.0 : 0.0;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
float fd = f * d.x;
|
|
225
|
+
float k = 1.0 - f * f;
|
|
226
|
+
float root = sqrt(max(fd * fd + dd * k, 0.0));
|
|
227
|
+
if (fd <= 0.0) {
|
|
228
|
+
float den = root - fd;
|
|
229
|
+
return den > 0.0 ? dd / den : 1.0;
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
return k > 0.0 ? (root + fd) / k : 1.0;
|
|
233
|
+
}`;
|
|
234
|
+
|
|
235
|
+
/** A radial gradient's texel moved to its ramp's entry at the fragment's place (radialPlace). */
|
|
236
|
+
const radialAt = ` if (vRadial.x > 0.0) {
|
|
237
|
+
// Rounded to the nearest entry, as Flash reads a radial's ramp (radialIndex).
|
|
238
|
+
float entry = radialPlace(vTexel, vRadial.y) * ${RAMP_TEXELS.toFixed(1)} + 0.5;
|
|
239
|
+
at = vec2(max(entry, vRadial.x), vRadial.z);
|
|
240
|
+
}
|
|
241
|
+
`;
|
|
242
|
+
|
|
175
243
|
/**
|
|
176
244
|
* Flash's colour transform on the straight colour, clamped, then
|
|
177
245
|
* premultiplied for blending: the vertex' colour, or with a texture the
|
|
178
246
|
* texel's (premultiplied in the texture) times it, as the colour batcher
|
|
179
|
-
* did, a clear texel staying clear. With `
|
|
180
|
-
* (
|
|
247
|
+
* did, a clear texel staying clear. With `radial`, a radial gradient's
|
|
248
|
+
* texel is its ramp's at the fragment's place (radialPlace), each pixel's
|
|
249
|
+
* own as Flash finds it (radialFillFragment). With `stage`, the stage fill
|
|
250
|
+
* program's (stageFillFragment).
|
|
181
251
|
*/
|
|
182
|
-
const fillFragmentOf = (stage: boolean) => `#version 300 es
|
|
252
|
+
const fillFragmentOf = (stage: boolean, radial: boolean) => `#version 300 es
|
|
183
253
|
precision highp float;
|
|
184
254
|
in vec4 vColor;
|
|
185
255
|
in vec2 vTexel;
|
|
186
256
|
flat in vec4 vMul;
|
|
187
257
|
flat in vec4 vAdd;
|
|
188
258
|
flat in int vSlot;
|
|
259
|
+
${radial ? "flat in vec3 vRadial;" : ""}
|
|
189
260
|
uniform sampler2D uTextures[${FILL_TEXTURES}];
|
|
190
261
|
${stage ? "uniform vec4 uStage;\n" : ""}out vec4 finalColor;
|
|
191
262
|
|
|
@@ -211,10 +282,14 @@ ${slotTexel}
|
|
|
211
282
|
return t;
|
|
212
283
|
}
|
|
213
284
|
|
|
285
|
+
${radial ? radialPlace : ""}
|
|
286
|
+
|
|
214
287
|
void main(void) {
|
|
215
288
|
vec4 straight = vColor;
|
|
216
289
|
if (${stage ? `(vSlot & ${STAGE_TEXEL - 1})` : "vSlot"} != 0) {
|
|
217
|
-
|
|
290
|
+
vec2 at = vTexel;
|
|
291
|
+
${radial ? radialAt : ""}
|
|
292
|
+
vec4 t = texel(at);
|
|
218
293
|
if (t.a == 0.0) {
|
|
219
294
|
finalColor = vec4(0.0);
|
|
220
295
|
return;
|
|
@@ -228,8 +303,21 @@ void main(void) {
|
|
|
228
303
|
}
|
|
229
304
|
`;
|
|
230
305
|
|
|
231
|
-
/**
|
|
232
|
-
|
|
306
|
+
/**
|
|
307
|
+
* The fill program's fragment shader, which every fill draws with but a
|
|
308
|
+
* radial gradient's (radialFillFragment) and those of stageFillFragment.
|
|
309
|
+
* A program of its own: in it, the radial gradient's path, though no fill
|
|
310
|
+
* took it, made a frame of plain fills take Intel's GPUs some tenth as long
|
|
311
|
+
* again (bench.ts --shapes 2000, Iris Xe).
|
|
312
|
+
*/
|
|
313
|
+
export const fillFragment = fillFragmentOf(false, false);
|
|
314
|
+
|
|
315
|
+
/**
|
|
316
|
+
* The radial fill program's, for runs of fills one of which is a radial
|
|
317
|
+
* gradient's (RADIAL_FILL): every fill as fillFragment draws it, and a radial
|
|
318
|
+
* gradient's texel at the fragment's place.
|
|
319
|
+
*/
|
|
320
|
+
export const radialFillFragment = fillFragmentOf(false, true);
|
|
233
321
|
|
|
234
322
|
/**
|
|
235
323
|
* The stage fill program's, for a fill some of whose texels are the
|
|
@@ -240,7 +328,7 @@ export const fillFragment = fillFragmentOf(false);
|
|
|
240
328
|
* its own: in the fill program, that path, though no fill took it, made a
|
|
241
329
|
* frame of plain fills take Intel's GPUs over half as long again.
|
|
242
330
|
*/
|
|
243
|
-
export const stageFillFragment = fillFragmentOf(true);
|
|
331
|
+
export const stageFillFragment = fillFragmentOf(true, true);
|
|
244
332
|
|
|
245
333
|
/**
|
|
246
334
|
* drawTriangles' textured triangles (MESH), placed as fills are, their u
|
|
@@ -735,16 +823,18 @@ ${BLEND_FRONT}}
|
|
|
735
823
|
/**
|
|
736
824
|
* A fill drawn straight onto what is below it in a blend mode, where its
|
|
737
825
|
* layer would hold it alone (a flat fill, GeometryData.flat): its pixel as
|
|
738
|
-
* fillFragment has it, then as
|
|
739
|
-
*
|
|
826
|
+
* fillFragment, or with `radial` radialFillFragment, has it, then as
|
|
827
|
+
* compositeFragment composites its layer's, coloured by the layer's row
|
|
828
|
+
* (uLayerRow, -1 for none) and blended by uMode.
|
|
740
829
|
*/
|
|
741
|
-
|
|
830
|
+
const blendFillFragmentOf = (radial: boolean) => `#version 300 es
|
|
742
831
|
precision highp float;
|
|
743
832
|
in vec4 vColor;
|
|
744
833
|
in vec2 vTexel;
|
|
745
834
|
flat in vec4 vMul;
|
|
746
835
|
flat in vec4 vAdd;
|
|
747
836
|
flat in int vSlot;
|
|
837
|
+
${radial ? "flat in vec3 vRadial;" : ""}
|
|
748
838
|
uniform sampler2D uTextures[${FILL_TEXTURES}];
|
|
749
839
|
uniform sampler2D uBack;
|
|
750
840
|
uniform highp sampler2D uRows;
|
|
@@ -763,12 +853,16 @@ ${slotTexel}
|
|
|
763
853
|
return t;
|
|
764
854
|
}
|
|
765
855
|
|
|
856
|
+
${radial ? radialPlace : ""}
|
|
857
|
+
|
|
766
858
|
void main(void) {
|
|
767
859
|
vec4 front = vec4(0.0);
|
|
768
860
|
vec4 fill = vColor;
|
|
769
861
|
bool clear = false;
|
|
770
862
|
if (vSlot != 0) {
|
|
771
|
-
|
|
863
|
+
vec2 at = vTexel;
|
|
864
|
+
${radial ? radialAt : ""}
|
|
865
|
+
vec4 t = texel(at);
|
|
772
866
|
clear = t.a == 0.0;
|
|
773
867
|
fill = clear ? fill : vec4(t.rgb / t.a * vColor.rgb, t.a * vColor.a);
|
|
774
868
|
}
|
|
@@ -781,3 +875,15 @@ void main(void) {
|
|
|
781
875
|
${layerColor("uLayerRow")}
|
|
782
876
|
${BLEND_FRONT}}
|
|
783
877
|
`;
|
|
878
|
+
|
|
879
|
+
/**
|
|
880
|
+
* The blend program's fragment shader, for every fill drawn straight in a
|
|
881
|
+
* blend mode but a radial gradient's (radialBlendFillFragment). A program of
|
|
882
|
+
* its own, as fillFragment is: the radial path in it, though no fill took
|
|
883
|
+
* it, made SwiftShader's frames of 500 shapes in blend modes 3 % longer
|
|
884
|
+
* (bench.ts --blends 500).
|
|
885
|
+
*/
|
|
886
|
+
export const blendFillFragment = blendFillFragmentOf(false);
|
|
887
|
+
|
|
888
|
+
/** The radial blend program's, for a radial gradient's fill drawn straight in a blend mode. */
|
|
889
|
+
export const radialBlendFillFragment = blendFillFragmentOf(true);
|