@ikijs/engine 0.3.1 → 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/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: the fragment shader
367
- // multiplies rgb by alpha, the blend function is ONE /
368
- // ONE_MINUS_SRC_ALPHA, and the page compositor reads the framebuffer
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, false);
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
- // Premultiply: the blend function and the canvas compositing contract
922
- // (premultipliedAlpha: true) both expect rgb already scaled by alpha.
923
- outColor = vec4(tinted.rgb * tinted.a, tinted.a);
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: "none"
939
+ premultiplyAlpha: "premultiply"
937
940
  });
938
941
  }
939
942
  function createUnitQuad(gl) {