@onerjs/core 8.29.7 → 8.29.9

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.
Files changed (39) hide show
  1. package/Cameras/arcRotateCamera.d.ts +2 -1
  2. package/Cameras/arcRotateCamera.js +11 -2
  3. package/Cameras/arcRotateCamera.js.map +1 -1
  4. package/Engines/abstractEngine.js +2 -2
  5. package/Engines/abstractEngine.js.map +1 -1
  6. package/Lights/Shadows/cascadedShadowGenerator.d.ts +1 -0
  7. package/Lights/Shadows/cascadedShadowGenerator.js +9 -1
  8. package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
  9. package/Lights/Shadows/shadowGenerator.js +10 -3
  10. package/Lights/Shadows/shadowGenerator.js.map +1 -1
  11. package/Materials/Textures/index.d.ts +1 -0
  12. package/Materials/Textures/index.js +1 -0
  13. package/Materials/Textures/index.js.map +1 -1
  14. package/Materials/Textures/textureMerger.d.ts +75 -0
  15. package/Materials/Textures/textureMerger.js +206 -0
  16. package/Materials/Textures/textureMerger.js.map +1 -0
  17. package/Materials/floatingOriginMatrixOverrides.d.ts +6 -0
  18. package/Materials/floatingOriginMatrixOverrides.js +35 -11
  19. package/Materials/floatingOriginMatrixOverrides.js.map +1 -1
  20. package/Misc/sceneSerializer.js +4 -1
  21. package/Misc/sceneSerializer.js.map +1 -1
  22. package/Shaders/ShadersInclude/openpbrBaseLayerData.js +1 -1
  23. package/Shaders/ShadersInclude/openpbrBaseLayerData.js.map +1 -1
  24. package/Shaders/default.fragment.js +1 -1
  25. package/Shaders/default.fragment.js.map +1 -1
  26. package/Shaders/textureMerger.fragment.d.ts +5 -0
  27. package/Shaders/textureMerger.fragment.js +94 -0
  28. package/Shaders/textureMerger.fragment.js.map +1 -0
  29. package/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.js +1 -1
  30. package/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.js.map +1 -1
  31. package/ShadersWGSL/default.fragment.js +1 -1
  32. package/ShadersWGSL/default.fragment.js.map +1 -1
  33. package/ShadersWGSL/textureMerger.fragment.d.ts +5 -0
  34. package/ShadersWGSL/textureMerger.fragment.js +86 -0
  35. package/ShadersWGSL/textureMerger.fragment.js.map +1 -0
  36. package/Sprites/spriteManager.d.ts +8 -0
  37. package/Sprites/spriteManager.js +4 -0
  38. package/Sprites/spriteManager.js.map +1 -1
  39. package/package.json +1 -1
@@ -22,6 +22,7 @@ export * from "./rawTexture2DArray.js";
22
22
  export * from "./rawTexture3D.js";
23
23
  export * from "./refractionTexture.js";
24
24
  export * from "./renderTargetTexture.js";
25
+ export * from "./textureMerger.js";
25
26
  export * from "./textureSampler.js";
26
27
  export * from "./texture.js";
27
28
  export * from "./thinTexture.js";
@@ -24,6 +24,7 @@ export * from "./rawTexture2DArray.js";
24
24
  export * from "./rawTexture3D.js";
25
25
  export * from "./refractionTexture.js";
26
26
  export * from "./renderTargetTexture.js";
27
+ export * from "./textureMerger.js";
27
28
  export * from "./textureSampler.js";
28
29
  export * from "./texture.js";
29
30
  export * from "./thinTexture.js";
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,yCAAyC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,kCAAkC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAEhD,gBAAgB;AAChB,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./baseTexture\";\r\n// eslint-disable-next-line import/export\r\nexport * from \"./baseTexture.polynomial\";\r\nexport * from \"./colorGradingTexture\";\r\nexport * from \"./cubeTexture\";\r\nexport * from \"./dynamicTexture\";\r\nexport * from \"./equiRectangularCubeTexture\";\r\nexport * from \"./externalTexture\";\r\nexport * from \"./Filtering/hdrFiltering\";\r\nexport * from \"./envCubeTexture\";\r\nexport * from \"./hdrCubeTexture\";\r\nexport * from \"./exrCubeTexture\";\r\nexport * from \"./htmlElementTexture\";\r\nexport * from \"./internalTexture\";\r\nexport * from \"./Loaders/index\";\r\nexport * from \"./mirrorTexture\";\r\nexport * from \"./multiRenderTarget\";\r\nexport * from \"./Packer/index\";\r\nexport * from \"./Procedurals/index\";\r\nexport * from \"./rawCubeTexture\";\r\nexport * from \"./rawTexture\";\r\nexport * from \"./rawTexture2DArray\";\r\nexport * from \"./rawTexture3D\";\r\nexport * from \"./refractionTexture\";\r\nexport * from \"./renderTargetTexture\";\r\nexport * from \"./textureSampler\";\r\nexport * from \"./texture\";\r\nexport * from \"./thinTexture\";\r\nexport * from \"./thinRenderTargetTexture\";\r\nexport * from \"./videoTexture\";\r\nexport * from \"./ktx2decoderTypes\";\r\nexport * from \"./textureCreationOptions\";\r\n\r\n// Shaders for procedural textures\r\nexport * from \"../../ShadersWGSL/procedural.vertex\";\r\nexport * from \"../../Shaders/procedural.vertex\";\r\n\r\n// HDR filtering\r\nexport * from \"../../Shaders/hdrFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.fragment\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.fragment\";\r\n"]}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,cAAc,eAAe,CAAC;AAC9B,yCAAyC;AACzC,cAAc,0BAA0B,CAAC;AACzC,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC;AAC9B,cAAc,kBAAkB,CAAC;AACjC,cAAc,8BAA8B,CAAC;AAC7C,cAAc,mBAAmB,CAAC;AAClC,cAAc,0BAA0B,CAAC;AACzC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,kBAAkB,CAAC;AACjC,cAAc,sBAAsB,CAAC;AACrC,cAAc,mBAAmB,CAAC;AAClC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,kBAAkB,CAAC;AACjC,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,qBAAqB,CAAC;AACpC,cAAc,uBAAuB,CAAC;AACtC,cAAc,iBAAiB,CAAC;AAChC,cAAc,kBAAkB,CAAC;AACjC,cAAc,WAAW,CAAC;AAC1B,cAAc,eAAe,CAAC;AAC9B,cAAc,2BAA2B,CAAC;AAC1C,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,0BAA0B,CAAC;AAEzC,kCAAkC;AAClC,cAAc,qCAAqC,CAAC;AACpD,cAAc,iCAAiC,CAAC;AAEhD,gBAAgB;AAChB,cAAc,mCAAmC,CAAC;AAClD,cAAc,qCAAqC,CAAC;AACpD,cAAc,uCAAuC,CAAC;AACtD,cAAc,yCAAyC,CAAC;AACxD,cAAc,6CAA6C,CAAC;AAC5D,cAAc,+CAA+C,CAAC;AAC9D,cAAc,iDAAiD,CAAC;AAChE,cAAc,mDAAmD,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/no-restricted-imports */\r\nexport * from \"./baseTexture\";\r\n// eslint-disable-next-line import/export\r\nexport * from \"./baseTexture.polynomial\";\r\nexport * from \"./colorGradingTexture\";\r\nexport * from \"./cubeTexture\";\r\nexport * from \"./dynamicTexture\";\r\nexport * from \"./equiRectangularCubeTexture\";\r\nexport * from \"./externalTexture\";\r\nexport * from \"./Filtering/hdrFiltering\";\r\nexport * from \"./envCubeTexture\";\r\nexport * from \"./hdrCubeTexture\";\r\nexport * from \"./exrCubeTexture\";\r\nexport * from \"./htmlElementTexture\";\r\nexport * from \"./internalTexture\";\r\nexport * from \"./Loaders/index\";\r\nexport * from \"./mirrorTexture\";\r\nexport * from \"./multiRenderTarget\";\r\nexport * from \"./Packer/index\";\r\nexport * from \"./Procedurals/index\";\r\nexport * from \"./rawCubeTexture\";\r\nexport * from \"./rawTexture\";\r\nexport * from \"./rawTexture2DArray\";\r\nexport * from \"./rawTexture3D\";\r\nexport * from \"./refractionTexture\";\r\nexport * from \"./renderTargetTexture\";\r\nexport * from \"./textureMerger\";\r\nexport * from \"./textureSampler\";\r\nexport * from \"./texture\";\r\nexport * from \"./thinTexture\";\r\nexport * from \"./thinRenderTargetTexture\";\r\nexport * from \"./videoTexture\";\r\nexport * from \"./ktx2decoderTypes\";\r\nexport * from \"./textureCreationOptions\";\r\n\r\n// Shaders for procedural textures\r\nexport * from \"../../ShadersWGSL/procedural.vertex\";\r\nexport * from \"../../Shaders/procedural.vertex\";\r\n\r\n// HDR filtering\r\nexport * from \"../../Shaders/hdrFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrFiltering.fragment\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../Shaders/hdrIrradianceFiltering.fragment\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.vertex\";\r\nexport * from \"../../ShadersWGSL/hdrIrradianceFiltering.fragment\";\r\n"]}
@@ -0,0 +1,75 @@
1
+ import type { Scene } from "../../scene.js";
2
+ import { ProceduralTexture } from "./Procedurals/proceduralTexture.js";
3
+ import type { BaseTexture } from "./baseTexture.js";
4
+ import type { TextureSize } from "./textureCreationOptions.js";
5
+ /**
6
+ * Configuration for a texture input source
7
+ */
8
+ export interface ITextureChannelInput {
9
+ /** The texture to use as input */
10
+ texture: BaseTexture;
11
+ /** Source channel to read from (0=R, 1=G, 2=B, 3=A) */
12
+ sourceChannel: number;
13
+ }
14
+ /**
15
+ * Configuration for a constant value input source
16
+ */
17
+ export interface IConstantChannelInput {
18
+ /** Constant value between 0.0 and 1.0 */
19
+ value: number;
20
+ }
21
+ /**
22
+ * Union type for channel input sources
23
+ */
24
+ export type ChannelInput = ITextureChannelInput | IConstantChannelInput;
25
+ /**
26
+ * Configuration for texture merging operation
27
+ */
28
+ export interface ITextureMergeConfiguration {
29
+ /** Configuration for red output channel */
30
+ red: ChannelInput;
31
+ /** Configuration for green output channel (optional, defaults to 0) */
32
+ green?: ChannelInput;
33
+ /** Configuration for blue output channel (optional, defaults to 0) */
34
+ blue?: ChannelInput;
35
+ /** Configuration for alpha output channel (optional, defaults to 1) */
36
+ alpha?: ChannelInput;
37
+ /** Output texture size. If not specified, uses the largest input texture size */
38
+ outputSize?: TextureSize;
39
+ /** Whether to generate mipmaps for the output texture */
40
+ generateMipMaps?: boolean;
41
+ }
42
+ /**
43
+ * @internal
44
+ * Merge multiple texture channels into a single texture
45
+ * @param name Name for the resulting texture
46
+ * @param config Merge configuration
47
+ * @param scene Scene to create the texture in
48
+ * @returns The merged texture
49
+ */
50
+ export declare function MergeTexturesAsync(name: string, config: ITextureMergeConfiguration, scene: Scene): Promise<ProceduralTexture>;
51
+ /**
52
+ * @internal
53
+ * Create a texture input configuration
54
+ * @param texture The texture to read from
55
+ * @param sourceChannel The channel to read (0=R, 1=G, 2=B, 3=A)
56
+ * @returns Texture channel input configuration
57
+ */
58
+ export declare function CreateTextureInput(texture: BaseTexture, sourceChannel: number): ITextureChannelInput;
59
+ /**
60
+ * @internal
61
+ * Create a constant value input configuration
62
+ * @param value The constant value (0.0-1.0)
63
+ * @returns Constant channel input configuration
64
+ */
65
+ export declare function CreateConstantInput(value: number): IConstantChannelInput;
66
+ /**
67
+ * @internal
68
+ * Create a simple RGBA channel packing configuration
69
+ * @param red Input for red channel
70
+ * @param green Input for green channel (optional, defaults to 0)
71
+ * @param blue Input for blue channel (optional, defaults to 0)
72
+ * @param alpha Input for alpha channel (optional, defaults to 1)
73
+ * @returns Texture merge configuration
74
+ */
75
+ export declare function CreateRGBAConfiguration(red: ChannelInput, green?: ChannelInput, blue?: ChannelInput, alpha?: ChannelInput): ITextureMergeConfiguration;
@@ -0,0 +1,206 @@
1
+ import { ProceduralTexture } from "./Procedurals/proceduralTexture.js";
2
+
3
+ const _ShaderName = "textureMerger";
4
+ /**
5
+ * @internal
6
+ * Check if a channel input is a texture input
7
+ * @param input The channel input to check
8
+ * @returns True if the input is a texture input, false otherwise
9
+ */
10
+ function IsTextureInput(input) {
11
+ return "texture" in input;
12
+ }
13
+ /**
14
+ * @internal
15
+ * Check if a channel input is a constant input
16
+ * @param input The channel input to check
17
+ * @returns True if the input is a constant input, false otherwise
18
+ */
19
+ function IsConstantInput(input) {
20
+ return "value" in input;
21
+ }
22
+ /**
23
+ * @internal
24
+ * Copy texture transformation properties from one texture to another
25
+ * @param source The source texture
26
+ * @param destination The destination texture
27
+ */
28
+ function CopyTextureTransform(source, destination) {
29
+ destination.uOffset = source.uOffset;
30
+ destination.vOffset = source.vOffset;
31
+ destination.uScale = source.uScale;
32
+ destination.vScale = source.vScale;
33
+ destination.uAng = source.uAng;
34
+ destination.vAng = source.vAng;
35
+ destination.wAng = source.wAng;
36
+ destination.uRotationCenter = source.uRotationCenter;
37
+ destination.vRotationCenter = source.vRotationCenter;
38
+ }
39
+ /**
40
+ * @internal
41
+ * Merge multiple texture channels into a single texture
42
+ * @param name Name for the resulting texture
43
+ * @param config Merge configuration
44
+ * @param scene Scene to create the texture in
45
+ * @returns The merged texture
46
+ */
47
+ export async function MergeTexturesAsync(name, config, scene) {
48
+ const channels = [config.red, config.green, config.blue, config.alpha];
49
+ const textureInputs = [];
50
+ const textureInputMap = []; // Maps channel index to texture input index (-1 for constants)
51
+ // Collect unique textures and validate inputs
52
+ for (let channelIndex = 0; channelIndex < 4; channelIndex++) {
53
+ const channel = channels[channelIndex];
54
+ if (channel) {
55
+ if (IsTextureInput(channel)) {
56
+ // Validate source channel
57
+ if (channel.sourceChannel < 0 || channel.sourceChannel > 3) {
58
+ throw new Error("Source channel must be between 0 and 3 (R, G, B, A)");
59
+ }
60
+ // Find or add texture to inputs
61
+ let textureIndex = textureInputs.indexOf(channel.texture);
62
+ if (textureIndex === -1) {
63
+ textureIndex = textureInputs.length;
64
+ textureInputs.push(channel.texture);
65
+ }
66
+ textureInputMap[channelIndex] = textureIndex;
67
+ }
68
+ else if (IsConstantInput(channel)) {
69
+ // Validate constant value
70
+ if (channel.value < 0 || channel.value > 1) {
71
+ throw new Error("Constant value must be between 0.0 and 1.0");
72
+ }
73
+ textureInputMap[channelIndex] = -1;
74
+ }
75
+ else {
76
+ throw new Error("Invalid channel input configuration");
77
+ }
78
+ }
79
+ else {
80
+ textureInputMap[channelIndex] = -1;
81
+ }
82
+ }
83
+ // Determine output size
84
+ let outputSize = config.outputSize;
85
+ if (!outputSize && textureInputs.length > 0) {
86
+ // Use the largest texture size
87
+ let maxSize = 0;
88
+ for (const texture of textureInputs) {
89
+ const size = texture.getSize();
90
+ const currentSize = Math.max(size.width, size.height);
91
+ if (currentSize > maxSize) {
92
+ maxSize = currentSize;
93
+ outputSize = size.width === size.height ? maxSize : size;
94
+ }
95
+ }
96
+ }
97
+ outputSize = outputSize || 512; // Fallback size
98
+ // Generate shader defines
99
+ const defines = [];
100
+ const usedTextures = new Set();
101
+ for (let channelIndex = 0; channelIndex < 4; channelIndex++) {
102
+ const channel = channels[channelIndex];
103
+ const channelName = ["RED", "GREEN", "BLUE", "ALPHA"][channelIndex];
104
+ if (channel && IsTextureInput(channel)) {
105
+ defines.push(`${channelName}_FROM_TEXTURE`);
106
+ const textureIndex = textureInputMap[channelIndex];
107
+ usedTextures.add(textureIndex);
108
+ }
109
+ }
110
+ // Add texture defines for used textures
111
+ usedTextures.forEach((textureIndex) => {
112
+ defines.push(`USE_TEXTURE${textureIndex}`);
113
+ });
114
+ // Create the procedural texture
115
+ const outputTextureOptions = {
116
+ type: 2,
117
+ format: 5,
118
+ samplingMode: 1,
119
+ generateDepthBuffer: false,
120
+ generateMipMaps: false,
121
+ shaderLanguage: scene.getEngine().isWebGPU ? 1 /* ShaderLanguage.WGSL */ : 0 /* ShaderLanguage.GLSL */,
122
+ extraInitializationsAsync: async () => {
123
+ if (scene.getEngine().isWebGPU) {
124
+ await Promise.all([import("../../ShadersWGSL/textureMerger.fragment.js")]);
125
+ }
126
+ else {
127
+ await Promise.all([import("../../Shaders/textureMerger.fragment.js")]);
128
+ }
129
+ },
130
+ };
131
+ const proceduralTexture = new ProceduralTexture(name, outputSize, _ShaderName, scene, outputTextureOptions);
132
+ proceduralTexture.refreshRate = -1; // Do not auto-refresh
133
+ // Set the defines
134
+ proceduralTexture.defines = defines.length > 0 ? "#define " + defines.join("\n#define ") + "\n" : "";
135
+ // Set up texture inputs
136
+ for (let i = 0; i < textureInputs.length; i++) {
137
+ CopyTextureTransform(textureInputs[i], proceduralTexture);
138
+ proceduralTexture.setTexture(`inputTexture${i}`, textureInputs[i]);
139
+ }
140
+ // Set up channel configuration
141
+ for (let channelIndex = 0; channelIndex < 4; channelIndex++) {
142
+ const channel = channels[channelIndex];
143
+ const channelName = ["red", "green", "blue", "alpha"][channelIndex];
144
+ if (channel && IsTextureInput(channel)) {
145
+ const textureIndex = textureInputMap[channelIndex];
146
+ proceduralTexture.setInt(`${channelName}TextureIndex`, textureIndex);
147
+ proceduralTexture.setInt(`${channelName}SourceChannel`, channel.sourceChannel);
148
+ }
149
+ else {
150
+ // Use constant value (either provided or default)
151
+ let constantValue;
152
+ if (channel && IsConstantInput(channel)) {
153
+ constantValue = channel.value;
154
+ }
155
+ else {
156
+ // Use default values: 0 for RGB, 1 for alpha
157
+ constantValue = channelIndex === 3 ? 1.0 : 0.0;
158
+ }
159
+ proceduralTexture.setFloat(`${channelName}ConstantValue`, constantValue);
160
+ }
161
+ }
162
+ return await new Promise((resolve, reject) => {
163
+ // Compile and render
164
+ proceduralTexture.executeWhenReady(() => {
165
+ try {
166
+ proceduralTexture.render();
167
+ resolve(proceduralTexture);
168
+ }
169
+ catch (error) {
170
+ reject(error instanceof Error ? error : new Error(String(error)));
171
+ }
172
+ });
173
+ });
174
+ }
175
+ /**
176
+ * @internal
177
+ * Create a texture input configuration
178
+ * @param texture The texture to read from
179
+ * @param sourceChannel The channel to read (0=R, 1=G, 2=B, 3=A)
180
+ * @returns Texture channel input configuration
181
+ */
182
+ export function CreateTextureInput(texture, sourceChannel) {
183
+ return { texture, sourceChannel };
184
+ }
185
+ /**
186
+ * @internal
187
+ * Create a constant value input configuration
188
+ * @param value The constant value (0.0-1.0)
189
+ * @returns Constant channel input configuration
190
+ */
191
+ export function CreateConstantInput(value) {
192
+ return { value };
193
+ }
194
+ /**
195
+ * @internal
196
+ * Create a simple RGBA channel packing configuration
197
+ * @param red Input for red channel
198
+ * @param green Input for green channel (optional, defaults to 0)
199
+ * @param blue Input for blue channel (optional, defaults to 0)
200
+ * @param alpha Input for alpha channel (optional, defaults to 1)
201
+ * @returns Texture merge configuration
202
+ */
203
+ export function CreateRGBAConfiguration(red, green, blue, alpha) {
204
+ return { red, green, blue, alpha };
205
+ }
206
+ //# sourceMappingURL=textureMerger.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"textureMerger.js","sourceRoot":"","sources":["../../../../../dev/core/src/Materials/Textures/textureMerger.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAIpE,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AA4CpD,MAAM,WAAW,GAAG,eAAe,CAAC;AAEpC;;;;;GAKG;AACH,SAAS,cAAc,CAAC,KAAmB;IACvC,OAAO,SAAS,IAAI,KAAK,CAAC;AAC9B,CAAC;AAED;;;;;GAKG;AACH,SAAS,eAAe,CAAC,KAAmB;IACxC,OAAO,OAAO,IAAI,KAAK,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,SAAS,oBAAoB,CAAC,MAAe,EAAE,WAAoB;IAC/D,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACrC,WAAW,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;IACrC,WAAW,CAAC,MAAM,GA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AC;AACtC,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,mBAAmB,CAAC,KAAa;IAC7C,OAAO,EAAE,KAAK,EAAE,CAAC;AACrB,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,uBAAuB,CAAC,GAAiB,EAAE,KAAoB,EAAE,IAAmB,EAAE,KAAoB;IACtH,OAAO,EAAE,GAAG,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC;AACvC,CAAC","sourcesContent":["import type { Scene } from \"../../scene\";\nimport type { IProceduralTextureCreationOptions } from \"core/Materials/Textures/Procedurals/proceduralTexture\";\nimport { ProceduralTexture } from \"./Procedurals/proceduralTexture\";\nimport type { BaseTexture } from \"./baseTexture\";\nimport type { TextureSize } from \"./textureCreationOptions\";\nimport { ShaderLanguage } from \"core/Materials/shaderLanguage\";\nimport { Constants } from \"../../Engines/constants\";\nimport type { Texture } from \"./texture\";\n\n/**\n * Configuration for a texture input source\n */\nexport interface ITextureChannelInput {\n /** The texture to use as input */\n texture: BaseTexture;\n /** Source channel to read from (0=R, 1=G, 2=B, 3=A) */\n sourceChannel: number;\n}\n\n/**\n * Configuration for a constant value input source\n */\nexport interface IConstantChannelInput {\n /** Constant value between 0.0 and 1.0 */\n value: number;\n}\n\n/**\n * Union type for channel input sources\n */\nexport type ChannelInput = ITextureChannelInput | IConstantChannelInput;\n\n/**\n * Configuration for texture merging operation\n */\nexport interface ITextureMergeConfiguration {\n /** Configuration for red output channel */\n red: ChannelInput;\n /** Configuration for green output channel (optional, defaults to 0) */\n green?: ChannelInput;\n /** Configuration for blue output channel (optional, defaults to 0) */\n blue?: ChannelInput;\n /** Configuration for alpha output channel (optional, defaults to 1) */\n alpha?: ChannelInput;\n /** Output texture size. If not specified, uses the largest input texture size */\n outputSize?: TextureSize;\n /** Whether to generate mipmaps for the output texture */\n generateMipMaps?: boolean;\n}\n\nconst _ShaderName = \"textureMerger\";\n\n/**\n * @internal\n * Check if a channel input is a texture input\n * @param input The channel input to check\n * @returns True if the input is a texture input, false otherwise\n */\nfunction IsTextureInput(input: ChannelInput): input is ITextureChannelInput {\n return \"texture\" in input;\n}\n\n/**\n * @internal\n * Check if a channel input is a constant input\n * @param input The channel input to check\n * @returns True if the input is a constant input, false otherwise\n */\nfunction IsConstantInput(input: ChannelInput): input is IConstantChannelInput {\n return \"value\" in input;\n}\n\n/**\n * @internal\n * Copy texture transformation properties from one texture to another\n * @param source The source texture\n * @param destination The destination texture\n */\nfunction CopyTextureTransform(source: Texture, destination: Texture) {\n destination.uOffset = source.uOffset;\n destination.vOffset = source.vOffset;\n destination.uScale = source.uScale;\n destination.vScale = source.vScale;\n destination.uAng = source.uAng;\n destination.vAng = source.vAng;\n destination.wAng = source.wAng;\n destination.uRotationCenter = source.uRotationCenter;\n destination.vRotationCenter = source.vRotationCenter;\n}\n\n/**\n * @internal\n * Merge multiple texture channels into a single texture\n * @param name Name for the resulting texture\n * @param config Merge configuration\n * @param scene Scene to create the texture in\n * @returns The merged texture\n */\nexport async function MergeTexturesAsync(name: string, config: ITextureMergeConfiguration, scene: Scene): Promise<ProceduralTexture> {\n const channels = [config.red, config.green, config.blue, config.alpha];\n const textureInputs: BaseTexture[] = [];\n const textureInputMap: number[] = []; // Maps channel index to texture input index (-1 for constants)\n\n // Collect unique textures and validate inputs\n for (let channelIndex = 0; channelIndex < 4; channelIndex++) {\n const channel = channels[channelIndex];\n if (channel) {\n if (IsTextureInput(channel)) {\n // Validate source channel\n if (channel.sourceChannel < 0 || channel.sourceChannel > 3) {\n throw new Error(\"Source channel must be between 0 and 3 (R, G, B, A)\");\n }\n\n // Find or add texture to inputs\n let textureIndex = textureInputs.indexOf(channel.texture);\n if (textureIndex === -1) {\n textureIndex = textureInputs.length;\n textureInputs.push(channel.texture);\n }\n textureInputMap[channelIndex] = textureIndex;\n } else if (IsConstantInput(channel)) {\n // Validate constant value\n if (channel.value < 0 || channel.value > 1) {\n throw new Error(\"Constant value must be between 0.0 and 1.0\");\n }\n textureInputMap[channelIndex] = -1;\n } else {\n throw new Error(\"Invalid channel input configuration\");\n }\n } else {\n textureInputMap[channelIndex] = -1;\n }\n }\n\n // Determine output size\n let outputSize = config.outputSize;\n if (!outputSize && textureInputs.length > 0) {\n // Use the largest texture size\n let maxSize = 0;\n for (const texture of textureInputs) {\n const size = texture.getSize();\n const currentSize = Math.max(size.width, size.height);\n if (currentSize > maxSize) {\n maxSize = currentSize;\n outputSize = size.width === size.height ? maxSize : size;\n }\n }\n }\n outputSize = outputSize || 512; // Fallback size\n\n // Generate shader defines\n const defines: string[] = [];\n const usedTextures = new Set<number>();\n\n for (let channelIndex = 0; channelIndex < 4; channelIndex++) {\n const channel = channels[channelIndex];\n const channelName = [\"RED\", \"GREEN\", \"BLUE\", \"ALPHA\"][channelIndex];\n\n if (channel && IsTextureInput(channel)) {\n defines.push(`${channelName}_FROM_TEXTURE`);\n const textureIndex = textureInputMap[channelIndex];\n usedTextures.add(textureIndex);\n }\n }\n\n // Add texture defines for used textures\n usedTextures.forEach((textureIndex) => {\n defines.push(`USE_TEXTURE${textureIndex}`);\n });\n\n // Create the procedural texture\n const outputTextureOptions: IProceduralTextureCreationOptions = {\n type: Constants.TEXTURETYPE_HALF_FLOAT,\n format: Constants.TEXTUREFORMAT_RGBA,\n samplingMode: Constants.TEXTURE_NEAREST_SAMPLINGMODE,\n generateDepthBuffer: false,\n generateMipMaps: false,\n shaderLanguage: scene.getEngine().isWebGPU ? ShaderLanguage.WGSL : ShaderLanguage.GLSL,\n extraInitializationsAsync: async () => {\n if (scene.getEngine().isWebGPU) {\n await Promise.all([import(\"../../ShadersWGSL/textureMerger.fragment\")]);\n } else {\n await Promise.all([import(\"../../Shaders/textureMerger.fragment\")]);\n }\n },\n };\n const proceduralTexture = new ProceduralTexture(name, outputSize, _ShaderName, scene, outputTextureOptions);\n proceduralTexture.refreshRate = -1; // Do not auto-refresh\n\n // Set the defines\n proceduralTexture.defines = defines.length > 0 ? \"#define \" + defines.join(\"\\n#define \") + \"\\n\" : \"\";\n\n // Set up texture inputs\n for (let i = 0; i < textureInputs.length; i++) {\n CopyTextureTransform(textureInputs[i] as Texture, proceduralTexture);\n proceduralTexture.setTexture(`inputTexture${i}`, textureInputs[i]);\n }\n\n // Set up channel configuration\n for (let channelIndex = 0; channelIndex < 4; channelIndex++) {\n const channel = channels[channelIndex];\n const channelName = [\"red\", \"green\", \"blue\", \"alpha\"][channelIndex];\n\n if (channel && IsTextureInput(channel)) {\n const textureIndex = textureInputMap[channelIndex];\n proceduralTexture.setInt(`${channelName}TextureIndex`, textureIndex);\n proceduralTexture.setInt(`${channelName}SourceChannel`, channel.sourceChannel);\n } else {\n // Use constant value (either provided or default)\n let constantValue: number;\n if (channel && IsConstantInput(channel)) {\n constantValue = channel.value;\n } else {\n // Use default values: 0 for RGB, 1 for alpha\n constantValue = channelIndex === 3 ? 1.0 : 0.0;\n }\n proceduralTexture.setFloat(`${channelName}ConstantValue`, constantValue);\n }\n }\n\n return await new Promise<ProceduralTexture>((resolve, reject) => {\n // Compile and render\n proceduralTexture.executeWhenReady(() => {\n try {\n proceduralTexture.render();\n resolve(proceduralTexture);\n } catch (error) {\n reject(error instanceof Error ? error : new Error(String(error)));\n }\n });\n });\n}\n\n/**\n * @internal\n * Create a texture input configuration\n * @param texture The texture to read from\n * @param sourceChannel The channel to read (0=R, 1=G, 2=B, 3=A)\n * @returns Texture channel input configuration\n */\nexport function CreateTextureInput(texture: BaseTexture, sourceChannel: number): ITextureChannelInput {\n return { texture, sourceChannel };\n}\n\n/**\n * @internal\n * Create a constant value input configuration\n * @param value The constant value (0.0-1.0)\n * @returns Constant channel input configuration\n */\nexport function CreateConstantInput(value: number): IConstantChannelInput {\n return { value };\n}\n\n/**\n * @internal\n * Create a simple RGBA channel packing configuration\n * @param red Input for red channel\n * @param green Input for green channel (optional, defaults to 0)\n * @param blue Input for blue channel (optional, defaults to 0)\n * @param alpha Input for alpha channel (optional, defaults to 1)\n * @returns Texture merge configuration\n */\nexport function CreateRGBAConfiguration(red: ChannelInput, green?: ChannelInput, blue?: ChannelInput, alpha?: ChannelInput): ITextureMergeConfiguration {\n return { red, green, blue, alpha };\n}\n"]}
@@ -1,9 +1,15 @@
1
+ import { Matrix } from "../Maths/math.vector.js";
2
+ import type { IMatrixLike, IVector3Like } from "../Maths/math.like.js";
1
3
  import type { Scene } from "../scene.js";
4
+ import type { DeepImmutable } from "../types.js";
2
5
  /**
3
6
  * When rendering, each scene will reset this to ensure the correct floating origin offset is when overriding the below functions
4
7
  */
5
8
  export declare const FloatingOriginCurrentScene: {
6
9
  getScene: () => Scene | undefined;
10
+ eyeAtCamera: boolean;
7
11
  };
12
+ export declare function GetOffsetTransformMatrices(offset: IVector3Like, viewMatrices: Array<Matrix>, projectionMatrices: Array<Matrix>, length: number, resultArray: Float32Array): Float32Array;
13
+ export declare function GetFullOffsetViewProjectionToRef(offset: IVector3Like, viewMatrix: DeepImmutable<IMatrixLike>, projectionMatrix: DeepImmutable<IMatrixLike>, ref: IMatrixLike): DeepImmutable<IMatrixLike>;
8
14
  export declare function ResetMatrixFunctions(): void;
9
15
  export declare function OverrideMatrixFunctions(): void;
@@ -10,6 +10,7 @@ const TempMat2 = new Matrix();
10
10
  */
11
11
  export const FloatingOriginCurrentScene = {
12
12
  getScene: () => undefined,
13
+ eyeAtCamera: true, // When true, we can assume viewMatrix translation is at origin. Otherwise, we must do full offset calculations
13
14
  };
14
15
  function OffsetWorldToRef(offset, world, ref) {
15
16
  const refArray = ref.asArray();
@@ -20,10 +21,20 @@ function OffsetWorldToRef(offset, world, ref) {
20
21
  refArray[12] -= offset.x;
21
22
  refArray[13] -= offset.y;
22
23
  refArray[14] -= offset.z;
23
- Matrix.FromArrayToRef(refArray, 0, ref);
24
+ ref.markAsUpdated();
24
25
  return ref;
25
26
  }
26
- function OffsetViewToRef(view, ref) {
27
+ function GetFullOffsetView(offset, viewMatrix, ref) {
28
+ InvertMatrixToRef(viewMatrix, TempMat1); // TempMat1 = light world matrix (inverse of view)
29
+ OffsetWorldToRef(offset, TempMat1, TempMat2); // TempMat2 = offset light world matrix
30
+ InvertMatrixToRef(TempMat2, ref); // TempMat1 = offset view matrix
31
+ return ref;
32
+ }
33
+ function OffsetViewToRef(offset, view, ref) {
34
+ // When eye is not at camera, we cannot assume the translation of view matrix is at origin, so we perform full offset calculation
35
+ if (!FloatingOriginCurrentScene.eyeAtCamera) {
36
+ return GetFullOffsetView(offset, view, ref);
37
+ }
27
38
  const refArray = ref.asArray();
28
39
  const viewArray = view.asArray();
29
40
  for (let i = 0; i < 16; i++) {
@@ -32,23 +43,35 @@ function OffsetViewToRef(view, ref) {
32
43
  refArray[12] = 0;
33
44
  refArray[13] = 0;
34
45
  refArray[14] = 0;
35
- Matrix.FromArrayToRef(refArray, 0, ref);
46
+ ref.markAsUpdated();
36
47
  return ref;
37
48
  }
38
- function OffsetViewProjectionToRef(view, projection, ref) {
39
- MultiplyMatricesToRef(OffsetViewToRef(view, ref), projection, ref);
49
+ function OffsetViewProjectionToRef(offset, view, projection, ref) {
50
+ MultiplyMatricesToRef(OffsetViewToRef(offset, view, ref), projection, ref);
40
51
  return ref;
41
52
  }
53
+ export function GetOffsetTransformMatrices(offset, viewMatrices, projectionMatrices, length, resultArray) {
54
+ for (let cascadeIndex = 0; cascadeIndex < length; ++cascadeIndex) {
55
+ GetFullOffsetViewProjectionToRef(offset, viewMatrices[cascadeIndex], projectionMatrices[cascadeIndex], TempMat1);
56
+ TempMat1.copyToArray(resultArray, cascadeIndex * 16);
57
+ }
58
+ return resultArray;
59
+ }
42
60
  function OffsetWorldViewToRef(offset, worldView, view, ref) {
43
61
  // ( world * view ) * inverse ( view ) = world
44
62
  InvertMatrixToRef(view, TempMat1); // TempMat1 = inverseView
45
63
  MultiplyMatricesToRef(worldView, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused
46
64
  // ( offsetWorld * offsetView ) = offsetWorldView
47
65
  OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld
48
- OffsetViewToRef(view, TempMat2); // TempMat2 = offsetView
66
+ OffsetViewToRef(offset, view, TempMat2); // TempMat2 = offsetView
49
67
  MultiplyMatricesToRef(TempMat1, TempMat2, ref);
50
68
  return ref;
51
69
  }
70
+ export function GetFullOffsetViewProjectionToRef(offset, viewMatrix, projectionMatrix, ref) {
71
+ GetFullOffsetView(offset, viewMatrix, TempMat2);
72
+ MultiplyMatricesToRef(TempMat2, projectionMatrix, ref);
73
+ return ref;
74
+ }
52
75
  function OffsetWorldViewProjectionToRef(offset, worldViewProjection, viewProjection, view, projection, ref) {
53
76
  // ( world * view * projection ) * inverse(projection) * inverse(view) = world
54
77
  // ( world * view * projection ) * inverse (view * projection) = world
@@ -56,27 +79,28 @@ function OffsetWorldViewProjectionToRef(offset, worldViewProjection, viewProject
56
79
  MultiplyMatricesToRef(worldViewProjection, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused
57
80
  // ( offsetWorld * offsetViewProjection) = offsetWorldViewProjection
58
81
  OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld
59
- OffsetViewProjectionToRef(view, projection, TempMat2); // TempMat2 = offsetViewProjection
82
+ OffsetViewProjectionToRef(offset, view, projection, TempMat2); // TempMat2 = offsetViewProjection
60
83
  MultiplyMatricesToRef(TempMat1, TempMat2, ref);
61
84
  return ref;
62
85
  }
63
86
  function GetOffsetMatrix(uniformName, mat) {
64
- TempFinalMat.updateFlag = mat.updateFlag;
65
87
  const scene = FloatingOriginCurrentScene.getScene();
66
88
  // Early out for scenes that don't have floatingOriginMode enabled
67
- if (!scene) {
89
+ // Effect.setMatrix will call pipelineContext.setMatrix. In WebGPU, this will in turn call ubo.updateMatrix. To avoid double offset, early out if mat is TempFinalMat
90
+ if (!scene || TempFinalMat === mat) {
68
91
  return mat;
69
92
  }
93
+ TempFinalMat.updateFlag = mat.updateFlag;
70
94
  const offset = scene.floatingOriginOffset;
71
95
  switch (uniformName) {
72
96
  case "world":
73
97
  return OffsetWorldToRef(offset, mat, TempFinalMat);
74
98
  case "view":
75
- return OffsetViewToRef(mat, TempFinalMat);
99
+ return OffsetViewToRef(offset, mat, TempFinalMat);
76
100
  case "worldView":
77
101
  return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);
78
102
  case "viewProjection":
79
- return OffsetViewProjectionToRef(scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
103
+ return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
80
104
  case "worldViewProjection":
81
105
  return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
82
106
  default:
@@ -1 +1 @@
1
- {"version":3,"file":"floatingOriginMatrixOverrides.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/floatingOriginMatrixOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAGxG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,YAAY,GAAW,IAAI,MAAM,EAAE,CAAC;AAC1C,MAAM,QAAQ,GAAW,IAAI,MAAM,EAAE,CAAC;AACtC,MAAM,QAAQ,GAAW,IAAI,MAAM,EAAE,CAAC;AACtC;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACtC,QAAQ,EAAE,GAAG,EAAE,CAAC,SAA8B;CACjD,CAAC;AAEF,SAAS,gBAAgB,CAAC,MAAoB,EAAE,KAAiC,EAAE,GAAW;IAC1F,MAAM,QAAQ,GAAG,GAAG,CAAC,OAAO,EAAE,CAAC;IAC/B,MAAM,UAAU,GAAG,KAAK,CAAC,OAAO,EAAE,CAAC;IACnC,KAAK,IAA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F,CAAC;AAED,MAAM,UAAU,uBAAuB;IACnC,cAAc,CAAC,SAAS,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChE,cAAc,CAAC,SAAS,CAAC,SAAS,GAAG,UAAU,WAAmB,EAAE,MAAmB;QACnF,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IACF,qBAAqB,CAAC,SAAS,CAAC,+BAA+B,GAAG,8BAA8B,CAAC;IACjG,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,GAAG,UAAU,WAAmB,EAAE,MAAmB;QACxG,IAAI,CAAC,+BAA+B,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5F,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { Effect } from \"../Materials/effect\";\r\nimport { Matrix } from \"../Maths/math.vector\";\r\nimport type { IMatrixLike, IVector3Like } from \"../Maths/math.like\";\r\nimport { InvertMatrixToRef, MultiplyMatricesToRef } from \"../Maths/ThinMaths/thinMath.matrix.functions\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { DeepImmutable } from \"../types\";\r\nimport { UniformBuffer } from \"./uniformBuffer\";\r\n\r\nconst TempFinalMat: Matrix = new Matrix();\r\nconst TempMat1: Matrix = new Matrix();\r\nconst TempMat2: Matrix = new Matrix();\r\n/**\r\n * When rendering, each scene will reset this to ensure the correct floating origin offset is when overriding the below functions\r\n */\r\nexport const FloatingOriginCurrentScene = {\r\n getScene: () => undefined as Scene | undefined,\r\n};\r\n\r\nfunction OffsetWorldToRef(offset: IVector3Like, world: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n const refArray = ref.asArray();\r\n const worldArray = world.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = worldArray[i];\r\n }\r\n refArray[12] -= offset.x;\r\n refArray[13] -= offset.y;\r\n refArray[14] -= offset.z;\r\n Matrix.FromArrayToRef(refArray, 0, ref);\r\n return ref;\r\n}\r\n\r\nfunction OffsetViewToRef(view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n const refArray = ref.asArray();\r\n const viewArray = view.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = viewArray[i];\r\n }\r\n refArray[12] = 0;\r\n refArray[13] = 0;\r\n refArray[14] = 0;\r\n Matrix.FromArrayToRef(refArray, 0, ref);\r\n return ref;\r\n}\r\n\r\nfunction OffsetViewProjectionToRef(view: DeepImmutable<IMatrixLike>, projection: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n MultiplyMatricesToRef(OffsetViewToRef(view, ref), projection, ref);\r\n return ref;\r\n}\r\n\r\nfunction OffsetWorldViewToRef(offset: IVector3Like, worldView: DeepImmutable<IMatrixLike>, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // ( world * view ) * inverse ( view ) = world\r\n InvertMatrixToRef(view, TempMat1); // TempMat1 = inverseView\r\n MultiplyMatricesToRef(worldView, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetView ) = offsetWorldView\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewToRef(view, TempMat2); // TempMat2 = offsetView\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nfunction OffsetWorldViewProjectionToRef(\r\n offset: IVector3Like,\r\n worldViewProjection: DeepImmutable<IMatrixLike>,\r\n viewProjection: DeepImmutable<IMatrixLike>,\r\n view: DeepImmutable<IMatrixLike>,\r\n projection: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n // ( world * view * projection ) * inverse(projection) * inverse(view) = world\r\n // ( world * view * projection ) * inverse (view * projection) = world\r\n InvertMatrixToRef(viewProjection, TempMat1); // TempMat1 = inverse (view * projection)\r\n MultiplyMatricesToRef(worldViewProjection, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetViewProjection) = offsetWorldViewProjection\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewProjectionToRef(view, projection, TempMat2); // TempMat2 = offsetViewProjection\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nfunction GetOffsetMatrix(uniformName: string, mat: IMatrixLike): IMatrixLike {\r\n TempFinalMat.updateFlag = mat.updateFlag;\r\n const scene = FloatingOriginCurrentScene.getScene();\r\n // Early out for scenes that don't have floatingOriginMode enabled\r\n if (!scene) {\r\n return mat;\r\n }\r\n const offset = scene.floatingOriginOffset;\r\n switch (uniformName) {\r\n case \"world\":\r\n return OffsetWorldToRef(offset, mat, TempFinalMat);\r\n case \"view\":\r\n return OffsetViewToRef(mat, TempFinalMat);\r\n case \"worldView\":\r\n return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);\r\n case \"viewProjection\":\r\n return OffsetViewProjectionToRef(scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n case \"worldViewProjection\":\r\n return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n default:\r\n return mat;\r\n }\r\n}\r\n\r\n// ---- Overriding the prototypes of effect and uniformBuffer's setMatrix functions ----\r\nconst UniformBufferInternal = UniformBuffer as any;\r\nconst EffectInternal = Effect as any;\r\nconst OriginalUpdateMatrixForUniform = UniformBufferInternal.prototype._updateMatrixForUniform;\r\nconst OriginalSetMatrix = Effect.prototype.setMatrix;\r\n\r\nexport function ResetMatrixFunctions() {\r\n Effect.prototype.setMatrix = OriginalSetMatrix;\r\n EffectInternal._setMatrixOverride = undefined;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = undefined;\r\n}\r\n\r\nexport function OverrideMatrixFunctions() {\r\n EffectInternal.prototype._setMatrixOverride = OriginalSetMatrix;\r\n EffectInternal.prototype.setMatrix = function (uniformName: string, matrix: IMatrixLike) {\r\n this._setMatrixOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n return this;\r\n };\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = function (uniformName: string, matrix: IMatrixLike) {\r\n this._updateMatrixForUniformOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n };\r\n}\r\n"]}
1
+ {"version":3,"file":"floatingOriginMatrixOverrides.js","sourceRoot":"","sources":["../../../../dev/core/src/Materials/floatingOriginMatrixOverrides.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,sBAAsB,CAAC;AAE9C,OAAO,EAAE,iBAAiB,EAAE,qBAAqB,EAAE,MAAM,8CAA8C,CAAC;AAGxG,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,MAAM,YAAY,GAAW,IAAI,MAAM,EAAE,CAAC;AAC1C,MAAM,QAAQ,GAAW,IAAI,MAAM,EAAE,CAAC;AACtC,MAAM,QAAQ,GAAW,IAAI,MAAM,EAAE,CAAC;AAEtC;;GAEG;AACH,MAAM,CAAC,MAAM,0BAA0B,GAAG;IACtC,QAAQ,EAAE,GAAG,EAAE,CAAC,SAA8B;IAC9C,WAAW,EAAE,IAAI,EAAE,+GAA+G;CACrI,CAAC;AAEF,SAAS,gBAAgB,CAAC,MAAoB,EAAE,KAAiC,EAAE,GAAW;IAC1F,MAAM,QAAQ,GAAG,GAAG,CAAC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,+BAA+B,GAAG,SAAS,CAAC;AAChF,CAAC;AAED,MAAM,UAAU,uBAAuB;IACnC,cAAc,CAAC,SAAS,CAAC,kBAAkB,GAAG,iBAAiB,CAAC;IAChE,cAAc,CAAC,SAAS,CAAC,SAAS,GAAG,UAAU,WAAmB,EAAE,MAAmB;QACnF,IAAI,CAAC,kBAAkB,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;QAC3E,OAAO,IAAI,CAAC;IAChB,CAAC,CAAC;IACF,qBAAqB,CAAC,SAAS,CAAC,+BAA+B,GAAG,8BAA8B,CAAC;IACjG,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,GAAG,UAAU,WAAmB,EAAE,MAAmB;QACxG,IAAI,CAAC,+BAA+B,CAAC,WAAW,EAAE,eAAe,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC,CAAC;IAC5F,CAAC,CAAC;AACN,CAAC","sourcesContent":["import { Effect } from \"../Materials/effect\";\r\nimport { Matrix } from \"../Maths/math.vector\";\r\nimport type { IMatrixLike, IVector3Like } from \"../Maths/math.like\";\r\nimport { InvertMatrixToRef, MultiplyMatricesToRef } from \"../Maths/ThinMaths/thinMath.matrix.functions\";\r\nimport type { Scene } from \"../scene\";\r\nimport type { DeepImmutable } from \"../types\";\r\nimport { UniformBuffer } from \"./uniformBuffer\";\r\n\r\nconst TempFinalMat: Matrix = new Matrix();\r\nconst TempMat1: Matrix = new Matrix();\r\nconst TempMat2: Matrix = new Matrix();\r\n\r\n/**\r\n * When rendering, each scene will reset this to ensure the correct floating origin offset is when overriding the below functions\r\n */\r\nexport const FloatingOriginCurrentScene = {\r\n getScene: () => undefined as Scene | undefined,\r\n eyeAtCamera: true, // When true, we can assume viewMatrix translation is at origin. Otherwise, we must do full offset calculations\r\n};\r\n\r\nfunction OffsetWorldToRef(offset: IVector3Like, world: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n const refArray = ref.asArray();\r\n const worldArray = world.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = worldArray[i];\r\n }\r\n refArray[12] -= offset.x;\r\n refArray[13] -= offset.y;\r\n refArray[14] -= offset.z;\r\n ref.markAsUpdated();\r\n return ref;\r\n}\r\n\r\nfunction GetFullOffsetView(offset: IVector3Like, viewMatrix: DeepImmutable<IMatrixLike>, ref: IMatrixLike) {\r\n InvertMatrixToRef(viewMatrix, TempMat1); // TempMat1 = light world matrix (inverse of view)\r\n OffsetWorldToRef(offset, TempMat1, TempMat2); // TempMat2 = offset light world matrix\r\n InvertMatrixToRef(TempMat2, ref); // TempMat1 = offset view matrix\r\n return ref;\r\n}\r\n\r\nfunction OffsetViewToRef(offset: IVector3Like, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // When eye is not at camera, we cannot assume the translation of view matrix is at origin, so we perform full offset calculation\r\n if (!FloatingOriginCurrentScene.eyeAtCamera) {\r\n return GetFullOffsetView(offset, view, ref);\r\n }\r\n const refArray = ref.asArray();\r\n const viewArray = view.asArray();\r\n for (let i = 0; i < 16; i++) {\r\n refArray[i] = viewArray[i];\r\n }\r\n refArray[12] = 0;\r\n refArray[13] = 0;\r\n refArray[14] = 0;\r\n ref.markAsUpdated();\r\n return ref;\r\n}\r\n\r\nfunction OffsetViewProjectionToRef(offset: IVector3Like, view: DeepImmutable<IMatrixLike>, projection: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n MultiplyMatricesToRef(OffsetViewToRef(offset, view, ref), projection, ref);\r\n return ref;\r\n}\r\n\r\nexport function GetOffsetTransformMatrices(\r\n offset: IVector3Like,\r\n viewMatrices: Array<Matrix>,\r\n projectionMatrices: Array<Matrix>,\r\n length: number,\r\n resultArray: Float32Array\r\n): Float32Array {\r\n for (let cascadeIndex = 0; cascadeIndex < length; ++cascadeIndex) {\r\n GetFullOffsetViewProjectionToRef(offset, viewMatrices[cascadeIndex], projectionMatrices[cascadeIndex], TempMat1);\r\n TempMat1.copyToArray(resultArray, cascadeIndex * 16);\r\n }\r\n return resultArray;\r\n}\r\n\r\nfunction OffsetWorldViewToRef(offset: IVector3Like, worldView: DeepImmutable<IMatrixLike>, view: DeepImmutable<IMatrixLike>, ref: Matrix): DeepImmutable<IMatrixLike> {\r\n // ( world * view ) * inverse ( view ) = world\r\n InvertMatrixToRef(view, TempMat1); // TempMat1 = inverseView\r\n MultiplyMatricesToRef(worldView, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetView ) = offsetWorldView\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewToRef(offset, view, TempMat2); // TempMat2 = offsetView\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nexport function GetFullOffsetViewProjectionToRef(\r\n offset: IVector3Like,\r\n viewMatrix: DeepImmutable<IMatrixLike>,\r\n projectionMatrix: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n GetFullOffsetView(offset, viewMatrix, TempMat2);\r\n MultiplyMatricesToRef(TempMat2, projectionMatrix, ref);\r\n return ref;\r\n}\r\n\r\nfunction OffsetWorldViewProjectionToRef(\r\n offset: IVector3Like,\r\n worldViewProjection: DeepImmutable<IMatrixLike>,\r\n viewProjection: DeepImmutable<IMatrixLike>,\r\n view: DeepImmutable<IMatrixLike>,\r\n projection: DeepImmutable<IMatrixLike>,\r\n ref: IMatrixLike\r\n): DeepImmutable<IMatrixLike> {\r\n // ( world * view * projection ) * inverse(projection) * inverse(view) = world\r\n // ( world * view * projection ) * inverse (view * projection) = world\r\n InvertMatrixToRef(viewProjection, TempMat1); // TempMat1 = inverse (view * projection)\r\n MultiplyMatricesToRef(worldViewProjection, TempMat1, TempMat2); // TempMat2 = world, TempMat1 can be reused\r\n\r\n // ( offsetWorld * offsetViewProjection) = offsetWorldViewProjection\r\n OffsetWorldToRef(offset, TempMat2, TempMat1); // TempMat1 = offsetWorld\r\n OffsetViewProjectionToRef(offset, view, projection, TempMat2); // TempMat2 = offsetViewProjection\r\n MultiplyMatricesToRef(TempMat1, TempMat2, ref);\r\n\r\n return ref;\r\n}\r\n\r\nfunction GetOffsetMatrix(uniformName: string, mat: IMatrixLike): IMatrixLike {\r\n const scene = FloatingOriginCurrentScene.getScene();\r\n // Early out for scenes that don't have floatingOriginMode enabled\r\n // Effect.setMatrix will call pipelineContext.setMatrix. In WebGPU, this will in turn call ubo.updateMatrix. To avoid double offset, early out if mat is TempFinalMat\r\n if (!scene || TempFinalMat === mat) {\r\n return mat;\r\n }\r\n TempFinalMat.updateFlag = mat.updateFlag;\r\n const offset = scene.floatingOriginOffset;\r\n switch (uniformName) {\r\n case \"world\":\r\n return OffsetWorldToRef(offset, mat, TempFinalMat);\r\n case \"view\":\r\n return OffsetViewToRef(offset, mat, TempFinalMat);\r\n case \"worldView\":\r\n return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);\r\n case \"viewProjection\":\r\n return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n case \"worldViewProjection\":\r\n return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);\r\n default:\r\n return mat;\r\n }\r\n}\r\n\r\n// ---- Overriding the prototypes of effect and uniformBuffer's setMatrix functions ----\r\nconst UniformBufferInternal = UniformBuffer as any;\r\nconst EffectInternal = Effect as any;\r\nconst OriginalUpdateMatrixForUniform = UniformBufferInternal.prototype._updateMatrixForUniform;\r\nconst OriginalSetMatrix = Effect.prototype.setMatrix;\r\n\r\nexport function ResetMatrixFunctions() {\r\n Effect.prototype.setMatrix = OriginalSetMatrix;\r\n EffectInternal._setMatrixOverride = undefined;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = undefined;\r\n}\r\n\r\nexport function OverrideMatrixFunctions() {\r\n EffectInternal.prototype._setMatrixOverride = OriginalSetMatrix;\r\n EffectInternal.prototype.setMatrix = function (uniformName: string, matrix: IMatrixLike) {\r\n this._setMatrixOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n return this;\r\n };\r\n UniformBufferInternal.prototype._updateMatrixForUniformOverride = OriginalUpdateMatrixForUniform;\r\n UniformBufferInternal.prototype._updateMatrixForUniform = function (uniformName: string, matrix: IMatrixLike) {\r\n this._updateMatrixForUniformOverride(uniformName, GetOffsetMatrix(uniformName, matrix));\r\n };\r\n}\r\n"]}
@@ -311,7 +311,10 @@ export class SceneSerializer {
311
311
  if (scene.spriteManagers) {
312
312
  serializationObject.spriteManagers = [];
313
313
  for (index = 0; index < scene.spriteManagers.length; index++) {
314
- serializationObject.spriteManagers.push(scene.spriteManagers[index].serialize(true));
314
+ const spriteManager = scene.spriteManagers[index];
315
+ if (!spriteManager.doNotSerialize) {
316
+ serializationObject.spriteManagers.push(spriteManager.serialize(true));
317
+ }
315
318
  }
316
319
  }
317
320
  return serializationObject;