laymur 0.13.5 → 0.13.7
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 +37 -16
- package/dist/index.js.map +1 -1
- package/dist/index.min.js +1 -1
- package/dist/index.min.js.map +1 -1
- package/dist/miscellaneous/checkSRGBSupport.d.ts +1 -0
- package/package.json +1 -1
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
|
|
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 {
|
|
@@ -6587,7 +6608,7 @@ class UIGraphics extends UIElement {
|
|
|
6587
6608
|
throw new Error("UIGraphics.constructor: failed to get 2D context from canvas");
|
|
6588
6609
|
}
|
|
6589
6610
|
const texture = new CanvasTexture(canvas);
|
|
6590
|
-
texture.colorSpace = SRGBColorSpace;
|
|
6611
|
+
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
6591
6612
|
texture.minFilter = LinearFilter;
|
|
6592
6613
|
texture.magFilter = LinearFilter;
|
|
6593
6614
|
texture.needsUpdate = true;
|
|
@@ -6973,7 +6994,7 @@ class UIInsets {
|
|
|
6973
6994
|
}
|
|
6974
6995
|
}
|
|
6975
6996
|
|
|
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
|
|
6997
|
+
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
6998
|
|
|
6978
6999
|
/** Controls how sliceRegions values are interpreted */
|
|
6979
7000
|
var UINineSliceRegionMode;
|
|
@@ -7225,7 +7246,7 @@ class UIProgressMaskFunctionDirectional extends UIProgressMaskFunction {
|
|
|
7225
7246
|
}
|
|
7226
7247
|
}
|
|
7227
7248
|
|
|
7228
|
-
var source$1 = "vec4 draw(){vec2 transformedUV=(p_textureTransform*vec3(p_uv,1.0)).xy;vec4 diffuseColor=
|
|
7249
|
+
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
7250
|
|
|
7230
7251
|
const PROGRESS_DEFAULT_VALUE = 1;
|
|
7231
7252
|
|
|
@@ -8156,7 +8177,7 @@ class UIText extends UIElement {
|
|
|
8156
8177
|
throw new Error("UIText.constructor: failed to create canvas context");
|
|
8157
8178
|
}
|
|
8158
8179
|
const texture = new CanvasTexture(canvas);
|
|
8159
|
-
texture.colorSpace = SRGBColorSpace;
|
|
8180
|
+
texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
8160
8181
|
texture.needsUpdate = true;
|
|
8161
8182
|
const color = new UIColor(options.color);
|
|
8162
8183
|
super(layer, source$4, {
|
|
@@ -8356,7 +8377,7 @@ class UIText extends UIElement {
|
|
|
8356
8377
|
if (resolutionDirty) {
|
|
8357
8378
|
this._private_texture.dispose();
|
|
8358
8379
|
this._private_texture = new CanvasTexture(this._private_canvas);
|
|
8359
|
-
this._private_texture.colorSpace = SRGBColorSpace;
|
|
8380
|
+
this._private_texture.colorSpace = SRGB_SUPPORTED ? SRGBColorSpace : NoColorSpace;
|
|
8360
8381
|
this._private_texture.needsUpdate = true;
|
|
8361
8382
|
properties !== null && properties !== void 0 ? properties : properties = {};
|
|
8362
8383
|
properties["texture"] = this._private_texture;
|