laymur 0.17.8 → 0.18.1

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.
@@ -1,9 +1,7 @@
1
1
  /** Transparency rendering modes */
2
2
  export declare enum UITransparencyMode {
3
- /** Binary transparency. Best performance. */
4
- CLIP = 0,
5
3
  /** Dithered transparency. Good performance. */
6
- HASH = 1,
7
- /** Alpha blending. Best quality, requires depth sorting. */
8
- BLEND = 2
4
+ HASH = 0,
5
+ /** Alpha blending. Best quality. */
6
+ BLEND = 1
9
7
  }
@@ -1,12 +1,10 @@
1
1
  /** Transparency rendering modes */
2
2
  var UITransparencyMode;
3
3
  (function (UITransparencyMode) {
4
- /** Binary transparency. Best performance. */
5
- UITransparencyMode[UITransparencyMode["CLIP"] = 0] = "CLIP";
6
4
  /** Dithered transparency. Good performance. */
7
- UITransparencyMode[UITransparencyMode["HASH"] = 1] = "HASH";
8
- /** Alpha blending. Best quality, requires depth sorting. */
9
- UITransparencyMode[UITransparencyMode["BLEND"] = 2] = "BLEND";
5
+ UITransparencyMode[UITransparencyMode["HASH"] = 0] = "HASH";
6
+ /** Alpha blending. Best quality. */
7
+ UITransparencyMode[UITransparencyMode["BLEND"] = 1] = "BLEND";
10
8
  })(UITransparencyMode || (UITransparencyMode = {}));
11
9
 
12
10
  export { UITransparencyMode };
@@ -1,7 +1,7 @@
1
1
  import { InstancedBufferGeometry, Uint16BufferAttribute, Float32BufferAttribute, Vector4, ShaderMaterial, DoubleSide, InstancedBufferAttribute, Vector2, Vector3, Matrix3, Matrix4 } from 'three';
2
2
  import { UIColor } from '../../color/UIColor.js';
3
3
  import { UITransparencyMode } from '../../UITransparencyMode.js';
4
- import { buildGenericPlaneFragmentShader, DEFAULT_ALPHA_TEST, resolveGLSLTypeInfo } from '../shared.js';
4
+ import { buildGenericPlaneFragmentShader, resolveGLSLTypeInfo } from '../shared.js';
5
5
 
6
6
  const INSTANCED_PLANE_GEOMETRY = (() => {
7
7
  const geometry = new InstancedBufferGeometry();
@@ -103,18 +103,21 @@ function buildMaterial(source, uniformProperties, varyingProperties, transparenc
103
103
  gl_Position = projectionMatrix * a_instanceTransform * vec4(position, 1.0);
104
104
  }
105
105
  `;
106
- const fragmentShader = buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source);
106
+ const alphaTestValue = 0.0075;
107
+ const premultipliedAlpha = transparency === UITransparencyMode.BLEND;
108
+ const fragmentShader = buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue, premultipliedAlpha);
107
109
  return new ShaderMaterial({
108
110
  uniforms,
109
111
  vertexShader,
110
112
  fragmentShader,
111
113
  transparent: transparency === UITransparencyMode.BLEND,
112
- alphaTest: transparency === UITransparencyMode.CLIP ? DEFAULT_ALPHA_TEST : 0.0,
114
+ alphaTest: alphaTestValue,
113
115
  alphaHash: transparency === UITransparencyMode.HASH,
114
- depthWrite: transparency !== UITransparencyMode.BLEND,
115
- depthTest: true,
116
+ depthWrite: false,
117
+ depthTest: false,
116
118
  side: DoubleSide,
117
119
  forceSinglePass: true,
120
+ premultipliedAlpha,
118
121
  });
119
122
  }
120
123
  function reconstructValue(referenceValue, array, offset) {
@@ -23,7 +23,6 @@ export interface PlaneData {
23
23
  visibility: boolean;
24
24
  transparency: UITransparencyMode;
25
25
  }
26
- export declare const DEFAULT_ALPHA_TEST = 0.5;
27
26
  export declare function resolveGLSLTypeInfo(value: UIProperty | UIPropertyName | UIPropertyConstructor): GLTypeInfo;
28
27
  export declare function resolvePropertyUniform(name: string, material: ShaderMaterial): IUniform<UIProperty>;
29
28
  export declare function arePropertiesPartiallyCompatible(full: Readonly<Record<string, Readonly<GLProperty>>>, partial: Readonly<Record<string, Readonly<GLProperty>>>): boolean;
@@ -35,4 +34,4 @@ export declare function cloneGLProperties(properties: Record<string, GLProperty>
35
34
  export declare function extractZIndex(transform: Matrix4): number;
36
35
  /** Extracts zIndex from transform buffer at given instance index */
37
36
  export declare function extractZIndexFromBuffer(buffer: Float32Array, instanceIndex: number): number;
38
- export declare function buildGenericPlaneFragmentShader(uniformDeclarations: string[], varyingDeclarations: string[], source: string): string;
37
+ export declare function buildGenericPlaneFragmentShader(uniformDeclarations: string[], varyingDeclarations: string[], source: string, alphaTestValue: number, usePremultipliedAlpha: boolean): string;
@@ -2,7 +2,6 @@ import { Texture, Vector2, Vector3, Vector4, Matrix3, Matrix4 } from 'three';
2
2
  import { UIColor } from '../color/UIColor.js';
3
3
  import { checkSRGBSupport } from '../webglCapabilities.js';
4
4
 
5
- const DEFAULT_ALPHA_TEST = 0.5;
6
5
  const GLSL_TYPE_INFO_FLOAT = Object.freeze({
7
6
  glslTypeName: "float",
8
7
  bufferSize: 1,
@@ -178,7 +177,7 @@ function extractZIndex(transform) {
178
177
  function extractZIndexFromBuffer(buffer, instanceIndex) {
179
178
  return buffer[instanceIndex * 16 + 14];
180
179
  }
181
- function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source) {
180
+ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclarations, source, alphaTestValue, usePremultipliedAlpha) {
182
181
  return `
183
182
  // Defines
184
183
  #define PI 3.14159265359
@@ -210,19 +209,19 @@ function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDeclaration
210
209
  ${source}
211
210
  void main() {
212
211
  vec4 diffuseColor = draw();
213
- #ifdef USE_ALPHATEST
214
- if (diffuseColor.a < ${DEFAULT_ALPHA_TEST.toFixed(2)}) {
215
- discard;
216
- }
217
- #endif
212
+ if (diffuseColor.a <= ${alphaTestValue.toFixed(8)}) {
213
+ discard;
214
+ }
218
215
  #ifdef USE_ALPHAHASH
219
216
  if (diffuseColor.a < getAlphaHashThreshold(p_position)) {
220
217
  discard;
221
218
  }
222
219
  #endif
220
+
223
221
  gl_FragColor = linearToOutputTexel(diffuseColor);
222
+ gl_FragColor = ${usePremultipliedAlpha ? "vec4(gl_FragColor.rgb * gl_FragColor.a, gl_FragColor.a)" : "gl_FragColor"};
224
223
  }
225
224
  `;
226
225
  }
227
226
 
228
- export { DEFAULT_ALPHA_TEST, arePropertiesPartiallyCompatible, buildGenericPlaneFragmentShader, cloneGLProperties, cloneProperties, cloneProperty, convertUIPropertiesToGLProperties, extractZIndex, extractZIndexFromBuffer, resolveGLSLTypeInfo, resolvePropertyUniform };
227
+ export { arePropertiesPartiallyCompatible, buildGenericPlaneFragmentShader, cloneGLProperties, cloneProperties, cloneProperty, convertUIPropertiesToGLProperties, extractZIndex, extractZIndexFromBuffer, resolveGLSLTypeInfo, resolvePropertyUniform };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "laymur",
3
- "version": "0.17.8",
3
+ "version": "0.18.1",
4
4
  "description": "Constraint-based UI library for Three.js mobile advertisements",
5
5
  "keywords": [
6
6
  "ui",