laymur 0.13.6 → 0.13.8

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.js CHANGED
@@ -1,4 +1,4 @@
1
- import { MathUtils, Color, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, CanvasTexture, SRGBColorSpace, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, Ray } from 'three';
1
+ import { MathUtils, Color, Vector4, Texture, Vector2, Vector3, Matrix3, Matrix4, PlaneGeometry, InstancedBufferGeometry, ShaderMaterial, InstancedBufferAttribute, Mesh, Scene, OrthographicCamera, Quaternion, CanvasTexture, SRGBColorSpace, NoColorSpace, LinearFilter, WebGLRenderTarget, UnsignedByteType, RGBAFormat, PerspectiveCamera, Ray } from 'three';
2
2
 
3
3
  class t {
4
4
  constructor(t, i) {
@@ -2556,6 +2556,20 @@ class UIColor {
2556
2556
  }
2557
2557
  }
2558
2558
 
2559
+ const checkSRGBSupport = () => {
2560
+ var _a;
2561
+ const canvas = document.createElement("canvas");
2562
+ const gl = (_a = canvas.getContext("webgl2")) !== null && _a !== void 0 ? _a : canvas.getContext("webgl");
2563
+ if (!gl) {
2564
+ return false;
2565
+ }
2566
+ if (gl instanceof WebGL2RenderingContext) {
2567
+ return true;
2568
+ }
2569
+ return gl.getExtension("EXT_sRGB") !== null;
2570
+ };
2571
+ const SRGB_SUPPORTED = checkSRGBSupport();
2572
+
2559
2573
  const DEFAULT_ALPHA_TEST = 0.5;
2560
2574
  const GLSL_TYPE_INFO_FLOAT = Object.freeze({
2561
2575
  glslTypeName: "float",
@@ -2720,37 +2734,44 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
2720
2734
  return `
2721
2735
  // Defines
2722
2736
  #define PI 3.14159265359
2723
-
2737
+ #define SRGB_SUPPORTED ${SRGB_SUPPORTED ? '1' : '0'}
2738
+
2724
2739
  // Uniforms
2725
2740
  ${uniformDeclarations.join("\n")}
2726
-
2741
+
2727
2742
  // Builtin varyings
2728
2743
  varying vec3 p_position;
2729
2744
  varying vec2 p_uv;
2730
-
2745
+
2731
2746
  // User varyings
2732
2747
  ${varyingDeclarations.join("\n")}
2733
-
2748
+
2734
2749
  #include <alphahash_pars_fragment>
2735
-
2750
+
2751
+ // sRGB decode helper
2752
+ vec4 srgbTexture2D(sampler2D textureSampler, vec2 uv) {
2753
+ #if SRGB_SUPPORTED
2754
+ return texture2D(textureSampler, uv);
2755
+ #else
2756
+ vec4 textureValue = texture2D(textureSampler, uv);
2757
+ return vec4(pow(textureValue.rgb, vec3(2.2)), textureValue.a);
2758
+ #endif
2759
+ }
2760
+
2736
2761
  // Source must define vec4 draw() function
2737
2762
  ${source}
2738
-
2739
2763
  void main() {
2740
2764
  vec4 diffuseColor = draw();
2741
-
2742
2765
  #ifdef USE_ALPHATEST
2743
2766
  if (diffuseColor.a < ${DEFAULT_ALPHA_TEST.toFixed(2)}) {
2744
2767
  discard;
2745
2768
  }
2746
2769
  #endif
2747
-
2748
2770
  #ifdef USE_ALPHAHASH
2749
2771
  if (diffuseColor.a < getAlphaHashThreshold(p_position)) {
2750
2772
  discard;
2751
2773
  }
2752
2774
  #endif
2753
-
2754
2775
  gl_FragColor = linearToOutputTexel(diffuseColor);
2755
2776
  }
2756
2777
  `;
@@ -5879,7 +5900,7 @@ class UITextureView extends i {
5879
5900
  }
5880
5901
  }
5881
5902
 
5882
- var source$4 = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;return texture2D(p_texture,transformedUV)*p_color;}";
5903
+ var source$4 = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;return srgbTexture2D(p_texture,transformedUV)*p_color;}";
5883
5904
 
5884
5905
  /** Transforms that don't affect constraints */
5885
5906
  class UIMicro {
@@ -6555,14 +6576,34 @@ class UIAnimatedImage extends UIElement {
6555
6576
  * @returns Canvas instance
6556
6577
  */
6557
6578
  function createCanvas(width, height) {
6558
- if (typeof OffscreenCanvas !== "undefined") {
6559
- return new OffscreenCanvas(width, height);
6560
- }
6561
6579
  const canvas = document.createElement("canvas");
6562
6580
  canvas.width = width;
6563
6581
  canvas.height = height;
6564
6582
  return canvas;
6565
6583
  }
6584
+ // /** Canvas type that works both in main thread and workers */
6585
+ // export type UICanvas = OffscreenCanvas | HTMLCanvasElement;
6586
+ // /** 2D rendering context type for UICanvas */
6587
+ // export type UICanvasRenderingContext2D =
6588
+ // | OffscreenCanvasRenderingContext2D
6589
+ // | CanvasRenderingContext2D;
6590
+ // /**
6591
+ // * Creates a canvas with OffscreenCanvas fallback to HTMLCanvasElement.
6592
+ // * Uses OffscreenCanvas when available, falls back to HTMLCanvasElement otherwise.
6593
+ // *
6594
+ // * @param width - Canvas width in pixels
6595
+ // * @param height - Canvas height in pixels
6596
+ // * @returns Canvas instance
6597
+ // */
6598
+ // export function createCanvas(width: number, height: number): UICanvas {
6599
+ // if (typeof OffscreenCanvas !== "undefined") {
6600
+ // return new OffscreenCanvas(width, height);
6601
+ // }
6602
+ // const canvas = document.createElement("canvas");
6603
+ // canvas.width = width;
6604
+ // canvas.height = height;
6605
+ // return canvas;
6606
+ // }
6566
6607
 
6567
6608
  const GRAPHICS_DEFAULT_WIDTH = 2;
6568
6609
  const GRAPHICS_DEFAULT_HEIGHT = 2;
@@ -6587,7 +6628,7 @@ class UIGraphics extends UIElement {
6587
6628
  throw new Error("UIGraphics.constructor: failed to get 2D context from canvas");
6588
6629
  }
6589
6630
  const texture = new CanvasTexture(canvas);
6590
- texture.colorSpace = SRGBColorSpace;
6631
+ texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
6591
6632
  texture.minFilter = LinearFilter;
6592
6633
  texture.magFilter = LinearFilter;
6593
6634
  texture.needsUpdate = true;
@@ -6973,7 +7014,7 @@ class UIInsets {
6973
7014
  }
6974
7015
  }
6975
7016
 
6976
- var source$3 = "vec4 draw(){vec2 localUV=p_uv;float left=p_sliceBorders.x;float right=p_sliceBorders.y;float top=p_sliceBorders.z;float bottom=p_sliceBorders.w;float leftFill=p_sliceRegions.x;float rightFill=p_sliceRegions.y;float topFill=p_sliceRegions.z;float bottomFill=p_sliceRegions.w;float lB=leftFill;float rB=1.0-rightFill;float bB=bottomFill;float tB=1.0-topFill;{float regionL=step(p_uv.x,lB);float regionR=step(rB,p_uv.x);float regionM=1.0-regionL-regionR;float xL=(p_uv.x/lB)*left;float xR=1.0-right+((p_uv.x-rB)/rightFill)*right;float xM=left+((p_uv.x-lB)/(rB-lB))*(1.0-left-right);localUV.x=regionL*xL+regionM*xM+regionR*xR;}{float regionB=step(p_uv.y,bB);float regionT=step(tB,p_uv.y);float regionC=1.0-regionB-regionT;float yB=(p_uv.y/bB)*bottom;float yT=1.0-top+((p_uv.y-tB)/topFill)*top;float yC=bottom+((p_uv.y-bB)/(tB-bB))*(1.0-bottom-top);localUV.y=regionB*yB+regionC*yC+regionT*yT;}vec2 transformedUV=(p_textureTransform*vec3(localUV,1.0)).xy;return texture2D(p_texture,transformedUV)*p_color;}";
7017
+ var source$3 = "vec4 draw(){vec2 localUV=p_uv;float left=p_sliceBorders.x;float right=p_sliceBorders.y;float top=p_sliceBorders.z;float bottom=p_sliceBorders.w;float leftFill=p_sliceRegions.x;float rightFill=p_sliceRegions.y;float topFill=p_sliceRegions.z;float bottomFill=p_sliceRegions.w;float lB=leftFill;float rB=1.0-rightFill;float bB=bottomFill;float tB=1.0-topFill;{float regionL=step(p_uv.x,lB);float regionR=step(rB,p_uv.x);float regionM=1.0-regionL-regionR;float xL=(p_uv.x/lB)*left;float xR=1.0-right+((p_uv.x-rB)/rightFill)*right;float xM=left+((p_uv.x-lB)/(rB-lB))*(1.0-left-right);localUV.x=regionL*xL+regionM*xM+regionR*xR;}{float regionB=step(p_uv.y,bB);float regionT=step(tB,p_uv.y);float regionC=1.0-regionB-regionT;float yB=(p_uv.y/bB)*bottom;float yT=1.0-top+((p_uv.y-tB)/topFill)*top;float yC=bottom+((p_uv.y-bB)/(tB-bB))*(1.0-bottom-top);localUV.y=regionB*yB+regionC*yC+regionT*yT;}vec2 transformedUV=(p_textureTransform*vec3(localUV,1.0)).xy;return srgbTexture2D(p_texture,transformedUV)*p_color;}";
6977
7018
 
6978
7019
  /** Controls how sliceRegions values are interpreted */
6979
7020
  var UINineSliceRegionMode;
@@ -7225,7 +7266,7 @@ class UIProgressMaskFunctionDirectional extends UIProgressMaskFunction {
7225
7266
  }
7226
7267
  }
7227
7268
 
7228
- var source$1 = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=texture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}";
7269
+ var source$1 = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=srgbTexture2D(p_texture,transformedUV)*p_color;diffuseColor.a*=calculateMask();return diffuseColor;}";
7229
7270
 
7230
7271
  const PROGRESS_DEFAULT_VALUE = 1;
7231
7272
 
@@ -8156,7 +8197,7 @@ class UIText extends UIElement {
8156
8197
  throw new Error("UIText.constructor: failed to create canvas context");
8157
8198
  }
8158
8199
  const texture = new CanvasTexture(canvas);
8159
- texture.colorSpace = SRGBColorSpace;
8200
+ texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
8160
8201
  texture.needsUpdate = true;
8161
8202
  const color = new UIColor(options.color);
8162
8203
  super(layer, source$4, {
@@ -8356,7 +8397,7 @@ class UIText extends UIElement {
8356
8397
  if (resolutionDirty) {
8357
8398
  this._private_texture.dispose();
8358
8399
  this._private_texture = new CanvasTexture(this._private_canvas);
8359
- this._private_texture.colorSpace = SRGBColorSpace;
8400
+ this._private_texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
8360
8401
  this._private_texture.needsUpdate = true;
8361
8402
  properties !== null && properties !== void 0 ? properties : properties = {};
8362
8403
  properties["texture"] = this._private_texture;