@swf2es/render 0.1.46 → 0.1.47
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/webgl/ramps.d.ts +5 -2
- package/dist/webgl/ramps.d.ts.map +1 -1
- package/dist/webgl/ramps.js +25 -18
- package/dist/webgl/ramps.js.map +1 -1
- package/package.json +3 -3
- package/src/webgl/ramps.ts +25 -18
package/dist/webgl/ramps.d.ts
CHANGED
|
@@ -10,9 +10,12 @@ export declare const RAMP_VERTEX = "#version 300 es\nprecision highp float;\npre
|
|
|
10
10
|
/**
|
|
11
11
|
* Each texel the entry of its line's ramp at its column, as rampOf finds it:
|
|
12
12
|
* the stop's colour, or the span's c0 + floor(d * j / w) in integers, the
|
|
13
|
-
* colour channels back through TO_SRGB in linear light, premultiplied.
|
|
13
|
+
* colour channels back through TO_SRGB in linear light, premultiplied. The
|
|
14
|
+
* ratios are read four a fetch, as the walk comes to them, and the quotient
|
|
15
|
+
* is found in floats and put right by its remainder: a fetch for each stop
|
|
16
|
+
* and four integer divisions an entry took SwiftShader a quarter more.
|
|
14
17
|
*/
|
|
15
|
-
export declare const RAMP_FRAGMENT = "#version 300 es\nprecision highp float;\nprecision highp int;\nuniform highp usampler2D uRecords;\nuniform highp usampler2D uSrgb;\nout vec4 finalColor;\nint line;\n\
|
|
18
|
+
export declare const RAMP_FRAGMENT = "#version 300 es\nprecision highp float;\nprecision highp int;\nuniform highp usampler2D uRecords;\nuniform highp usampler2D uSrgb;\nout vec4 finalColor;\nint line;\n\nivec4 colorOf(int i) {\n return ivec4(texelFetch(uRecords, ivec2(8 + i, line), 0));\n}\n\nint srgb(int l) {\n return int(texelFetch(uSrgb, ivec2(l, 0), 0).r);\n}\n\nvoid main(void) {\n line = int(gl_FragCoord.y);\n int k = int(gl_FragCoord.x);\n uvec4 head = texelFetch(uRecords, ivec2(0, line), 0);\n int count = int(head[0]);\n bool linear = head[1] != 0u;\n uvec4 ratios = texelFetch(uRecords, ivec2(1, line), 0);\n int from = int(ratios.x);\n ivec4 c;\n if (k <= from) {\n c = colorOf(0);\n } else {\n // The span k lies in, as rampOf walks them: each one entry wide at least.\n int span = 0;\n int w = 0;\n int at = from + 1;\n for (int i = 1; i < 16; i++) {\n if (i >= count || at > 255) {\n break;\n }\n\n if ((i & 3) == 0) {\n ratios = texelFetch(uRecords, ivec2(1 + (i >> 2), line), 0);\n }\n\n int to = int(ratios[i & 3]);\n w = to - from;\n int end = w <= 0 ? at : max(at, min(to, 255));\n if (k <= end) {\n span = i;\n break;\n }\n\n at = end + 1;\n from = to;\n }\n\n if (span == 0) {\n c = colorOf(count - 1);\n } else {\n ivec4 x = colorOf(span - 1);\n c = x;\n if (w > 0) {\n ivec4 d = colorOf(span) - x;\n int j = k - from;\n // floor(n / w) exactly: n is within 255 * 255 of 0, so (n + 0.5) / w is\n // at least 0.5 / w from a whole number, which a division up to about 16 ULP\n // out cannot cross; the remainder puts the quotient right on a GPU that\n // divides worse.\n ivec4 n = d * j;\n ivec4 q = ivec4(floor((vec4(n) + 0.5) / float(w)));\n ivec4 r = n - q * w;\n q += ivec4(greaterThanEqual(r, ivec4(w))) - ivec4(lessThan(r, ivec4(0)));\n c = (x + q) & 255;\n }\n }\n }\n\n ivec3 rgb = c.rgb;\n if (linear) {\n rgb = ivec3(srgb(c.r), srgb(c.g), srgb(c.b));\n }\n\n rgb = (rgb * (c.a + 1)) >> 8;\n finalColor = vec4(vec3(rgb), float(c.a)) / 255.0;\n}\n";
|
|
16
19
|
/**
|
|
17
20
|
* Builds the lines GpuTextures marked (builds) from their records: the
|
|
18
21
|
* records uploaded, then drawn into the lines' texture through a
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ramps.d.ts","sourceRoot":"","sources":["../../src/webgl/ramps.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,OAAO,EAAe,MAAM,0BAA0B,CAAC;AAWrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,ijBAevB,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"ramps.d.ts","sourceRoot":"","sources":["../../src/webgl/ramps.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,OAAO,EAAe,MAAM,0BAA0B,CAAC;AAWrE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AASrD;;;;;GAKG;AACH,eAAO,MAAM,WAAW,ijBAevB,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,woEAkFzB,CAAC;AAEF;;;;GAIG;AACH,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAyB;IAC5C,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAU;IAChC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,IAAI,CAA6B;IACzC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAA+B;IACtD,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAmC;IACxD,OAAO,CAAC,WAAW,CAAiC;IACpD,OAAO,CAAC,MAAM,CAA6B;IAE3C,YAAY,EAAE,EAAE,sBAAsB,EAAE,KAAK,EAAE,OAAO,EAGrD;IAED;;;;OAIG;IACH,KAAK,IAAI,IAAI,CAQZ;IAED;;;;;OAKG;IACH,IAAI,IAAI,IAAI,CAQX;IAED,4CAA4C;IAC5C,OAAO,IAAI,IAAI,CAYd;IAED,6EAA6E;IAC7E,KAAK,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,EAAE,YAAY,GAAG,IAAI,CAwEnD;IAED,wGAAwG;IACxG,OAAO,CAAC,MAAM;CAyDf"}
|
package/dist/webgl/ramps.js
CHANGED
|
@@ -38,7 +38,10 @@ void main(void) {
|
|
|
38
38
|
/**
|
|
39
39
|
* Each texel the entry of its line's ramp at its column, as rampOf finds it:
|
|
40
40
|
* the stop's colour, or the span's c0 + floor(d * j / w) in integers, the
|
|
41
|
-
* colour channels back through TO_SRGB in linear light, premultiplied.
|
|
41
|
+
* colour channels back through TO_SRGB in linear light, premultiplied. The
|
|
42
|
+
* ratios are read four a fetch, as the walk comes to them, and the quotient
|
|
43
|
+
* is found in floats and put right by its remainder: a fetch for each stop
|
|
44
|
+
* and four integer divisions an entry took SwiftShader a quarter more.
|
|
42
45
|
*/
|
|
43
46
|
export const RAMP_FRAGMENT = `#version 300 es
|
|
44
47
|
precision highp float;
|
|
@@ -48,19 +51,10 @@ uniform highp usampler2D uSrgb;
|
|
|
48
51
|
out vec4 finalColor;
|
|
49
52
|
int line;
|
|
50
53
|
|
|
51
|
-
int ratioOf(int i) {
|
|
52
|
-
uvec4 t = texelFetch(uRecords, ivec2(${RAMP_RATIOS / 4} + (i >> 2), line), 0);
|
|
53
|
-
return int(t[i & 3]);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
54
|
ivec4 colorOf(int i) {
|
|
57
55
|
return ivec4(texelFetch(uRecords, ivec2(${RAMP_COLORS / 4} + i, line), 0));
|
|
58
56
|
}
|
|
59
57
|
|
|
60
|
-
int floorDiv(int n, int w) {
|
|
61
|
-
return n >= 0 ? n / w : -((w - 1 - n) / w);
|
|
62
|
-
}
|
|
63
|
-
|
|
64
58
|
int srgb(int l) {
|
|
65
59
|
return int(texelFetch(uSrgb, ivec2(l, 0), 0).r);
|
|
66
60
|
}
|
|
@@ -71,7 +65,8 @@ void main(void) {
|
|
|
71
65
|
uvec4 head = texelFetch(uRecords, ivec2(0, line), 0);
|
|
72
66
|
int count = int(head[${RAMP_COUNT}]);
|
|
73
67
|
bool linear = head[${RAMP_LINEAR}] != 0u;
|
|
74
|
-
|
|
68
|
+
uvec4 ratios = texelFetch(uRecords, ivec2(${RAMP_RATIOS / 4}, line), 0);
|
|
69
|
+
int from = int(ratios.x);
|
|
75
70
|
ivec4 c;
|
|
76
71
|
if (k <= from) {
|
|
77
72
|
c = colorOf(0);
|
|
@@ -85,7 +80,11 @@ void main(void) {
|
|
|
85
80
|
break;
|
|
86
81
|
}
|
|
87
82
|
|
|
88
|
-
|
|
83
|
+
if ((i & 3) == 0) {
|
|
84
|
+
ratios = texelFetch(uRecords, ivec2(${RAMP_RATIOS / 4} + (i >> 2), line), 0);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
int to = int(ratios[i & 3]);
|
|
89
88
|
w = to - from;
|
|
90
89
|
int end = w <= 0 ? at : max(at, min(to, 255));
|
|
91
90
|
if (k <= end) {
|
|
@@ -105,16 +104,24 @@ void main(void) {
|
|
|
105
104
|
if (w > 0) {
|
|
106
105
|
ivec4 d = colorOf(span) - x;
|
|
107
106
|
int j = k - from;
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
107
|
+
// floor(n / w) exactly: n is within 255 * 255 of 0, so (n + 0.5) / w is
|
|
108
|
+
// at least 0.5 / w from a whole number, which a division up to about 16 ULP
|
|
109
|
+
// out cannot cross; the remainder puts the quotient right on a GPU that
|
|
110
|
+
// divides worse.
|
|
111
|
+
ivec4 n = d * j;
|
|
112
|
+
ivec4 q = ivec4(floor((vec4(n) + 0.5) / float(w)));
|
|
113
|
+
ivec4 r = n - q * w;
|
|
114
|
+
q += ivec4(greaterThanEqual(r, ivec4(w))) - ivec4(lessThan(r, ivec4(0)));
|
|
115
|
+
c = (x + q) & 255;
|
|
113
116
|
}
|
|
114
117
|
}
|
|
115
118
|
}
|
|
116
119
|
|
|
117
|
-
ivec3 rgb =
|
|
120
|
+
ivec3 rgb = c.rgb;
|
|
121
|
+
if (linear) {
|
|
122
|
+
rgb = ivec3(srgb(c.r), srgb(c.g), srgb(c.b));
|
|
123
|
+
}
|
|
124
|
+
|
|
118
125
|
rgb = (rgb * (c.a + 1)) >> 8;
|
|
119
126
|
finalColor = vec4(vec3(rgb), float(c.a)) / 255.0;
|
|
120
127
|
}
|
package/dist/webgl/ramps.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ramps.js","sourceRoot":"","sources":["../../src/webgl/ramps.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,yEAAyE;AACzE,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,4EAA4E;AAC5E,uCAAuC;AACvC,OAAO,EAAgB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,OAAO,GACR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEpE,8DAA8D;AAC9D,MAAM,aAAa,GAAG,UAAU,GAAG,CAAC,CAAC;AAErC,0FAA0F;AAC1F,MAAM,WAAW,GAAG,IAAI,CAAC;AAEzB;;;;;GAKG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG;;;;;;;;;;;;;;;CAe1B,CAAC;AAEF
|
|
1
|
+
{"version":3,"file":"ramps.js","sourceRoot":"","sources":["../../src/webgl/ramps.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,yEAAyE;AACzE,2EAA2E;AAC3E,0EAA0E;AAC1E,6EAA6E;AAC7E,4EAA4E;AAC5E,uCAAuC;AACvC,OAAO,EAAgB,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACrE,OAAO,EACL,UAAU,EACV,WAAW,EACX,UAAU,EACV,WAAW,EACX,WAAW,EACX,UAAU,EACV,OAAO,GACR,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAEpE,8D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,UAAU,EACf,CAAC,EACD,EAAE,CAAC,YAAY,EACf,EAAE,CAAC,aAAa,EAChB,GAAG,CAAC,WAAW,CAChB,CAAC;YACF,OAAO;QACT,CAAC;QAED,EAAE,CAAC,aAAa,CACd,EAAE,CAAC,UAAU,EACb,CAAC,EACD,CAAC,EACD,IAAI,EACJ,aAAa,EACb,EAAE,GAAG,IAAI,EACT,EAAE,CAAC,YAAY,EACf,EAAE,CAAC,aAAa,EAChB,GAAG,CAAC,WAAW,EACf,IAAI,GAAG,UAAU,CAClB,CAAC;IACJ,CAAC;CACF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@swf2es/render",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.47",
|
|
4
4
|
"description": "swf2es's own renderer: a scene list, a planner and a WebGL 2 backend (docs/renderer.md)",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"swf",
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"renderer",
|
|
9
9
|
"webgl2"
|
|
10
10
|
],
|
|
11
|
-
"homepage": "https://swf2es.
|
|
11
|
+
"homepage": "https://swf2es.dev/",
|
|
12
12
|
"bugs": "https://github.com/swf2es/swf2es/issues",
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
@@ -37,6 +37,6 @@
|
|
|
37
37
|
"src"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@swf2es/context3d": "0.1.
|
|
40
|
+
"@swf2es/context3d": "0.1.47"
|
|
41
41
|
}
|
|
42
42
|
}
|
package/src/webgl/ramps.ts
CHANGED
|
@@ -51,7 +51,10 @@ void main(void) {
|
|
|
51
51
|
/**
|
|
52
52
|
* Each texel the entry of its line's ramp at its column, as rampOf finds it:
|
|
53
53
|
* the stop's colour, or the span's c0 + floor(d * j / w) in integers, the
|
|
54
|
-
* colour channels back through TO_SRGB in linear light, premultiplied.
|
|
54
|
+
* colour channels back through TO_SRGB in linear light, premultiplied. The
|
|
55
|
+
* ratios are read four a fetch, as the walk comes to them, and the quotient
|
|
56
|
+
* is found in floats and put right by its remainder: a fetch for each stop
|
|
57
|
+
* and four integer divisions an entry took SwiftShader a quarter more.
|
|
55
58
|
*/
|
|
56
59
|
export const RAMP_FRAGMENT = `#version 300 es
|
|
57
60
|
precision highp float;
|
|
@@ -61,19 +64,10 @@ uniform highp usampler2D uSrgb;
|
|
|
61
64
|
out vec4 finalColor;
|
|
62
65
|
int line;
|
|
63
66
|
|
|
64
|
-
int ratioOf(int i) {
|
|
65
|
-
uvec4 t = texelFetch(uRecords, ivec2(${RAMP_RATIOS / 4} + (i >> 2), line), 0);
|
|
66
|
-
return int(t[i & 3]);
|
|
67
|
-
}
|
|
68
|
-
|
|
69
67
|
ivec4 colorOf(int i) {
|
|
70
68
|
return ivec4(texelFetch(uRecords, ivec2(${RAMP_COLORS / 4} + i, line), 0));
|
|
71
69
|
}
|
|
72
70
|
|
|
73
|
-
int floorDiv(int n, int w) {
|
|
74
|
-
return n >= 0 ? n / w : -((w - 1 - n) / w);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
71
|
int srgb(int l) {
|
|
78
72
|
return int(texelFetch(uSrgb, ivec2(l, 0), 0).r);
|
|
79
73
|
}
|
|
@@ -84,7 +78,8 @@ void main(void) {
|
|
|
84
78
|
uvec4 head = texelFetch(uRecords, ivec2(0, line), 0);
|
|
85
79
|
int count = int(head[${RAMP_COUNT}]);
|
|
86
80
|
bool linear = head[${RAMP_LINEAR}] != 0u;
|
|
87
|
-
|
|
81
|
+
uvec4 ratios = texelFetch(uRecords, ivec2(${RAMP_RATIOS / 4}, line), 0);
|
|
82
|
+
int from = int(ratios.x);
|
|
88
83
|
ivec4 c;
|
|
89
84
|
if (k <= from) {
|
|
90
85
|
c = colorOf(0);
|
|
@@ -98,7 +93,11 @@ void main(void) {
|
|
|
98
93
|
break;
|
|
99
94
|
}
|
|
100
95
|
|
|
101
|
-
|
|
96
|
+
if ((i & 3) == 0) {
|
|
97
|
+
ratios = texelFetch(uRecords, ivec2(${RAMP_RATIOS / 4} + (i >> 2), line), 0);
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
int to = int(ratios[i & 3]);
|
|
102
101
|
w = to - from;
|
|
103
102
|
int end = w <= 0 ? at : max(at, min(to, 255));
|
|
104
103
|
if (k <= end) {
|
|
@@ -118,16 +117,24 @@ void main(void) {
|
|
|
118
117
|
if (w > 0) {
|
|
119
118
|
ivec4 d = colorOf(span) - x;
|
|
120
119
|
int j = k - from;
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
120
|
+
// floor(n / w) exactly: n is within 255 * 255 of 0, so (n + 0.5) / w is
|
|
121
|
+
// at least 0.5 / w from a whole number, which a division up to about 16 ULP
|
|
122
|
+
// out cannot cross; the remainder puts the quotient right on a GPU that
|
|
123
|
+
// divides worse.
|
|
124
|
+
ivec4 n = d * j;
|
|
125
|
+
ivec4 q = ivec4(floor((vec4(n) + 0.5) / float(w)));
|
|
126
|
+
ivec4 r = n - q * w;
|
|
127
|
+
q += ivec4(greaterThanEqual(r, ivec4(w))) - ivec4(lessThan(r, ivec4(0)));
|
|
128
|
+
c = (x + q) & 255;
|
|
126
129
|
}
|
|
127
130
|
}
|
|
128
131
|
}
|
|
129
132
|
|
|
130
|
-
ivec3 rgb =
|
|
133
|
+
ivec3 rgb = c.rgb;
|
|
134
|
+
if (linear) {
|
|
135
|
+
rgb = ivec3(srgb(c.r), srgb(c.g), srgb(c.b));
|
|
136
|
+
}
|
|
137
|
+
|
|
131
138
|
rgb = (rgb * (c.a + 1)) >> 8;
|
|
132
139
|
finalColor = vec4(vec3(rgb), float(c.a)) / 255.0;
|
|
133
140
|
}
|