@onerjs/core 8.29.6 → 8.29.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/Engines/abstractEngine.js +2 -2
- package/Engines/abstractEngine.js.map +1 -1
- package/Lights/Shadows/cascadedShadowGenerator.d.ts +1 -0
- package/Lights/Shadows/cascadedShadowGenerator.js +9 -1
- package/Lights/Shadows/cascadedShadowGenerator.js.map +1 -1
- package/Lights/Shadows/shadowGenerator.js +10 -3
- package/Lights/Shadows/shadowGenerator.js.map +1 -1
- package/Materials/Textures/index.d.ts +1 -0
- package/Materials/Textures/index.js +1 -0
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/Textures/texture.d.ts +2 -0
- package/Materials/Textures/texture.js +15 -4
- package/Materials/Textures/texture.js.map +1 -1
- package/Materials/Textures/textureMerger.d.ts +75 -0
- package/Materials/Textures/textureMerger.js +206 -0
- package/Materials/Textures/textureMerger.js.map +1 -0
- package/Materials/floatingOriginMatrixOverrides.d.ts +6 -0
- package/Materials/floatingOriginMatrixOverrides.js +32 -9
- package/Materials/floatingOriginMatrixOverrides.js.map +1 -1
- package/Shaders/ShadersInclude/openpbrBaseLayerData.js +1 -1
- package/Shaders/ShadersInclude/openpbrBaseLayerData.js.map +1 -1
- package/Shaders/textureMerger.fragment.d.ts +5 -0
- package/Shaders/textureMerger.fragment.js +94 -0
- package/Shaders/textureMerger.fragment.js.map +1 -0
- package/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.js +1 -1
- package/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.js.map +1 -1
- package/ShadersWGSL/textureMerger.fragment.d.ts +5 -0
- package/ShadersWGSL/textureMerger.fragment.js +86 -0
- package/ShadersWGSL/textureMerger.fragment.js.map +1 -0
- package/package.json +1 -1
|
@@ -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,o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L,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC;AAED;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,OAAoB,EAAE,aAAqB;IAC1E,OAAO,EAAE,OAAO,EAAE,aAAa,EAAE,CAAC;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
|
-
|
|
24
|
+
ref.markAsUpdated();
|
|
24
25
|
return ref;
|
|
25
26
|
}
|
|
26
|
-
function
|
|
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
|
-
|
|
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,7 +79,7 @@ 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
|
}
|
|
@@ -72,11 +95,11 @@ function GetOffsetMatrix(uniformName, mat) {
|
|
|
72
95
|
case "world":
|
|
73
96
|
return OffsetWorldToRef(offset, mat, TempFinalMat);
|
|
74
97
|
case "view":
|
|
75
|
-
return OffsetViewToRef(mat, TempFinalMat);
|
|
98
|
+
return OffsetViewToRef(offset, mat, TempFinalMat);
|
|
76
99
|
case "worldView":
|
|
77
100
|
return OffsetWorldViewToRef(offset, mat, scene.getViewMatrix(), TempFinalMat);
|
|
78
101
|
case "viewProjection":
|
|
79
|
-
return OffsetViewProjectionToRef(scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
|
|
102
|
+
return OffsetViewProjectionToRef(offset, scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
|
|
80
103
|
case "worldViewProjection":
|
|
81
104
|
return OffsetWorldViewProjectionToRef(offset, mat, scene.getTransformMatrix(), scene.getViewMatrix(), scene.getProjectionMatrix(), TempFinalMat);
|
|
82
105
|
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,qBAA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rJ;YACI,OAAO,GAAG,CAAC;IACnB,CAAC;AACL,CAAC;AAED,wFAAwF;AACxF,MAAM,qBAAqB,GAAG,aAAoB,CAAC;AACnD,MAAM,cAAc,GAAG,MAAa,CAAC;AACrC,MAAM,8BAA8B,GAAG,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,CAAC;AAC/F,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;AAErD,MAAM,UAAU,oBAAoB;IAChC,MAAM,CAAC,SAAS,CAAC,SAAS,GAAG,iBAAiB,CAAC;IAC/C,cAAc,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAC9C,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,GAAG,8BAA8B,CAAC;IACzF,qBAAqB,CAAC,SAAS,CAAC,+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 * 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,MA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J;YACI,OAAO,GAAG,CAAC;IACnB,CAAC;AACL,CAAC;AAED,wFAAwF;AACxF,MAAM,qBAAqB,GAAG,aAAoB,CAAC;AACnD,MAAM,cAAc,GAAG,MAAa,CAAC;AACrC,MAAM,8BAA8B,GAAG,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,CAAC;AAC/F,MAAM,iBAAiB,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC;AAErD,MAAM,UAAU,oBAAoB;IAChC,MAAM,CAAC,SAAS,CAAC,SAAS,GAAG,iBAAiB,CAAC;IAC/C,cAAc,CAAC,kBAAkB,GAAG,SAAS,CAAC;IAC9C,qBAAqB,CAAC,SAAS,CAAC,uBAAuB,GAAG,8BAA8B,CAAC;IACzF,qBAAqB,CAAC,SAAS,CAAC,+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 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(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"]}
|
|
@@ -26,7 +26,7 @@ float anisotropyFromTexture=texture2D(specularRoughnessAnisotropySampler,vSpecul
|
|
|
26
26
|
float baseDiffuseRoughnessFromTexture=texture2D(baseDiffuseRoughnessSampler,vBaseDiffuseRoughnessUV+uvOffset).r;
|
|
27
27
|
#endif
|
|
28
28
|
#ifdef GEOMETRY_OPACITY
|
|
29
|
-
vec4 opacityFromTexture=texture2D(
|
|
29
|
+
vec4 opacityFromTexture=texture2D(geometryOpacitySampler,vGeometryOpacityUV+uvOffset);
|
|
30
30
|
#endif
|
|
31
31
|
#ifdef DECAL
|
|
32
32
|
vec4 decalFromTexture=texture2D(decalSampler,vDecalUV+uvOffset);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openpbrBaseLayerData.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/openpbrBaseLayerData.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoHd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;IAC1C,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACpD,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"openpbrBaseLayerData\";\nconst shader = `vec3 base_color=vec3(0.8);float base_metalness=0.0;float base_diffuse_roughness=0.0;float specular_weight=1.0;float specular_roughness=0.3;vec3 specular_color=vec3(1.0);float specular_roughness_anisotropy=0.0;float specular_ior=1.5;float alpha=1.0;vec2 geometry_tangent=vec2(1.0,0.0);\n#ifdef BASE_WEIGHT\nvec4 baseWeightFromTexture=texture2D(baseWeightSampler,vBaseWeightUV+uvOffset);\n#endif\n#ifdef BASE_COLOR\nvec4 baseColorFromTexture=texture2D(baseColorSampler,vBaseColorUV+uvOffset);\n#endif\n#ifdef BASE_METALNESS\nvec4 metallicFromTexture=texture2D(baseMetalnessSampler,vBaseMetalnessUV+uvOffset);\n#endif\n#if defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS)\nfloat roughnessFromTexture=metallicFromTexture.g;\n#elif defined(SPECULAR_ROUGHNESS)\nfloat roughnessFromTexture=texture2D(specularRoughnessSampler,vSpecularRoughnessUV+uvOffset).r;\n#endif\n#ifdef GEOMETRY_TANGENT\nvec3 geometryTangentFromTexture=texture2D(geometryTangentSampler,vGeometryTangentUV+uvOffset).rgb;\n#endif\n#ifdef SPECULAR_ROUGHNESS_ANISOTROPY\nfloat anisotropyFromTexture=texture2D(specularRoughnessAnisotropySampler,vSpecularRoughnessAnisotropyUV+uvOffset).r*vSpecularRoughnessAnisotropyInfos.y;\n#endif\n#ifdef BASE_DIFFUSE_ROUGHNESS\nfloat baseDiffuseRoughnessFromTexture=texture2D(baseDiffuseRoughnessSampler,vBaseDiffuseRoughnessUV+uvOffset).r;\n#endif\n#ifdef GEOMETRY_OPACITY\nvec4 opacityFromTexture=texture2D(
|
|
1
|
+
{"version":3,"file":"openpbrBaseLayerData.js","sourceRoot":"","sources":["../../../../../dev/core/src/Shaders/ShadersInclude/openpbrBaseLayerData.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoHd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,EAAE,CAAC;IAC1C,WAAW,CAAC,oBAAoB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACpD,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,oBAAoB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"openpbrBaseLayerData\";\nconst shader = `vec3 base_color=vec3(0.8);float base_metalness=0.0;float base_diffuse_roughness=0.0;float specular_weight=1.0;float specular_roughness=0.3;vec3 specular_color=vec3(1.0);float specular_roughness_anisotropy=0.0;float specular_ior=1.5;float alpha=1.0;vec2 geometry_tangent=vec2(1.0,0.0);\n#ifdef BASE_WEIGHT\nvec4 baseWeightFromTexture=texture2D(baseWeightSampler,vBaseWeightUV+uvOffset);\n#endif\n#ifdef BASE_COLOR\nvec4 baseColorFromTexture=texture2D(baseColorSampler,vBaseColorUV+uvOffset);\n#endif\n#ifdef BASE_METALNESS\nvec4 metallicFromTexture=texture2D(baseMetalnessSampler,vBaseMetalnessUV+uvOffset);\n#endif\n#if defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS)\nfloat roughnessFromTexture=metallicFromTexture.g;\n#elif defined(SPECULAR_ROUGHNESS)\nfloat roughnessFromTexture=texture2D(specularRoughnessSampler,vSpecularRoughnessUV+uvOffset).r;\n#endif\n#ifdef GEOMETRY_TANGENT\nvec3 geometryTangentFromTexture=texture2D(geometryTangentSampler,vGeometryTangentUV+uvOffset).rgb;\n#endif\n#ifdef SPECULAR_ROUGHNESS_ANISOTROPY\nfloat anisotropyFromTexture=texture2D(specularRoughnessAnisotropySampler,vSpecularRoughnessAnisotropyUV+uvOffset).r*vSpecularRoughnessAnisotropyInfos.y;\n#endif\n#ifdef BASE_DIFFUSE_ROUGHNESS\nfloat baseDiffuseRoughnessFromTexture=texture2D(baseDiffuseRoughnessSampler,vBaseDiffuseRoughnessUV+uvOffset).r;\n#endif\n#ifdef GEOMETRY_OPACITY\nvec4 opacityFromTexture=texture2D(geometryOpacitySampler,vGeometryOpacityUV+uvOffset);\n#endif\n#ifdef DECAL\nvec4 decalFromTexture=texture2D(decalSampler,vDecalUV+uvOffset);\n#endif\n#ifdef SPECULAR_COLOR\nvec4 specularColorFromTexture=texture2D(specularColorSampler,vSpecularColorUV+uvOffset);\n#endif\n#ifdef SPECULAR_WEIGHT\n#ifdef SPECULAR_WEIGHT_IN_ALPHA\nfloat specularWeightFromTexture=texture2D(specularWeightSampler,vSpecularWeightUV+uvOffset).a;\n#else\nfloat specularWeightFromTexture=texture2D(specularWeightSampler,vSpecularWeightUV+uvOffset).r;\n#endif\n#endif\n#if defined(ANISOTROPIC) || defined(FUZZ)\nvec3 noise=texture2D(blueNoiseSampler,gl_FragCoord.xy/256.0).xyz;\n#endif\nbase_color=vBaseColor.rgb;\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbase_color*=vColor.rgb;\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=vColor.a;\n#endif\nbase_color*=vec3(vBaseWeight);alpha=vBaseColor.a;base_metalness=vReflectanceInfo.x;base_diffuse_roughness=vBaseDiffuseRoughness;specular_roughness=vReflectanceInfo.y;specular_color=vSpecularColor.rgb;specular_weight=vReflectanceInfo.a;specular_ior=vReflectanceInfo.z;specular_roughness_anisotropy=vSpecularAnisotropy.b;geometry_tangent=vSpecularAnisotropy.rg;\n#ifdef BASE_COLOR\n#ifdef BASE_COLOR_GAMMA\nbase_color*=toLinearSpace(baseColorFromTexture.rgb);\n#else\nbase_color*=baseColorFromTexture.rgb;\n#endif\nbase_color*=vBaseColorInfos.y;\n#endif\n#ifdef BASE_WEIGHT\nbase_color*=baseWeightFromTexture.r;\n#endif\n#if defined(BASE_COLOR) && defined(ALPHA_FROM_BASE_COLOR_TEXTURE)\nalpha*=baseColorFromTexture.a;\n#elif defined(GEOMETRY_OPACITY)\nalpha*=opacityFromTexture.r;alpha*=vGeometryOpacityInfos.y;\n#endif\n#ifdef ALPHATEST\n#if DEBUGMODE != 88\nif (alpha<ALPHATESTVALUE)\ndiscard;\n#endif\n#ifndef ALPHABLEND\nalpha=1.0;\n#endif\n#endif\n#ifdef BASE_METALNESS\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nbase_metalness*=metallicFromTexture.b;\n#else\nbase_metalness*=metallicFromTexture.r;\n#endif\n#endif\n#ifdef BASE_DIFFUSE_ROUGHNESS\nbase_diffuse_roughness*=baseDiffuseRoughnessFromTexture*vBaseDiffuseRoughnessInfos.y;\n#endif\n#ifdef SPECULAR_COLOR\n#ifdef SPECULAR_COLOR_GAMMA\nspecular_color*=toLinearSpace(specularColorFromTexture.rgb);\n#else\nspecular_color*=specularColorFromTexture.rgb;\n#endif\n#endif\n#ifdef SPECULAR_WEIGHT_FROM_SPECULAR_COLOR_TEXTURE\nspecular_weight*=specularColorFromTexture.a;\n#elif defined(SPECULAR_WEIGHT)\nspecular_weight*=specularWeightFromTexture;\n#endif\n#if defined(SPECULAR_ROUGHNESS) || (defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS))\nspecular_roughness*=roughnessFromTexture;\n#endif\n#ifdef GEOMETRY_TANGENT\n{vec2 tangentFromTexture=normalize(geometryTangentFromTexture.xy*2.0-1.0);float tangent_angle_texture=atan(tangentFromTexture.y,tangentFromTexture.x);float tangent_angle_uniform=atan(geometry_tangent.y,geometry_tangent.x);float tangent_angle=tangent_angle_texture+tangent_angle_uniform;geometry_tangent=vec2(cos(tangent_angle),sin(tangent_angle));}\n#endif\n#if defined(GEOMETRY_TANGENT) && \\\ndefined(SPECULAR_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE)\nspecular_roughness_anisotropy*=geometryTangentFromTexture.b;\n#elif defined(SPECULAR_ROUGHNESS_ANISOTROPY)\nspecular_roughness_anisotropy*=anisotropyFromTexture;\n#endif\n#ifdef DETAIL\nfloat detailRoughness=mix(0.5,detailColor.b,vDetailInfos.w);float loLerp=mix(0.,specular_roughness,detailRoughness*2.);float hiLerp=mix(specular_roughness,1.,(detailRoughness-0.5)*2.);specular_roughness=mix(loLerp,hiLerp,step(detailRoughness,0.5));\n#endif\n#ifdef USE_GLTF_STYLE_ANISOTROPY\nfloat baseAlpha=specular_roughness*specular_roughness;float roughnessT=mix(baseAlpha,1.0,specular_roughness_anisotropy*specular_roughness_anisotropy);float roughnessB=baseAlpha;specular_roughness_anisotropy=1.0-roughnessB/max(roughnessT,0.00001);specular_roughness=sqrt(roughnessT/sqrt(2.0/(1.0+(1.0-specular_roughness_anisotropy)*(1.0-specular_roughness_anisotropy))));\n#endif\n`;\n// Sideeffect\nif (!ShaderStore.IncludesShadersStore[name]) {\n ShaderStore.IncludesShadersStore[name] = shader;\n}\n/** @internal */\nexport const openpbrBaseLayerData = { name, shader };\n"]}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
// Do not edit.
|
|
2
|
+
import { ShaderStore } from "../Engines/shaderStore.js";
|
|
3
|
+
const name = "textureMergerPixelShader";
|
|
4
|
+
const shader = `#ifdef USE_TEXTURE0
|
|
5
|
+
uniform sampler2D inputTexture0;
|
|
6
|
+
#endif
|
|
7
|
+
#ifdef USE_TEXTURE1
|
|
8
|
+
uniform sampler2D inputTexture1;
|
|
9
|
+
#endif
|
|
10
|
+
#ifdef USE_TEXTURE2
|
|
11
|
+
uniform sampler2D inputTexture2;
|
|
12
|
+
#endif
|
|
13
|
+
#ifdef USE_TEXTURE3
|
|
14
|
+
uniform sampler2D inputTexture3;
|
|
15
|
+
#endif
|
|
16
|
+
#ifdef RED_FROM_TEXTURE
|
|
17
|
+
uniform int redTextureIndex;uniform int redSourceChannel;
|
|
18
|
+
#else
|
|
19
|
+
uniform float redConstantValue;
|
|
20
|
+
#endif
|
|
21
|
+
#ifdef GREEN_FROM_TEXTURE
|
|
22
|
+
uniform int greenTextureIndex;uniform int greenSourceChannel;
|
|
23
|
+
#else
|
|
24
|
+
uniform float greenConstantValue;
|
|
25
|
+
#endif
|
|
26
|
+
#ifdef BLUE_FROM_TEXTURE
|
|
27
|
+
uniform int blueTextureIndex;uniform int blueSourceChannel;
|
|
28
|
+
#else
|
|
29
|
+
uniform float blueConstantValue;
|
|
30
|
+
#endif
|
|
31
|
+
#ifdef ALPHA_FROM_TEXTURE
|
|
32
|
+
uniform int alphaTextureIndex;uniform int alphaSourceChannel;
|
|
33
|
+
#else
|
|
34
|
+
uniform float alphaConstantValue;
|
|
35
|
+
#endif
|
|
36
|
+
varying vec2 vUV;
|
|
37
|
+
#if defined(RED_FROM_TEXTURE) || defined(GREEN_FROM_TEXTURE) || defined(BLUE_FROM_TEXTURE) || defined(ALPHA_FROM_TEXTURE)
|
|
38
|
+
vec4 sampleTexture(int textureIndex,vec2 uv) {switch (textureIndex) {
|
|
39
|
+
#ifdef USE_TEXTURE0
|
|
40
|
+
case 0:
|
|
41
|
+
return texture2D(inputTexture0,uv);
|
|
42
|
+
#endif
|
|
43
|
+
#ifdef USE_TEXTURE1
|
|
44
|
+
case 1:
|
|
45
|
+
return texture2D(inputTexture1,uv);
|
|
46
|
+
#endif
|
|
47
|
+
#ifdef USE_TEXTURE2
|
|
48
|
+
case 2:
|
|
49
|
+
return texture2D(inputTexture2,uv);
|
|
50
|
+
#endif
|
|
51
|
+
#ifdef USE_TEXTURE3
|
|
52
|
+
case 3:
|
|
53
|
+
return texture2D(inputTexture3,uv);
|
|
54
|
+
#endif
|
|
55
|
+
default:
|
|
56
|
+
return vec4(0.0,0.0,0.0,1.0); }}
|
|
57
|
+
float extractChannel(vec4 color,int channelIndex) {switch (channelIndex) {case 0:
|
|
58
|
+
return color.r;
|
|
59
|
+
case 1:
|
|
60
|
+
return color.g;
|
|
61
|
+
case 2:
|
|
62
|
+
return color.b;
|
|
63
|
+
default:
|
|
64
|
+
return color.a; }}
|
|
65
|
+
#endif
|
|
66
|
+
void main() {vec2 uv=vUV;
|
|
67
|
+
#ifdef RED_FROM_TEXTURE
|
|
68
|
+
vec4 redSample=sampleTexture(redTextureIndex,uv);float r=extractChannel(redSample,redSourceChannel);
|
|
69
|
+
#else
|
|
70
|
+
float r=redConstantValue;
|
|
71
|
+
#endif
|
|
72
|
+
#ifdef GREEN_FROM_TEXTURE
|
|
73
|
+
vec4 greenSample=sampleTexture(greenTextureIndex,uv);float g=extractChannel(greenSample,greenSourceChannel);
|
|
74
|
+
#else
|
|
75
|
+
float g=greenConstantValue;
|
|
76
|
+
#endif
|
|
77
|
+
#ifdef BLUE_FROM_TEXTURE
|
|
78
|
+
vec4 blueSample=sampleTexture(blueTextureIndex,uv);float b=extractChannel(blueSample,blueSourceChannel);
|
|
79
|
+
#else
|
|
80
|
+
float b=blueConstantValue;
|
|
81
|
+
#endif
|
|
82
|
+
#ifdef ALPHA_FROM_TEXTURE
|
|
83
|
+
vec4 alphaSample=sampleTexture(alphaTextureIndex,uv);float a=extractChannel(alphaSample,alphaSourceChannel);
|
|
84
|
+
#else
|
|
85
|
+
float a=alphaConstantValue;
|
|
86
|
+
#endif
|
|
87
|
+
gl_FragColor=vec4(r,g,b,a);}`;
|
|
88
|
+
// Sideeffect
|
|
89
|
+
if (!ShaderStore.ShadersStore[name]) {
|
|
90
|
+
ShaderStore.ShadersStore[name] = shader;
|
|
91
|
+
}
|
|
92
|
+
/** @internal */
|
|
93
|
+
export const textureMergerPixelShader = { name, shader };
|
|
94
|
+
//# sourceMappingURL=textureMerger.fragment.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"textureMerger.fragment.js","sourceRoot":"","sources":["../../../../dev/core/src/Shaders/textureMerger.fragment.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAC;AAErD,MAAM,IAAI,GAAG,0BAA0B,CAAC;AACxC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;6BAmFc,CAAC;AAC9B,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,EAAE,CAAC;IAClC,WAAW,CAAC,YAAY,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AAC5C,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../Engines/shaderStore\";\n\nconst name = \"textureMergerPixelShader\";\nconst shader = `#ifdef USE_TEXTURE0\nuniform sampler2D inputTexture0;\n#endif\n#ifdef USE_TEXTURE1\nuniform sampler2D inputTexture1;\n#endif\n#ifdef USE_TEXTURE2\nuniform sampler2D inputTexture2;\n#endif\n#ifdef USE_TEXTURE3\nuniform sampler2D inputTexture3;\n#endif\n#ifdef RED_FROM_TEXTURE\nuniform int redTextureIndex;uniform int redSourceChannel;\n#else\nuniform float redConstantValue;\n#endif\n#ifdef GREEN_FROM_TEXTURE\nuniform int greenTextureIndex;uniform int greenSourceChannel;\n#else\nuniform float greenConstantValue;\n#endif\n#ifdef BLUE_FROM_TEXTURE\nuniform int blueTextureIndex;uniform int blueSourceChannel;\n#else\nuniform float blueConstantValue;\n#endif\n#ifdef ALPHA_FROM_TEXTURE\nuniform int alphaTextureIndex;uniform int alphaSourceChannel;\n#else\nuniform float alphaConstantValue;\n#endif\nvarying vec2 vUV;\n#if defined(RED_FROM_TEXTURE) || defined(GREEN_FROM_TEXTURE) || defined(BLUE_FROM_TEXTURE) || defined(ALPHA_FROM_TEXTURE)\nvec4 sampleTexture(int textureIndex,vec2 uv) {switch (textureIndex) {\n#ifdef USE_TEXTURE0\ncase 0:\nreturn texture2D(inputTexture0,uv);\n#endif\n#ifdef USE_TEXTURE1\ncase 1:\nreturn texture2D(inputTexture1,uv);\n#endif\n#ifdef USE_TEXTURE2\ncase 2:\nreturn texture2D(inputTexture2,uv);\n#endif\n#ifdef USE_TEXTURE3\ncase 3:\nreturn texture2D(inputTexture3,uv);\n#endif\ndefault:\nreturn vec4(0.0,0.0,0.0,1.0); }}\nfloat extractChannel(vec4 color,int channelIndex) {switch (channelIndex) {case 0:\nreturn color.r; \ncase 1:\nreturn color.g; \ncase 2:\nreturn color.b; \ndefault:\nreturn color.a; }}\n#endif\nvoid main() {vec2 uv=vUV;\n#ifdef RED_FROM_TEXTURE\nvec4 redSample=sampleTexture(redTextureIndex,uv);float r=extractChannel(redSample,redSourceChannel);\n#else\nfloat r=redConstantValue;\n#endif\n#ifdef GREEN_FROM_TEXTURE\nvec4 greenSample=sampleTexture(greenTextureIndex,uv);float g=extractChannel(greenSample,greenSourceChannel);\n#else\nfloat g=greenConstantValue;\n#endif\n#ifdef BLUE_FROM_TEXTURE\nvec4 blueSample=sampleTexture(blueTextureIndex,uv);float b=extractChannel(blueSample,blueSourceChannel);\n#else\nfloat b=blueConstantValue;\n#endif\n#ifdef ALPHA_FROM_TEXTURE\nvec4 alphaSample=sampleTexture(alphaTextureIndex,uv);float a=extractChannel(alphaSample,alphaSourceChannel);\n#else\nfloat a=alphaConstantValue;\n#endif\ngl_FragColor=vec4(r,g,b,a);}`;\n// Sideeffect\nif (!ShaderStore.ShadersStore[name]) {\n ShaderStore.ShadersStore[name] = shader;\n}\n/** @internal */\nexport const textureMergerPixelShader = { name, shader };\n"]}
|
|
@@ -21,7 +21,7 @@ let geometryTangentFromTexture: vec3f=textureSample(geometryTangentSampler,geome
|
|
|
21
21
|
let anisotropyFromTexture: f32=textureSample(specularRoughnessAnisotropySampler,specularRoughnessAnisotropySamplerSampler,fragmentInputs.vSpecularRoughnessAnisotropyUV+uvOffset).r*uniforms.vSpecularRoughnessAnisotropyInfos.y;
|
|
22
22
|
#endif
|
|
23
23
|
#ifdef GEOMETRY_OPACITY
|
|
24
|
-
let opacityFromTexture: vec4f=textureSample(
|
|
24
|
+
let opacityFromTexture: vec4f=textureSample(geometryOpacitySampler,geometryOpacitySamplerSampler,fragmentInputs.vGeometryOpacityUV+uvOffset);
|
|
25
25
|
#endif
|
|
26
26
|
#ifdef DECAL
|
|
27
27
|
let decalFromTexture: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"openpbrBaseLayerData.js","sourceRoot":"","sources":["../../../../../dev/core/src/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmHd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9C,WAAW,CAAC,wBAAwB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxD,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"openpbrBaseLayerData\";\nconst shader = `var base_color=vec3f(0.8);var base_metalness: f32=0.0;var base_diffuse_roughness: f32=0.0;var specular_weight: f32=1.0;var specular_roughness: f32=0.3;var specular_color: vec3f=vec3f(1.0);var specular_roughness_anisotropy: f32=0.0;var specular_ior: f32=1.5;var alpha: f32=1.0;var geometry_tangent: vec2f=vec2f(1.0,0.0);\n#ifdef BASE_WEIGHT\nlet baseWeightFromTexture: vec4f=textureSample(baseWeightSampler,baseWeightSamplerSampler,fragmentInputs.vBaseWeightUV+uvOffset);\n#endif\n#ifdef BASE_COLOR\nlet baseColorFromTexture: vec4f=textureSample(baseColorSampler,baseColorSamplerSampler,fragmentInputs.vBaseColorUV+uvOffset);\n#endif\n#ifdef BASE_METALNESS\nlet metallicFromTexture: vec4f=textureSample(baseMetalnessSampler,baseMetalnessSamplerSampler,fragmentInputs.vBaseMetalnessUV+uvOffset);\n#endif\n#ifdef BASE_DIFFUSE_ROUGHNESS\nlet baseDiffuseRoughnessFromTexture: f32=textureSample(baseDiffuseRoughnessSampler,baseDiffuseRoughnessSamplerSampler,fragmentInputs.vBaseDiffuseRoughnessUV+uvOffset).r;\n#endif\n#ifdef GEOMETRY_TANGENT\nlet geometryTangentFromTexture: vec3f=textureSample(geometryTangentSampler,geometryTangentSamplerSampler,fragmentInputs.vGeometryTangentUV+uvOffset).rgb;\n#endif\n#ifdef SPECULAR_ROUGHNESS_ANISOTROPY\nlet anisotropyFromTexture: f32=textureSample(specularRoughnessAnisotropySampler,specularRoughnessAnisotropySamplerSampler,fragmentInputs.vSpecularRoughnessAnisotropyUV+uvOffset).r*uniforms.vSpecularRoughnessAnisotropyInfos.y;\n#endif\n#ifdef GEOMETRY_OPACITY\nlet opacityFromTexture: vec4f=textureSample(
|
|
1
|
+
{"version":3,"file":"openpbrBaseLayerData.js","sourceRoot":"","sources":["../../../../../dev/core/src/ShadersWGSL/ShadersInclude/openpbrBaseLayerData.ts"],"names":[],"mappings":"AAAA,eAAe;AACf,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,MAAM,IAAI,GAAG,sBAAsB,CAAC;AACpC,MAAM,MAAM,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmHd,CAAC;AACF,aAAa;AACb,IAAI,CAAC,WAAW,CAAC,wBAAwB,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9C,WAAW,CAAC,wBAAwB,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC;AACxD,CAAC;AACD,gBAAgB;AAChB,MAAM,CAAC,MAAM,wBAAwB,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,CAAC","sourcesContent":["// Do not edit.\nimport { ShaderStore } from \"../../Engines/shaderStore\";\n\nconst name = \"openpbrBaseLayerData\";\nconst shader = `var base_color=vec3f(0.8);var base_metalness: f32=0.0;var base_diffuse_roughness: f32=0.0;var specular_weight: f32=1.0;var specular_roughness: f32=0.3;var specular_color: vec3f=vec3f(1.0);var specular_roughness_anisotropy: f32=0.0;var specular_ior: f32=1.5;var alpha: f32=1.0;var geometry_tangent: vec2f=vec2f(1.0,0.0);\n#ifdef BASE_WEIGHT\nlet baseWeightFromTexture: vec4f=textureSample(baseWeightSampler,baseWeightSamplerSampler,fragmentInputs.vBaseWeightUV+uvOffset);\n#endif\n#ifdef BASE_COLOR\nlet baseColorFromTexture: vec4f=textureSample(baseColorSampler,baseColorSamplerSampler,fragmentInputs.vBaseColorUV+uvOffset);\n#endif\n#ifdef BASE_METALNESS\nlet metallicFromTexture: vec4f=textureSample(baseMetalnessSampler,baseMetalnessSamplerSampler,fragmentInputs.vBaseMetalnessUV+uvOffset);\n#endif\n#ifdef BASE_DIFFUSE_ROUGHNESS\nlet baseDiffuseRoughnessFromTexture: f32=textureSample(baseDiffuseRoughnessSampler,baseDiffuseRoughnessSamplerSampler,fragmentInputs.vBaseDiffuseRoughnessUV+uvOffset).r;\n#endif\n#ifdef GEOMETRY_TANGENT\nlet geometryTangentFromTexture: vec3f=textureSample(geometryTangentSampler,geometryTangentSamplerSampler,fragmentInputs.vGeometryTangentUV+uvOffset).rgb;\n#endif\n#ifdef SPECULAR_ROUGHNESS_ANISOTROPY\nlet anisotropyFromTexture: f32=textureSample(specularRoughnessAnisotropySampler,specularRoughnessAnisotropySamplerSampler,fragmentInputs.vSpecularRoughnessAnisotropyUV+uvOffset).r*uniforms.vSpecularRoughnessAnisotropyInfos.y;\n#endif\n#ifdef GEOMETRY_OPACITY\nlet opacityFromTexture: vec4f=textureSample(geometryOpacitySampler,geometryOpacitySamplerSampler,fragmentInputs.vGeometryOpacityUV+uvOffset);\n#endif\n#ifdef DECAL\nlet decalFromTexture: vec4f=textureSample(decalSampler,decalSamplerSampler,fragmentInputs.vDecalUV+uvOffset);\n#endif\n#ifdef SPECULAR_COLOR\nlet specularColorFromTexture: vec4f=textureSample(specularColorSampler,specularColorSamplerSampler,fragmentInputs.vSpecularColorUV+uvOffset);\n#endif\n#if defined(SPECULAR_WEIGHT)\n#ifdef SPECULAR_WEIGHT_IN_ALPHA\nlet specularWeightFromTexture: f32=textureSample(specularWeightSampler,specularWeightSamplerSampler,fragmentInputs.vSpecularWeightUV+uvOffset).a;\n#else\nlet specularWeightFromTexture: f32=textureSample(specularWeightSampler,specularWeightSamplerSampler,fragmentInputs.vSpecularWeightUV+uvOffset).r;\n#endif\n#endif\n#if defined(ANISOTROPIC) || defined(FUZZ)\nlet noise=textureSample(blueNoiseSampler,blueNoiseSamplerSampler,fragmentInputs.position.xy/256.0).xyz;\n#endif\n#if defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS)\nlet roughnessFromTexture: f32=metallicFromTexture.g;\n#elif defined(SPECULAR_ROUGHNESS)\nlet roughnessFromTexture: f32=textureSample(specularRoughnessSampler,specularRoughnessSamplerSampler,fragmentInputs.vSpecularRoughnessUV+uvOffset).r;\n#endif\nbase_color=uniforms.vBaseColor.rgb;\n#if defined(VERTEXCOLOR) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nbase_color*=fragmentInputs.vColor.rgb;\n#endif\n#if defined(VERTEXALPHA) || defined(INSTANCESCOLOR) && defined(INSTANCES)\nalpha*=fragmentInputs.vColor.a;\n#endif\nbase_color*=vec3(uniforms.vBaseWeight);alpha=uniforms.vBaseColor.a;base_metalness=uniforms.vReflectanceInfo.x;base_diffuse_roughness=uniforms.vBaseDiffuseRoughness;specular_roughness=uniforms.vReflectanceInfo.y;specular_color=uniforms.vSpecularColor.rgb;specular_weight=uniforms.vReflectanceInfo.a;specular_ior=uniforms.vReflectanceInfo.z;specular_roughness_anisotropy=uniforms.vSpecularAnisotropy.b;geometry_tangent=uniforms.vSpecularAnisotropy.rg;\n#ifdef BASE_COLOR\n#ifdef BASE_COLOR_GAMMA\nbase_color*=toLinearSpace(baseColorFromTexture.rgb);\n#else\nbase_color*=baseColorFromTexture.rgb;\n#endif\nbase_color*=uniforms.vBaseColorInfos.y;\n#endif\n#ifdef BASE_WEIGHT\nbase_color*=baseWeightFromTexture.r;\n#endif\n#if defined(BASE_COLOR) && defined(ALPHA_FROM_BASE_COLOR_TEXTURE)\nalpha*=baseColorFromTexture.a;\n#elif defined(GEOMETRY_OPACITY)\nalpha*=opacityFromTexture.a;alpha*=uniforms.vGeometryOpacityInfos.y;\n#endif\n#ifdef ALPHATEST\n#if DEBUGMODE != 88\nif (alpha<ALPHATESTVALUE)\ndiscard;\n#endif\n#ifndef ALPHABLEND\nalpha=1.0;\n#endif\n#endif\n#ifdef BASE_METALNESS\n#ifdef METALLNESSSTOREINMETALMAPBLUE\nbase_metalness*=metallicFromTexture.b;\n#else\nbase_metalness*=metallicFromTexture.r;\n#endif\n#endif\n#ifdef BASE_DIFFUSE_ROUGHNESS\nbase_diffuse_roughness*=baseDiffuseRoughnessFromTexture*uniforms.vBaseDiffuseRoughnessInfos.y;\n#endif\n#ifdef SPECULAR_COLOR\n#ifdef SPECULAR_COLOR_GAMMA\nspecular_color*=toLinearSpace(specularColorFromTexture.rgb);\n#else\nspecular_color*=specularColorFromTexture.rgb;\n#endif\n#endif\n#ifdef SPECULAR_WEIGHT_FROM_SPECULAR_COLOR_TEXTURE\nspecular_weight*=specularColorFromTexture.a;\n#elif defined(SPECULAR_WEIGHT)\nspecular_weight*=specularWeightFromTexture;\n#endif\n#if defined(SPECULAR_ROUGHNESS) || (defined(ROUGHNESSSTOREINMETALMAPGREEN) && defined(BASE_METALNESS))\nspecular_roughness*=roughnessFromTexture;\n#endif\n#ifdef GEOMETRY_TANGENT\n{let tangentFromTexture: vec2f=normalize(geometryTangentFromTexture.xy*vec2f(2.0f)-vec2f(1.0f));let tangent_angle_texture: f32=atan2(tangentFromTexture.y,tangentFromTexture.x);let tangent_angle_uniform: f32=atan2(geometry_tangent.y,geometry_tangent.x);let tangent_angle: f32=tangent_angle_texture+tangent_angle_uniform;geometry_tangent=vec2f(cos(tangent_angle),sin(tangent_angle));}\n#endif\n#if defined(GEOMETRY_TANGENT) && defined(SPECULAR_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE)\nspecular_roughness_anisotropy*=geometryTangentFromTexture.b;\n#elif defined(SPECULAR_ROUGHNESS_ANISOTROPY)\nspecular_roughness_anisotropy*=anisotropyFromTexture;\n#endif\n#ifdef DETAIL\nlet detailRoughness: f32=mix(0.5f,detailColor.b,vDetailInfos.w);let loLerp: f32=mix(0.f,specular_roughness,detailRoughness*2.f);let hiLerp: f32=mix(specular_roughness,1.f,(detailRoughness-0.5f)*2.f);specular_roughness=mix(loLerp,hiLerp,step(detailRoughness,0.5f));\n#endif\n#ifdef USE_GLTF_STYLE_ANISOTROPY\nlet baseAlpha: f32=specular_roughness*specular_roughness;let roughnessT: f32=mix(baseAlpha,1.0f,specular_roughness_anisotropy*specular_roughness_anisotropy);let roughnessB: f32=baseAlpha;specular_roughness_anisotropy=1.0f-roughnessB/max(roughnessT,0.00001f);specular_roughness=sqrt(roughnessT/sqrt(2.0f/(1.0f+(1.0f-specular_roughness_anisotropy)*(1.0f-specular_roughness_anisotropy))));\n#endif\n`;\n// Sideeffect\nif (!ShaderStore.IncludesShadersStoreWGSL[name]) {\n ShaderStore.IncludesShadersStoreWGSL[name] = shader;\n}\n/** @internal */\nexport const openpbrBaseLayerDataWGSL = { name, shader };\n"]}
|