laymur 0.25.2 → 0.27.0
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 +114 -34
- package/dist/core/constraints/UICustomConstraint.d.ts +1 -1
- package/dist/core/constraints/UIHorizontalInterpolationConstraint/UIHorizontalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/UIVerticalInterpolationConstraint/UIVerticalInterpolationConstraint.js +1 -1
- package/dist/core/constraints/builders/UIConstraint2DBuilder.d.ts +2 -3
- package/dist/core/elements/UIAnchor/UIAnchor.d.ts +2 -2
- package/dist/core/elements/UIAnchor/UIAnchor.js +3 -2
- package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.d.ts +2 -2
- package/dist/core/elements/UIAnimatedImage/UIAnimatedImage.js +24 -12
- package/dist/core/elements/UIDummy/UIDummy.Internal.d.ts +13 -0
- package/dist/core/elements/UIDummy/UIDummy.d.ts +74 -5
- package/dist/core/elements/UIDummy/UIDummy.js +222 -29
- package/dist/core/elements/UIElement/UIElement.Internal.d.ts +1 -1
- package/dist/core/elements/UIElement/UIElement.d.ts +37 -1
- package/dist/core/elements/UIElement/UIElement.js +84 -6
- package/dist/core/elements/UIGraphics/UIGraphics.Internal.d.ts +1 -1
- package/dist/core/elements/UIGraphics/UIGraphics.d.ts +1 -1
- package/dist/core/elements/UIGraphics/UIGraphics.js +4 -4
- package/dist/core/elements/UIImage/UIImage.d.ts +2 -2
- package/dist/core/elements/UIImage/UIImage.js +10 -8
- package/dist/core/elements/UINineSlice/UINineSlice.d.ts +4 -4
- package/dist/core/elements/UINineSlice/UINineSlice.js +11 -9
- package/dist/core/elements/UIProgress/UIProgress.d.ts +2 -2
- package/dist/core/elements/UIProgress/UIProgress.js +17 -15
- package/dist/core/elements/UIScene/UIScene.Internal.d.ts +1 -1
- package/dist/core/elements/UIScene/UIScene.d.ts +3 -2
- package/dist/core/elements/UIScene/UIScene.js +21 -14
- package/dist/core/elements/UIText/UIText.Measuring.d.ts +1 -1
- package/dist/core/elements/UIText/UIText.d.ts +3 -3
- package/dist/core/elements/UIText/UIText.js +8 -8
- package/dist/core/index.d.ts +60 -11
- package/dist/core/index.js +22 -7
- package/dist/core/layers/UILayer/UILayer.d.ts +45 -5
- package/dist/core/layers/UILayer/UILayer.js +103 -10
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.Internal.d.ts +27 -0
- package/dist/core/layers/{UIFullscreenLayer/UIFullscreenLayer.Internal.js → UIViewportLayer/UIViewportLayer.Internal.js} +1 -1
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.d.ts +98 -0
- package/dist/core/layers/UIViewportLayer/UIViewportLayer.js +251 -0
- package/dist/core/miscellaneous/UIAffineMatrix3.d.ts +13 -0
- package/dist/core/miscellaneous/UIAffineMatrix3.js +13 -0
- package/dist/core/miscellaneous/area/UIArea.d.ts +10 -1
- package/dist/core/miscellaneous/area/UIArea.js +4 -1
- package/dist/core/miscellaneous/area/UIAreaCircle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaCircle.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaPolygon.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaPolygon.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaRectangle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaRectangle.js +0 -1
- package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.d.ts +1 -0
- package/dist/core/miscellaneous/area/UIAreaRoundedRectangle.js +0 -1
- package/dist/core/miscellaneous/asserts.d.ts +23 -0
- package/dist/core/miscellaneous/asserts.js +44 -0
- package/dist/core/miscellaneous/canvas.js +7 -2
- package/dist/core/miscellaneous/color/UIColor.js +5 -2
- package/dist/core/miscellaneous/computeTransform.d.ts +12 -0
- package/dist/core/miscellaneous/computeTransform.js +20 -0
- package/dist/core/miscellaneous/context-monitor/UIContextMonitor.d.ts +1 -0
- package/dist/core/miscellaneous/context-monitor/UIContextMonitor.js +60 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.d.ts +17 -3
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Internal.js +88 -26
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.d.ts +9 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.Layout.js +29 -6
- package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js +51 -11
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.Internal.d.ts +2 -0
- package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js +47 -6
- package/dist/core/miscellaneous/generic-plane/shared.d.ts +15 -3
- package/dist/core/miscellaneous/generic-plane/shared.js +38 -7
- package/dist/core/miscellaneous/generic-plane/varyingPacking.d.ts +46 -0
- package/dist/core/miscellaneous/generic-plane/varyingPacking.js +170 -0
- package/dist/core/miscellaneous/mask/UIMask.Internal.d.ts +61 -0
- package/dist/core/miscellaneous/mask/UIMask.Internal.js +56 -0
- package/dist/core/miscellaneous/mask/UIMask.d.ts +84 -0
- package/dist/core/miscellaneous/mask/UIMask.js +265 -0
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.d.ts +50 -0
- package/dist/core/miscellaneous/mask/UIMaskMaterialPatch.js +233 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.d.ts +10 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunction.js +7 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.d.ts +2 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionCircular.js +0 -1
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.d.ts +2 -0
- package/dist/core/miscellaneous/mask-function/UIProgressMaskFunctionDirectional.js +0 -1
- package/dist/core/miscellaneous/micro/UIMicro.Internal.d.ts +3 -0
- package/dist/core/miscellaneous/micro/UIMicro.Internal.js +1 -0
- package/dist/core/miscellaneous/micro/UIMicro.d.ts +18 -1
- package/dist/core/miscellaneous/micro/UIMicro.js +23 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.d.ts +19 -1
- package/dist/core/miscellaneous/resize-policy/UIResizePolicy.js +16 -3
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCover.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCross.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyCrossInverted.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFit.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedHeight.js +2 -2
- package/dist/core/miscellaneous/resize-policy/UIResizePolicyFixedWidth.js +2 -2
- package/dist/core/miscellaneous/text-style/UITextStyle.js +2 -2
- package/dist/core/miscellaneous/texture/UITextureView.d.ts +6 -2
- package/dist/core/miscellaneous/texture/UITextureView.js +13 -9
- package/dist/core/miscellaneous/viewport/UIElementViewport.d.ts +31 -0
- package/dist/core/miscellaneous/viewport/UIElementViewport.js +54 -0
- package/dist/core/miscellaneous/viewport/UIViewport.d.ts +37 -0
- package/dist/core/miscellaneous/viewport/UIViewport.js +31 -0
- package/dist/core/miscellaneous/viewport/UIWindowViewport.d.ts +13 -0
- package/dist/core/miscellaneous/viewport/UIWindowViewport.js +25 -0
- package/dist/core/miscellaneous/webglCapabilities.js +61 -55
- package/dist/core/shaders/UIMask.d.ts +15 -0
- package/dist/core/shaders/UIMask.js +45 -0
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.Internal.d.ts +36 -5
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.d.ts +23 -2
- package/dist/core/wrappers/UIInputWrapper/UIInputWrapper.js +153 -15
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.Internal.d.ts +3 -1
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.d.ts +1 -0
- package/dist/core/wrappers/UISceneWrapper/UISceneWrapper.js +3 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.Internal.d.ts +2 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.d.ts +3 -0
- package/dist/core/wrappers/UISolverWrapper/UISolverWrapper.js +36 -16
- package/dist/debug/UIAspectDebug.js +4 -0
- package/dist/debug/UIHeightDebug.js +4 -0
- package/dist/debug/UIHorizontalDistanceDebug.js +5 -0
- package/dist/debug/UIHorizontalInterpolationDebug.js +5 -0
- package/dist/debug/UILayerDebug.d.ts +7 -0
- package/dist/debug/UILayerDebug.js +21 -0
- package/dist/debug/UIVerticalDistanceDebug.js +5 -0
- package/dist/debug/UIVerticalInterpolationDebug.js +5 -0
- package/dist/debug/UIWidthDebug.js +4 -0
- package/dist/debug/index.d.ts +2 -0
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorDirectionalGravity.js +0 -2
- package/dist/particles/behaviorModules/UIBehaviorModule.d.ts +12 -2
- package/dist/particles/behaviorModules/UIBehaviorModule.js +2 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorPointGravity.js +13 -12
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOscillation.js +6 -6
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorScaleOverLife.js +4 -5
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.d.ts +8 -1
- package/dist/particles/behaviorModules/UIBehaviorTorqueDamping.js +8 -10
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.d.ts +10 -2
- package/dist/particles/behaviorModules/UIBehaviorTorqueNoise.js +8 -7
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.d.ts +7 -0
- package/dist/particles/behaviorModules/UIBehaviorVelocityDamping.js +8 -10
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.d.ts +13 -4
- package/dist/particles/behaviorModules/UIBehaviorVelocityNoise.js +12 -10
- package/dist/particles/elements/UIEmitter.Internal.d.ts +21 -1
- package/dist/particles/elements/UIEmitter.Internal.js +6 -0
- package/dist/particles/elements/UIEmitter.d.ts +20 -11
- package/dist/particles/elements/UIEmitter.js +100 -54
- package/dist/particles/index.d.ts +7 -1
- package/dist/particles/index.js +4 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.d.ts +19 -4
- package/dist/particles/instancedParticle/UIInstancedParticle.Internal.js +117 -83
- package/dist/particles/instancedParticle/UIInstancedParticle.d.ts +8 -0
- package/dist/particles/instancedParticle/UIInstancedParticle.js +41 -4
- package/dist/particles/miscellaneous/miscellaneous.d.ts +34 -0
- package/dist/particles/miscellaneous/miscellaneous.js +72 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingColorOverLife.js +2 -4
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingColorOverVelocity.js +2 -5
- package/dist/particles/renderingModules/UIRenderingModule.d.ts +11 -1
- package/dist/particles/renderingModules/UIRenderingModule.js +4 -1
- package/dist/particles/renderingModules/UIRenderingTexture.d.ts +4 -0
- package/dist/particles/renderingModules/UIRenderingTexture.js +2 -1
- package/dist/particles/shaders/UIRenderingColorOverLife.d.ts +1 -2
- package/dist/particles/shaders/UIRenderingColorOverLife.js +5 -3
- package/dist/particles/shaders/UIRenderingColorOverVelocity.d.ts +1 -9
- package/dist/particles/shaders/UIRenderingColorOverVelocity.js +6 -13
- package/dist/particles/spawnModules/UISpawnModule.d.ts +16 -1
- package/dist/particles/spawnModules/UISpawnModule.js +3 -1
- package/dist/particles/spawnModules/UISpawnOffset.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnOffset.js +0 -2
- package/dist/particles/spawnModules/UISpawnRandomLifetime.d.ts +8 -1
- package/dist/particles/spawnModules/UISpawnRandomLifetime.js +5 -7
- package/dist/particles/spawnModules/UISpawnRandomRotation.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomRotation.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomScale.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomScale.js +4 -5
- package/dist/particles/spawnModules/UISpawnRandomTorque.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomTorque.js +5 -5
- package/dist/particles/spawnModules/UISpawnRandomVelocity.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRandomVelocity.js +6 -6
- package/dist/particles/spawnModules/UISpawnRectangle.d.ts +7 -0
- package/dist/particles/spawnModules/UISpawnRectangle.js +6 -6
- package/package.json +13 -4
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.Internal.d.ts +0 -21
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.d.ts +0 -63
- package/dist/core/layers/UIFullscreenLayer/UIFullscreenLayer.js +0 -144
|
@@ -19,7 +19,7 @@ export function packedAttributeName(attributeIndex) {
|
|
|
19
19
|
return `a_packed${attributeIndex}`;
|
|
20
20
|
}
|
|
21
21
|
export function buildPackedFieldSpec(name, glslTypeInfo) {
|
|
22
|
-
const { glslTypeName, bufferSize, columnCount, instantiable } = glslTypeInfo;
|
|
22
|
+
const { glslTypeName, bufferSize, columnCount, instantiable, affine } = glslTypeInfo;
|
|
23
23
|
if (!instantiable) {
|
|
24
24
|
throw new Error(`buildPackedFieldSpec.glslTypeInfo: "${name}" (${glslTypeName}) is not instantiable`);
|
|
25
25
|
}
|
|
@@ -28,7 +28,7 @@ export function buildPackedFieldSpec(name, glslTypeInfo) {
|
|
|
28
28
|
for (let i = 0; i < columnCount; i++) {
|
|
29
29
|
columns.push({ sourceOffset: i * columnSize, size: columnSize });
|
|
30
30
|
}
|
|
31
|
-
return { name, glslTypeName, flatSize: bufferSize, columns };
|
|
31
|
+
return { name, glslTypeName, flatSize: bufferSize, columns, affine: affine === true };
|
|
32
32
|
}
|
|
33
33
|
function compareNames(a, b) {
|
|
34
34
|
return a < b ? -1 : a > b ? 1 : 0;
|
|
@@ -89,10 +89,17 @@ export function buildPackedLayout(specs) {
|
|
|
89
89
|
? attributeName
|
|
90
90
|
: `${attributeName}.${SWIZZLE_COMPONENTS.slice(componentOffset, componentOffset + size)}`;
|
|
91
91
|
});
|
|
92
|
-
const expression =
|
|
93
|
-
? columnExpressions[0]
|
|
94
|
-
:
|
|
95
|
-
|
|
92
|
+
const expression = spec.affine === true
|
|
93
|
+
? `mat3(vec3(${columnExpressions[0]}, 0.0), vec3(${columnExpressions[1]}, 0.0), vec3(${columnExpressions[2]}, 1.0))`
|
|
94
|
+
: columnExpressions.length === 1
|
|
95
|
+
? columnExpressions[0]
|
|
96
|
+
: `${spec.glslTypeName}(${columnExpressions.join(", ")})`;
|
|
97
|
+
fields.set(spec.name, {
|
|
98
|
+
glslTypeName: spec.glslTypeName,
|
|
99
|
+
columns,
|
|
100
|
+
expression,
|
|
101
|
+
affine: spec.affine === true,
|
|
102
|
+
});
|
|
96
103
|
const sourceOffsets = columns.map(({ sourceOffset }) => sourceOffset).join(",");
|
|
97
104
|
signatureParts.push(`${spec.name}:${spec.glslTypeName}[${sourceOffsets}]=${expression}`);
|
|
98
105
|
}
|
|
@@ -105,6 +112,22 @@ export function resolvePackedField(layout, name) {
|
|
|
105
112
|
}
|
|
106
113
|
return field;
|
|
107
114
|
}
|
|
115
|
+
/**
|
|
116
|
+
* Vertex shader expressions of the scalar components of a packed field, in the order the GLSL
|
|
117
|
+
* constructor of its type takes them; used to pass the field on through packed varyings.
|
|
118
|
+
*/
|
|
119
|
+
export function buildPackedFieldComponents(layout, field) {
|
|
120
|
+
const components = [];
|
|
121
|
+
for (const { attributeIndex, componentOffset, size } of field.columns) {
|
|
122
|
+
const attributeName = packedAttributeName(attributeIndex);
|
|
123
|
+
for (let i = 0; i < size; i++) {
|
|
124
|
+
components.push(layout.attributeSizes[attributeIndex] === 1
|
|
125
|
+
? attributeName
|
|
126
|
+
: `${attributeName}.${SWIZZLE_COMPONENTS[componentOffset + i]}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
return components;
|
|
130
|
+
}
|
|
108
131
|
export function buildPackedAttributeDeclarations(layout) {
|
|
109
132
|
return layout.attributeSizes.map((size, index) => `attribute ${PACKED_ATTRIBUTE_TYPES[size - 1]} ${packedAttributeName(index)};`);
|
|
110
133
|
}
|
package/dist/core/miscellaneous/generic-plane/UIGenericInstancedPlane/UIGenericInstancedPlane.js
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { Mesh } from "three";
|
|
2
|
-
import { assertVertexAttributeBudget } from "../../asserts.js";
|
|
2
|
+
import { assertVaryingBudget, assertVertexAttributeBudget } from "../../asserts.js";
|
|
3
|
+
import { MASK_DATA_MODE_OFFSET, MASK_DATA_ROW0_OFFSET, MASK_DATA_ROW1_OFFSET, MASK_DATA_SHAPE_OFFSET, } from "../../mask/UIMask.Internal.js";
|
|
3
4
|
import { arePropertiesPartiallyCompatible, cloneGLProperties, resolvePropertyUniform, TRANSFORM_ZINDEX_OFFSET, } from "../shared.js";
|
|
4
|
-
import { BUILTIN_BLEND, BUILTIN_HSL,
|
|
5
|
+
import { buildMaterial, buildPackedAttribute, buildPlaneLayout, BUILTIN_BLEND, BUILTIN_HSL, BUILTIN_MASK_MODE, BUILTIN_MASK_ROW0, BUILTIN_MASK_ROW1, BUILTIN_MASK_SHAPE, BUILTIN_TRANSFORM, BUILTIN_VISIBILITY, CAPACITY_STEP, copyBetweenBuffers, INITIAL_CAPACITY, INSTANCED_PLANE_GEOMETRY, shiftBufferRegion, writePropertyToArray, } from "./UIGenericInstancedPlane.Internal.js";
|
|
5
6
|
import { packedAttributeName, resolvePackedField } from "./UIGenericInstancedPlane.Layout.js";
|
|
6
7
|
const TEMP_FIELD_VALUES = new Float32Array(16);
|
|
7
8
|
/**
|
|
@@ -14,10 +15,13 @@ const TEMP_FIELD_VALUES = new Float32Array(16);
|
|
|
14
15
|
* property) is packed into as few vertex attributes as possible, see
|
|
15
16
|
* UIGenericInstancedPlane.Layout.ts. The zIndex is read back from the packed transform.
|
|
16
17
|
*
|
|
18
|
+
* A masked plane is a separate shader variant with the builtin mask fields added; unmasked
|
|
19
|
+
* planes pay nothing for masking. See UIMask.Internal.ts for the mask data.
|
|
20
|
+
*
|
|
17
21
|
* @internal
|
|
18
22
|
*/
|
|
19
23
|
export class UIGenericInstancedPlane extends Mesh {
|
|
20
|
-
constructor(source, properties, transparency, initialCapacity = INITIAL_CAPACITY) {
|
|
24
|
+
constructor(source, properties, transparency, masked, initialCapacity = INITIAL_CAPACITY) {
|
|
21
25
|
const uniformProperties = {};
|
|
22
26
|
const varyingProperties = {};
|
|
23
27
|
for (const name in properties) {
|
|
@@ -29,18 +33,20 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
29
33
|
uniformProperties[name] = descriptor;
|
|
30
34
|
}
|
|
31
35
|
}
|
|
32
|
-
const layout = buildPlaneLayout(varyingProperties);
|
|
36
|
+
const layout = buildPlaneLayout(varyingProperties, masked);
|
|
33
37
|
const instancedGeometry = INSTANCED_PLANE_GEOMETRY.clone();
|
|
34
|
-
const shaderMaterial = buildMaterial(source, uniformProperties, layout, transparency);
|
|
38
|
+
const { material: shaderMaterial, varyingRowCount } = buildMaterial(source, uniformProperties, layout, transparency, masked);
|
|
35
39
|
super(instancedGeometry, shaderMaterial);
|
|
36
40
|
this.onBeforeRenderInternal = (renderer) => {
|
|
37
41
|
assertVertexAttributeBudget(renderer, this.vertexAttributeCount, this.vertexAttributeSubject);
|
|
42
|
+
assertVaryingBudget(renderer, this.varyingRowCount, this.vertexAttributeSubject);
|
|
38
43
|
};
|
|
39
44
|
this.frustumCulled = false;
|
|
40
45
|
this.matrixAutoUpdate = false;
|
|
41
46
|
this.matrixWorldAutoUpdate = false;
|
|
42
47
|
this.source = source;
|
|
43
48
|
this.transparency = transparency;
|
|
49
|
+
this.masked = masked;
|
|
44
50
|
this.instancedGeometry = instancedGeometry;
|
|
45
51
|
this.shaderMaterial = shaderMaterial;
|
|
46
52
|
this.properties = properties;
|
|
@@ -51,6 +57,15 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
51
57
|
this.visibilityField = resolvePackedField(layout, BUILTIN_VISIBILITY);
|
|
52
58
|
this.blendField = resolvePackedField(layout, BUILTIN_BLEND);
|
|
53
59
|
this.hslField = resolvePackedField(layout, BUILTIN_HSL);
|
|
60
|
+
// Same order as the mask data: row 0, row 1, shape, mode
|
|
61
|
+
this.maskFields = masked
|
|
62
|
+
? [
|
|
63
|
+
resolvePackedField(layout, BUILTIN_MASK_ROW0),
|
|
64
|
+
resolvePackedField(layout, BUILTIN_MASK_ROW1),
|
|
65
|
+
resolvePackedField(layout, BUILTIN_MASK_SHAPE),
|
|
66
|
+
resolvePackedField(layout, BUILTIN_MASK_MODE),
|
|
67
|
+
]
|
|
68
|
+
: undefined;
|
|
54
69
|
const zIndexColumn = this.transformField.columns.find(({ sourceOffset, size }) => sourceOffset <= TRANSFORM_ZINDEX_OFFSET && TRANSFORM_ZINDEX_OFFSET < sourceOffset + size);
|
|
55
70
|
if (zIndexColumn === undefined) {
|
|
56
71
|
throw new Error(`UIGenericInstancedPlane.constructor: transform layout lacks the zIndex`);
|
|
@@ -61,6 +76,7 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
61
76
|
this.vertexAttributeCount =
|
|
62
77
|
Object.keys(INSTANCED_PLANE_GEOMETRY.attributes).length + layout.attributeSizes.length;
|
|
63
78
|
this.vertexAttributeSubject = `UIGenericInstancedPlane.onBeforeRender.properties (${Object.keys(varyingProperties).join(", ")})`;
|
|
79
|
+
this.varyingRowCount = varyingRowCount;
|
|
64
80
|
this.onBeforeRender = this.onBeforeRenderInternal;
|
|
65
81
|
this.capacity = Math.max(Math.ceil(initialCapacity / CAPACITY_STEP) * CAPACITY_STEP, CAPACITY_STEP);
|
|
66
82
|
this.instancesCountInternal = 0;
|
|
@@ -84,7 +100,7 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
84
100
|
/**
|
|
85
101
|
* Insert instance at given index. Elements at [index..end) are shifted right.
|
|
86
102
|
*/
|
|
87
|
-
insertAt(index, properties, transform, visibility, blend, hsl) {
|
|
103
|
+
insertAt(index, properties, transform, visibility, blend, hsl, mask) {
|
|
88
104
|
if (index < 0 || index > this.instancesCountInternal) {
|
|
89
105
|
throw new Error(`UIGenericInstancedPlane.insertAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`);
|
|
90
106
|
}
|
|
@@ -97,6 +113,9 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
97
113
|
this.writeBlend(index, blend);
|
|
98
114
|
this.writeHSL(index, hsl);
|
|
99
115
|
this.writeProperties(index, properties);
|
|
116
|
+
if (mask !== null) {
|
|
117
|
+
this.writeMask(index, mask);
|
|
118
|
+
}
|
|
100
119
|
this.instancesCountInternal++;
|
|
101
120
|
this.instancedGeometry.instanceCount = this.instancesCountInternal;
|
|
102
121
|
}
|
|
@@ -148,6 +167,13 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
148
167
|
}
|
|
149
168
|
this.writeHSL(index, hsl);
|
|
150
169
|
}
|
|
170
|
+
/** Update mask data at given index; the plane must be masked */
|
|
171
|
+
setMaskAt(index, mask) {
|
|
172
|
+
if (index < 0 || index >= this.instancesCountInternal) {
|
|
173
|
+
throw new Error(`UIGenericInstancedPlane.setMaskAt.index: out of bounds (index=${index}, count=${this.instancesCountInternal})`);
|
|
174
|
+
}
|
|
175
|
+
this.writeMask(index, mask);
|
|
176
|
+
}
|
|
151
177
|
/** Get zIndex at given index (from transform buffer) */
|
|
152
178
|
getZIndexAt(index) {
|
|
153
179
|
if (index < 0 || index >= this.instancesCountInternal) {
|
|
@@ -189,7 +215,7 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
189
215
|
throw new Error(`UIGenericInstancedPlane.split.atIndex: must be in range (0, count) (atIndex=${atIndex}, count=${this.instancesCountInternal})`);
|
|
190
216
|
}
|
|
191
217
|
const tailCount = this.instancesCountInternal - atIndex;
|
|
192
|
-
const newPlane = new UIGenericInstancedPlane(this.source, cloneGLProperties(this.properties), this.transparency, tailCount);
|
|
218
|
+
const newPlane = new UIGenericInstancedPlane(this.source, cloneGLProperties(this.properties), this.transparency, this.masked, tailCount);
|
|
193
219
|
for (let i = 0; i < this.packedAttributes.length; i++) {
|
|
194
220
|
const thisAttribute = this.packedAttributes[i];
|
|
195
221
|
const newAttribute = newPlane.packedAttributes[i];
|
|
@@ -206,18 +232,20 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
206
232
|
/**
|
|
207
233
|
* Check if this plane can accept elements with given parameters.
|
|
208
234
|
*/
|
|
209
|
-
isCompatibleWith(source, properties, transparency) {
|
|
235
|
+
isCompatibleWith(source, properties, transparency, masked) {
|
|
210
236
|
return (this.source === source &&
|
|
211
237
|
this.transparency === transparency &&
|
|
238
|
+
this.masked === masked &&
|
|
212
239
|
arePropertiesPartiallyCompatible(this.properties, properties));
|
|
213
240
|
}
|
|
214
241
|
/**
|
|
215
|
-
* Check if another plane can be merged into this one: same shader source
|
|
216
|
-
* attribute layout and the same uniform values.
|
|
242
|
+
* Check if another plane can be merged into this one: same shader source, transparency and
|
|
243
|
+
* mask variant, same attribute layout and the same uniform values.
|
|
217
244
|
*/
|
|
218
245
|
canMerge(other) {
|
|
219
246
|
return (this.source === other.source &&
|
|
220
247
|
this.transparency === other.transparency &&
|
|
248
|
+
this.masked === other.masked &&
|
|
221
249
|
this.layout.signature === other.layout.signature &&
|
|
222
250
|
arePropertiesPartiallyCompatible(this.uniformProperties, other.uniformProperties) &&
|
|
223
251
|
arePropertiesPartiallyCompatible(other.uniformProperties, this.uniformProperties));
|
|
@@ -275,7 +303,9 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
275
303
|
for (const name in properties) {
|
|
276
304
|
const { value, glslTypeInfo } = properties[name];
|
|
277
305
|
if (glslTypeInfo.instantiable) {
|
|
278
|
-
|
|
306
|
+
// The layout of the plane decides, so a plain Matrix3 fits an affine field too
|
|
307
|
+
const affine = this.properties[name].glslTypeInfo.affine === true;
|
|
308
|
+
writePropertyToArray(value, TEMP_FIELD_VALUES, 0, affine);
|
|
279
309
|
this.writeField(index, resolvePackedField(this.layout, name), TEMP_FIELD_VALUES);
|
|
280
310
|
}
|
|
281
311
|
else {
|
|
@@ -299,6 +329,16 @@ export class UIGenericInstancedPlane extends Mesh {
|
|
|
299
329
|
TEMP_FIELD_VALUES[2] = hsl.l;
|
|
300
330
|
this.writeField(index, this.hslField, TEMP_FIELD_VALUES);
|
|
301
331
|
}
|
|
332
|
+
writeMask(index, mask) {
|
|
333
|
+
if (this.maskFields === undefined) {
|
|
334
|
+
throw new Error(`UIGenericInstancedPlane.writeMask: plane is not masked`);
|
|
335
|
+
}
|
|
336
|
+
const [row0Field, row1Field, shapeField, modeField] = this.maskFields;
|
|
337
|
+
this.writeField(index, row0Field, mask.subarray(MASK_DATA_ROW0_OFFSET));
|
|
338
|
+
this.writeField(index, row1Field, mask.subarray(MASK_DATA_ROW1_OFFSET));
|
|
339
|
+
this.writeField(index, shapeField, mask.subarray(MASK_DATA_SHAPE_OFFSET));
|
|
340
|
+
this.writeField(index, modeField, mask.subarray(MASK_DATA_MODE_OFFSET));
|
|
341
|
+
}
|
|
302
342
|
writeField(index, field, values) {
|
|
303
343
|
for (const { attributeIndex, componentOffset, sourceOffset, size } of field.columns) {
|
|
304
344
|
const attribute = this.packedAttributes[attributeIndex];
|
package/dist/core/miscellaneous/generic-plane/UIGenericPlaneRegistry/UIGenericPlaneRegistry.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { Matrix3 } from "three";
|
|
1
2
|
import { cloneGLProperties, cloneProperties, convertUIPropertiesToGLProperties, extractZIndex, } from "../shared.js";
|
|
2
3
|
import { UIGenericInstancedPlane } from "../UIGenericInstancedPlane/UIGenericInstancedPlane.js";
|
|
3
4
|
/**
|
|
@@ -45,6 +46,7 @@ export class UIPlaneRegistry {
|
|
|
45
46
|
transparency,
|
|
46
47
|
blend,
|
|
47
48
|
hsl: { h: hsl.h, s: hsl.s, l: hsl.l },
|
|
49
|
+
mask: null,
|
|
48
50
|
zIndex,
|
|
49
51
|
};
|
|
50
52
|
this.handlerToState.set(handler, state);
|
|
@@ -81,6 +83,9 @@ export class UIPlaneRegistry {
|
|
|
81
83
|
for (const name in glProperties) {
|
|
82
84
|
const newProp = glProperties[name];
|
|
83
85
|
const oldProp = state.properties[name];
|
|
86
|
+
if (oldProp === undefined) {
|
|
87
|
+
throw new Error(`UIPlaneRegistry.setProperties.properties: unknown property "${name}" for handler ${handler}`);
|
|
88
|
+
}
|
|
84
89
|
if (!newProp.glslTypeInfo.instantiable) {
|
|
85
90
|
if (oldProp.value !== newProp.value) {
|
|
86
91
|
textureChanged = true;
|
|
@@ -88,7 +93,11 @@ export class UIPlaneRegistry {
|
|
|
88
93
|
}
|
|
89
94
|
state.properties[name] = {
|
|
90
95
|
value: newProp.value,
|
|
91
|
-
|
|
96
|
+
// A mat3 field keeps the layout it was created with for any Matrix3, affine or full,
|
|
97
|
+
// see UIAffineMatrix3; the element stays in its batch
|
|
98
|
+
glslTypeInfo: oldProp.glslTypeInfo.glslTypeName === "mat3" && newProp.value instanceof Matrix3
|
|
99
|
+
? oldProp.glslTypeInfo
|
|
100
|
+
: newProp.glslTypeInfo,
|
|
92
101
|
};
|
|
93
102
|
}
|
|
94
103
|
if (textureChanged && !this.pendingCreate.has(handler)) {
|
|
@@ -162,6 +171,37 @@ export class UIPlaneRegistry {
|
|
|
162
171
|
descriptor.mesh.setHSLAt(descriptor.instanceIndex, hsl);
|
|
163
172
|
}
|
|
164
173
|
}
|
|
174
|
+
/**
|
|
175
|
+
* Updates plane mask; null removes it. Data is copied.
|
|
176
|
+
* Masked and unmasked planes are different shader variants, so adding or removing the mask
|
|
177
|
+
* relocates the element on flush(); changing the data of a masked plane is applied immediately.
|
|
178
|
+
*/
|
|
179
|
+
setMask(handler, mask) {
|
|
180
|
+
const state = this.resolveState(handler);
|
|
181
|
+
const wasMasked = state.mask !== null;
|
|
182
|
+
if (mask === null) {
|
|
183
|
+
state.mask = null;
|
|
184
|
+
}
|
|
185
|
+
else if (state.mask === null) {
|
|
186
|
+
state.mask = new Float32Array(mask);
|
|
187
|
+
}
|
|
188
|
+
else {
|
|
189
|
+
state.mask.set(mask);
|
|
190
|
+
}
|
|
191
|
+
if (wasMasked !== (mask !== null)) {
|
|
192
|
+
if (!this.pendingCreate.has(handler)) {
|
|
193
|
+
this.pendingRelocate.add(handler);
|
|
194
|
+
this.needsFlush = true;
|
|
195
|
+
}
|
|
196
|
+
return;
|
|
197
|
+
}
|
|
198
|
+
if (state.mask !== null) {
|
|
199
|
+
const descriptor = this.handlerToDescriptor.get(handler);
|
|
200
|
+
if (descriptor && !this.pendingRelocate.has(handler)) {
|
|
201
|
+
descriptor.mesh.setMaskAt(descriptor.instanceIndex, state.mask);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
165
205
|
/**
|
|
166
206
|
* Updates plane transparency mode.
|
|
167
207
|
* Element will be relocated on flush() if transparency changes.
|
|
@@ -299,7 +339,8 @@ export class UIPlaneRegistry {
|
|
|
299
339
|
}
|
|
300
340
|
}
|
|
301
341
|
insertSingleElement(handler, state) {
|
|
302
|
-
const { source, properties, transform, visibility, transparency, blend, hsl, zIndex } = state;
|
|
342
|
+
const { source, properties, transform, visibility, transparency, blend, hsl, mask, zIndex } = state;
|
|
343
|
+
const masked = mask !== null;
|
|
303
344
|
let newMeshIndex = this.orderedMeshes.length;
|
|
304
345
|
for (let i = 0; i < this.orderedMeshes.length; i++) {
|
|
305
346
|
const mesh = this.orderedMeshes[i];
|
|
@@ -313,9 +354,9 @@ export class UIPlaneRegistry {
|
|
|
313
354
|
break;
|
|
314
355
|
}
|
|
315
356
|
if (zIndex <= meshMaxZ) {
|
|
316
|
-
if (mesh.isCompatibleWith(source, properties, transparency)) {
|
|
357
|
+
if (mesh.isCompatibleWith(source, properties, transparency, masked)) {
|
|
317
358
|
const instanceIndex = this.findInstanceIndexInMesh(mesh, zIndex);
|
|
318
|
-
mesh.insertAt(instanceIndex, properties, transform, visibility, blend, hsl);
|
|
359
|
+
mesh.insertAt(instanceIndex, properties, transform, visibility, blend, hsl, mask);
|
|
319
360
|
this.shiftHandlerIndices(mesh, instanceIndex, 1);
|
|
320
361
|
this.handlerToDescriptor.set(handler, { mesh, instanceIndex });
|
|
321
362
|
return;
|
|
@@ -335,8 +376,8 @@ export class UIPlaneRegistry {
|
|
|
335
376
|
}
|
|
336
377
|
newMeshIndex = i + 1;
|
|
337
378
|
}
|
|
338
|
-
const mesh = new UIGenericInstancedPlane(source, cloneGLProperties(properties), transparency);
|
|
339
|
-
mesh.insertAt(0, properties, transform, visibility, blend, hsl);
|
|
379
|
+
const mesh = new UIGenericInstancedPlane(source, cloneGLProperties(properties), transparency, masked);
|
|
380
|
+
mesh.insertAt(0, properties, transform, visibility, blend, hsl, mask);
|
|
340
381
|
this.orderedMeshes.splice(newMeshIndex, 0, mesh);
|
|
341
382
|
this.scene.add(mesh);
|
|
342
383
|
this.handlerToDescriptor.set(handler, { mesh, instanceIndex: 0 });
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { IUniform, ShaderMaterial } from "three";
|
|
2
2
|
import { Matrix3, Matrix4, Texture, Vector2, Vector3, Vector4 } from "three";
|
|
3
3
|
import { UIColor } from "../color/UIColor.js";
|
|
4
|
+
import { UIAffineMatrix3 } from "../UIAffineMatrix3.js";
|
|
4
5
|
export type UIProperty = Texture | UIColor | Vector2 | Vector3 | Vector4 | Matrix3 | Matrix4 | number;
|
|
5
|
-
export type UIPropertyName = "Texture" | "UIColor" | "Vector2" | "Vector3" | "Vector4" | "Matrix3" | "Matrix4" | "number";
|
|
6
|
-
export type UIPropertyConstructor = typeof Texture | typeof UIColor | typeof Vector2 | typeof Vector3 | typeof Vector4 | typeof Matrix3 | typeof Matrix4 | NumberConstructor;
|
|
6
|
+
export type UIPropertyName = "Texture" | "UIColor" | "Vector2" | "Vector3" | "Vector4" | "Matrix3" | "UIAffineMatrix3" | "Matrix4" | "number";
|
|
7
|
+
export type UIPropertyConstructor = typeof Texture | typeof UIColor | typeof Vector2 | typeof Vector3 | typeof Vector4 | typeof Matrix3 | typeof UIAffineMatrix3 | typeof Matrix4 | NumberConstructor;
|
|
7
8
|
export type UIPropertyCopyTo = UIColor | Vector2 | Vector3 | Vector4 | Matrix3 | Matrix4;
|
|
8
9
|
export type UIPropertyCopyFrom = UIColor & Vector2 & Vector3 & Vector4 & Matrix3 & Matrix4;
|
|
9
10
|
export interface GLTypeInfo {
|
|
@@ -16,6 +17,11 @@ export interface GLTypeInfo {
|
|
|
16
17
|
*/
|
|
17
18
|
columnCount: number;
|
|
18
19
|
instantiable: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Whether a mat3 is stored as a 2D affine transform: three columns of two floats, the bottom
|
|
22
|
+
* row taken as (0, 0, 1). See UIAffineMatrix3.
|
|
23
|
+
*/
|
|
24
|
+
affine?: boolean;
|
|
19
25
|
}
|
|
20
26
|
export interface GLProperty {
|
|
21
27
|
value: UIProperty;
|
|
@@ -43,4 +49,10 @@ export declare function cloneGLProperties(properties: Record<string, GLProperty>
|
|
|
43
49
|
export declare const TRANSFORM_ZINDEX_OFFSET = 14;
|
|
44
50
|
/** Extracts zIndex from transform matrix (translation.z component) */
|
|
45
51
|
export declare function extractZIndex(transform: Matrix4): number;
|
|
46
|
-
|
|
52
|
+
/**
|
|
53
|
+
* Builds the fragment shader of a plane. The p_* fields the source reads are plain globals,
|
|
54
|
+
* filled from the packed varyings at the start of main (see varyingPacking.ts).
|
|
55
|
+
* @param fieldDeclarations Packed varying and p_* global declarations
|
|
56
|
+
* @param fieldAssignments Statements filling the p_* globals from the packed varyings
|
|
57
|
+
*/
|
|
58
|
+
export declare function buildGenericPlaneFragmentShader(uniformDeclarations: string[], fieldDeclarations: string[], fieldAssignments: string[], source: string, alphaTestValue: number, usePremultipliedAlpha: boolean, maskSource?: string): string;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Matrix3, Matrix4, Texture, Vector2, Vector3, Vector4 } from "three";
|
|
2
2
|
import { UIColor } from "../color/UIColor.js";
|
|
3
|
+
import { UIAffineMatrix3 } from "../UIAffineMatrix3.js";
|
|
3
4
|
import { checkSRGBSupport } from "../webglCapabilities.js";
|
|
4
5
|
const GLSL_TYPE_INFO_FLOAT = Object.freeze({
|
|
5
6
|
glslTypeName: "float",
|
|
@@ -37,6 +38,13 @@ const GLSL_TYPE_INFO_MAT3 = Object.freeze({
|
|
|
37
38
|
columnCount: 3,
|
|
38
39
|
instantiable: true,
|
|
39
40
|
});
|
|
41
|
+
const GLSL_TYPE_INFO_AFFINE_MAT3 = Object.freeze({
|
|
42
|
+
glslTypeName: "mat3",
|
|
43
|
+
bufferSize: 6,
|
|
44
|
+
columnCount: 3,
|
|
45
|
+
instantiable: true,
|
|
46
|
+
affine: true,
|
|
47
|
+
});
|
|
40
48
|
const GLSL_TYPE_INFO_MAT4 = Object.freeze({
|
|
41
49
|
glslTypeName: "mat4",
|
|
42
50
|
bufferSize: 16,
|
|
@@ -60,6 +68,8 @@ export function resolveGLSLTypeInfo(value) {
|
|
|
60
68
|
return GLSL_TYPE_INFO_VEC4;
|
|
61
69
|
case "Matrix3":
|
|
62
70
|
return GLSL_TYPE_INFO_MAT3;
|
|
71
|
+
case "UIAffineMatrix3":
|
|
72
|
+
return GLSL_TYPE_INFO_AFFINE_MAT3;
|
|
63
73
|
case "Matrix4":
|
|
64
74
|
return GLSL_TYPE_INFO_MAT4;
|
|
65
75
|
default:
|
|
@@ -85,6 +95,9 @@ export function resolveGLSLTypeInfo(value) {
|
|
|
85
95
|
if (value === Vector4) {
|
|
86
96
|
return GLSL_TYPE_INFO_VEC4;
|
|
87
97
|
}
|
|
98
|
+
if (value === UIAffineMatrix3) {
|
|
99
|
+
return GLSL_TYPE_INFO_AFFINE_MAT3;
|
|
100
|
+
}
|
|
88
101
|
if (value === Matrix3) {
|
|
89
102
|
return GLSL_TYPE_INFO_MAT3;
|
|
90
103
|
}
|
|
@@ -111,6 +124,9 @@ export function resolveGLSLTypeInfo(value) {
|
|
|
111
124
|
if (value instanceof Vector4) {
|
|
112
125
|
return GLSL_TYPE_INFO_VEC4;
|
|
113
126
|
}
|
|
127
|
+
if (value instanceof UIAffineMatrix3) {
|
|
128
|
+
return GLSL_TYPE_INFO_AFFINE_MAT3;
|
|
129
|
+
}
|
|
114
130
|
if (value instanceof Matrix3) {
|
|
115
131
|
return GLSL_TYPE_INFO_MAT3;
|
|
116
132
|
}
|
|
@@ -133,7 +149,9 @@ export function arePropertiesPartiallyCompatible(full, partial) {
|
|
|
133
149
|
}
|
|
134
150
|
const infoFull = full[key].glslTypeInfo;
|
|
135
151
|
const infoPartial = partial[key].glslTypeInfo;
|
|
136
|
-
|
|
152
|
+
// An affine mat3 and a full one share the GLSL type but not the layout
|
|
153
|
+
if (infoFull.glslTypeName !== infoPartial.glslTypeName ||
|
|
154
|
+
infoFull.bufferSize !== infoPartial.bufferSize) {
|
|
137
155
|
return false;
|
|
138
156
|
}
|
|
139
157
|
if (!infoFull.instantiable && full[key].value !== partial[key].value) {
|
|
@@ -183,21 +201,27 @@ export const TRANSFORM_ZINDEX_OFFSET = 14;
|
|
|
183
201
|
export function extractZIndex(transform) {
|
|
184
202
|
return transform.elements[TRANSFORM_ZINDEX_OFFSET];
|
|
185
203
|
}
|
|
186
|
-
|
|
204
|
+
/**
|
|
205
|
+
* Builds the fragment shader of a plane. The p_* fields the source reads are plain globals,
|
|
206
|
+
* filled from the packed varyings at the start of main (see varyingPacking.ts).
|
|
207
|
+
* @param fieldDeclarations Packed varying and p_* global declarations
|
|
208
|
+
* @param fieldAssignments Statements filling the p_* globals from the packed varyings
|
|
209
|
+
*/
|
|
210
|
+
export function buildGenericPlaneFragmentShader(uniformDeclarations, fieldDeclarations, fieldAssignments, source, alphaTestValue, usePremultipliedAlpha, maskSource) {
|
|
187
211
|
return `
|
|
188
212
|
// Defines
|
|
189
213
|
#define PI 3.14159265359
|
|
190
214
|
#define SRGB_SUPPORTED ${checkSRGBSupport() ? "1" : "0"}
|
|
215
|
+
${maskSource === undefined ? "" : "#define LAYMUR_MASK_DERIVATIVES"}
|
|
191
216
|
|
|
192
217
|
// Uniforms
|
|
193
218
|
${uniformDeclarations.join("\n")}
|
|
194
219
|
|
|
195
|
-
//
|
|
196
|
-
|
|
197
|
-
varying vec2 p_uv;
|
|
220
|
+
// Packed varyings and the fields read from them
|
|
221
|
+
${fieldDeclarations.join("\n")}
|
|
198
222
|
|
|
199
|
-
//
|
|
200
|
-
|
|
223
|
+
// The unit quad position equals its uv
|
|
224
|
+
#define p_position vec3(p_uv, 0.0)
|
|
201
225
|
|
|
202
226
|
#include <alphahash_pars_fragment>
|
|
203
227
|
|
|
@@ -270,9 +294,14 @@ export function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDecl
|
|
|
270
294
|
return hslToRgb(hsl);
|
|
271
295
|
}
|
|
272
296
|
|
|
297
|
+
// Mask coverage, masked planes only
|
|
298
|
+
${maskSource ?? ""}
|
|
299
|
+
|
|
273
300
|
// Source must define vec4 draw() function
|
|
274
301
|
${source}
|
|
275
302
|
void main() {
|
|
303
|
+
${fieldAssignments.join("\n")}
|
|
304
|
+
|
|
276
305
|
vec4 diffuseColor = draw();
|
|
277
306
|
|
|
278
307
|
// Skip the HSL roundtrip entirely for the default (identity) case.
|
|
@@ -280,6 +309,8 @@ export function buildGenericPlaneFragmentShader(uniformDeclarations, varyingDecl
|
|
|
280
309
|
diffuseColor.rgb = applyInstanceHSL(diffuseColor.rgb);
|
|
281
310
|
}
|
|
282
311
|
|
|
312
|
+
${maskSource === undefined ? "" : "diffuseColor.a *= laymurMaskCoverage(p_instanceMaskLocal, p_instanceMaskShape, p_instanceMaskMode);"}
|
|
313
|
+
|
|
283
314
|
if (diffuseColor.a <= ${alphaTestValue.toFixed(8)}) {
|
|
284
315
|
discard;
|
|
285
316
|
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Packing of varyings into as few vec4 rows as possible.
|
|
3
|
+
*
|
|
4
|
+
* The varying budget (MAX_VARYING_VECTORS: at least 8 on WebGL1, 15 on WebGL2) is counted in
|
|
5
|
+
* rows of four components, and drivers lay varyings out with the GLSL ES reference algorithm:
|
|
6
|
+
* a vec3 or a mat3 column leaves its fourth component to floats only, so vec3 + vec2 already
|
|
7
|
+
* takes two rows. Instead every field is cut into scalars and placed into packed vec4 varyings
|
|
8
|
+
* by the shader generator itself, which takes exactly ceil(components / 4) rows. Fields are
|
|
9
|
+
* kept contiguous where they fit, so most reads stay plain swizzles.
|
|
10
|
+
*
|
|
11
|
+
* Packing changes nothing for interpolation: varyings are interpolated per component. The
|
|
12
|
+
* fragment shader reassembles each field once, which costs a few register moves.
|
|
13
|
+
*
|
|
14
|
+
* The row count is exact, so the budget can be checked before the program fails to link.
|
|
15
|
+
*/
|
|
16
|
+
/** A value passed from the vertex to the fragment shader */
|
|
17
|
+
export interface VaryingFieldSpec {
|
|
18
|
+
/** Name the fragment shader knows the field by; only used to key the result */
|
|
19
|
+
name: string;
|
|
20
|
+
glslTypeName: string;
|
|
21
|
+
/**
|
|
22
|
+
* Vertex shader expressions of the scalar components, in the order the GLSL constructor of
|
|
23
|
+
* glslTypeName takes them (column-major for matrices)
|
|
24
|
+
*/
|
|
25
|
+
components: readonly string[];
|
|
26
|
+
/** A mat3 given as three columns of two, the bottom row taken as (0, 0, 1) */
|
|
27
|
+
affine?: boolean;
|
|
28
|
+
}
|
|
29
|
+
export interface PackedVaryings {
|
|
30
|
+
/** Number of varying rows (vec4 locations) taken */
|
|
31
|
+
rowCount: number;
|
|
32
|
+
/** Varying declarations, the same for both shaders */
|
|
33
|
+
declarations: string[];
|
|
34
|
+
/** Vertex shader statements writing the packed varyings */
|
|
35
|
+
vertexAssignments: string[];
|
|
36
|
+
/** Fragment shader expression reassembling each field, by field name */
|
|
37
|
+
fragmentExpressions: Map<string, string>;
|
|
38
|
+
}
|
|
39
|
+
export declare function packedVaryingName(row: number): string;
|
|
40
|
+
/** Whether the code mentions the identifier as a whole word */
|
|
41
|
+
export declare function isIdentifierReferenced(code: string, identifier: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Packs the fields into vec4 varyings. The layout depends on the fields and their order only.
|
|
44
|
+
* @throws If a field has an unsupported type or a wrong number of components
|
|
45
|
+
*/
|
|
46
|
+
export declare function packVaryings(fields: readonly VaryingFieldSpec[]): PackedVaryings;
|