@babylonjs/loaders 9.6.2 → 9.8.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/splatFileLoader.js +2 -2
- package/SPLAT/splatFileLoader.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +8 -14
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/glTFLoader.d.ts +2 -1
- package/glTF/2.0/glTFLoader.js +12 -7
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/materialLoadingAdapter.d.ts +22 -2
- package/glTF/2.0/materialLoadingAdapter.js.map +1 -1
- package/glTF/2.0/openpbrMaterialLoadingAdapter.d.ts +25 -1
- package/glTF/2.0/openpbrMaterialLoadingAdapter.js +178 -26
- package/glTF/2.0/openpbrMaterialLoadingAdapter.js.map +1 -1
- package/glTF/2.0/pbrMaterialLoadingAdapter.d.ts +24 -0
- package/glTF/2.0/pbrMaterialLoadingAdapter.js +60 -5
- package/glTF/2.0/pbrMaterialLoadingAdapter.js.map +1 -1
- package/package.json +3 -3
|
@@ -2,6 +2,7 @@ import { type Material } from "@babylonjs/core/Materials/material.js";
|
|
|
2
2
|
import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture.js";
|
|
3
3
|
import { type Nullable } from "@babylonjs/core/types.js";
|
|
4
4
|
import { type Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
5
|
+
import { type GLTFLoader } from "./glTFLoader.js";
|
|
5
6
|
/**
|
|
6
7
|
* Interface for material loading adapters that provides a unified OpenPBR-like interface
|
|
7
8
|
* for both OpenPBR and PBR materials, eliminating conditional branches in extensions.
|
|
@@ -12,9 +13,16 @@ export interface IMaterialLoadingAdapter {
|
|
|
12
13
|
*/
|
|
13
14
|
readonly material: Material;
|
|
14
15
|
/**
|
|
15
|
-
* Finalizes material properties after loading is complete.
|
|
16
|
+
* Finalizes material properties after all loading is complete.
|
|
17
|
+
* May do async work (e.g. GPU texture processing); the returned Promise is tracked
|
|
18
|
+
* by the loader and awaited before the COMPLETE state is reached, so callers can rely
|
|
19
|
+
* on onCompleteObservable for fully processed materials.
|
|
20
|
+
*
|
|
21
|
+
* Implementations should check `loader._disposed` between awaits to bail out early
|
|
22
|
+
* when the loader is disposed mid-flight.
|
|
23
|
+
* @param loader The glTF loader driving the finalize step.
|
|
16
24
|
*/
|
|
17
|
-
|
|
25
|
+
finalizeAsync(loader: GLTFLoader): Promise<void>;
|
|
18
26
|
/**
|
|
19
27
|
* Whether the material should be treated as unlit
|
|
20
28
|
*/
|
|
@@ -76,6 +84,10 @@ export interface IMaterialLoadingAdapter {
|
|
|
76
84
|
* @param enableEdgeColor - Whether to enable edge color support
|
|
77
85
|
*/
|
|
78
86
|
enableSpecularEdgeColor(enableEdgeColor?: boolean): void;
|
|
87
|
+
/**
|
|
88
|
+
* Enable the specular/glossiness workflow and disable metallic/roughness.
|
|
89
|
+
*/
|
|
90
|
+
configureSpecularGlossiness(): void;
|
|
79
91
|
/**
|
|
80
92
|
* Sets/gets the specular weight
|
|
81
93
|
*/
|
|
@@ -104,6 +116,11 @@ export interface IMaterialLoadingAdapter {
|
|
|
104
116
|
* Sets/gets the specular IOR
|
|
105
117
|
*/
|
|
106
118
|
specularIor: number;
|
|
119
|
+
/**
|
|
120
|
+
* Sets/gets the glossiness (inverted roughness)
|
|
121
|
+
* ONLY used for specular/glossiness workflow; has no effect when metallic/roughness workflow is active
|
|
122
|
+
*/
|
|
123
|
+
glossiness: number;
|
|
107
124
|
/**
|
|
108
125
|
* Sets/gets the emissive color
|
|
109
126
|
*/
|
|
@@ -220,6 +237,9 @@ export interface IMaterialLoadingAdapter {
|
|
|
220
237
|
* Configures transmission for thin-surface transmission (KHR_materials_transmission)
|
|
221
238
|
*/
|
|
222
239
|
configureTransmission(): void;
|
|
240
|
+
/**
|
|
241
|
+
* Configures volume properties for volumetric transmission (KHR_materials_volume)
|
|
242
|
+
*/
|
|
223
243
|
configureVolume(): void;
|
|
224
244
|
/**
|
|
225
245
|
* Sets whether the material is thin-walled (i.e. non-volumetric) or not.
|
|
@@ -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\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 loading is complete.\r\n */\r\n finalize?(): 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 * 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 // 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 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 * 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"]}
|
|
@@ -4,11 +4,13 @@ import { type BaseTexture } from "@babylonjs/core/Materials/Textures/baseTexture
|
|
|
4
4
|
import { type Nullable } from "@babylonjs/core/types.js";
|
|
5
5
|
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
6
6
|
import { type IMaterialLoadingAdapter } from "./materialLoadingAdapter.js";
|
|
7
|
+
import { type GLTFLoader } from "./glTFLoader.js";
|
|
7
8
|
/**
|
|
8
9
|
* Material Loading Adapter for OpenPBR materials that provides a unified OpenPBR-like interface.
|
|
9
10
|
*/
|
|
10
11
|
export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAdapter {
|
|
11
12
|
private _material;
|
|
13
|
+
private _specWorkflow;
|
|
12
14
|
/**
|
|
13
15
|
* Creates a new instance of the OpenPBRMaterialLoadingAdapter.
|
|
14
16
|
* @param material - The OpenPBR material to adapt.
|
|
@@ -151,6 +153,7 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
151
153
|
* @param _enableEdgeColor Whether to enable edge color support (ignored for OpenPBR)
|
|
152
154
|
*/
|
|
153
155
|
enableSpecularEdgeColor(_enableEdgeColor?: boolean): void;
|
|
156
|
+
configureSpecularGlossiness(): void;
|
|
154
157
|
/**
|
|
155
158
|
* Sets the specular weight of the OpenPBR material.
|
|
156
159
|
* @param value The specular weight value (0-1)
|
|
@@ -223,6 +226,11 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
223
226
|
* @returns The IOR value
|
|
224
227
|
*/
|
|
225
228
|
get specularIor(): number;
|
|
229
|
+
/**
|
|
230
|
+
* Sets the glossiness (inverted roughness) of the OpenPBR material.
|
|
231
|
+
*/
|
|
232
|
+
set glossiness(value: number);
|
|
233
|
+
get glossiness(): number;
|
|
226
234
|
/**
|
|
227
235
|
* Sets the emission color of the OpenPBR material.
|
|
228
236
|
* @param value The emission color as a Color3
|
|
@@ -303,6 +311,10 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
303
311
|
* @param value The coat color as a Color3
|
|
304
312
|
*/
|
|
305
313
|
set coatColor(value: Color3);
|
|
314
|
+
/**
|
|
315
|
+
* Gets the coat color of the OpenPBR material.
|
|
316
|
+
*/
|
|
317
|
+
get coatColor(): Color3;
|
|
306
318
|
/**
|
|
307
319
|
* Sets the coat color texture of the OpenPBR material.
|
|
308
320
|
* @param value The coat color texture or null
|
|
@@ -332,11 +344,13 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
332
344
|
* Sets the coat index of refraction (IOR) of the OpenPBR material.
|
|
333
345
|
*/
|
|
334
346
|
set coatIor(value: number);
|
|
347
|
+
get coatIor(): number;
|
|
335
348
|
/**
|
|
336
349
|
* Sets the coat darkening value of the OpenPBR material.
|
|
337
350
|
* @param value The coat darkening value
|
|
338
351
|
*/
|
|
339
352
|
set coatDarkening(value: number);
|
|
353
|
+
get coatDarkening(): number;
|
|
340
354
|
/**
|
|
341
355
|
* Sets the coat darkening texture (OpenPBR: coatDarkeningTexture, no PBR equivalent)
|
|
342
356
|
*/
|
|
@@ -385,6 +399,7 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
385
399
|
* @param value The transmission weight texture or null
|
|
386
400
|
*/
|
|
387
401
|
set transmissionWeightTexture(value: Nullable<BaseTexture>);
|
|
402
|
+
get transmissionWeightTexture(): Nullable<BaseTexture>;
|
|
388
403
|
/**
|
|
389
404
|
* Gets the transmission weight.
|
|
390
405
|
* @returns Currently returns 0 as transmission is not yet available
|
|
@@ -453,6 +468,9 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
453
468
|
* @param value The refraction background texture or null
|
|
454
469
|
*/
|
|
455
470
|
set refractionBackgroundTexture(value: Nullable<BaseTexture>);
|
|
471
|
+
/**
|
|
472
|
+
* Configures volume properties for OpenPBR material.
|
|
473
|
+
*/
|
|
456
474
|
configureVolume(): void;
|
|
457
475
|
/**
|
|
458
476
|
* Sets whether the material is thin-walled (i.e. non-volumetric) or not.
|
|
@@ -485,6 +503,7 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
485
503
|
* Sets the subsurface weight texture
|
|
486
504
|
*/
|
|
487
505
|
set subsurfaceWeightTexture(value: Nullable<BaseTexture>);
|
|
506
|
+
get subsurfaceWeightTexture(): Nullable<BaseTexture>;
|
|
488
507
|
/**
|
|
489
508
|
* Sets the subsurface color.
|
|
490
509
|
* @param value The subsurface tint color as a Color3
|
|
@@ -684,5 +703,10 @@ export declare class OpenPBRMaterialLoadingAdapter implements IMaterialLoadingAd
|
|
|
684
703
|
* @param value The scale value for the coat normal texture
|
|
685
704
|
*/
|
|
686
705
|
set geometryCoatNormalTextureScale(value: number);
|
|
687
|
-
|
|
706
|
+
/**
|
|
707
|
+
* Finalizes material properties after all loading is complete.
|
|
708
|
+
* @param loader The glTF loader; `loader._disposed` is polled between texture passes to bail early on dispose.
|
|
709
|
+
*/
|
|
710
|
+
finalizeAsync(loader: GLTFLoader): Promise<void>;
|
|
711
|
+
private copySurfaceToCoatAsync;
|
|
688
712
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { Color3 } from "@babylonjs/core/Maths/math.color.js";
|
|
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
3
|
/**
|
|
3
4
|
* Material Loading Adapter for OpenPBR materials that provides a unified OpenPBR-like interface.
|
|
4
5
|
*/
|
|
@@ -8,6 +9,7 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
8
9
|
* @param material - The OpenPBR material to adapt.
|
|
9
10
|
*/
|
|
10
11
|
constructor(material) {
|
|
12
|
+
this._specWorkflow = false;
|
|
11
13
|
this._diffuseTransmissionTint = Color3.White();
|
|
12
14
|
this._diffuseTransmissionTintTexture = null;
|
|
13
15
|
this._material = material;
|
|
@@ -218,6 +220,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
218
220
|
enableSpecularEdgeColor(_enableEdgeColor = false) {
|
|
219
221
|
// OpenPBR already supports edge color natively, no configuration needed
|
|
220
222
|
}
|
|
223
|
+
configureSpecularGlossiness() {
|
|
224
|
+
this._specWorkflow = true;
|
|
225
|
+
}
|
|
221
226
|
/**
|
|
222
227
|
* Sets the specular weight of the OpenPBR material.
|
|
223
228
|
* @param value The specular weight value (0-1)
|
|
@@ -330,6 +335,15 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
330
335
|
get specularIor() {
|
|
331
336
|
return this._material.specularIor;
|
|
332
337
|
}
|
|
338
|
+
/**
|
|
339
|
+
* Sets the glossiness (inverted roughness) of the OpenPBR material.
|
|
340
|
+
*/
|
|
341
|
+
set glossiness(value) {
|
|
342
|
+
this._material.specularRoughness = Math.max(1.0 - value, 0.0);
|
|
343
|
+
}
|
|
344
|
+
get glossiness() {
|
|
345
|
+
return 1.0 - this._material.specularRoughness;
|
|
346
|
+
}
|
|
333
347
|
// ========================================
|
|
334
348
|
// EMISSION PARAMETERS
|
|
335
349
|
// ========================================
|
|
@@ -455,6 +469,12 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
455
469
|
set coatColor(value) {
|
|
456
470
|
this._material.coatColor = value;
|
|
457
471
|
}
|
|
472
|
+
/**
|
|
473
|
+
* Gets the coat color of the OpenPBR material.
|
|
474
|
+
*/
|
|
475
|
+
get coatColor() {
|
|
476
|
+
return this._material.coatColor;
|
|
477
|
+
}
|
|
458
478
|
/**
|
|
459
479
|
* Sets the coat color texture of the OpenPBR material.
|
|
460
480
|
* @param value The coat color texture or null
|
|
@@ -499,6 +519,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
499
519
|
set coatIor(value) {
|
|
500
520
|
this._material.coatIor = value;
|
|
501
521
|
}
|
|
522
|
+
get coatIor() {
|
|
523
|
+
return this._material.coatIor;
|
|
524
|
+
}
|
|
502
525
|
/**
|
|
503
526
|
* Sets the coat darkening value of the OpenPBR material.
|
|
504
527
|
* @param value The coat darkening value
|
|
@@ -506,6 +529,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
506
529
|
set coatDarkening(value) {
|
|
507
530
|
this._material.coatDarkening = value;
|
|
508
531
|
}
|
|
532
|
+
get coatDarkening() {
|
|
533
|
+
return this._material.coatDarkening;
|
|
534
|
+
}
|
|
509
535
|
/**
|
|
510
536
|
* Sets the coat darkening texture (OpenPBR: coatDarkeningTexture, no PBR equivalent)
|
|
511
537
|
*/
|
|
@@ -580,6 +606,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
580
606
|
set transmissionWeightTexture(value) {
|
|
581
607
|
this._material.transmissionWeightTexture = value;
|
|
582
608
|
}
|
|
609
|
+
get transmissionWeightTexture() {
|
|
610
|
+
return this._material.transmissionWeightTexture;
|
|
611
|
+
}
|
|
583
612
|
/**
|
|
584
613
|
* Gets the transmission weight.
|
|
585
614
|
* @returns Currently returns 0 as transmission is not yet available
|
|
@@ -692,6 +721,9 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
692
721
|
// ========================================
|
|
693
722
|
// VOLUME PROPERTIES
|
|
694
723
|
// ========================================
|
|
724
|
+
/**
|
|
725
|
+
* Configures volume properties for OpenPBR material.
|
|
726
|
+
*/
|
|
695
727
|
configureVolume() {
|
|
696
728
|
// If we're configuring volume, we assume the material is not thin-walled (i.e. it's volumetric).
|
|
697
729
|
this._material.geometryThinWalled = 0.0;
|
|
@@ -748,6 +780,10 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
748
780
|
*/
|
|
749
781
|
set subsurfaceWeightTexture(value) {
|
|
750
782
|
this._material.subsurfaceWeightTexture = value;
|
|
783
|
+
this._material._useSubsurfaceWeightFromTextureAlpha = true;
|
|
784
|
+
}
|
|
785
|
+
get subsurfaceWeightTexture() {
|
|
786
|
+
return this._material.subsurfaceWeightTexture;
|
|
751
787
|
}
|
|
752
788
|
/**
|
|
753
789
|
* Sets the subsurface color.
|
|
@@ -1044,7 +1080,11 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1044
1080
|
this._material.geometryCoatNormalTexture.level = value;
|
|
1045
1081
|
}
|
|
1046
1082
|
}
|
|
1047
|
-
|
|
1083
|
+
/**
|
|
1084
|
+
* Finalizes material properties after all loading is complete.
|
|
1085
|
+
* @param loader The glTF loader; `loader._disposed` is polled between texture passes to bail early on dispose.
|
|
1086
|
+
*/
|
|
1087
|
+
async finalizeAsync(loader) {
|
|
1048
1088
|
// Do final configuration for the material to handle any interactions/dependencies between properties that we had to defer until all properties were loaded.
|
|
1049
1089
|
// If the material is volumetric, we may need to create a coat layer to handle the surface tint.
|
|
1050
1090
|
if ((this._diffuseTransmissionTint && !this._diffuseTransmissionTint.equals(Color3.White())) || this._diffuseTransmissionTintTexture) {
|
|
@@ -1054,20 +1094,10 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1054
1094
|
this.subsurfaceColorTexture = this._diffuseTransmissionTintTexture;
|
|
1055
1095
|
}
|
|
1056
1096
|
else {
|
|
1057
|
-
//
|
|
1058
|
-
|
|
1059
|
-
if (
|
|
1060
|
-
|
|
1061
|
-
this._material.coatWeightTexture = this.subsurfaceWeightTexture;
|
|
1062
|
-
this._material.coatColor = this._diffuseTransmissionTint;
|
|
1063
|
-
this._material.coatColorTexture = this._diffuseTransmissionTintTexture;
|
|
1064
|
-
this._material.coatIor = this._material.specularIor; // Use the same IOR for the coat as the specular layer to try to match the original reflection as closely as possible.
|
|
1065
|
-
this._material.coatDarkening = 0.0;
|
|
1066
|
-
this._material.coatRoughness = this._material.specularRoughness;
|
|
1067
|
-
this._material.coatRoughnessTexture = this._material.specularRoughnessTexture;
|
|
1068
|
-
// To simulate diffuse transmission, set the specular roughness to maximum and remove the roughness texture.
|
|
1069
|
-
this._material.specularRoughness = 1.0;
|
|
1070
|
-
this._material.specularRoughnessTexture = null;
|
|
1097
|
+
// Otherwise, we have volumetric attenuation so we need to use the coat layer to preserve the base color tinting of glTF.
|
|
1098
|
+
await this.copySurfaceToCoatAsync(loader, this.subsurfaceWeight, this.subsurfaceWeightTexture, TextureChannel.A, this._diffuseTransmissionTint, this._diffuseTransmissionTintTexture, true);
|
|
1099
|
+
if (loader._disposed) {
|
|
1100
|
+
return;
|
|
1071
1101
|
}
|
|
1072
1102
|
}
|
|
1073
1103
|
}
|
|
@@ -1078,17 +1108,139 @@ export class OpenPBRMaterialLoadingAdapter {
|
|
|
1078
1108
|
this._material.transmissionColor = this._material.baseColor;
|
|
1079
1109
|
this._material.transmissionColorTexture = this._material.baseColorTexture;
|
|
1080
1110
|
}
|
|
1081
|
-
else if (
|
|
1111
|
+
else if (!this.baseColor.equals(Color3.White()) || this.baseColorTexture !== null) {
|
|
1082
1112
|
// Otherwise, we have volumetric attenuation so we need to use the coat layer to preserve the base color tinting of glTF.
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1113
|
+
await this.copySurfaceToCoatAsync(loader, this.transmissionWeight, this.transmissionWeightTexture, TextureChannel.R, this.baseColor, this.baseColorTexture, false);
|
|
1114
|
+
if (loader._disposed) {
|
|
1115
|
+
return;
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
if (this._specWorkflow) {
|
|
1120
|
+
// To convert from spec-gloss to OpenPBR, we'll grab the specular color's alpha channel (which contains glossiness) and
|
|
1121
|
+
// invert it to get roughness.
|
|
1122
|
+
const newRoughnessTexture = await InvertTextureAsync("newRoughnessTexture (" + this._material.name + ")", await ExtractChannelAsync("glossiness (" + this._material.name + ")", CreateTextureWithFactorOperand(this.specularColorTexture, new Color4(this.specularColor.r, this.specularColor.g, this.specularColor.b, this.glossiness), TextureChannel.A, TextureColorSpace.Linear), TextureChannel.A, this._material.getScene(), TextureColorSpace.Linear, ChannelMask.R), this._material.getScene(), ChannelMask.R, TextureColorSpace.Linear, ChannelMask.R);
|
|
1123
|
+
if (loader._disposed) {
|
|
1124
|
+
newRoughnessTexture.texture?.dispose();
|
|
1125
|
+
return;
|
|
1126
|
+
}
|
|
1127
|
+
this.specularRoughnessTexture = newRoughnessTexture.texture;
|
|
1128
|
+
this.specularRoughness = newRoughnessTexture.factor ? newRoughnessTexture.factor.r : 1.0;
|
|
1129
|
+
// Metallic = max(linearize(specular).rgb). The specular texture is sRGB so we must
|
|
1130
|
+
// linearize it first (TextureColorSpace.SRGB). The factor is already linear per convention.
|
|
1131
|
+
// We store metallic as linear (no outputColorSpace) because it is a data/scalar value;
|
|
1132
|
+
// 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, TextureColorSpace.Linear), this._material.getScene(), false, TextureColorSpace.SRGB, ChannelMask.RGB);
|
|
1134
|
+
if (loader._disposed) {
|
|
1135
|
+
newMetallic.texture?.dispose();
|
|
1136
|
+
return;
|
|
1137
|
+
}
|
|
1138
|
+
this.baseMetalnessTexture = newMetallic.texture;
|
|
1139
|
+
this.baseMetalness = newMetallic.factor ? newMetallic.factor.r : 1.0;
|
|
1140
|
+
// base_color = lerp(diffuse, specular, metallic).
|
|
1141
|
+
// Strip dispose before passing newMetallic as t — its texture is already owned by the
|
|
1142
|
+
// 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, TextureColorSpace.Linear), CreateTextureWithFactorOperand(this.specularColorTexture, this.specularColor.toColor4(), TextureChannel.RGBA, TextureColorSpace.Linear), { ...newMetallic, dispose: undefined, colorSpace: TextureColorSpace.Linear }, this._material.getScene(), TextureColorSpace.SRGB, ChannelMask.RGB);
|
|
1144
|
+
if (loader._disposed) {
|
|
1145
|
+
newBaseColor.texture?.dispose();
|
|
1146
|
+
return;
|
|
1147
|
+
}
|
|
1148
|
+
const oldBaseColorTexture = this.baseColorTexture;
|
|
1149
|
+
oldBaseColorTexture?.dispose();
|
|
1150
|
+
this.baseColorTexture = newBaseColor.texture;
|
|
1151
|
+
this.baseColor = newBaseColor.factor ? new Color3(newBaseColor.factor.r, newBaseColor.factor.g, newBaseColor.factor.b) : Color3.White();
|
|
1152
|
+
const oldSpecularColorTexture = this.specularColorTexture;
|
|
1153
|
+
oldSpecularColorTexture?.dispose();
|
|
1154
|
+
this.specularColorTexture = null;
|
|
1155
|
+
}
|
|
1156
|
+
}
|
|
1157
|
+
async copySurfaceToCoatAsync(loader, weight, weightTexture, weightTextureChannel, color, colorTexture, diffuseTransmission = false) {
|
|
1158
|
+
// Blend coat properties using:
|
|
1159
|
+
// New coat will cover all areas that previously had coat or transmission.
|
|
1160
|
+
// new_coat_weight = max(weight, existing_coat_weight)
|
|
1161
|
+
// New coat color is the multiplication of the base color tint and the existing coat tint, each blended by their respective weights:
|
|
1162
|
+
// new_coat_color = lerp(white, existing_coat_color, existing_coat_weight)
|
|
1163
|
+
// * lerp(white, color, weight)
|
|
1164
|
+
// Snapshot the original coat properties before mutating them, so both lerps
|
|
1165
|
+
// use the pre-merge values (the first lerp blends the *existing* coat color
|
|
1166
|
+
// by the *existing* coat weight; we must not use the merged weight here).
|
|
1167
|
+
const origCoatWeight = this._material.coatWeight;
|
|
1168
|
+
const origCoatWeightTexture = this._material.coatWeightTexture;
|
|
1169
|
+
const origCoatColor = this._material.coatColor.clone();
|
|
1170
|
+
const origCoatColorTexture = this._material.coatColorTexture;
|
|
1171
|
+
const origCoatNormalTexture = this._material.geometryCoatNormalTexture;
|
|
1172
|
+
const origCoatWeightCol4 = new Color4(origCoatWeight, origCoatWeight, origCoatWeight, origCoatWeight);
|
|
1173
|
+
const weightCol4 = new Color4(weight, weight, weight, weight);
|
|
1174
|
+
this.coatWeightTexture = null;
|
|
1175
|
+
this.coatWeight = 1.0;
|
|
1176
|
+
const results = await Promise.allSettled([
|
|
1177
|
+
LerpTexturesAsync("lerpExistingCoat", CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1)), CreateTextureWithFactorOperand(origCoatColorTexture, origCoatColor.toColor4(), TextureChannel.RGBA, TextureColorSpace.SRGB), CreateTextureWithFactorOperand(origCoatWeightTexture, origCoatWeightCol4, TextureChannel.R), this._material.getScene(), TextureColorSpace.SRGB),
|
|
1178
|
+
LerpTexturesAsync("lerpSurfaceColor", CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1)), CreateTextureWithFactorOperand(colorTexture, color.toColor4(), TextureChannel.RGBA, TextureColorSpace.SRGB), CreateTextureWithFactorOperand(weightTexture, weightCol4, weightTextureChannel), this._material.getScene(), TextureColorSpace.SRGB),
|
|
1179
|
+
]);
|
|
1180
|
+
const rejected = results.find((r) => r.status === "rejected");
|
|
1181
|
+
if (rejected) {
|
|
1182
|
+
for (const r of results) {
|
|
1183
|
+
if (r.status === "fulfilled") {
|
|
1184
|
+
r.value.texture?.dispose();
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
throw rejected.reason;
|
|
1188
|
+
}
|
|
1189
|
+
const [lerpCoatColor, lerpSurfaceColor] = results.map((r) => r.value);
|
|
1190
|
+
if (loader._disposed) {
|
|
1191
|
+
lerpCoatColor.texture?.dispose();
|
|
1192
|
+
lerpSurfaceColor.texture?.dispose();
|
|
1193
|
+
return;
|
|
1194
|
+
}
|
|
1195
|
+
const newCoatColor = await MultiplyTexturesAsync("newCoatColor (" + this._material.name + ")", lerpCoatColor, lerpSurfaceColor, this._material.getScene(), TextureColorSpace.SRGB);
|
|
1196
|
+
if (loader._disposed) {
|
|
1197
|
+
newCoatColor.texture?.dispose();
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
if (newCoatColor.texture) {
|
|
1201
|
+
this.coatColorTexture = newCoatColor.texture;
|
|
1202
|
+
this.coatColor = Color3.White();
|
|
1203
|
+
}
|
|
1204
|
+
else if (newCoatColor.factor) {
|
|
1205
|
+
this.coatColorTexture = null;
|
|
1206
|
+
this.coatColor.fromArray([newCoatColor.factor.r, newCoatColor.factor.g, newCoatColor.factor.b]);
|
|
1207
|
+
}
|
|
1208
|
+
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
|
+
if (loader._disposed) {
|
|
1210
|
+
newCoatIor.texture?.dispose();
|
|
1211
|
+
return;
|
|
1212
|
+
}
|
|
1213
|
+
this.coatIor = newCoatIor.factor ? newCoatIor.factor.r : this.coatIor;
|
|
1214
|
+
const newCoatRoughness = await LerpTexturesAsync("newCoatRoughness (" + this._material.name + ")", CreateTextureWithFactorOperand(this.specularRoughnessTexture, new Color4(this.specularRoughness, this.specularRoughness, this.specularRoughness, 1.0), TextureChannel.G), CreateTextureWithFactorOperand(this.coatRoughnessTexture, new Color4(this.coatRoughness, this.coatRoughness, this.coatRoughness, 1.0), TextureChannel.G), CreateTextureWithFactorOperand(origCoatWeightTexture, origCoatWeightCol4, TextureChannel.R), this._material.getScene());
|
|
1215
|
+
if (loader._disposed) {
|
|
1216
|
+
newCoatRoughness.texture?.dispose();
|
|
1217
|
+
return;
|
|
1218
|
+
}
|
|
1219
|
+
this.coatRoughness = newCoatRoughness.factor ? newCoatRoughness.factor.r : 1.0;
|
|
1220
|
+
this.coatRoughnessTexture = newCoatRoughness.texture;
|
|
1221
|
+
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
|
+
if (loader._disposed) {
|
|
1223
|
+
newCoatDarkening.texture?.dispose();
|
|
1224
|
+
return;
|
|
1225
|
+
}
|
|
1226
|
+
this.coatDarkening = newCoatDarkening.factor ? newCoatDarkening.factor.r : this.coatDarkening;
|
|
1227
|
+
if (diffuseTransmission) {
|
|
1228
|
+
const newSpecularRoughness = await LerpTexturesAsync("newSpecularRoughness (" + this._material.name + ")", CreateTextureWithFactorOperand(this.specularRoughnessTexture, new Color4(this._material.specularRoughness, this._material.specularRoughness, this._material.specularRoughness, 1.0), TextureChannel.G), CreateTextureWithFactorOperand(null, new Color4(1, 1, 1, 1.0), TextureChannel.R), CreateTextureWithFactorOperand(weightTexture, weightCol4, weightTextureChannel), this._material.getScene());
|
|
1229
|
+
if (loader._disposed) {
|
|
1230
|
+
newSpecularRoughness.texture?.dispose();
|
|
1231
|
+
return;
|
|
1232
|
+
}
|
|
1233
|
+
this.specularRoughness = newSpecularRoughness.factor ? newSpecularRoughness.factor.r : 1.0;
|
|
1234
|
+
this.specularRoughnessTexture = newSpecularRoughness.texture;
|
|
1235
|
+
}
|
|
1236
|
+
if (origCoatNormalTexture || this.geometryNormalTexture) {
|
|
1237
|
+
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());
|
|
1238
|
+
if (loader._disposed) {
|
|
1239
|
+
newCoatNormal.texture?.dispose();
|
|
1240
|
+
return;
|
|
1241
|
+
}
|
|
1242
|
+
if (newCoatNormal.texture) {
|
|
1243
|
+
this.geometryCoatNormalTexture = newCoatNormal.texture;
|
|
1092
1244
|
}
|
|
1093
1245
|
}
|
|
1094
1246
|
}
|