@ikijs/engine 0.3.0 → 0.3.2
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/README.md +4 -2
- package/dist/index.js +28 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +28 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -363,10 +363,10 @@ var IkiPlayer = class {
|
|
|
363
363
|
this.canvas = canvas;
|
|
364
364
|
const gl = canvas.getContext("webgl2", {
|
|
365
365
|
alpha: true,
|
|
366
|
-
// The whole pipeline is premultiplied-alpha:
|
|
367
|
-
//
|
|
368
|
-
// ONE_MINUS_SRC_ALPHA, and the page compositor reads the
|
|
369
|
-
// as premultiplied. Straight-alpha (`premultipliedAlpha: false`) cannot
|
|
366
|
+
// The whole pipeline is premultiplied-alpha: textures are uploaded
|
|
367
|
+
// premultiplied, the fragment shader keeps them so, the blend function
|
|
368
|
+
// is ONE / ONE_MINUS_SRC_ALPHA, and the page compositor reads the
|
|
369
|
+
// framebuffer as premultiplied. Straight-alpha (`premultipliedAlpha: false`) cannot
|
|
370
370
|
// be made consistent with SRC_ALPHA-style blending: semi-transparent
|
|
371
371
|
// pixels over a transparent background come out premultiplied anyway
|
|
372
372
|
// and composite too dark.
|
|
@@ -502,7 +502,7 @@ var IkiPlayer = class {
|
|
|
502
502
|
return null;
|
|
503
503
|
}
|
|
504
504
|
gl.bindTexture(gl.TEXTURE_2D, texture);
|
|
505
|
-
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL,
|
|
505
|
+
gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, true);
|
|
506
506
|
gl.pixelStorei(gl.UNPACK_FLIP_Y_WEBGL, false);
|
|
507
507
|
drainGlErrors(gl);
|
|
508
508
|
gl.texImage2D(
|
|
@@ -913,14 +913,17 @@ uniform float u_alphaCutoff;
|
|
|
913
913
|
in vec2 v_uv;
|
|
914
914
|
out vec4 outColor;
|
|
915
915
|
void main() {
|
|
916
|
+
// Texels are premultiplied (see the upload); the untextured fill is opaque
|
|
917
|
+
// white, premultiplied or not.
|
|
916
918
|
vec4 base = u_useTexture ? texture(u_tex, v_uv) : vec4(1.0);
|
|
917
919
|
vec4 tinted = base * u_color;
|
|
918
920
|
// 0 for normal draws (no-op); raised during the stencil mask-write pass so
|
|
919
921
|
// only opaque mask coverage marks the stencil (the transparent fringe is cut).
|
|
920
922
|
if (tinted.a < u_alphaCutoff) discard;
|
|
921
|
-
//
|
|
922
|
-
//
|
|
923
|
-
|
|
923
|
+
// The blend function and the canvas compositing contract (premultipliedAlpha:
|
|
924
|
+
// true) both expect rgb already scaled by alpha. base.rgb is; the tint's own
|
|
925
|
+
// alpha still has to scale it (base.a is already folded into base.rgb).
|
|
926
|
+
outColor = vec4(tinted.rgb * u_color.a, tinted.a);
|
|
924
927
|
}`;
|
|
925
928
|
async function decodeTexture(source) {
|
|
926
929
|
if (!source.startsWith("data:")) {
|
|
@@ -933,7 +936,7 @@ async function decodeTexture(source) {
|
|
|
933
936
|
const blob = await (await fetch(source)).blob();
|
|
934
937
|
return createImageBitmap(blob, {
|
|
935
938
|
imageOrientation: "none",
|
|
936
|
-
premultiplyAlpha: "
|
|
939
|
+
premultiplyAlpha: "premultiply"
|
|
937
940
|
});
|
|
938
941
|
}
|
|
939
942
|
function createUnitQuad(gl) {
|
|
@@ -1037,7 +1040,10 @@ var FixedStepClock = class {
|
|
|
1037
1040
|
// src/idle-motion.ts
|
|
1038
1041
|
var BLINK_INTERVAL_MIN_MS = 1500;
|
|
1039
1042
|
var BLINK_INTERVAL_MAX_MS = 6e3;
|
|
1040
|
-
var
|
|
1043
|
+
var BLINK_CLOSE_MS = 60;
|
|
1044
|
+
var BLINK_HOLD_MS = 20;
|
|
1045
|
+
var BLINK_OPEN_MS = 100;
|
|
1046
|
+
var BLINK_DURATION_MS = BLINK_CLOSE_MS + BLINK_HOLD_MS + BLINK_OPEN_MS;
|
|
1041
1047
|
var BREATH_PERIOD_MS = 3500;
|
|
1042
1048
|
var GAZE_RADIUS = 0.3;
|
|
1043
1049
|
var GAZE_RETARGET_MIN_MS = 1200;
|
|
@@ -1055,7 +1061,18 @@ function lerp(a, b, t) {
|
|
|
1055
1061
|
return a + (b - a) * t;
|
|
1056
1062
|
}
|
|
1057
1063
|
function blinkEnvelope(phase) {
|
|
1058
|
-
|
|
1064
|
+
const ms = phase * BLINK_DURATION_MS;
|
|
1065
|
+
if (ms <= 0) return 1;
|
|
1066
|
+
if (ms < BLINK_CLOSE_MS) {
|
|
1067
|
+
const t = ms / BLINK_CLOSE_MS;
|
|
1068
|
+
return 1 - t * t * (3 - 2 * t);
|
|
1069
|
+
}
|
|
1070
|
+
if (ms <= BLINK_CLOSE_MS + BLINK_HOLD_MS) return 0;
|
|
1071
|
+
if (ms < BLINK_DURATION_MS) {
|
|
1072
|
+
const t = (ms - BLINK_CLOSE_MS - BLINK_HOLD_MS) / BLINK_OPEN_MS;
|
|
1073
|
+
return 1 - (1 - t) * (1 - t);
|
|
1074
|
+
}
|
|
1075
|
+
return 1;
|
|
1059
1076
|
}
|
|
1060
1077
|
function randomInDisk(rng, radius) {
|
|
1061
1078
|
const r = Math.sqrt(rng()) * radius;
|