@babylonjs/loaders 9.32.1 → 9.33.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/SPLAT/gaussianSplattingWorkBuffer.js +1 -1
- package/SPLAT/gaussianSplattingWorkBuffer.js.map +1 -1
- package/SPLAT/sog.pure.js +2 -2
- package/SPLAT/sog.pure.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_scatter.d.ts +6 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.js +9 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.pure.d.ts +40 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.pure.js +105 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.pure.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.types.d.ts +9 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.types.js +2 -0
- package/glTF/2.0/Extensions/KHR_materials_scatter.types.js.map +1 -0
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js +2 -0
- package/glTF/2.0/Extensions/KHR_materials_volume_scatter.pure.js.map +1 -1
- package/glTF/2.0/Extensions/dynamic.js +5 -0
- package/glTF/2.0/Extensions/dynamic.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +1 -0
- package/glTF/2.0/Extensions/index.js +1 -0
- package/glTF/2.0/Extensions/index.js.map +1 -1
- package/glTF/2.0/Extensions/pure.d.ts +1 -0
- package/glTF/2.0/Extensions/pure.js +1 -0
- package/glTF/2.0/Extensions/pure.js.map +1 -1
- package/glTF/2.0/glTFLoader.pure.d.ts +7 -0
- package/glTF/2.0/glTFLoader.pure.js +29 -3
- package/glTF/2.0/glTFLoader.pure.js.map +1 -1
- package/glTF/2.0/materialLoadingAdapter.d.ts +23 -0
- package/glTF/2.0/materialLoadingAdapter.js.map +1 -1
- package/glTF/2.0/openpbrMaterialLoadingAdapter.d.ts +30 -4
- package/glTF/2.0/openpbrMaterialLoadingAdapter.js +172 -14
- package/glTF/2.0/openpbrMaterialLoadingAdapter.js.map +1 -1
- package/glTF/2.0/pbrMaterialLoadingAdapter.d.ts +89 -7
- package/glTF/2.0/pbrMaterialLoadingAdapter.js +278 -25
- package/glTF/2.0/pbrMaterialLoadingAdapter.js.map +1 -1
- package/package.json +4 -4
|
@@ -217,6 +217,29 @@ export interface IMaterialLoadingAdapter {
|
|
|
217
217
|
* Sets the transmission scatter texture
|
|
218
218
|
*/
|
|
219
219
|
transmissionScatterTexture: Nullable<BaseTexture>;
|
|
220
|
+
/**
|
|
221
|
+
* Staging: the constant scatter strength for volumetric mode.
|
|
222
|
+
* Set by KHR_materials_scatter and consumed by the adapter during finalization.
|
|
223
|
+
*/
|
|
224
|
+
volumetricScatterStrengthFactor: Nullable<number>;
|
|
225
|
+
/**
|
|
226
|
+
* Staging: scatter strength texture for volumetric mode (non-thin-walled).
|
|
227
|
+
* Set by KHR_materials_scatter when scatterStrengthTexture is present; applied together with
|
|
228
|
+
* transmissionScatterTexture in finalizeAsync and then cleared.
|
|
229
|
+
*/
|
|
230
|
+
volumetricScatterStrengthTexture: Nullable<BaseTexture>;
|
|
231
|
+
/**
|
|
232
|
+
* Staging: the constant scatter strength for thin-walled mode.
|
|
233
|
+
* Set by KHR_materials_scatter and consumed by the material adapter during finalization.
|
|
234
|
+
* Null means no thin-walled scatter has been staged.
|
|
235
|
+
*/
|
|
236
|
+
thinWalledScatterStrengthFactor: Nullable<number>;
|
|
237
|
+
/**
|
|
238
|
+
* Staging: scatter strength texture for thin-walled mode.
|
|
239
|
+
* Set by KHR_materials_scatter when scatterStrengthTexture is present; combined with
|
|
240
|
+
* the transmission weight in finalizeAsync and then cleared.
|
|
241
|
+
*/
|
|
242
|
+
thinWalledScatterStrengthTexture: Nullable<BaseTexture>;
|
|
220
243
|
/**
|
|
221
244
|
* Sets the scattering anisotropy (-1 to 1)
|
|
222
245
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"materialLoadingAdapter.js","sourceRoot":"","sources":["../../../../../dev/loaders/src/glTF/2.0/materialLoadingAdapter.ts"],"names":[],"mappings":"","sourcesContent":["import { type Material } from \"core/Materials/material\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { type Nullable } from \"core/types\";\r\nimport { type Color3 } from \"core/Maths/math.color\";\r\nimport { type GLTFLoader } from \"./glTFLoader\";\r\n\r\n/**\r\n * Interface for material loading adapters that provides a unified OpenPBR-like interface\r\n * for both OpenPBR and PBR materials, eliminating conditional branches in extensions.\r\n */\r\nexport interface IMaterialLoadingAdapter {\r\n /**\r\n * Gets the underlying material\r\n */\r\n readonly material: Material;\r\n\r\n /**\r\n * Finalizes material properties after all loading is complete.\r\n * May do async work (e.g. GPU texture processing); the returned Promise is tracked\r\n * by the loader and awaited before the COMPLETE state is reached, so callers can rely\r\n * on onCompleteObservable for fully processed materials.\r\n *\r\n * Implementations should check `loader._disposed` between awaits to bail out early\r\n * when the loader is disposed mid-flight.\r\n * @param loader The glTF loader driving the finalize step.\r\n */\r\n finalizeAsync(loader: GLTFLoader): Promise<void>;\r\n\r\n /**\r\n * Whether the material should be treated as unlit\r\n */\r\n isUnlit: boolean;\r\n\r\n // ========================================\r\n // CULLING PROPERTIES\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the back face culling\r\n */\r\n backFaceCulling: boolean;\r\n\r\n /**\r\n * Sets/gets the two sided lighting\r\n */\r\n twoSidedLighting: boolean;\r\n\r\n // ========================================\r\n // ALPHA PROPERTIES\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the alpha cutoff value (used for alpha test mode)\r\n */\r\n alphaCutOff: number;\r\n\r\n /**\r\n * Sets/gets whether to use alpha from albedo/base color texture\r\n */\r\n useAlphaFromBaseColorTexture: boolean;\r\n\r\n /**\r\n * Sets/Gets whether the transparency is treated as alpha coverage\r\n */\r\n transparencyAsAlphaCoverage: boolean;\r\n\r\n // ========================================\r\n // BASE PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the base color\r\n */\r\n baseColor: Color3;\r\n\r\n /**\r\n * Sets/gets the base color texture\r\n */\r\n baseColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the base diffuse roughness\r\n */\r\n baseDiffuseRoughness: number;\r\n\r\n /**\r\n * Sets/gets the base diffuse roughness texture\r\n */\r\n baseDiffuseRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the base metalness\r\n */\r\n baseMetalness: number;\r\n\r\n /**\r\n * Sets/gets the base metalness texture\r\n */\r\n baseMetalnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets whether to use roughness from metallic texture green channel\r\n */\r\n useRoughnessFromMetallicTextureGreen: boolean;\r\n\r\n /**\r\n * Sets whether to use metallic from metallic texture blue channel\r\n */\r\n useMetallicFromMetallicTextureBlue: boolean;\r\n\r\n // ========================================\r\n // SPECULAR PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Configures specular properties and enables OpenPBR BRDF model for edge color support\r\n * @param enableEdgeColor - Whether to enable edge color support\r\n */\r\n enableSpecularEdgeColor(enableEdgeColor?: boolean): void;\r\n\r\n /**\r\n * Enable the specular/glossiness workflow and disable metallic/roughness.\r\n */\r\n configureSpecularGlossiness(): void;\r\n\r\n /**\r\n * Sets/gets the specular weight\r\n */\r\n specularWeight: number;\r\n\r\n /**\r\n * Sets/gets the specular weight texture\r\n */\r\n specularWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the specular color\r\n */\r\n specularColor: Color3;\r\n\r\n /**\r\n * Sets/gets the specular color texture\r\n */\r\n specularColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the specular roughness\r\n */\r\n specularRoughness: number;\r\n\r\n /**\r\n * Sets/gets the specular roughness texture\r\n */\r\n specularRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the specular IOR\r\n */\r\n specularIor: number;\r\n\r\n /**\r\n * Sets/gets the glossiness (inverted roughness)\r\n * ONLY used for specular/glossiness workflow; has no effect when metallic/roughness workflow is active\r\n */\r\n glossiness: number;\r\n\r\n // ========================================\r\n // EMISSION PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the emissive color\r\n */\r\n emissionColor: Color3;\r\n\r\n /**\r\n * Sets/gets the emissive luminance\r\n */\r\n emissionLuminance: number;\r\n\r\n /**\r\n * Sets/gets the emissive texture\r\n */\r\n emissionColorTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // AMBIENT OCCLUSION\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the ambient occlusion texture\r\n */\r\n ambientOcclusionTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the ambient occlusion texture strength/level\r\n */\r\n ambientOcclusionTextureStrength: number;\r\n\r\n // ========================================\r\n // COAT PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Configures clear coat for PBR material\r\n */\r\n configureCoat(): void;\r\n\r\n /**\r\n * Sets/gets the coat weight\r\n */\r\n coatWeight: number;\r\n\r\n /**\r\n * Sets/gets the coat weight texture\r\n */\r\n coatWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the coat color\r\n */\r\n coatColor: Color3;\r\n\r\n /**\r\n * Sets the coat color texture\r\n */\r\n coatColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the coat roughness\r\n */\r\n coatRoughness: number;\r\n\r\n /**\r\n * Sets/gets the coat roughness texture\r\n */\r\n coatRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the coat index of refraction (IOR)\r\n */\r\n coatIor: number;\r\n\r\n /**\r\n * Sets the coat darkening\r\n */\r\n coatDarkening: number;\r\n\r\n /**\r\n * Sets the coat darkening texture\r\n */\r\n coatDarkeningTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the coat roughness anisotropy\r\n */\r\n coatRoughnessAnisotropy: number;\r\n\r\n /**\r\n * Sets the coat tangent angle for anisotropy\r\n */\r\n geometryCoatTangentAngle: number;\r\n\r\n /**\r\n * Sets the coat tangent texture for anisotropy\r\n */\r\n geometryCoatTangentTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // TRANSMISSION LAYER\r\n // ========================================\r\n\r\n /**\r\n * Sets the transmission weight\r\n */\r\n transmissionWeight: number;\r\n\r\n /**\r\n * Sets the transmission weight texture\r\n */\r\n transmissionWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the attenuation distance\r\n */\r\n transmissionDepth: number;\r\n\r\n /**\r\n * Sets the attenuation color\r\n */\r\n transmissionColor: Color3;\r\n\r\n /**\r\n * Sets the scattering coefficient\r\n */\r\n transmissionScatter: Color3;\r\n\r\n /**\r\n * Sets the transmission scatter texture\r\n */\r\n transmissionScatterTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the scattering anisotropy (-1 to 1)\r\n */\r\n transmissionScatterAnisotropy: number;\r\n\r\n /**\r\n * Sets the dispersion Abbe number\r\n */\r\n transmissionDispersionAbbeNumber: number;\r\n\r\n /**\r\n * Sets the dispersion scale\r\n */\r\n transmissionDispersionScale: number;\r\n\r\n /**\r\n * The refraction background texture\r\n */\r\n refractionBackgroundTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Configures transmission for thin-surface transmission (KHR_materials_transmission)\r\n */\r\n configureTransmission(): void;\r\n\r\n // ========================================\r\n // VOLUME PROPERTIES\r\n // ========================================\r\n\r\n /**\r\n * Configures volume properties for volumetric transmission (KHR_materials_volume)\r\n */\r\n configureVolume(): void;\r\n\r\n /**\r\n * Sets whether the material is thin-walled (i.e. non-volumetric) or not.\r\n */\r\n geometryThinWalled: boolean;\r\n\r\n /**\r\n * Sets the thickness texture\r\n */\r\n volumeThicknessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the thickness factor\r\n */\r\n volumeThickness: number;\r\n\r\n // ========================================\r\n // SUBSURFACE PROPERTIES (Subsurface Scattering)\r\n // ========================================\r\n\r\n /**\r\n * Configures subsurface properties\r\n */\r\n configureSubsurface(): void;\r\n\r\n /**\r\n * Sets/gets the subsurface weight\r\n */\r\n subsurfaceWeight: number;\r\n\r\n /**\r\n * Sets/gets the subsurface weight texture\r\n */\r\n subsurfaceWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the subsurface color\r\n */\r\n subsurfaceColor: Color3;\r\n\r\n /**\r\n * Sets/gets the subsurface color texture\r\n */\r\n subsurfaceColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the diffuse transmission tint of the material\r\n */\r\n diffuseTransmissionTint: Color3;\r\n\r\n /**\r\n * Sets/gets the diffuse transmission tint texture of the material\r\n */\r\n diffuseTransmissionTintTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the subsurface radius (used for subsurface scattering)\r\n */\r\n subsurfaceRadius: number;\r\n\r\n /**\r\n * Sets/gets the subsurface radius scale (used for subsurface scattering)\r\n */\r\n subsurfaceRadiusScale: Color3;\r\n\r\n /**\r\n * Sets/gets the subsurface scattering anisotropy\r\n */\r\n subsurfaceScatterAnisotropy: number;\r\n\r\n /**\r\n * Does this material have a translucent surface (i.e. either transmission or subsurface)?\r\n */\r\n isTranslucent(): boolean;\r\n\r\n // ========================================\r\n // FUZZ LAYER (Sheen)\r\n // ========================================\r\n\r\n /**\r\n * Configures initial settings for fuzz for material.\r\n */\r\n configureFuzz(): void;\r\n\r\n /**\r\n * Sets the fuzz weight\r\n */\r\n fuzzWeight: number;\r\n\r\n /**\r\n * Sets the fuzz weight texture\r\n */\r\n fuzzWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the fuzz color\r\n */\r\n fuzzColor: Color3;\r\n\r\n /**\r\n * Sets the fuzz color texture\r\n */\r\n fuzzColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the fuzz roughness\r\n */\r\n fuzzRoughness: number;\r\n\r\n /**\r\n * Sets the fuzz roughness texture\r\n */\r\n fuzzRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // ANISOTROPY\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the specular roughness anisotropy\r\n */\r\n specularRoughnessAnisotropy: number;\r\n\r\n /**\r\n * Sets the anisotropy rotation\r\n */\r\n geometryTangentAngle: number;\r\n\r\n /**\r\n * Sets/gets the anisotropy texture\r\n */\r\n geometryTangentTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Configures glTF-style anisotropy for OpenPBR materials\r\n * @param useGltfStyle - Whether to use glTF-style anisotropy (default: true)\r\n */\r\n configureGltfStyleAnisotropy(useGltfStyle?: boolean): void;\r\n\r\n // ========================================\r\n // THIN FILM IRIDESCENCE\r\n // ========================================\r\n\r\n /**\r\n * Sets the thin film weight\r\n */\r\n thinFilmWeight: number;\r\n\r\n /**\r\n * Sets the thin film IOR\r\n */\r\n thinFilmIor: number;\r\n\r\n /**\r\n * Sets the thin film thickness minimum\r\n */\r\n thinFilmThicknessMinimum: number;\r\n\r\n /**\r\n * Sets the thin film thickness maximum\r\n */\r\n thinFilmThicknessMaximum: number;\r\n\r\n /**\r\n * Sets the thin film iridescence texture\r\n */\r\n thinFilmWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the thin film thickness texture\r\n */\r\n thinFilmThicknessTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // UNLIT MATERIALS\r\n // ========================================\r\n\r\n /**\r\n * Sets the unlit flag\r\n */\r\n unlit: boolean;\r\n\r\n // ========================================\r\n // GEOMETRY PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the geometry opacity\r\n */\r\n geometryOpacity: number;\r\n\r\n /**\r\n * Sets/gets the geometry normal texture\r\n */\r\n geometryNormalTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the normal map inversions for PBR material only\r\n * @param invertX - Whether to invert the normal map on the X axis\r\n * @param invertY - Whether to invert the normal map on the Y axis\r\n */\r\n setNormalMapInversions(invertX: boolean, invertY: boolean): void;\r\n\r\n /**\r\n * Sets/gets the coat normal texture\r\n */\r\n geometryCoatNormalTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the coat normal texture scale\r\n */\r\n geometryCoatNormalTextureScale: number;\r\n}\r\n"]}
|
|
1
|
+
{"version":3,"file":"materialLoadingAdapter.js","sourceRoot":"","sources":["../../../../../dev/loaders/src/glTF/2.0/materialLoadingAdapter.ts"],"names":[],"mappings":"","sourcesContent":["import { type Material } from \"core/Materials/material\";\r\nimport { type BaseTexture } from \"core/Materials/Textures/baseTexture\";\r\nimport { type Nullable } from \"core/types\";\r\nimport { type Color3 } from \"core/Maths/math.color\";\r\nimport { type GLTFLoader } from \"./glTFLoader\";\r\n\r\n/**\r\n * Interface for material loading adapters that provides a unified OpenPBR-like interface\r\n * for both OpenPBR and PBR materials, eliminating conditional branches in extensions.\r\n */\r\nexport interface IMaterialLoadingAdapter {\r\n /**\r\n * Gets the underlying material\r\n */\r\n readonly material: Material;\r\n\r\n /**\r\n * Finalizes material properties after all loading is complete.\r\n * May do async work (e.g. GPU texture processing); the returned Promise is tracked\r\n * by the loader and awaited before the COMPLETE state is reached, so callers can rely\r\n * on onCompleteObservable for fully processed materials.\r\n *\r\n * Implementations should check `loader._disposed` between awaits to bail out early\r\n * when the loader is disposed mid-flight.\r\n * @param loader The glTF loader driving the finalize step.\r\n */\r\n finalizeAsync(loader: GLTFLoader): Promise<void>;\r\n\r\n /**\r\n * Whether the material should be treated as unlit\r\n */\r\n isUnlit: boolean;\r\n\r\n // ========================================\r\n // CULLING PROPERTIES\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the back face culling\r\n */\r\n backFaceCulling: boolean;\r\n\r\n /**\r\n * Sets/gets the two sided lighting\r\n */\r\n twoSidedLighting: boolean;\r\n\r\n // ========================================\r\n // ALPHA PROPERTIES\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the alpha cutoff value (used for alpha test mode)\r\n */\r\n alphaCutOff: number;\r\n\r\n /**\r\n * Sets/gets whether to use alpha from albedo/base color texture\r\n */\r\n useAlphaFromBaseColorTexture: boolean;\r\n\r\n /**\r\n * Sets/Gets whether the transparency is treated as alpha coverage\r\n */\r\n transparencyAsAlphaCoverage: boolean;\r\n\r\n // ========================================\r\n // BASE PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the base color\r\n */\r\n baseColor: Color3;\r\n\r\n /**\r\n * Sets/gets the base color texture\r\n */\r\n baseColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the base diffuse roughness\r\n */\r\n baseDiffuseRoughness: number;\r\n\r\n /**\r\n * Sets/gets the base diffuse roughness texture\r\n */\r\n baseDiffuseRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the base metalness\r\n */\r\n baseMetalness: number;\r\n\r\n /**\r\n * Sets/gets the base metalness texture\r\n */\r\n baseMetalnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets whether to use roughness from metallic texture green channel\r\n */\r\n useRoughnessFromMetallicTextureGreen: boolean;\r\n\r\n /**\r\n * Sets whether to use metallic from metallic texture blue channel\r\n */\r\n useMetallicFromMetallicTextureBlue: boolean;\r\n\r\n // ========================================\r\n // SPECULAR PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Configures specular properties and enables OpenPBR BRDF model for edge color support\r\n * @param enableEdgeColor - Whether to enable edge color support\r\n */\r\n enableSpecularEdgeColor(enableEdgeColor?: boolean): void;\r\n\r\n /**\r\n * Enable the specular/glossiness workflow and disable metallic/roughness.\r\n */\r\n configureSpecularGlossiness(): void;\r\n\r\n /**\r\n * Sets/gets the specular weight\r\n */\r\n specularWeight: number;\r\n\r\n /**\r\n * Sets/gets the specular weight texture\r\n */\r\n specularWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the specular color\r\n */\r\n specularColor: Color3;\r\n\r\n /**\r\n * Sets/gets the specular color texture\r\n */\r\n specularColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the specular roughness\r\n */\r\n specularRoughness: number;\r\n\r\n /**\r\n * Sets/gets the specular roughness texture\r\n */\r\n specularRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the specular IOR\r\n */\r\n specularIor: number;\r\n\r\n /**\r\n * Sets/gets the glossiness (inverted roughness)\r\n * ONLY used for specular/glossiness workflow; has no effect when metallic/roughness workflow is active\r\n */\r\n glossiness: number;\r\n\r\n // ========================================\r\n // EMISSION PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the emissive color\r\n */\r\n emissionColor: Color3;\r\n\r\n /**\r\n * Sets/gets the emissive luminance\r\n */\r\n emissionLuminance: number;\r\n\r\n /**\r\n * Sets/gets the emissive texture\r\n */\r\n emissionColorTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // AMBIENT OCCLUSION\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the ambient occlusion texture\r\n */\r\n ambientOcclusionTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the ambient occlusion texture strength/level\r\n */\r\n ambientOcclusionTextureStrength: number;\r\n\r\n // ========================================\r\n // COAT PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Configures clear coat for PBR material\r\n */\r\n configureCoat(): void;\r\n\r\n /**\r\n * Sets/gets the coat weight\r\n */\r\n coatWeight: number;\r\n\r\n /**\r\n * Sets/gets the coat weight texture\r\n */\r\n coatWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the coat color\r\n */\r\n coatColor: Color3;\r\n\r\n /**\r\n * Sets the coat color texture\r\n */\r\n coatColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the coat roughness\r\n */\r\n coatRoughness: number;\r\n\r\n /**\r\n * Sets/gets the coat roughness texture\r\n */\r\n coatRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the coat index of refraction (IOR)\r\n */\r\n coatIor: number;\r\n\r\n /**\r\n * Sets the coat darkening\r\n */\r\n coatDarkening: number;\r\n\r\n /**\r\n * Sets the coat darkening texture\r\n */\r\n coatDarkeningTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the coat roughness anisotropy\r\n */\r\n coatRoughnessAnisotropy: number;\r\n\r\n /**\r\n * Sets the coat tangent angle for anisotropy\r\n */\r\n geometryCoatTangentAngle: number;\r\n\r\n /**\r\n * Sets the coat tangent texture for anisotropy\r\n */\r\n geometryCoatTangentTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // TRANSMISSION LAYER\r\n // ========================================\r\n\r\n /**\r\n * Sets the transmission weight\r\n */\r\n transmissionWeight: number;\r\n\r\n /**\r\n * Sets the transmission weight texture\r\n */\r\n transmissionWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the attenuation distance\r\n */\r\n transmissionDepth: number;\r\n\r\n /**\r\n * Sets the attenuation color\r\n */\r\n transmissionColor: Color3;\r\n\r\n /**\r\n * Sets the scattering coefficient\r\n */\r\n transmissionScatter: Color3;\r\n\r\n /**\r\n * Sets the transmission scatter texture\r\n */\r\n transmissionScatterTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Staging: the constant scatter strength for volumetric mode.\r\n * Set by KHR_materials_scatter and consumed by the adapter during finalization.\r\n */\r\n volumetricScatterStrengthFactor: Nullable<number>;\r\n\r\n /**\r\n * Staging: scatter strength texture for volumetric mode (non-thin-walled).\r\n * Set by KHR_materials_scatter when scatterStrengthTexture is present; applied together with\r\n * transmissionScatterTexture in finalizeAsync and then cleared.\r\n */\r\n volumetricScatterStrengthTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Staging: the constant scatter strength for thin-walled mode.\r\n * Set by KHR_materials_scatter and consumed by the material adapter during finalization.\r\n * Null means no thin-walled scatter has been staged.\r\n */\r\n thinWalledScatterStrengthFactor: Nullable<number>;\r\n\r\n /**\r\n * Staging: scatter strength texture for thin-walled mode.\r\n * Set by KHR_materials_scatter when scatterStrengthTexture is present; combined with\r\n * the transmission weight in finalizeAsync and then cleared.\r\n */\r\n thinWalledScatterStrengthTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the scattering anisotropy (-1 to 1)\r\n */\r\n transmissionScatterAnisotropy: number;\r\n\r\n /**\r\n * Sets the dispersion Abbe number\r\n */\r\n transmissionDispersionAbbeNumber: number;\r\n\r\n /**\r\n * Sets the dispersion scale\r\n */\r\n transmissionDispersionScale: number;\r\n\r\n /**\r\n * The refraction background texture\r\n */\r\n refractionBackgroundTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Configures transmission for thin-surface transmission (KHR_materials_transmission)\r\n */\r\n configureTransmission(): void;\r\n\r\n // ========================================\r\n // VOLUME PROPERTIES\r\n // ========================================\r\n\r\n /**\r\n * Configures volume properties for volumetric transmission (KHR_materials_volume)\r\n */\r\n configureVolume(): void;\r\n\r\n /**\r\n * Sets whether the material is thin-walled (i.e. non-volumetric) or not.\r\n */\r\n geometryThinWalled: boolean;\r\n\r\n /**\r\n * Sets the thickness texture\r\n */\r\n volumeThicknessTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the thickness factor\r\n */\r\n volumeThickness: number;\r\n\r\n // ========================================\r\n // SUBSURFACE PROPERTIES (Subsurface Scattering)\r\n // ========================================\r\n\r\n /**\r\n * Configures subsurface properties\r\n */\r\n configureSubsurface(): void;\r\n\r\n /**\r\n * Sets/gets the subsurface weight\r\n */\r\n subsurfaceWeight: number;\r\n\r\n /**\r\n * Sets/gets the subsurface weight texture\r\n */\r\n subsurfaceWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the subsurface color\r\n */\r\n subsurfaceColor: Color3;\r\n\r\n /**\r\n * Sets/gets the subsurface color texture\r\n */\r\n subsurfaceColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the diffuse transmission tint of the material\r\n */\r\n diffuseTransmissionTint: Color3;\r\n\r\n /**\r\n * Sets/gets the diffuse transmission tint texture of the material\r\n */\r\n diffuseTransmissionTintTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets/gets the subsurface radius (used for subsurface scattering)\r\n */\r\n subsurfaceRadius: number;\r\n\r\n /**\r\n * Sets/gets the subsurface radius scale (used for subsurface scattering)\r\n */\r\n subsurfaceRadiusScale: Color3;\r\n\r\n /**\r\n * Sets/gets the subsurface scattering anisotropy\r\n */\r\n subsurfaceScatterAnisotropy: number;\r\n\r\n /**\r\n * Does this material have a translucent surface (i.e. either transmission or subsurface)?\r\n */\r\n isTranslucent(): boolean;\r\n\r\n // ========================================\r\n // FUZZ LAYER (Sheen)\r\n // ========================================\r\n\r\n /**\r\n * Configures initial settings for fuzz for material.\r\n */\r\n configureFuzz(): void;\r\n\r\n /**\r\n * Sets the fuzz weight\r\n */\r\n fuzzWeight: number;\r\n\r\n /**\r\n * Sets the fuzz weight texture\r\n */\r\n fuzzWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the fuzz color\r\n */\r\n fuzzColor: Color3;\r\n\r\n /**\r\n * Sets the fuzz color texture\r\n */\r\n fuzzColorTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the fuzz roughness\r\n */\r\n fuzzRoughness: number;\r\n\r\n /**\r\n * Sets the fuzz roughness texture\r\n */\r\n fuzzRoughnessTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // ANISOTROPY\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the specular roughness anisotropy\r\n */\r\n specularRoughnessAnisotropy: number;\r\n\r\n /**\r\n * Sets the anisotropy rotation\r\n */\r\n geometryTangentAngle: number;\r\n\r\n /**\r\n * Sets/gets the anisotropy texture\r\n */\r\n geometryTangentTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Configures glTF-style anisotropy for OpenPBR materials\r\n * @param useGltfStyle - Whether to use glTF-style anisotropy (default: true)\r\n */\r\n configureGltfStyleAnisotropy(useGltfStyle?: boolean): void;\r\n\r\n // ========================================\r\n // THIN FILM IRIDESCENCE\r\n // ========================================\r\n\r\n /**\r\n * Sets the thin film weight\r\n */\r\n thinFilmWeight: number;\r\n\r\n /**\r\n * Sets the thin film IOR\r\n */\r\n thinFilmIor: number;\r\n\r\n /**\r\n * Sets the thin film thickness minimum\r\n */\r\n thinFilmThicknessMinimum: number;\r\n\r\n /**\r\n * Sets the thin film thickness maximum\r\n */\r\n thinFilmThicknessMaximum: number;\r\n\r\n /**\r\n * Sets the thin film iridescence texture\r\n */\r\n thinFilmWeightTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the thin film thickness texture\r\n */\r\n thinFilmThicknessTexture: Nullable<BaseTexture>;\r\n\r\n // ========================================\r\n // UNLIT MATERIALS\r\n // ========================================\r\n\r\n /**\r\n * Sets the unlit flag\r\n */\r\n unlit: boolean;\r\n\r\n // ========================================\r\n // GEOMETRY PARAMETERS\r\n // ========================================\r\n\r\n /**\r\n * Sets/gets the geometry opacity\r\n */\r\n geometryOpacity: number;\r\n\r\n /**\r\n * Sets/gets the geometry normal texture\r\n */\r\n geometryNormalTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the normal map inversions for PBR material only\r\n * @param invertX - Whether to invert the normal map on the X axis\r\n * @param invertY - Whether to invert the normal map on the Y axis\r\n */\r\n setNormalMapInversions(invertX: boolean, invertY: boolean): void;\r\n\r\n /**\r\n * Sets/gets the coat normal texture\r\n */\r\n geometryCoatNormalTexture: Nullable<BaseTexture>;\r\n\r\n /**\r\n * Sets the coat normal texture scale\r\n */\r\n geometryCoatNormalTextureScale: number;\r\n}\r\n"]}
|
|
@@ -406,13 +406,13 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
406
406
|
*/
|
|
407
407
|
get transmissionWeight(): number;
|
|
408
408
|
/**
|
|
409
|
-
* Sets the transmission scatter coefficient.
|
|
410
|
-
* @param value The scatter coefficient as a Vector3
|
|
409
|
+
* Sets the transmission scatter coefficient, scaled by transmissionDepth.
|
|
410
|
+
* @param value The scatter coefficient * transmissionDepth as a Vector3
|
|
411
411
|
*/
|
|
412
412
|
set transmissionScatter(value: Color3);
|
|
413
413
|
/**
|
|
414
|
-
* Gets the transmission scatter coefficient.
|
|
415
|
-
* @returns The scatter coefficient as a Vector3
|
|
414
|
+
* Gets the transmission scatter coefficient, scaled by transmissionDepth.
|
|
415
|
+
* @returns The scatter coefficient * transmissionDepth as a Vector3
|
|
416
416
|
*/
|
|
417
417
|
get transmissionScatter(): Color3;
|
|
418
418
|
/**
|
|
@@ -425,6 +425,24 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
425
425
|
* @returns The transmission scatter texture or null
|
|
426
426
|
*/
|
|
427
427
|
get transmissionScatterTexture(): Nullable<BaseTexture>;
|
|
428
|
+
private _volumetricScatterStrengthFactor;
|
|
429
|
+
/** @internal */
|
|
430
|
+
set volumetricScatterStrengthFactor(value: Nullable<number>);
|
|
431
|
+
/** @internal */
|
|
432
|
+
get volumetricScatterStrengthFactor(): Nullable<number>;
|
|
433
|
+
private _volumetricScatterStrengthTexture;
|
|
434
|
+
set volumetricScatterStrengthTexture(value: Nullable<BaseTexture>);
|
|
435
|
+
get volumetricScatterStrengthTexture(): Nullable<BaseTexture>;
|
|
436
|
+
private _thinWalledScatterStrengthFactor;
|
|
437
|
+
/** @internal */
|
|
438
|
+
set thinWalledScatterStrengthFactor(value: Nullable<number>);
|
|
439
|
+
/** @internal */
|
|
440
|
+
get thinWalledScatterStrengthFactor(): Nullable<number>;
|
|
441
|
+
private _thinWalledScatterStrengthTexture;
|
|
442
|
+
/** @internal */
|
|
443
|
+
set thinWalledScatterStrengthTexture(value: Nullable<BaseTexture>);
|
|
444
|
+
/** @internal */
|
|
445
|
+
get thinWalledScatterStrengthTexture(): Nullable<BaseTexture>;
|
|
428
446
|
/**
|
|
429
447
|
* Sets the transmission scattering anisotropy.
|
|
430
448
|
* @param value The anisotropy intensity value (-1 to 1)
|
|
@@ -708,5 +726,13 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
708
726
|
* @param loader The glTF loader; `loader._disposed` is polled between texture passes to bail early on dispose.
|
|
709
727
|
*/
|
|
710
728
|
finalizeAsync(loader: GLTFLoader): Promise<void>;
|
|
729
|
+
/**
|
|
730
|
+
* Disposes a texture that has been replaced on this material, unless another slot on this
|
|
731
|
+
* material (or on any other material created by the loader) still references it.
|
|
732
|
+
* Must be called after the texture has been removed from the slot being replaced.
|
|
733
|
+
* @param loader The glTF loader that created the materials
|
|
734
|
+
* @param texture The replaced texture
|
|
735
|
+
*/
|
|
736
|
+
private _disposeTextureIfUnused;
|
|
711
737
|
private copySurfaceToCoatAsync;
|
|
712
738
|
}
|
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
import { Color3, Color4 } from "@babylonjs/core/Maths/math.color.js";
|
|
2
|
-
import { MultiplyTexturesAsync, LerpTexturesAsync, CreateTextureWithFactorOperand, TextureChannel, TextureColorSpace, InvertTextureAsync, ExtractChannelAsync, ChannelMask, ExtractMaxChannelAsync, } from "@babylonjs/core/Materials/Textures/textureProcessor.js";
|
|
2
|
+
import { MultiplyTexturesAsync, LerpTexturesAsync, CreateTextureWithFactorOperand, TextureChannel, TextureColorSpace, InvertTextureAsync, ExtractChannelAsync, ChannelMask, ExtractMaxChannelAsync, ThinWalledScatterWeightsAsync, MultiScatterToSingleScatterAlbedoAsync, } from "@babylonjs/core/Materials/Textures/textureProcessor.js";
|
|
3
|
+
/**
|
|
4
|
+
* Returns the color space to sample a color texture in. Textures loaded with hardware sRGB buffers
|
|
5
|
+
* already return linear values (gammaSpace is false), so they must not be decoded a second time.
|
|
6
|
+
* Only use this for color textures; data textures report gammaSpace as true but are linear.
|
|
7
|
+
* @param texture The color texture to be sampled
|
|
8
|
+
* @returns The texture color space to use for the operand
|
|
9
|
+
*/
|
|
10
|
+
function GetColorTextureSpace(texture) {
|
|
11
|
+
return texture?.gammaSpace ? TextureColorSpace.SRGB : TextureColorSpace.Linear;
|
|
12
|
+
}
|
|
3
13
|
/**
|
|
4
14
|
* Material Loading Adapter for OpenPBR materials that provides a unified OpenPBR-like interface.
|
|
5
15
|
*/
|
|
@@ -10,6 +20,10 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
10
20
|
*/
|
|
11
21
|
constructor(material) {
|
|
12
22
|
this._specWorkflow = false;
|
|
23
|
+
this._volumetricScatterStrengthFactor = null;
|
|
24
|
+
this._volumetricScatterStrengthTexture = null;
|
|
25
|
+
this._thinWalledScatterStrengthFactor = null;
|
|
26
|
+
this._thinWalledScatterStrengthTexture = null;
|
|
13
27
|
this._diffuseTransmissionTint = Color3.White();
|
|
14
28
|
this._diffuseTransmissionTintTexture = null;
|
|
15
29
|
this._material = material;
|
|
@@ -617,15 +631,15 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
617
631
|
return this._material.transmissionWeight;
|
|
618
632
|
}
|
|
619
633
|
/**
|
|
620
|
-
* Sets the transmission scatter coefficient.
|
|
621
|
-
* @param value The scatter coefficient as a Vector3
|
|
634
|
+
* Sets the transmission scatter coefficient, scaled by transmissionDepth.
|
|
635
|
+
* @param value The scatter coefficient * transmissionDepth as a Vector3
|
|
622
636
|
*/
|
|
623
637
|
set transmissionScatter(value) {
|
|
624
638
|
this._material.transmissionScatter = value;
|
|
625
639
|
}
|
|
626
640
|
/**
|
|
627
|
-
* Gets the transmission scatter coefficient.
|
|
628
|
-
* @returns The scatter coefficient as a Vector3
|
|
641
|
+
* Gets the transmission scatter coefficient, scaled by transmissionDepth.
|
|
642
|
+
* @returns The scatter coefficient * transmissionDepth as a Vector3
|
|
629
643
|
*/
|
|
630
644
|
get transmissionScatter() {
|
|
631
645
|
return this._material.transmissionScatter;
|
|
@@ -644,6 +658,36 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
644
658
|
get transmissionScatterTexture() {
|
|
645
659
|
return this._material.transmissionScatterTexture;
|
|
646
660
|
}
|
|
661
|
+
/** @internal */
|
|
662
|
+
set volumetricScatterStrengthFactor(value) {
|
|
663
|
+
this._volumetricScatterStrengthFactor = value;
|
|
664
|
+
}
|
|
665
|
+
/** @internal */
|
|
666
|
+
get volumetricScatterStrengthFactor() {
|
|
667
|
+
return this._volumetricScatterStrengthFactor;
|
|
668
|
+
}
|
|
669
|
+
set volumetricScatterStrengthTexture(value) {
|
|
670
|
+
this._volumetricScatterStrengthTexture = value;
|
|
671
|
+
}
|
|
672
|
+
get volumetricScatterStrengthTexture() {
|
|
673
|
+
return this._volumetricScatterStrengthTexture;
|
|
674
|
+
}
|
|
675
|
+
/** @internal */
|
|
676
|
+
set thinWalledScatterStrengthFactor(value) {
|
|
677
|
+
this._thinWalledScatterStrengthFactor = value;
|
|
678
|
+
}
|
|
679
|
+
/** @internal */
|
|
680
|
+
get thinWalledScatterStrengthFactor() {
|
|
681
|
+
return this._thinWalledScatterStrengthFactor;
|
|
682
|
+
}
|
|
683
|
+
/** @internal */
|
|
684
|
+
set thinWalledScatterStrengthTexture(value) {
|
|
685
|
+
this._thinWalledScatterStrengthTexture = value;
|
|
686
|
+
}
|
|
687
|
+
/** @internal */
|
|
688
|
+
get thinWalledScatterStrengthTexture() {
|
|
689
|
+
return this._thinWalledScatterStrengthTexture;
|
|
690
|
+
}
|
|
647
691
|
/**
|
|
648
692
|
* Sets the transmission scattering anisotropy.
|
|
649
693
|
* @param value The anisotropy intensity value (-1 to 1)
|
|
@@ -762,8 +806,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
762
806
|
* Configures subsurface properties for PBR material
|
|
763
807
|
*/
|
|
764
808
|
configureSubsurface() {
|
|
765
|
-
// glTF diffuse transmission is thin-walled (before volume extension is applied) will map to the subsurface slab
|
|
809
|
+
// glTF diffuse transmission is thin-walled (before volume extension is applied) will map to the subsurface slab
|
|
766
810
|
this._material.geometryThinWalled = 1.0;
|
|
811
|
+
// and, without a volume extension, diffuse transmission is fully transmitting, like having scatter aniso = +1.
|
|
767
812
|
this._material.subsurfaceScatterAnisotropy = 1.0;
|
|
768
813
|
}
|
|
769
814
|
/**
|
|
@@ -1086,6 +1131,83 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1086
1131
|
*/
|
|
1087
1132
|
async finalizeAsync(loader) {
|
|
1088
1133
|
// Do final configuration for the material to handle any interactions/dependencies between properties that we had to defer until all properties were loaded.
|
|
1134
|
+
// Thin-walled scatter: KHR_materials_scatter explicitly stages scatter strength S. Only staged
|
|
1135
|
+
// values are converted; live material values may have been changed by user code in
|
|
1136
|
+
// onMaterialLoadedObservable, which fires before finalization.
|
|
1137
|
+
// This must run before the diffuse-transmission-tint block which reads subsurfaceWeight.
|
|
1138
|
+
const thinScatterStrength = this._thinWalledScatterStrengthFactor;
|
|
1139
|
+
const thinScatterTex = this._thinWalledScatterStrengthTexture;
|
|
1140
|
+
this._thinWalledScatterStrengthFactor = null;
|
|
1141
|
+
this._thinWalledScatterStrengthTexture = null;
|
|
1142
|
+
if (thinScatterStrength !== null && !this._diffuseTransmissionTint.equals(Color3.White())) {
|
|
1143
|
+
// Tinted diffuse transmission: use the scatter strength directly as the subsurface weight.
|
|
1144
|
+
this.subsurfaceWeight = thinScatterStrength;
|
|
1145
|
+
if (thinScatterTex) {
|
|
1146
|
+
this.subsurfaceWeightTexture = thinScatterTex;
|
|
1147
|
+
}
|
|
1148
|
+
}
|
|
1149
|
+
else if (thinScatterStrength !== null && (thinScatterStrength > 0 || thinScatterTex)) {
|
|
1150
|
+
// Compute final transmission_weight = T*(1-S) and subsurface_weight = T*S/(1-T*(1-S)).
|
|
1151
|
+
const transmissionFactor = this.transmissionWeight;
|
|
1152
|
+
const transmissionTex = this.transmissionWeightTexture;
|
|
1153
|
+
const scatterStrength = thinScatterStrength;
|
|
1154
|
+
const scatterTex = thinScatterTex;
|
|
1155
|
+
const weights = await ThinWalledScatterWeightsAsync(`${this._material.name}`, CreateTextureWithFactorOperand(transmissionTex, new Color4(transmissionFactor, transmissionFactor, transmissionFactor, 1.0), TextureChannel.R), CreateTextureWithFactorOperand(scatterTex, new Color4(scatterStrength, scatterStrength, scatterStrength, 1.0), TextureChannel.A), this._material.getScene());
|
|
1156
|
+
if (loader._disposed) {
|
|
1157
|
+
weights.transmission.dispose?.();
|
|
1158
|
+
weights.subsurface.dispose?.();
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
this.transmissionWeight = weights.transmission.factor?.r ?? transmissionFactor * (1.0 - scatterStrength);
|
|
1162
|
+
if (weights.transmission.texture) {
|
|
1163
|
+
this.transmissionWeight = 1.0;
|
|
1164
|
+
this.transmissionWeightTexture = weights.transmission.texture;
|
|
1165
|
+
this._disposeTextureIfUnused(loader, transmissionTex);
|
|
1166
|
+
}
|
|
1167
|
+
this.subsurfaceWeight = weights.subsurface.factor?.r ?? 0.0;
|
|
1168
|
+
if (weights.subsurface.texture) {
|
|
1169
|
+
const oldSubsurfaceWeightTexture = this.subsurfaceWeightTexture;
|
|
1170
|
+
this.subsurfaceWeight = 1.0;
|
|
1171
|
+
this.subsurfaceWeightTexture = weights.subsurface.texture;
|
|
1172
|
+
this._material._useSubsurfaceWeightFromTextureAlpha = false;
|
|
1173
|
+
this._disposeTextureIfUnused(loader, oldSubsurfaceWeightTexture);
|
|
1174
|
+
}
|
|
1175
|
+
this._disposeTextureIfUnused(loader, scatterTex);
|
|
1176
|
+
}
|
|
1177
|
+
else {
|
|
1178
|
+
this._disposeTextureIfUnused(loader, thinScatterTex);
|
|
1179
|
+
}
|
|
1180
|
+
// KHR_materials_scatter supplies multi-scatter albedo, while OpenPBR 1.1 expects the
|
|
1181
|
+
// scattering coefficient multiplied by transmission depth. Bake the nonlinear conversion
|
|
1182
|
+
// to single-scatter albedo into the texture, then keep extinctionCoefficient * depth in the
|
|
1183
|
+
// material factor so their product has the representation expected by OpenPBR.
|
|
1184
|
+
if (this._volumetricScatterStrengthFactor !== null) {
|
|
1185
|
+
const colorTex = this.transmissionScatterTexture;
|
|
1186
|
+
const colorFactor = this.transmissionScatter;
|
|
1187
|
+
const strengthTex = this._volumetricScatterStrengthTexture;
|
|
1188
|
+
const scatterStrength = this._volumetricScatterStrengthFactor;
|
|
1189
|
+
// Fuse the strength scale into the conversion so the small multi-scatter product is not
|
|
1190
|
+
// quantized to an unsigned-byte intermediate before the nonlinear conversion.
|
|
1191
|
+
const singleScatter = await MultiScatterToSingleScatterAlbedoAsync(`single-scatter (${this._material.name})`, CreateTextureWithFactorOperand(colorTex, colorFactor.toColor4(), TextureChannel.RGBA, GetColorTextureSpace(colorTex)), this._material.getScene(), this._material.transmissionScatterAnisotropy, CreateTextureWithFactorOperand(strengthTex, new Color4(scatterStrength, scatterStrength, scatterStrength, 1.0), TextureChannel.A));
|
|
1192
|
+
if (loader._disposed) {
|
|
1193
|
+
singleScatter.dispose?.();
|
|
1194
|
+
this._disposeTextureIfUnused(loader, strengthTex);
|
|
1195
|
+
return;
|
|
1196
|
+
}
|
|
1197
|
+
this._volumetricScatterStrengthFactor = null;
|
|
1198
|
+
this._volumetricScatterStrengthTexture = null;
|
|
1199
|
+
// OpenPBR transmission_scatter is scatterCoefficient * depth which is equivalent to extinctionCoefficient * ssAlbedo * depth.
|
|
1200
|
+
const extinctionTimesDepth = new Color3(-Math.log(Math.max(this.transmissionColor.r, 1e-7)), -Math.log(Math.max(this.transmissionColor.g, 1e-7)), -Math.log(Math.max(this.transmissionColor.b, 1e-7)));
|
|
1201
|
+
if (singleScatter.texture) {
|
|
1202
|
+
this.transmissionScatter = extinctionTimesDepth;
|
|
1203
|
+
this.transmissionScatterTexture = singleScatter.texture;
|
|
1204
|
+
}
|
|
1205
|
+
else if (singleScatter.factor) {
|
|
1206
|
+
this.transmissionScatter.set(extinctionTimesDepth.r * singleScatter.factor.r, extinctionTimesDepth.g * singleScatter.factor.g, extinctionTimesDepth.b * singleScatter.factor.b);
|
|
1207
|
+
}
|
|
1208
|
+
this._disposeTextureIfUnused(loader, colorTex);
|
|
1209
|
+
this._disposeTextureIfUnused(loader, strengthTex);
|
|
1210
|
+
}
|
|
1089
1211
|
// If the material is volumetric, we may need to create a coat layer to handle the surface tint.
|
|
1090
1212
|
if ((this._diffuseTransmissionTint && !this._diffuseTransmissionTint.equals(Color3.White())) || this._diffuseTransmissionTintTexture) {
|
|
1091
1213
|
if (this._material.geometryThinWalled) {
|
|
@@ -1126,11 +1248,11 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1126
1248
|
}
|
|
1127
1249
|
this.specularRoughnessTexture = newRoughnessTexture.texture;
|
|
1128
1250
|
this.specularRoughness = newRoughnessTexture.factor ? newRoughnessTexture.factor.r : 1.0;
|
|
1129
|
-
// Metallic = max(linearize(specular).rgb). The specular texture is sRGB so we must
|
|
1130
|
-
//
|
|
1251
|
+
// Metallic = max(linearize(specular).rgb). The specular texture is sRGB so we must linearize it
|
|
1252
|
+
// first, unless it was loaded into an sRGB buffer. The factor is already linear per convention.
|
|
1131
1253
|
// We store metallic as linear (no outputColorSpace) because it is a data/scalar value;
|
|
1132
1254
|
// encoding it as sRGB would corrupt it when it is used as the lerp t below.
|
|
1133
|
-
const newMetallic = await ExtractMaxChannelAsync("metallicTexture (" + this._material.name + ")", CreateTextureWithFactorOperand(this.specularColorTexture, this.specularColor.toColor4(), TextureChannel.RGBA,
|
|
1255
|
+
const newMetallic = await ExtractMaxChannelAsync("metallicTexture (" + this._material.name + ")", CreateTextureWithFactorOperand(this.specularColorTexture, this.specularColor.toColor4(), TextureChannel.RGBA, GetColorTextureSpace(this.specularColorTexture)), this._material.getScene(), false, TextureColorSpace.SRGB, ChannelMask.RGB);
|
|
1134
1256
|
if (loader._disposed) {
|
|
1135
1257
|
newMetallic.texture?.dispose();
|
|
1136
1258
|
return;
|
|
@@ -1140,18 +1262,30 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1140
1262
|
// base_color = lerp(diffuse, specular, metallic).
|
|
1141
1263
|
// Strip dispose before passing newMetallic as t — its texture is already owned by the
|
|
1142
1264
|
// material (baseMetalnessTexture) and must not be released after the lerp pass.
|
|
1143
|
-
const newBaseColor = await LerpTexturesAsync("newBaseColor (" + this._material.name + ")", CreateTextureWithFactorOperand(this.baseColorTexture, this.baseColor.toColor4(), TextureChannel.RGBA,
|
|
1265
|
+
const newBaseColor = await LerpTexturesAsync("newBaseColor (" + this._material.name + ")", CreateTextureWithFactorOperand(this.baseColorTexture, this.baseColor.toColor4(), TextureChannel.RGBA, GetColorTextureSpace(this.baseColorTexture)), CreateTextureWithFactorOperand(this.specularColorTexture, this.specularColor.toColor4(), TextureChannel.RGBA, GetColorTextureSpace(this.specularColorTexture)), { ...newMetallic, dispose: undefined, colorSpace: TextureColorSpace.Linear }, this._material.getScene(), TextureColorSpace.SRGB, ChannelMask.RGB);
|
|
1144
1266
|
if (loader._disposed) {
|
|
1145
1267
|
newBaseColor.texture?.dispose();
|
|
1146
1268
|
return;
|
|
1147
1269
|
}
|
|
1148
1270
|
const oldBaseColorTexture = this.baseColorTexture;
|
|
1149
|
-
oldBaseColorTexture?.dispose();
|
|
1150
1271
|
this.baseColorTexture = newBaseColor.texture;
|
|
1151
1272
|
this.baseColor = newBaseColor.factor ? new Color3(newBaseColor.factor.r, newBaseColor.factor.g, newBaseColor.factor.b) : Color3.White();
|
|
1273
|
+
this._disposeTextureIfUnused(loader, oldBaseColorTexture);
|
|
1152
1274
|
const oldSpecularColorTexture = this.specularColorTexture;
|
|
1153
|
-
oldSpecularColorTexture?.dispose();
|
|
1154
1275
|
this.specularColorTexture = null;
|
|
1276
|
+
this._disposeTextureIfUnused(loader, oldSpecularColorTexture);
|
|
1277
|
+
}
|
|
1278
|
+
}
|
|
1279
|
+
/**
|
|
1280
|
+
* Disposes a texture that has been replaced on this material, unless another slot on this
|
|
1281
|
+
* material (or on any other material created by the loader) still references it.
|
|
1282
|
+
* Must be called after the texture has been removed from the slot being replaced.
|
|
1283
|
+
* @param loader The glTF loader that created the materials
|
|
1284
|
+
* @param texture The replaced texture
|
|
1285
|
+
*/
|
|
1286
|
+
_disposeTextureIfUnused(loader, texture) {
|
|
1287
|
+
if (texture && !loader._isTextureUsedByMaterials(texture)) {
|
|
1288
|
+
texture.dispose();
|
|
1155
1289
|
}
|
|
1156
1290
|
}
|
|
1157
1291
|
async copySurfaceToCoatAsync(loader, weight, weightTexture, weightTextureChannel, color, colorTexture, diffuseTransmission = false) {
|
|
@@ -1171,11 +1305,18 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1171
1305
|
const origCoatNormalTexture = this._material.geometryCoatNormalTexture;
|
|
1172
1306
|
const origCoatWeightCol4 = new Color4(origCoatWeight, origCoatWeight, origCoatWeight, origCoatWeight);
|
|
1173
1307
|
const weightCol4 = new Color4(weight, weight, weight, weight);
|
|
1308
|
+
// Textures removed from material slots are collected here and disposed only at the end, because
|
|
1309
|
+
// they may still be needed as inputs to later passes (e.g. origCoatWeightTexture, or a packed
|
|
1310
|
+
// texture that is shared between several coat slots).
|
|
1311
|
+
const replacedTextures = new Set();
|
|
1312
|
+
if (origCoatWeightTexture) {
|
|
1313
|
+
replacedTextures.add(origCoatWeightTexture);
|
|
1314
|
+
}
|
|
1174
1315
|
this.coatWeightTexture = null;
|
|
1175
1316
|
this.coatWeight = 1.0;
|
|
1176
1317
|
const results = await Promise.allSettled([
|
|
1177
|
-
LerpTexturesAsync("lerpExistingCoat", CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1)), CreateTextureWithFactorOperand(origCoatColorTexture, origCoatColor.toColor4(), TextureChannel.RGBA,
|
|
1178
|
-
LerpTexturesAsync("lerpSurfaceColor", CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1)), CreateTextureWithFactorOperand(colorTexture, color.toColor4(), TextureChannel.RGBA,
|
|
1318
|
+
LerpTexturesAsync("lerpExistingCoat", CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1)), CreateTextureWithFactorOperand(origCoatColorTexture, origCoatColor.toColor4(), TextureChannel.RGBA, GetColorTextureSpace(origCoatColorTexture)), CreateTextureWithFactorOperand(origCoatWeightTexture, origCoatWeightCol4, TextureChannel.R), this._material.getScene(), TextureColorSpace.SRGB),
|
|
1319
|
+
LerpTexturesAsync("lerpSurfaceColor", CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1)), CreateTextureWithFactorOperand(colorTexture, color.toColor4(), TextureChannel.RGBA, GetColorTextureSpace(colorTexture)), CreateTextureWithFactorOperand(weightTexture, weightCol4, weightTextureChannel), this._material.getScene(), TextureColorSpace.SRGB),
|
|
1179
1320
|
]);
|
|
1180
1321
|
const rejected = results.find((r) => r.status === "rejected");
|
|
1181
1322
|
if (rejected) {
|
|
@@ -1205,6 +1346,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1205
1346
|
this.coatColorTexture = null;
|
|
1206
1347
|
this.coatColor.fromArray([newCoatColor.factor.r, newCoatColor.factor.g, newCoatColor.factor.b]);
|
|
1207
1348
|
}
|
|
1349
|
+
if (origCoatColorTexture) {
|
|
1350
|
+
replacedTextures.add(origCoatColorTexture);
|
|
1351
|
+
}
|
|
1208
1352
|
const newCoatIor = await LerpTexturesAsync("newCoatIor (" + this._material.name + ")", CreateTextureWithFactorOperand(null, new Color4(this._material.specularIor, this._material.specularIor, this._material.specularIor, 1.0), TextureChannel.R), CreateTextureWithFactorOperand(null, new Color4(this.coatIor, this.coatIor, this.coatIor, 1.0), TextureChannel.R), CreateTextureWithFactorOperand(origCoatWeightTexture, origCoatWeightCol4, TextureChannel.R), this._material.getScene());
|
|
1209
1353
|
if (loader._disposed) {
|
|
1210
1354
|
newCoatIor.texture?.dispose();
|
|
@@ -1216,8 +1360,12 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1216
1360
|
newCoatRoughness.texture?.dispose();
|
|
1217
1361
|
return;
|
|
1218
1362
|
}
|
|
1363
|
+
const oldCoatRoughnessTexture = this.coatRoughnessTexture;
|
|
1219
1364
|
this.coatRoughness = newCoatRoughness.factor ? newCoatRoughness.factor.r : 1.0;
|
|
1220
1365
|
this.coatRoughnessTexture = newCoatRoughness.texture;
|
|
1366
|
+
if (oldCoatRoughnessTexture) {
|
|
1367
|
+
replacedTextures.add(oldCoatRoughnessTexture);
|
|
1368
|
+
}
|
|
1221
1369
|
const newCoatDarkening = await LerpTexturesAsync("newCoatDarkening (" + this._material.name + ")", CreateTextureWithFactorOperand(null, new Color4(0, 0, 0, 1.0), TextureChannel.R), CreateTextureWithFactorOperand(null, new Color4(this.coatDarkening, this.coatDarkening, this.coatDarkening, 1.0), TextureChannel.R), CreateTextureWithFactorOperand(origCoatWeightTexture, origCoatWeightCol4, TextureChannel.R), this._material.getScene());
|
|
1222
1370
|
if (loader._disposed) {
|
|
1223
1371
|
newCoatDarkening.texture?.dispose();
|
|
@@ -1230,8 +1378,12 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1230
1378
|
newSpecularRoughness.texture?.dispose();
|
|
1231
1379
|
return;
|
|
1232
1380
|
}
|
|
1381
|
+
const oldSpecularRoughnessTexture = this.specularRoughnessTexture;
|
|
1233
1382
|
this.specularRoughness = newSpecularRoughness.factor ? newSpecularRoughness.factor.r : 1.0;
|
|
1234
1383
|
this.specularRoughnessTexture = newSpecularRoughness.texture;
|
|
1384
|
+
if (oldSpecularRoughnessTexture) {
|
|
1385
|
+
replacedTextures.add(oldSpecularRoughnessTexture);
|
|
1386
|
+
}
|
|
1235
1387
|
}
|
|
1236
1388
|
if (origCoatNormalTexture || this.geometryNormalTexture) {
|
|
1237
1389
|
const newCoatNormal = await LerpTexturesAsync("newCoatNormal (" + this._material.name + ")", CreateTextureWithFactorOperand(this.geometryNormalTexture, this.geometryNormalTexture ? new Color4(1, 1, 1, 1) : new Color4(0.5, 0.5, 1.0, 1.0), TextureChannel.RGBA), CreateTextureWithFactorOperand(origCoatNormalTexture, origCoatNormalTexture ? new Color4(1, 1, 1, 1) : new Color4(0.5, 0.5, 1.0, 1.0), TextureChannel.RGBA), CreateTextureWithFactorOperand(origCoatWeightTexture, origCoatWeightCol4, TextureChannel.R), this._material.getScene());
|
|
@@ -1241,8 +1393,14 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1241
1393
|
}
|
|
1242
1394
|
if (newCoatNormal.texture) {
|
|
1243
1395
|
this.geometryCoatNormalTexture = newCoatNormal.texture;
|
|
1396
|
+
if (origCoatNormalTexture) {
|
|
1397
|
+
replacedTextures.add(origCoatNormalTexture);
|
|
1398
|
+
}
|
|
1244
1399
|
}
|
|
1245
1400
|
}
|
|
1401
|
+
for (const texture of replacedTextures) {
|
|
1402
|
+
this._disposeTextureIfUnused(loader, texture);
|
|
1403
|
+
}
|
|
1246
1404
|
}
|
|
1247
1405
|
}
|
|
1248
1406
|
//# sourceMappingURL=openpbrMaterialLoadingAdapter.js.map
|