@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
4,673 lines • 296 kB
JavaScript
import { z as __classPrivateFieldGet, D as __classPrivateFieldSet, l as __runInitializers, C as Constants, q as __esDecorate, aw as MaterialDefines, s as serialize, H as expandToProperty, i as Color3, as as MaterialFlags, $ as PrepareDefinesForMergedUV, ak as BindTextureMatrix, J as serializeAsTexture, K as serializeAsColor3, b3 as Vector2, a7 as VertexBuffer, a$ as serializeAsVector2, T as TmpVectors, bc as Vector4, Q as SmartArray, y as Logger, W as AreLightsTexturesReady, a4 as EffectFallbacks, a5 as HandleFallbacksForShadows, a6 as PrepareAttributesForBones, a8 as PrepareAttributesForInstances, a9 as PrepareAttributesForMorphTargets, aa as PrepareAttributesForBakedVertexAnimation, ab as PrepareUniformsAndSamplersForIBL, ae as AddClipPlaneUniforms, af as PrepareVertexPullingUniforms, ac as ImageProcessingConfiguration, ad as PrepareUniformsAndSamplersList, U as PrepareDefinesForLights, X as PrepareDefinesForMultiview, Y as PrepareDefinesForPrePass, Z as PrepareDefinesForOIT, a0 as PrepareDefinesForIBL, a1 as PrepareDefinesForMisc, a2 as PrepareDefinesForFrameBoundValues, a3 as PrepareDefinesForAttributes, ag as PrepareUniformLayoutForIBL, ah as BindBonesParameters, ai as BindVertexPullingUniforms, al as BindIBLParameters, aj as TmpColors, bf as BindIBLSamplers, am as BindClipPlane, an as BindLights, ao as Scene, ap as BindFogParameters, aq as BindMorphTargetParameters, ar as BindLogDepth, F as Material, at as ImageProcessingDefinesMixin, au as ImageProcessingMixin, av as PushMaterial, ay as _MissingSideEffectProperty } from './index-HyNDfLMI.esm.js';
import { G as GetEnvironmentBRDFTexture } from './brdfTextureTools-CrS8Z4G9.esm.js';
import { M as MaterialPluginBase, D as DetailMapConfiguration } from './material.detailMapConfiguration-C33hA3Hm.esm.js';
import { P as PrePassConfiguration, M as MaterialHelperGeometryRendering, a as PrepassDefinesMixin, U as UVDefinesMixin } from './prepass.defines-NGwPAvhm.esm.js';
/**
* @internal
*/
class MaterialBRDFDefines extends MaterialDefines {
constructor() {
super(...arguments);
this.BRDF_V_HEIGHT_CORRELATED = false;
this.MS_BRDF_ENERGY_CONSERVATION = false;
this.SPHERICAL_HARMONICS = false;
this.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = false;
this.MIX_IBL_RADIANCE_WITH_IRRADIANCE = true;
this.LEGACY_SPECULAR_ENERGY_CONSERVATION = false;
this.BASE_DIFFUSE_MODEL = 0;
this.DIELECTRIC_SPECULAR_MODEL = 0;
this.CONDUCTOR_SPECULAR_MODEL = 0;
}
}
/**
* Plugin that implements the BRDF component of the PBR material
*/
let PBRBRDFConfiguration = (() => {
var _a, _PBRBRDFConfiguration_useEnergyConservation_accessor_storage, _PBRBRDFConfiguration_useSmithVisibilityHeightCorrelated_accessor_storage, _PBRBRDFConfiguration_useSphericalHarmonics_accessor_storage, _PBRBRDFConfiguration_useSpecularGlossinessInputEnergyConservation_accessor_storage, _PBRBRDFConfiguration_mixIblRadianceWithIrradiance_accessor_storage, _PBRBRDFConfiguration_useLegacySpecularEnergyConservation_accessor_storage, _PBRBRDFConfiguration_baseDiffuseModel_accessor_storage, _PBRBRDFConfiguration_dielectricSpecularModel_accessor_storage, _PBRBRDFConfiguration_conductorSpecularModel_accessor_storage;
let _classSuper = MaterialPluginBase;
let _useEnergyConservation_decorators;
let _useEnergyConservation_initializers = [];
let _useEnergyConservation_extraInitializers = [];
let _useSmithVisibilityHeightCorrelated_decorators;
let _useSmithVisibilityHeightCorrelated_initializers = [];
let _useSmithVisibilityHeightCorrelated_extraInitializers = [];
let _useSphericalHarmonics_decorators;
let _useSphericalHarmonics_initializers = [];
let _useSphericalHarmonics_extraInitializers = [];
let _useSpecularGlossinessInputEnergyConservation_decorators;
let _useSpecularGlossinessInputEnergyConservation_initializers = [];
let _useSpecularGlossinessInputEnergyConservation_extraInitializers = [];
let _mixIblRadianceWithIrradiance_decorators;
let _mixIblRadianceWithIrradiance_initializers = [];
let _mixIblRadianceWithIrradiance_extraInitializers = [];
let _useLegacySpecularEnergyConservation_decorators;
let _useLegacySpecularEnergyConservation_initializers = [];
let _useLegacySpecularEnergyConservation_extraInitializers = [];
let _baseDiffuseModel_decorators;
let _baseDiffuseModel_initializers = [];
let _baseDiffuseModel_extraInitializers = [];
let _dielectricSpecularModel_decorators;
let _dielectricSpecularModel_initializers = [];
let _dielectricSpecularModel_extraInitializers = [];
let _conductorSpecularModel_decorators;
let _conductorSpecularModel_initializers = [];
let _conductorSpecularModel_extraInitializers = [];
return _a = class PBRBRDFConfiguration extends _classSuper {
/**
* Defines if the material uses energy conservation.
*/
get useEnergyConservation() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_useEnergyConservation_accessor_storage, "f"); }
set useEnergyConservation(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_useEnergyConservation_accessor_storage, value, "f"); }
/**
* LEGACY Mode set to false
* Defines if the material uses height smith correlated visibility term.
* If you intent to not use our default BRDF, you need to load a separate BRDF Texture for the PBR
* You can either load https://assets.babylonjs.com/environments/uncorrelatedBRDF.png
* or https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds to have more precision
* Not relying on height correlated will also disable energy conservation.
*/
get useSmithVisibilityHeightCorrelated() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_useSmithVisibilityHeightCorrelated_accessor_storage, "f"); }
set useSmithVisibilityHeightCorrelated(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_useSmithVisibilityHeightCorrelated_accessor_storage, value, "f"); }
/**
* LEGACY Mode set to false
* Defines if the material uses spherical harmonics vs spherical polynomials for the
* diffuse part of the IBL.
* The harmonics despite a tiny bigger cost has been proven to provide closer results
* to the ground truth.
*/
get useSphericalHarmonics() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_useSphericalHarmonics_accessor_storage, "f"); }
set useSphericalHarmonics(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_useSphericalHarmonics_accessor_storage, value, "f"); }
/**
* Defines if the material uses energy conservation, when the specular workflow is active.
* If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).
* If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.
* In the deactivated case, the material author has to ensure energy conservation, for a physically plausible rendering.
*/
get useSpecularGlossinessInputEnergyConservation() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_useSpecularGlossinessInputEnergyConservation_accessor_storage, "f"); }
set useSpecularGlossinessInputEnergyConservation(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_useSpecularGlossinessInputEnergyConservation_accessor_storage, value, "f"); }
/**
* Defines if IBL irradiance is used to augment rough radiance.
* If activated, irradiance is blended into the radiance contribution when the material is rough.
* This better approximates raytracing results for rough surfaces.
*/
get mixIblRadianceWithIrradiance() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_mixIblRadianceWithIrradiance_accessor_storage, "f"); }
set mixIblRadianceWithIrradiance(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_mixIblRadianceWithIrradiance_accessor_storage, value, "f"); }
/**
* Defines if the legacy specular energy conservation is used.
* If activated, the specular color is multiplied with (1. - maxChannel(albedo color)).
*/
get useLegacySpecularEnergyConservation() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_useLegacySpecularEnergyConservation_accessor_storage, "f"); }
set useLegacySpecularEnergyConservation(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_useLegacySpecularEnergyConservation_accessor_storage, value, "f"); }
/**
* Defines the base diffuse roughness model of the material.
*/
get baseDiffuseModel() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_baseDiffuseModel_accessor_storage, "f"); }
set baseDiffuseModel(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_baseDiffuseModel_accessor_storage, value, "f"); }
/**
* The material model to use for specular lighting of dielectric materials.
*/
get dielectricSpecularModel() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_dielectricSpecularModel_accessor_storage, "f"); }
set dielectricSpecularModel(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_dielectricSpecularModel_accessor_storage, value, "f"); }
/**
* The material model to use for specular lighting.
*/
get conductorSpecularModel() { return __classPrivateFieldGet(this, _PBRBRDFConfiguration_conductorSpecularModel_accessor_storage, "f"); }
set conductorSpecularModel(value) { __classPrivateFieldSet(this, _PBRBRDFConfiguration_conductorSpecularModel_accessor_storage, value, "f"); }
/** @internal */
_markAllSubMeshesAsMiscDirty() {
this._internalMarkAllSubMeshesAsMiscDirty();
}
/**
* Gets a boolean indicating that the plugin is compatible with a given shader language.
* @returns true if the plugin is compatible with the shader language
*/
isCompatible() {
return true;
}
constructor(material, addToPluginList = true) {
super(material, "PBRBRDF", 90, new MaterialBRDFDefines(), addToPluginList);
this._useEnergyConservation = _a.DEFAULT_USE_ENERGY_CONSERVATION;
_PBRBRDFConfiguration_useEnergyConservation_accessor_storage.set(this, __runInitializers(this, _useEnergyConservation_initializers, _a.DEFAULT_USE_ENERGY_CONSERVATION));
this._useSmithVisibilityHeightCorrelated = (__runInitializers(this, _useEnergyConservation_extraInitializers), _a.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED);
_PBRBRDFConfiguration_useSmithVisibilityHeightCorrelated_accessor_storage.set(this, __runInitializers(this, _useSmithVisibilityHeightCorrelated_initializers, _a.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED));
this._useSphericalHarmonics = (__runInitializers(this, _useSmithVisibilityHeightCorrelated_extraInitializers), _a.DEFAULT_USE_SPHERICAL_HARMONICS);
_PBRBRDFConfiguration_useSphericalHarmonics_accessor_storage.set(this, __runInitializers(this, _useSphericalHarmonics_initializers, _a.DEFAULT_USE_SPHERICAL_HARMONICS));
this._useSpecularGlossinessInputEnergyConservation = (__runInitializers(this, _useSphericalHarmonics_extraInitializers), _a.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION);
_PBRBRDFConfiguration_useSpecularGlossinessInputEnergyConservation_accessor_storage.set(this, __runInitializers(this, _useSpecularGlossinessInputEnergyConservation_initializers, _a.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION));
this._mixIblRadianceWithIrradiance = (__runInitializers(this, _useSpecularGlossinessInputEnergyConservation_extraInitializers), _a.DEFAULT_MIX_IBL_RADIANCE_WITH_IRRADIANCE);
_PBRBRDFConfiguration_mixIblRadianceWithIrradiance_accessor_storage.set(this, __runInitializers(this, _mixIblRadianceWithIrradiance_initializers, _a.DEFAULT_MIX_IBL_RADIANCE_WITH_IRRADIANCE));
this._useLegacySpecularEnergyConservation = (__runInitializers(this, _mixIblRadianceWithIrradiance_extraInitializers), _a.DEFAULT_USE_LEGACY_SPECULAR_ENERGY_CONSERVATION);
_PBRBRDFConfiguration_useLegacySpecularEnergyConservation_accessor_storage.set(this, __runInitializers(this, _useLegacySpecularEnergyConservation_initializers, _a.DEFAULT_USE_LEGACY_SPECULAR_ENERGY_CONSERVATION));
this._baseDiffuseModel = (__runInitializers(this, _useLegacySpecularEnergyConservation_extraInitializers), _a.DEFAULT_DIFFUSE_MODEL);
_PBRBRDFConfiguration_baseDiffuseModel_accessor_storage.set(this, __runInitializers(this, _baseDiffuseModel_initializers, _a.DEFAULT_DIFFUSE_MODEL));
this._dielectricSpecularModel = (__runInitializers(this, _baseDiffuseModel_extraInitializers), _a.DEFAULT_DIELECTRIC_SPECULAR_MODEL);
_PBRBRDFConfiguration_dielectricSpecularModel_accessor_storage.set(this, __runInitializers(this, _dielectricSpecularModel_initializers, _a.DEFAULT_DIELECTRIC_SPECULAR_MODEL));
this._conductorSpecularModel = (__runInitializers(this, _dielectricSpecularModel_extraInitializers), _a.DEFAULT_CONDUCTOR_SPECULAR_MODEL);
_PBRBRDFConfiguration_conductorSpecularModel_accessor_storage.set(this, __runInitializers(this, _conductorSpecularModel_initializers, _a.DEFAULT_CONDUCTOR_SPECULAR_MODEL));
/** @internal */
this._internalMarkAllSubMeshesAsMiscDirty = __runInitializers(this, _conductorSpecularModel_extraInitializers);
this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[Constants.MATERIAL_MiscDirtyFlag];
this._enable(true);
}
/**
* Updates the material defines for BRDF settings.
* @param defines defines the material defines to update
*/
prepareDefines(defines) {
defines.BRDF_V_HEIGHT_CORRELATED = this._useSmithVisibilityHeightCorrelated;
defines.MS_BRDF_ENERGY_CONSERVATION = this._useEnergyConservation && this._useSmithVisibilityHeightCorrelated;
defines.SPHERICAL_HARMONICS = this._useSphericalHarmonics;
defines.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = this._useSpecularGlossinessInputEnergyConservation;
defines.MIX_IBL_RADIANCE_WITH_IRRADIANCE = this._mixIblRadianceWithIrradiance && !this._material._disableLighting;
defines.LEGACY_SPECULAR_ENERGY_CONSERVATION = this._useLegacySpecularEnergyConservation;
defines.BASE_DIFFUSE_MODEL = this._baseDiffuseModel;
defines.DIELECTRIC_SPECULAR_MODEL = this._dielectricSpecularModel;
defines.CONDUCTOR_SPECULAR_MODEL = this._conductorSpecularModel;
}
getClassName() {
return "PBRBRDFConfiguration";
}
},
_PBRBRDFConfiguration_useEnergyConservation_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_useSmithVisibilityHeightCorrelated_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_useSphericalHarmonics_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_useSpecularGlossinessInputEnergyConservation_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_mixIblRadianceWithIrradiance_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_useLegacySpecularEnergyConservation_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_baseDiffuseModel_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_dielectricSpecularModel_accessor_storage = new WeakMap(),
_PBRBRDFConfiguration_conductorSpecularModel_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_useEnergyConservation_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_useSmithVisibilityHeightCorrelated_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_useSphericalHarmonics_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_useSpecularGlossinessInputEnergyConservation_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_mixIblRadianceWithIrradiance_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_useLegacySpecularEnergyConservation_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_baseDiffuseModel_decorators = [serialize("baseDiffuseModel"), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_dielectricSpecularModel_decorators = [serialize("dielectricSpecularModel"), expandToProperty("_markAllSubMeshesAsMiscDirty")];
_conductorSpecularModel_decorators = [serialize("conductorSpecularModel"), expandToProperty("_markAllSubMeshesAsMiscDirty")];
__esDecorate(_a, null, _useEnergyConservation_decorators, { kind: "accessor", name: "useEnergyConservation", static: false, private: false, access: { has: obj => "useEnergyConservation" in obj, get: obj => obj.useEnergyConservation, set: (obj, value) => { obj.useEnergyConservation = value; } }, metadata: _metadata }, _useEnergyConservation_initializers, _useEnergyConservation_extraInitializers);
__esDecorate(_a, null, _useSmithVisibilityHeightCorrelated_decorators, { kind: "accessor", name: "useSmithVisibilityHeightCorrelated", static: false, private: false, access: { has: obj => "useSmithVisibilityHeightCorrelated" in obj, get: obj => obj.useSmithVisibilityHeightCorrelated, set: (obj, value) => { obj.useSmithVisibilityHeightCorrelated = value; } }, metadata: _metadata }, _useSmithVisibilityHeightCorrelated_initializers, _useSmithVisibilityHeightCorrelated_extraInitializers);
__esDecorate(_a, null, _useSphericalHarmonics_decorators, { kind: "accessor", name: "useSphericalHarmonics", static: false, private: false, access: { has: obj => "useSphericalHarmonics" in obj, get: obj => obj.useSphericalHarmonics, set: (obj, value) => { obj.useSphericalHarmonics = value; } }, metadata: _metadata }, _useSphericalHarmonics_initializers, _useSphericalHarmonics_extraInitializers);
__esDecorate(_a, null, _useSpecularGlossinessInputEnergyConservation_decorators, { kind: "accessor", name: "useSpecularGlossinessInputEnergyConservation", static: false, private: false, access: { has: obj => "useSpecularGlossinessInputEnergyConservation" in obj, get: obj => obj.useSpecularGlossinessInputEnergyConservation, set: (obj, value) => { obj.useSpecularGlossinessInputEnergyConservation = value; } }, metadata: _metadata }, _useSpecularGlossinessInputEnergyConservation_initializers, _useSpecularGlossinessInputEnergyConservation_extraInitializers);
__esDecorate(_a, null, _mixIblRadianceWithIrradiance_decorators, { kind: "accessor", name: "mixIblRadianceWithIrradiance", static: false, private: false, access: { has: obj => "mixIblRadianceWithIrradiance" in obj, get: obj => obj.mixIblRadianceWithIrradiance, set: (obj, value) => { obj.mixIblRadianceWithIrradiance = value; } }, metadata: _metadata }, _mixIblRadianceWithIrradiance_initializers, _mixIblRadianceWithIrradiance_extraInitializers);
__esDecorate(_a, null, _useLegacySpecularEnergyConservation_decorators, { kind: "accessor", name: "useLegacySpecularEnergyConservation", static: false, private: false, access: { has: obj => "useLegacySpecularEnergyConservation" in obj, get: obj => obj.useLegacySpecularEnergyConservation, set: (obj, value) => { obj.useLegacySpecularEnergyConservation = value; } }, metadata: _metadata }, _useLegacySpecularEnergyConservation_initializers, _useLegacySpecularEnergyConservation_extraInitializers);
__esDecorate(_a, null, _baseDiffuseModel_decorators, { kind: "accessor", name: "baseDiffuseModel", static: false, private: false, access: { has: obj => "baseDiffuseModel" in obj, get: obj => obj.baseDiffuseModel, set: (obj, value) => { obj.baseDiffuseModel = value; } }, metadata: _metadata }, _baseDiffuseModel_initializers, _baseDiffuseModel_extraInitializers);
__esDecorate(_a, null, _dielectricSpecularModel_decorators, { kind: "accessor", name: "dielectricSpecularModel", static: false, private: false, access: { has: obj => "dielectricSpecularModel" in obj, get: obj => obj.dielectricSpecularModel, set: (obj, value) => { obj.dielectricSpecularModel = value; } }, metadata: _metadata }, _dielectricSpecularModel_initializers, _dielectricSpecularModel_extraInitializers);
__esDecorate(_a, null, _conductorSpecularModel_decorators, { kind: "accessor", name: "conductorSpecularModel", static: false, private: false, access: { has: obj => "conductorSpecularModel" in obj, get: obj => obj.conductorSpecularModel, set: (obj, value) => { obj.conductorSpecularModel = value; } }, metadata: _metadata }, _conductorSpecularModel_initializers, _conductorSpecularModel_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
/**
* Default value used for the energy conservation.
* This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.
*/
_a.DEFAULT_USE_ENERGY_CONSERVATION = true,
/**
* Default value used for the Smith Visibility Height Correlated mode.
* This should only be changed to adapt to the type of texture in scene.environmentBRDFTexture.
*/
_a.DEFAULT_USE_SMITH_VISIBILITY_HEIGHT_CORRELATED = true,
/**
* Default value used for the IBL diffuse part.
* This can help switching back to the polynomials mode globally which is a tiny bit
* less GPU intensive at the drawback of a lower quality.
*/
_a.DEFAULT_USE_SPHERICAL_HARMONICS = true,
/**
* Default value used for activating energy conservation for the specular workflow.
* If activated, the albedo color is multiplied with (1. - maxChannel(specular color)).
* If deactivated, a material is only physically plausible, when (albedo color + specular color) < 1.
*/
_a.DEFAULT_USE_SPECULAR_GLOSSINESS_INPUT_ENERGY_CONSERVATION = true,
/**
* Default value for whether IBL irradiance is used to augment rough radiance.
* If activated, irradiance is blended into the radiance contribution when the material is rough.
* This better approximates raytracing results for rough surfaces.
*/
_a.DEFAULT_MIX_IBL_RADIANCE_WITH_IRRADIANCE = true,
/**
* Default value for whether the legacy specular energy conservation is used.
*/
_a.DEFAULT_USE_LEGACY_SPECULAR_ENERGY_CONSERVATION = true,
/**
* Defines the default diffuse model used by the material.
*/
_a.DEFAULT_DIFFUSE_MODEL = Constants.MATERIAL_DIFFUSE_MODEL_E_OREN_NAYAR,
/**
* Defines the default dielectric specular model used by the material.
*/
_a.DEFAULT_DIELECTRIC_SPECULAR_MODEL = Constants.MATERIAL_DIELECTRIC_SPECULAR_MODEL_GLTF,
/**
* Defines the default conductor specular model used by the material.
*/
_a.DEFAULT_CONDUCTOR_SPECULAR_MODEL = Constants.MATERIAL_CONDUCTOR_SPECULAR_MODEL_GLTF,
_a;
})();
/**
* @internal
*/
class MaterialClearCoatDefines extends MaterialDefines {
constructor() {
super(...arguments);
this.CLEARCOAT = false;
this.CLEARCOAT_DEFAULTIOR = false;
this.CLEARCOAT_TEXTURE = false;
this.CLEARCOAT_TEXTURE_ROUGHNESS = false;
this.CLEARCOAT_TEXTUREDIRECTUV = 0;
this.CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV = 0;
this.CLEARCOAT_BUMP = false;
this.CLEARCOAT_BUMPDIRECTUV = 0;
this.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = false;
this.CLEARCOAT_REMAP_F0 = false;
this.CLEARCOAT_TINT = false;
this.CLEARCOAT_TINT_TEXTURE = false;
this.CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;
this.CLEARCOAT_TINT_GAMMATEXTURE = false;
}
}
/**
* Plugin that implements the clear coat component of the PBR material
*/
let PBRClearCoatConfiguration = (() => {
var _a, _PBRClearCoatConfiguration_isEnabled_accessor_storage, _PBRClearCoatConfiguration_indexOfRefraction_accessor_storage, _PBRClearCoatConfiguration_texture_accessor_storage, _PBRClearCoatConfiguration_useRoughnessFromMainTexture_accessor_storage, _PBRClearCoatConfiguration_textureRoughness_accessor_storage, _PBRClearCoatConfiguration_remapF0OnInterfaceChange_accessor_storage, _PBRClearCoatConfiguration_bumpTexture_accessor_storage, _PBRClearCoatConfiguration_isTintEnabled_accessor_storage, _PBRClearCoatConfiguration_tintTexture_accessor_storage;
let _classSuper = MaterialPluginBase;
let _isEnabled_decorators;
let _isEnabled_initializers = [];
let _isEnabled_extraInitializers = [];
let _intensity_decorators;
let _intensity_initializers = [];
let _intensity_extraInitializers = [];
let _roughness_decorators;
let _roughness_initializers = [];
let _roughness_extraInitializers = [];
let _indexOfRefraction_decorators;
let _indexOfRefraction_initializers = [];
let _indexOfRefraction_extraInitializers = [];
let _texture_decorators;
let _texture_initializers = [];
let _texture_extraInitializers = [];
let _useRoughnessFromMainTexture_decorators;
let _useRoughnessFromMainTexture_initializers = [];
let _useRoughnessFromMainTexture_extraInitializers = [];
let _textureRoughness_decorators;
let _textureRoughness_initializers = [];
let _textureRoughness_extraInitializers = [];
let _remapF0OnInterfaceChange_decorators;
let _remapF0OnInterfaceChange_initializers = [];
let _remapF0OnInterfaceChange_extraInitializers = [];
let _bumpTexture_decorators;
let _bumpTexture_initializers = [];
let _bumpTexture_extraInitializers = [];
let _isTintEnabled_decorators;
let _isTintEnabled_initializers = [];
let _isTintEnabled_extraInitializers = [];
let _tintColor_decorators;
let _tintColor_initializers = [];
let _tintColor_extraInitializers = [];
let _tintColorAtDistance_decorators;
let _tintColorAtDistance_initializers = [];
let _tintColorAtDistance_extraInitializers = [];
let _tintThickness_decorators;
let _tintThickness_initializers = [];
let _tintThickness_extraInitializers = [];
let _tintTexture_decorators;
let _tintTexture_initializers = [];
let _tintTexture_extraInitializers = [];
return _a = class PBRClearCoatConfiguration extends _classSuper {
/**
* Defines if the clear coat is enabled in the material.
*/
get isEnabled() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_isEnabled_accessor_storage, "f"); }
set isEnabled(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_isEnabled_accessor_storage, value, "f"); }
/**
* Defines the index of refraction of the clear coat.
* This defaults to 1.5 corresponding to a 0.04 f0 or a 4% reflectance at normal incidence
* The default fits with a polyurethane material.
* Changing the default value is more performance intensive.
*/
get indexOfRefraction() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_indexOfRefraction_accessor_storage, "f"); }
set indexOfRefraction(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_indexOfRefraction_accessor_storage, value, "f"); }
/**
* Stores the clear coat values in a texture (red channel is intensity and green channel is roughness)
* If useRoughnessFromMainTexture is false, the green channel of texture is not used and the green channel of textureRoughness is used instead
* if textureRoughness is not empty, else no texture roughness is used
*/
get texture() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_texture_accessor_storage, "f"); }
set texture(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_texture_accessor_storage, value, "f"); }
/**
* Indicates that the green channel of the texture property will be used for roughness (default: true)
* If false, the green channel from textureRoughness is used for roughness
*/
get useRoughnessFromMainTexture() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_useRoughnessFromMainTexture_accessor_storage, "f"); }
set useRoughnessFromMainTexture(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_useRoughnessFromMainTexture_accessor_storage, value, "f"); }
/**
* Stores the clear coat roughness in a texture (green channel)
* Not used if useRoughnessFromMainTexture is true
*/
get textureRoughness() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_textureRoughness_accessor_storage, "f"); }
set textureRoughness(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_textureRoughness_accessor_storage, value, "f"); }
/**
* Defines if the F0 value should be remapped to account for the interface change in the material.
*/
get remapF0OnInterfaceChange() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_remapF0OnInterfaceChange_accessor_storage, "f"); }
set remapF0OnInterfaceChange(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_remapF0OnInterfaceChange_accessor_storage, value, "f"); }
/**
* Define the clear coat specific bump texture.
*/
get bumpTexture() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_bumpTexture_accessor_storage, "f"); }
set bumpTexture(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_bumpTexture_accessor_storage, value, "f"); }
/**
* Defines if the clear coat tint is enabled in the material.
*/
get isTintEnabled() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_isTintEnabled_accessor_storage, "f"); }
set isTintEnabled(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_isTintEnabled_accessor_storage, value, "f"); }
/**
* Stores the clear tint values in a texture.
* rgb is tint
* a is a thickness factor
*/
get tintTexture() { return __classPrivateFieldGet(this, _PBRClearCoatConfiguration_tintTexture_accessor_storage, "f"); }
set tintTexture(value) { __classPrivateFieldSet(this, _PBRClearCoatConfiguration_tintTexture_accessor_storage, value, "f"); }
/** @internal */
_markAllSubMeshesAsTexturesDirty() {
this._enable(this._isEnabled);
this._internalMarkAllSubMeshesAsTexturesDirty();
}
/**
* Gets a boolean indicating that the plugin is compatible with a given shader language.
* @returns true if the plugin is compatible with the shader language
*/
isCompatible() {
return true;
}
constructor(material, addToPluginList = true) {
super(material, "PBRClearCoat", 100, new MaterialClearCoatDefines(), addToPluginList);
this._isEnabled = false;
_PBRClearCoatConfiguration_isEnabled_accessor_storage.set(this, __runInitializers(this, _isEnabled_initializers, false));
/**
* Defines the clear coat layer strength (between 0 and 1) it defaults to 1.
*/
this.intensity = (__runInitializers(this, _isEnabled_extraInitializers), __runInitializers(this, _intensity_initializers, 1));
/**
* Defines the clear coat layer roughness.
*/
this.roughness = (__runInitializers(this, _intensity_extraInitializers), __runInitializers(this, _roughness_initializers, 0));
this._indexOfRefraction = (__runInitializers(this, _roughness_extraInitializers), _a._DefaultIndexOfRefraction);
_PBRClearCoatConfiguration_indexOfRefraction_accessor_storage.set(this, __runInitializers(this, _indexOfRefraction_initializers, _a._DefaultIndexOfRefraction));
this._texture = (__runInitializers(this, _indexOfRefraction_extraInitializers), null);
_PBRClearCoatConfiguration_texture_accessor_storage.set(this, __runInitializers(this, _texture_initializers, null));
this._useRoughnessFromMainTexture = (__runInitializers(this, _texture_extraInitializers), true);
_PBRClearCoatConfiguration_useRoughnessFromMainTexture_accessor_storage.set(this, __runInitializers(this, _useRoughnessFromMainTexture_initializers, true));
this._textureRoughness = (__runInitializers(this, _useRoughnessFromMainTexture_extraInitializers), null);
_PBRClearCoatConfiguration_textureRoughness_accessor_storage.set(this, __runInitializers(this, _textureRoughness_initializers, null));
this._remapF0OnInterfaceChange = (__runInitializers(this, _textureRoughness_extraInitializers), true);
_PBRClearCoatConfiguration_remapF0OnInterfaceChange_accessor_storage.set(this, __runInitializers(this, _remapF0OnInterfaceChange_initializers, true));
this._bumpTexture = (__runInitializers(this, _remapF0OnInterfaceChange_extraInitializers), null);
_PBRClearCoatConfiguration_bumpTexture_accessor_storage.set(this, __runInitializers(this, _bumpTexture_initializers, null));
this._isTintEnabled = (__runInitializers(this, _bumpTexture_extraInitializers), false);
_PBRClearCoatConfiguration_isTintEnabled_accessor_storage.set(this, __runInitializers(this, _isTintEnabled_initializers, false));
/**
* Defines the clear coat tint of the material.
* This is only use if tint is enabled
*/
this.tintColor = (__runInitializers(this, _isTintEnabled_extraInitializers), __runInitializers(this, _tintColor_initializers, Color3.White()));
/**
* Defines the distance at which the tint color should be found in the
* clear coat media.
* This is only use if tint is enabled
*/
this.tintColorAtDistance = (__runInitializers(this, _tintColor_extraInitializers), __runInitializers(this, _tintColorAtDistance_initializers, 1));
/**
* Defines the clear coat layer thickness.
* This is only use if tint is enabled
*/
this.tintThickness = (__runInitializers(this, _tintColorAtDistance_extraInitializers), __runInitializers(this, _tintThickness_initializers, 1));
this._tintTexture = (__runInitializers(this, _tintThickness_extraInitializers), null);
_PBRClearCoatConfiguration_tintTexture_accessor_storage.set(this, __runInitializers(this, _tintTexture_initializers, null));
/** @internal */
this._internalMarkAllSubMeshesAsTexturesDirty = __runInitializers(this, _tintTexture_extraInitializers);
this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];
}
/**
* Checks whether the clear coat textures are ready for the sub mesh.
* @param defines defines the material defines to inspect
* @param scene defines the scene to use for readiness checks
* @param engine defines the engine to use for readiness checks
* @returns true if clear coat is ready
*/
isReadyForSubMesh(defines, scene, engine) {
if (!this._isEnabled) {
return true;
}
const disableBumpMap = this._material._disableBumpMap;
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {
if (!this._texture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._textureRoughness && MaterialFlags.ClearCoatTextureEnabled) {
if (!this._textureRoughness.isReadyOrNotBlocking()) {
return false;
}
}
if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.ClearCoatBumpTextureEnabled && !disableBumpMap) {
// Bump texture cannot be not blocking.
if (!this._bumpTexture.isReady()) {
return false;
}
}
if (this._isTintEnabled && this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {
if (!this._tintTexture.isReadyOrNotBlocking()) {
return false;
}
}
}
}
return true;
}
/**
* Updates shader defines for clear coat before attributes are processed.
* @param defines defines the material defines to update
* @param scene defines the scene to use for texture checks
*/
prepareDefinesBeforeAttributes(defines, scene) {
if (this._isEnabled) {
defines.CLEARCOAT = true;
defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = this._useRoughnessFromMainTexture;
defines.CLEARCOAT_REMAP_F0 = this._remapF0OnInterfaceChange;
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {
PrepareDefinesForMergedUV(this._texture, defines, "CLEARCOAT_TEXTURE");
}
else {
defines.CLEARCOAT_TEXTURE = false;
}
if (this._textureRoughness && MaterialFlags.ClearCoatTextureEnabled) {
PrepareDefinesForMergedUV(this._textureRoughness, defines, "CLEARCOAT_TEXTURE_ROUGHNESS");
}
else {
defines.CLEARCOAT_TEXTURE_ROUGHNESS = false;
}
if (this._bumpTexture && MaterialFlags.ClearCoatBumpTextureEnabled) {
PrepareDefinesForMergedUV(this._bumpTexture, defines, "CLEARCOAT_BUMP");
}
else {
defines.CLEARCOAT_BUMP = false;
}
defines.CLEARCOAT_DEFAULTIOR = this._indexOfRefraction === _a._DefaultIndexOfRefraction;
if (this._isTintEnabled) {
defines.CLEARCOAT_TINT = true;
if (this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {
PrepareDefinesForMergedUV(this._tintTexture, defines, "CLEARCOAT_TINT_TEXTURE");
defines.CLEARCOAT_TINT_GAMMATEXTURE = this._tintTexture.gammaSpace;
}
else {
defines.CLEARCOAT_TINT_TEXTURE = false;
}
}
else {
defines.CLEARCOAT_TINT = false;
defines.CLEARCOAT_TINT_TEXTURE = false;
}
}
}
}
else {
defines.CLEARCOAT = false;
defines.CLEARCOAT_TEXTURE = false;
defines.CLEARCOAT_TEXTURE_ROUGHNESS = false;
defines.CLEARCOAT_BUMP = false;
defines.CLEARCOAT_TINT = false;
defines.CLEARCOAT_TINT_TEXTURE = false;
defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE = false;
defines.CLEARCOAT_DEFAULTIOR = false;
defines.CLEARCOAT_TEXTUREDIRECTUV = 0;
defines.CLEARCOAT_TEXTURE_ROUGHNESSDIRECTUV = 0;
defines.CLEARCOAT_BUMPDIRECTUV = 0;
defines.CLEARCOAT_REMAP_F0 = false;
defines.CLEARCOAT_TINT_TEXTUREDIRECTUV = 0;
defines.CLEARCOAT_TINT_GAMMATEXTURE = false;
}
}
/**
* Binds clear coat data for a sub mesh.
* @param uniformBuffer defines the uniform buffer to update
* @param scene defines the scene to use for texture binding
* @param engine defines the engine to use for capability checks
* @param subMesh defines the sub mesh being rendered
*/
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
if (!this._isEnabled) {
return;
}
const defines = subMesh.materialDefines;
const isFrozen = this._material.isFrozen;
const disableBumpMap = this._material._disableBumpMap;
const invertNormalMapX = this._material._invertNormalMapX;
const invertNormalMapY = this._material._invertNormalMapY;
if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {
if ((this._texture || this._textureRoughness) && MaterialFlags.ClearCoatTextureEnabled) {
uniformBuffer.updateFloat4("vClearCoatInfos", this._texture?.coordinatesIndex ?? 0, this._texture?.level ?? 0, this._textureRoughness?.coordinatesIndex ?? 0, this._textureRoughness?.level ?? 0);
if (this._texture) {
BindTextureMatrix(this._texture, uniformBuffer, "clearCoat");
}
if (this._textureRoughness && !defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE) {
BindTextureMatrix(this._textureRoughness, uniformBuffer, "clearCoatRoughness");
}
}
if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.ClearCoatTextureEnabled && !disableBumpMap) {
uniformBuffer.updateFloat2("vClearCoatBumpInfos", this._bumpTexture.coordinatesIndex, this._bumpTexture.level);
BindTextureMatrix(this._bumpTexture, uniformBuffer, "clearCoatBump");
if (scene._mirroredCameraPosition) {
uniformBuffer.updateFloat2("vClearCoatTangentSpaceParams", invertNormalMapX ? 1.0 : -1, invertNormalMapY ? 1.0 : -1);
}
else {
uniformBuffer.updateFloat2("vClearCoatTangentSpaceParams", invertNormalMapX ? -1 : 1.0, invertNormalMapY ? -1 : 1.0);
}
}
if (this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {
uniformBuffer.updateFloat2("vClearCoatTintInfos", this._tintTexture.coordinatesIndex, this._tintTexture.level);
BindTextureMatrix(this._tintTexture, uniformBuffer, "clearCoatTint");
}
// Clear Coat General params
uniformBuffer.updateFloat2("vClearCoatParams", this.intensity, this.roughness);
// Clear Coat Refraction params
const a = 1 - this._indexOfRefraction;
const b = 1 + this._indexOfRefraction;
const f0 = Math.pow(-a / b, 2); // Schlicks approx: (ior1 - ior2) / (ior1 + ior2) where ior2 for air is close to vacuum = 1.
const eta = 1 / this._indexOfRefraction;
uniformBuffer.updateFloat4("vClearCoatRefractionParams", f0, eta, a, b);
if (this._isTintEnabled) {
uniformBuffer.updateFloat4("vClearCoatTintParams", this.tintColor.r, this.tintColor.g, this.tintColor.b, Math.max(0.00001, this.tintThickness));
uniformBuffer.updateFloat("clearCoatColorAtDistance", Math.max(0.00001, this.tintColorAtDistance));
}
}
// Textures
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.ClearCoatTextureEnabled) {
uniformBuffer.setTexture("clearCoatSampler", this._texture);
}
if (this._textureRoughness && !defines.CLEARCOAT_USE_ROUGHNESS_FROM_MAINTEXTURE && MaterialFlags.ClearCoatTextureEnabled) {
uniformBuffer.setTexture("clearCoatRoughnessSampler", this._textureRoughness);
}
if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.ClearCoatBumpTextureEnabled && !disableBumpMap) {
uniformBuffer.setTexture("clearCoatBumpSampler", this._bumpTexture);
}
if (this._isTintEnabled && this._tintTexture && MaterialFlags.ClearCoatTintTextureEnabled) {
uniformBuffer.setTexture("clearCoatTintSampler", this._tintTexture);
}
}
}
/**
* Checks whether clear coat uses a texture.
* @param texture defines the texture to check
* @returns true if the texture is used by clear coat
*/
hasTexture(texture) {
if (this._texture === texture) {
return true;
}
if (this._textureRoughness === texture) {
return true;
}
if (this._bumpTexture === texture) {
return true;
}
if (this._tintTexture === texture) {
return true;
}
return false;
}
/**
* Adds the active clear coat textures.
* @param activeTextures defines the list of active textures to update
*/
getActiveTextures(activeTextures) {
if (this._texture) {
activeTextures.push(this._texture);
}
if (this._textureRoughness) {
activeTextures.push(this._textureRoughness);
}
if (this._bumpTexture) {
activeTextures.push(this._bumpTexture);
}
if (this._tintTexture) {
activeTextures.push(this._tintTexture);
}
}
/**
* Adds the animatable clear coat textures.
* @param animatables defines the list of animatables to update
*/
getAnimatables(animatables) {
if (this._texture && this._texture.animations && this._texture.animations.length > 0) {
animatables.push(this._texture);
}
if (this._textureRoughness && this._textureRoughness.animations && this._textureRoughness.animations.length > 0) {
animatables.push(this._textureRoughness);
}
if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {
animatables.push(this._bumpTexture);
}
if (this._tintTexture && this._tintTexture.animations && this._tintTexture.animations.length > 0) {
animatables.push(this._tintTexture);
}
}
/**
* Disposes the clear coat textures.
* @param forceDisposeTextures defines whether to dispose the textures
*/
dispose(forceDisposeTextures) {
if (forceDisposeTextures) {
this._texture?.dispose();
this._textureRoughness?.dispose();
this._bumpTexture?.dispose();
this._tintTexture?.dispose();
}
}
getClassName() {
return "PBRClearCoatConfiguration";
}
addFallbacks(defines, fallbacks, currentRank) {
if (defines.CLEARCOAT_BUMP) {
fallbacks.addFallback(currentRank++, "CLEARCOAT_BUMP");
}
if (defines.CLEARCOAT_TINT) {
fallbacks.addFallback(currentRank++, "CLEARCOAT_TINT");
}
if (defines.CLEARCOAT) {
fallbacks.addFallback(currentRank++, "CLEARCOAT");
}
return currentRank;
}
/**
* Adds the clear coat sampler names.
* @param samplers defines the list of sampler names to update
*/
getSamplers(samplers) {
samplers.push("clearCoatSampler", "clearCoatRoughnessSampler", "clearCoatBumpSampler", "clearCoatTintSampler");
}
getUniforms() {
return {
ubo: [
{ name: "vClearCoatParams", size: 2, type: "vec2" },
{ name: "vClearCoatRefractionParams", size: 4, type: "vec4" },
{ name: "vClearCoatInfos", size: 4, type: "vec4" },
{ name: "clearCoatMatrix", size: 16, type: "mat4" },
{ name: "clearCoatRoughnessMatrix", size: 16, type: "mat4" },
{ name: "vClearCoatBumpInfos", size: 2, type: "vec2" },
{ name: "vClearCoatTangentSpaceParams", size: 2, type: "vec2" },
{ name: "clearCoatBumpMatrix", size: 16, type: "mat4" },
{ name: "vClearCoatTintParams", size: 4, type: "vec4" },
{ name: "clearCoatColorAtDistance", size: 1, type: "float" },
{ name: "vClearCoatTintInfos", size: 2, type: "vec2" },
{ name: "clearCoatTintMatrix", size: 16, type: "mat4" },
],
};
}
},
_PBRClearCoatConfiguration_isEnabled_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_indexOfRefraction_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_texture_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_useRoughnessFromMainTexture_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_textureRoughness_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_remapF0OnInterfaceChange_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_bumpTexture_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_isTintEnabled_accessor_storage = new WeakMap(),
_PBRClearCoatConfiguration_tintTexture_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_isEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_intensity_decorators = [serialize()];
_roughness_decorators = [serialize()];
_indexOfRefraction_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_texture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_useRoughnessFromMainTexture_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_textureRoughness_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_remapF0OnInterfaceChange_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_bumpTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_isTintEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_tintColor_decorators = [serializeAsColor3()];
_tintColorAtDistance_decorators = [serialize()];
_tintThickness_decorators = [serialize()];
_tintTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
__esDecorate(_a, null, _isEnabled_decorators, { kind: "accessor", name: "isEnabled", static: false, private: false, access: { has: obj => "isEnabled" in obj, get: obj => obj.isEnabled, set: (obj, value) => { obj.isEnabled = value; } }, metadata: _metadata }, _isEnabled_initializers, _isEnabled_extraInitializers);
__esDecorate(_a, null, _indexOfRefraction_decorators, { kind: "accessor", name: "indexOfRefraction", static: false, private: false, access: { has: obj => "indexOfRefraction" in obj, get: obj => obj.indexOfRefraction, set: (obj, value) => { obj.indexOfRefraction = value; } }, metadata: _metadata }, _indexOfRefraction_initializers, _indexOfRefraction_extraInitializers);
__esDecorate(_a, null, _texture_decorators, { kind: "accessor", name: "texture", static: false, private: false, access: { has: obj => "texture" in obj, get: obj => obj.texture, set: (obj, value) => { obj.texture = value; } }, metadata: _metadata }, _texture_initializers, _texture_extraInitializers);
__esDecorate(_a, null, _useRoughnessFromMainTexture_decorators, { kind: "accessor", name: "useRoughnessFromMainTexture", static: false, private: false, access: { has: obj => "useRoughnessFromMainTexture" in obj, get: obj => obj.useRoughnessFromMainTexture, set: (obj, value) => { obj.useRoughnessFromMainTexture = value; } }, metadata: _metadata }, _useRoughnessFromMainTexture_initializers, _useRoughnessFromMainTexture_extraInitializers);
__esDecorate(_a, null, _textureRoughness_decorators, { kind: "accessor", name: "textureRoughness", static: false, private: false, access: { has: obj => "textureRoughness" in obj, get: obj => obj.textureRoughness, set: (obj, value) => { obj.textureRoughness = value; } }, metadata: _metadata }, _textureRoughness_initializers, _textureRoughness_extraInitializers);
__esDecorate(_a, null, _remapF0OnInterfaceChange_decorators, { kind: "accessor", name: "remapF0OnInterfaceChange", static: false, private: false, access: { has: obj => "remapF0OnInterfaceChange" in obj, get: obj => obj.remapF0OnInterfaceChange, set: (obj, value) => { obj.remapF0OnInterfaceChange = value; } }, metadata: _metadata }, _remapF0OnInterfaceChange_initializers, _remapF0OnInterfaceChange_extraInitializers);
__esDecorate(_a, null, _bumpTexture_decorators, { kind: "accessor", name: "bumpTexture", static: false, private: false, access: { has: obj => "bumpTexture" in obj, get: obj => obj.bumpTexture, set: (obj, value) => { obj.bumpTexture = value; } }, metadata: _metadata }, _bumpTexture_initializers, _bumpTexture_extraInitializers);
__esDecorate(_a, null, _isTintEnabled_decorators, { kind: "accessor", name: "isTintEnabled", static: false, private: false, access: { has: obj => "isTintEnabled" in obj, get: obj => obj.isTintEnabled, set: (obj, value) => { obj.isTintEnabled = value; } }, metadata: _metadata }, _isTintEnabled_initializers, _isTintEnabled_extraInitializers);
__esDecorate(_a, null, _tintTexture_decorators, { kind: "accessor", name: "tintTexture", static: false, private: false, access: { has: obj => "tintTexture" in obj, get: obj => obj.tintTexture, set: (obj, value) => { obj.tintTexture = value; } }, metadata: _metadata }, _tintTexture_initializers, _tintTexture_extraInitializers);
__esDecorate(null, null, _intensity_decorators, { kind: "field", name: "intensity", static: false, private: false, access: { has: obj => "intensity" in obj, get: obj => obj.intensity, set: (obj, value) => { obj.intensity = value; } }, metadata: _metadata }, _intensity_initializers, _intensity_extraInitializers);
__esDecorate(null, null, _roughness_decorators, { kind: "field", name: "roughness", static: false, private: false, access: { has: obj => "roughness" in obj, get: obj => obj.roughness, set: (obj, value) => { obj.roughness = value; } }, metadata: _metadata }, _roughness_initializers, _roughness_extraInitializers);
__esDecorate(null, null, _tintColor_decorators, { kind: "field", name: "tintColor", static: false, private: false, access: { has: obj => "tintColor" in obj, get: obj => obj.tintColor, set: (obj, value) => { obj.tintColor = value; } }, metadata: _metadata }, _tintColor_initializers, _tintColor_extraInitializers);
__esDecorate(null, null, _tintColorAtDistance_decorators, { kind: "field", name: "tintColorAtDistance", static: false, private: false, access: { has: obj => "tintColorAtDistance" in obj, get: obj => obj.tintColorAtDistance, set: (obj, value) => { obj.tintColorAtDistance = value; } }, metadata: _metadata }, _tintColorAtDistance_initializers, _tintColorAtDistance_extraInitializers);
__esDecorate(null, null, _tintThickness_decorators, { kind: "field", name: "tintThickness", static: false, private: false, access: { has: obj => "tintThickness" in obj, get: obj => obj.tintThickness, set: (obj, value) => { obj.tintThickness = value; } }, metadata: _metadata }, _tintThickness_initializers, _tintThickness_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
/**
* This defaults to 1.5 corresponding to a 0.04 f0 or a 4% reflectance at normal incidence
* The default fits with a polyurethane material.
* @internal
*/
_a._DefaultIndexOfRefraction = 1.5,
_a;
})();
/**
* @internal
*/
class MaterialIridescenceDefines extends MaterialDefines {
constructor() {
super(...arguments);
this.IRIDESCENCE = false;
this.IRIDESCENCE_TEXTURE = false;
this.IRIDESCENCE_TEXTUREDIRECTUV = 0;
this.IRIDESCENCE_THICKNESS_TEXTURE = false;
this.IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV = 0;
}
}
/**
* Plugin that implements the iridescence (thin film) component of the PBR material
*/
let PBRIridescenceConfiguration = (() => {
var _a, _PBRIridescenceConfiguration_isEnabled_accessor_storage, _PBRIridescenceConfiguration_texture_accessor_storage, _PBRIridescenceConfiguration_thicknessTexture_accessor_storage;
let _classSuper = MaterialPluginBase;
let _isEnabled_decorators;
let _isEnabled_initializers = [];
let _isEnabled_extraInitializers = [];
let _intensity_decorators;
let _intensity_initializers = [];
let _intensity_extraInitializers = [];
let _minimumThickness_decorators;
let _minimumThickness_initializers = [];
let _minimumThickness_extraInitializers = [];
let _maximumThickness_decorators;
let _maximumThickness_initializers = [];
let _maximumThickness_extraInitializers = [];
let _indexOfRefraction_decorators;
let _indexOfRefraction_initializers = [];
let _indexOfRefraction_extraInitializers = [];
let _texture_decorators;
let _texture_initializers = [];
let _texture_extraInitializers = [];
let _thicknessTexture_decorators;
let _thicknessTexture_initializers = [];
let _thicknessTexture_extraInitializers = [];
return _a = class PBRIridescenceConfiguration extends _classSuper {
/**
* Defines if the iridescence is enabled in the material.
*/
get isEnabled() { return __classPrivateFieldGet(this, _PBRIridescenceConfiguration_isEnabled_accessor_storage, "f"); }
set isEnabled(value) { __classPrivateFieldSet(this, _PBRIridescenceConfiguration_isEnabled_accessor_storage, value, "f"); }
/**
* Stores the iridescence intensity in a texture (red channel)
*/
get texture() { return __classPrivateFieldGet(this, _PBRIridescenceConfiguration_texture_accessor_storage, "f"); }
set texture(value) { __classPrivateFieldSet(this, _PBRIridescenceConfiguration_texture_accessor_storage, value, "f"); }
/**
* Stores the iridescence thickness in a texture (green channel)
*/
get thicknessTexture() { return __classPrivateFieldGet(this, _PBRIridescenceConfiguration_thicknessTexture_accessor_storage, "f"); }
set thicknessTexture(value) { __classPrivateFieldSet(this, _PBRIridescenceConfiguration_thicknessTexture_accessor_storage, value, "f"); }
/** @internal */
_markAllSubMeshesAsTexturesDirty() {
this._enable(this._isEnabled);
this._internalMarkAllSubMeshesAsTexturesDirty();
}
/**
* Gets a boolean indicating that the plugin is compatible with a given shader language.
* @returns true if the plugin is compatible with the shader language
*/
isCompatible() {
return true;
}
constructor(material, addToPluginList = true) {
super(material, "PBRIridescence", 110, new MaterialIridescenceDefines(), addToPluginList);
this._isEnabled = false;
_PBRIridescenceConfiguration_isEnabled_accessor_storage.set(this, __runInitializers(this, _isEnabled_initializers, false));
/**
* Defines the iridescence layer strength (between 0 and 1) it defaults to 1.
*/
this.intensity = (__runInitializers(this, _isEnabled_extraInitializers), __runInitializers(this, _intensity_initializers, 1));
/**
* Defines the minimum thickness of the thin-film layer given in nanometers (nm).
*/
this.minimumThickness = (__runInitializers(this, _intensity_extraInitializers), __runInitializers(this, _minimumThickness_initializers, _a._DefaultMinimumThickness));
/**
* Defines the maximum thickness of the thin-film layer given in nanometers (nm). This will be the thickness used if not thickness texture has been set.
*/
this.maximumThickness = (__runInitializers(this, _minimumThickness_extraInitializers), __runInitializers(this, _maximumThickness_initializers, _a._DefaultMaximumThickness));
/**
* Defines the maximum thickness of the thin-film layer given in nanometers (nm).
*/
this.indexOfRefraction = (__runInitializers(this, _maximumThickness_extraInitializers), __runInitializers(this, _indexOfRefraction_initializers, _a._DefaultIndexOfRefraction));
this._texture = (__runInitializers(this, _indexOfRefraction_extraInitializers), null);
_PBRIridescenceConfiguration_texture_accessor_storage.set(this, __runInitializers(this, _texture_initializers, null));
this._thicknessTexture = (__runInitializers(this, _texture_extraInitializers), null);
_PBRIridescenceConfiguration_thicknessTexture_accessor_storage.set(this, __runInitializers(this, _thicknessTexture_initializers, null));
/** @internal */
this._internalMarkAllSubMeshesAsTexturesDirty = __runInitializers(this, _thicknessTexture_extraInitializers);
this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];
}
/**
* Checks whether the iridescence textures are ready for the sub mesh.
* @param defines defines the material defines to inspect
* @param scene defines the scene to use for readiness checks
* @returns true if iridescence is ready
*/
isReadyForSubMesh(defines, scene) {
if (!this._isEnabled) {
return true;
}
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.IridescenceTextureEnabled) {
if (!this._texture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {
if (!this._thicknessTexture.isReadyOrNotBlocking()) {
return false;
}
}
}
}
return true;
}
/**
* Updates shader defines for iridescence before attributes are processed.
* @param defines defines the material defines to update
* @param scene defines the scene to use for texture checks
*/
prepareDefinesBeforeAttributes(defines, scene) {
if (this._isEnabled) {
defines.IRIDESCENCE = true;
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.IridescenceTextureEnabled) {
PrepareDefinesForMergedUV(this._texture, defines, "IRIDESCENCE_TEXTURE");
}
else {
defines.IRIDESCENCE_TEXTURE = false;
}
if (this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {
PrepareDefinesForMergedUV(this._thicknessTexture, defines, "IRIDESCENCE_THICKNESS_TEXTURE");
}
else {
defines.IRIDESCENCE_THICKNESS_TEXTURE = false;
}
}
}
}
else {
defines.IRIDESCENCE = false;
defines.IRIDESCENCE_TEXTURE = false;
defines.IRIDESCENCE_THICKNESS_TEXTURE = false;
defines.IRIDESCENCE_TEXTUREDIRECTUV = 0;
defines.IRIDESCENCE_THICKNESS_TEXTUREDIRECTUV = 0;
}
}
/**
* Binds iridescence data for a sub mesh.
* @param uniformBuffer defines the uniform buffer to update
* @param scene defines the scene to use for texture binding
*/
bindForSubMesh(uniformBuffer, scene) {
if (!this._isEnabled) {
return;
}
const isFrozen = this._material.isFrozen;
if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {
if ((this._texture || this._thicknessTexture) && MaterialFlags.IridescenceTextureEnabled) {
uniformBuffer.updateFloat4("vIridescenceInfos", this._texture?.coordinatesIndex ?? 0, this._texture?.level ?? 0, this._thicknessTexture?.coordinatesIndex ?? 0, this._thicknessTexture?.level ?? 0);
if (this._texture) {
BindTextureMatrix(this._texture, uniformBuffer, "iridescence");
}
if (this._thicknessTexture) {
BindTextureMatrix(this._thicknessTexture, uniformBuffer, "iridescenceThickness");
}
}
// Clear Coat General params
uniformBuffer.updateFloat4("vIridescenceParams", this.intensity, this.indexOfRefraction, this.minimumThickness, this.maximumThickness);
}
// Textures
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.IridescenceTextureEnabled) {
uniformBuffer.setTexture("iridescenceSampler", this._texture);
}
if (this._thicknessTexture && MaterialFlags.IridescenceTextureEnabled) {
uniformBuffer.setTexture("iridescenceThicknessSampler", this._thicknessTexture);
}
}
}
/**
* Checks whether iridescence uses a texture.
* @param texture defines the texture to check
* @returns true if the texture is used by iridescence
*/
hasTexture(texture) {
if (this._texture === texture) {
return true;
}
if (this._thicknessTexture === texture) {
return true;
}
return false;
}
/**
* Adds the active iridescence textures.
* @param activeTextures defines the list of active textures to update
*/
getActiveTextures(activeTextures) {
if (this._texture) {
activeTextures.push(this._texture);
}
if (this._thicknessTexture) {
activeTextures.push(this._thicknessTexture);
}
}
/**
* Adds the animatable iridescence textures.
* @param animatables defines the list of animatables to update
*/
getAnimatables(animatables) {
if (this._texture && this._texture.animations && this._texture.animations.length > 0) {
animatables.push(this._texture);
}
if (this._thicknessTexture && this._thicknessTexture.animations && this._thicknessTexture.animations.length > 0) {
animatables.push(this._thicknessTexture);
}
}
/**
* Disposes the iridescence textures.
* @param forceDisposeTextures defines whether to dispose the textures
*/
dispose(forceDisposeTextures) {
if (forceDisposeTextures) {
this._texture?.dispose();
this._thicknessTexture?.dispose();
}
}
getClassName() {
return "PBRIridescenceConfiguration";
}
addFallbacks(defines, fallbacks, currentRank) {
if (defines.IRIDESCENCE) {
fallbacks.addFallback(currentRank++, "IRIDESCENCE");
}
return currentRank;
}
/**
* Adds the iridescence sampler names.
* @param samplers defines the list of sampler names to update
*/
getSamplers(samplers) {
samplers.push("iridescenceSampler", "iridescenceThicknessSampler");
}
getUniforms() {
return {
ubo: [
{ name: "vIridescenceParams", size: 4, type: "vec4" },
{ name: "vIridescenceInfos", size: 4, type: "vec4" },
{ name: "iridescenceMatrix", size: 16, type: "mat4" },
{ name: "iridescenceThicknessMatrix", size: 16, type: "mat4" },
],
};
}
},
_PBRIridescenceConfiguration_isEnabled_accessor_storage = new WeakMap(),
_PBRIridescenceConfiguration_texture_accessor_storage = new WeakMap(),
_PBRIridescenceConfiguration_thicknessTexture_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_isEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_intensity_decorators = [serialize()];
_minimumThickness_decorators = [serialize()];
_maximumThickness_decorators = [serialize()];
_indexOfRefraction_decorators = [serialize()];
_texture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_thicknessTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
__esDecorate(_a, null, _isEnabled_decorators, { kind: "accessor", name: "isEnabled", static: false, private: false, access: { has: obj => "isEnabled" in obj, get: obj => obj.isEnabled, set: (obj, value) => { obj.isEnabled = value; } }, metadata: _metadata }, _isEnabled_initializers, _isEnabled_extraInitializers);
__esDecorate(_a, null, _texture_decorators, { kind: "accessor", name: "texture", static: false, private: false, access: { has: obj => "texture" in obj, get: obj => obj.texture, set: (obj, value) => { obj.texture = value; } }, metadata: _metadata }, _texture_initializers, _texture_extraInitializers);
__esDecorate(_a, null, _thicknessTexture_decorators, { kind: "accessor", name: "thicknessTexture", static: false, private: false, access: { has: obj => "thicknessTexture" in obj, get: obj => obj.thicknessTexture, set: (obj, value) => { obj.thicknessTexture = value; } }, metadata: _metadata }, _thicknessTexture_initializers, _thicknessTexture_extraInitializers);
__esDecorate(null, null, _intensity_decorators, { kind: "field", name: "intensity", static: false, private: false, access: { has: obj => "intensity" in obj, get: obj => obj.intensity, set: (obj, value) => { obj.intensity = value; } }, metadata: _metadata }, _intensity_initializers, _intensity_extraInitializers);
__esDecorate(null, null, _minimumThickness_decorators, { kind: "field", name: "minimumThickness", static: false, private: false, access: { has: obj => "minimumThickness" in obj, get: obj => obj.minimumThickness, set: (obj, value) => { obj.minimumThickness = value; } }, metadata: _metadata }, _minimumThickness_initializers, _minimumThickness_extraInitializers);
__esDecorate(null, null, _maximumThickness_decorators, { kind: "field", name: "maximumThickness", static: false, private: false, access: { has: obj => "maximumThickness" in obj, get: obj => obj.maximumThickness, set: (obj, value) => { obj.maximumThickness = value; } }, metadata: _metadata }, _maximumThickness_initializers, _maximumThickness_extraInitializers);
__esDecorate(null, null, _indexOfRefraction_decorators, { kind: "field", name: "indexOfRefraction", static: false, private: false, access: { has: obj => "indexOfRefraction" in obj, get: obj => obj.indexOfRefraction, set: (obj, value) => { obj.indexOfRefraction = value; } }, metadata: _metadata }, _indexOfRefraction_initializers, _indexOfRefraction_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
/**
* The default minimum thickness of the thin-film layer given in nanometers (nm).
* Defaults to 100 nm.
* @internal
*/
_a._DefaultMinimumThickness = 100,
/**
* The default maximum thickness of the thin-film layer given in nanometers (nm).
* Defaults to 400 nm.
* @internal
*/
_a._DefaultMaximumThickness = 400,
/**
* The default index of refraction of the thin-film layer.
* Defaults to 1.3
* @internal
*/
_a._DefaultIndexOfRefraction = 1.3,
_a;
})();
/**
* @internal
*/
class MaterialAnisotropicDefines extends MaterialDefines {
constructor() {
super(...arguments);
this.ANISOTROPIC = false;
this.ANISOTROPIC_TEXTURE = false;
this.ANISOTROPIC_TEXTUREDIRECTUV = 0;
this.ANISOTROPIC_LEGACY = false;
this.MAINUV1 = false;
}
}
/**
* Plugin that implements the anisotropic component of the PBR material
*/
let PBRAnisotropicConfiguration = (() => {
var _a, _PBRAnisotropicConfiguration_isEnabled_accessor_storage, _PBRAnisotropicConfiguration_texture_accessor_storage, _PBRAnisotropicConfiguration_legacy_accessor_storage;
let _classSuper = MaterialPluginBase;
let _isEnabled_decorators;
let _isEnabled_initializers = [];
let _isEnabled_extraInitializers = [];
let _intensity_decorators;
let _intensity_initializers = [];
let _intensity_extraInitializers = [];
let _direction_decorators;
let _direction_initializers = [];
let _direction_extraInitializers = [];
let _texture_decorators;
let _texture_initializers = [];
let _texture_extraInitializers = [];
let _legacy_decorators;
let _legacy_initializers = [];
let _legacy_extraInitializers = [];
return _a = class PBRAnisotropicConfiguration extends _classSuper {
/**
* Defines if the anisotropy is enabled in the material.
*/
get isEnabled() { return __classPrivateFieldGet(this, _PBRAnisotropicConfiguration_isEnabled_accessor_storage, "f"); }
set isEnabled(value) { __classPrivateFieldSet(this, _PBRAnisotropicConfiguration_isEnabled_accessor_storage, value, "f"); }
/**
* Sets the anisotropy direction as an angle.
*/
set angle(value) {
this.direction.x = Math.cos(value);
this.direction.y = Math.sin(value);
}
/**
* Gets the anisotropy angle value in radians.
* @returns the anisotropy angle value in radians.
*/
get angle() {
return Math.atan2(this.direction.y, this.direction.x);
}
/**
* Stores the anisotropy values in a texture.
* rg is direction (like normal from -1 to 1)
* b is a intensity
*/
get texture() { return __classPrivateFieldGet(this, _PBRAnisotropicConfiguration_texture_accessor_storage, "f"); }
set texture(value) { __classPrivateFieldSet(this, _PBRAnisotropicConfiguration_texture_accessor_storage, value, "f"); }
/**
* Defines if the anisotropy is in legacy mode for backwards compatibility before 6.4.0.
*/
get legacy() { return __classPrivateFieldGet(this, _PBRAnisotropicConfiguration_legacy_accessor_storage, "f"); }
set legacy(value) { __classPrivateFieldSet(this, _PBRAnisotropicConfiguration_legacy_accessor_storage, value, "f"); }
/** @internal */
_markAllSubMeshesAsTexturesDirty() {
this._enable(this._isEnabled);
this._internalMarkAllSubMeshesAsTexturesDirty();
}
/** @internal */
_markAllSubMeshesAsMiscDirty() {
this._enable(this._isEnabled);
this._internalMarkAllSubMeshesAsMiscDirty();
}
/**
* Gets a boolean indicating that the plugin is compatible with a given shader language.
* @returns true if the plugin is compatible with the shader language
*/
isCompatible() {
return true;
}
constructor(material, addToPluginList = true) {
super(material, "PBRAnisotropic", 110, new MaterialAnisotropicDefines(), addToPluginList);
this._isEnabled = false;
_PBRAnisotropicConfiguration_isEnabled_accessor_storage.set(this, __runInitializers(this, _isEnabled_initializers, false));
/**
* Defines the anisotropy strength (between 0 and 1) it defaults to 1.
*/
this.intensity = (__runInitializers(this, _isEnabled_extraInitializers), __runInitializers(this, _intensity_initializers, 1));
/**
* Defines if the effect is along the tangents, bitangents or in between.
* By default, the effect is "stretching" the highlights along the tangents.
*/
this.direction = (__runInitializers(this, _intensity_extraInitializers), __runInitializers(this, _direction_initializers, new Vector2(1, 0)));
this._texture = (__runInitializers(this, _direction_extraInitializers), null);
_PBRAnisotropicConfiguration_texture_accessor_storage.set(this, __runInitializers(this, _texture_initializers, null));
this._legacy = (__runInitializers(this, _texture_extraInitializers), false);
_PBRAnisotropicConfiguration_legacy_accessor_storage.set(this, __runInitializers(this, _legacy_initializers, false));
/** @internal */
this._internalMarkAllSubMeshesAsTexturesDirty = __runInitializers(this, _legacy_extraInitializers);
this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];
this._internalMarkAllSubMeshesAsMiscDirty = material._dirtyCallbacks[Constants.MATERIAL_MiscDirtyFlag];
}
/**
* Checks whether the anisotropy textures are ready for the sub mesh.
* @param defines defines the material defines to inspect
* @param scene defines the scene to use for readiness checks
* @returns true if anisotropy is ready
*/
isReadyForSubMesh(defines, scene) {
if (!this._isEnabled) {
return true;
}
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {
if (!this._texture.isReadyOrNotBlocking()) {
return false;
}
}
}
}
return true;
}
/**
* Updates shader defines for anisotropy before attributes are processed.
* @param defines defines the material defines to update
* @param scene defines the scene to use for texture checks
* @param mesh defines the mesh to inspect for tangent data
*/
prepareDefinesBeforeAttributes(defines, scene, mesh) {
if (this._isEnabled) {
defines.ANISOTROPIC = this._isEnabled;
if (this._isEnabled && !mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {
defines._needUVs = true;
defines.MAINUV1 = true;
}
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {
PrepareDefinesForMergedUV(this._texture, defines, "ANISOTROPIC_TEXTURE");
}
else {
defines.ANISOTROPIC_TEXTURE = false;
}
}
}
if (defines._areMiscDirty) {
defines.ANISOTROPIC_LEGACY = this._legacy;
}
}
else {
defines.ANISOTROPIC = false;
defines.ANISOTROPIC_TEXTURE = false;
defines.ANISOTROPIC_TEXTUREDIRECTUV = 0;
defines.ANISOTROPIC_LEGACY = false;
}
}
/**
* Binds anisotropy data for a sub mesh.
* @param uniformBuffer defines the uniform buffer to update
* @param scene defines the scene to use for texture binding
*/
bindForSubMesh(uniformBuffer, scene) {
if (!this._isEnabled) {
return;
}
const isFrozen = this._material.isFrozen;
if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {
if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {
uniformBuffer.updateFloat2("vAnisotropyInfos", this._texture.coordinatesIndex, this._texture.level);
BindTextureMatrix(this._texture, uniformBuffer, "anisotropy");
}
// Anisotropy
uniformBuffer.updateFloat3("vAnisotropy", this.direction.x, this.direction.y, this.intensity);
}
// Textures
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.AnisotropicTextureEnabled) {
uniformBuffer.setTexture("anisotropySampler", this._texture);
}
}
}
/**
* Checks whether anisotropy uses a texture.
* @param texture defines the texture to check
* @returns true if the texture is used by anisotropy
*/
hasTexture(texture) {
if (this._texture === texture) {
return true;
}
return false;
}
/**
* Adds the active anisotropy textures.
* @param activeTextures defines the list of active textures to update
*/
getActiveTextures(activeTextures) {
if (this._texture) {
activeTextures.push(this._texture);
}
}
/**
* Adds the animatable anisotropy textures.
* @param animatables defines the list of animatables to update
*/
getAnimatables(animatables) {
if (this._texture && this._texture.animations && this._texture.animations.length > 0) {
animatables.push(this._texture);
}
}
/**
* Disposes the anisotropy textures.
* @param forceDisposeTextures defines whether to dispose the textures
*/
dispose(forceDisposeTextures) {
if (forceDisposeTextures) {
if (this._texture) {
this._texture.dispose();
}
}
}
getClassName() {
return "PBRAnisotropicConfiguration";
}
addFallbacks(defines, fallbacks, currentRank) {
if (defines.ANISOTROPIC) {
fallbacks.addFallback(currentRank++, "ANISOTROPIC");
}
return currentRank;
}
/**
* Adds the anisotropy sampler names.
* @param samplers defines the list of sampler names to update
*/
getSamplers(samplers) {
samplers.push("anisotropySampler");
}
getUniforms() {
return {
ubo: [
{ name: "vAnisotropy", size: 3, type: "vec3" },
{ name: "vAnisotropyInfos", size: 2, type: "vec2" },
{ name: "anisotropyMatrix", size: 16, type: "mat4" },
],
};
}
/**
* Parses a anisotropy Configuration from a serialized object.
* @param source - Serialized object.
* @param scene Defines the scene we are parsing for
* @param rootUrl Defines the rootUrl to load from
*/
parse(source, scene, rootUrl) {
super.parse(source, scene, rootUrl);
// Backward compatibility
if (source.legacy === undefined) {
this.legacy = true;
}
}
},
_PBRAnisotropicConfiguration_isEnabled_accessor_storage = new WeakMap(),
_PBRAnisotropicConfiguration_texture_accessor_storage = new WeakMap(),
_PBRAnisotropicConfiguration_legacy_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_isEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_intensity_decorators = [serialize()];
_direction_decorators = [serializeAsVector2()];
_texture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_legacy_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsMiscDirty")];
__esDecorate(_a, null, _isEnabled_decorators, { kind: "accessor", name: "isEnabled", static: false, private: false, access: { has: obj => "isEnabled" in obj, get: obj => obj.isEnabled, set: (obj, value) => { obj.isEnabled = value; } }, metadata: _metadata }, _isEnabled_initializers, _isEnabled_extraInitializers);
__esDecorate(_a, null, _texture_decorators, { kind: "accessor", name: "texture", static: false, private: false, access: { has: obj => "texture" in obj, get: obj => obj.texture, set: (obj, value) => { obj.texture = value; } }, metadata: _metadata }, _texture_initializers, _texture_extraInitializers);
__esDecorate(_a, null, _legacy_decorators, { kind: "accessor", name: "legacy", static: false, private: false, access: { has: obj => "legacy" in obj, get: obj => obj.legacy, set: (obj, value) => { obj.legacy = value; } }, metadata: _metadata }, _legacy_initializers, _legacy_extraInitializers);
__esDecorate(null, null, _intensity_decorators, { kind: "field", name: "intensity", static: false, private: false, access: { has: obj => "intensity" in obj, get: obj => obj.intensity, set: (obj, value) => { obj.intensity = value; } }, metadata: _metadata }, _intensity_initializers, _intensity_extraInitializers);
__esDecorate(null, null, _direction_decorators, { kind: "field", name: "direction", static: false, private: false, access: { has: obj => "direction" in obj, get: obj => obj.direction, set: (obj, value) => { obj.direction = value; } }, metadata: _metadata }, _direction_initializers, _direction_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
/**
* @internal
*/
class MaterialSheenDefines extends MaterialDefines {
constructor() {
super(...arguments);
this.SHEEN = false;
this.SHEEN_TEXTURE = false;
this.SHEEN_GAMMATEXTURE = false;
this.SHEEN_TEXTURE_ROUGHNESS = false;
this.SHEEN_TEXTUREDIRECTUV = 0;
this.SHEEN_TEXTURE_ROUGHNESSDIRECTUV = 0;
this.SHEEN_LINKWITHALBEDO = false;
this.SHEEN_ROUGHNESS = false;
this.SHEEN_ALBEDOSCALING = false;
this.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = false;
}
}
/**
* Plugin that implements the sheen component of the PBR material.
*/
let PBRSheenConfiguration = (() => {
var _a, _PBRSheenConfiguration_isEnabled_accessor_storage, _PBRSheenConfiguration_linkSheenWithAlbedo_accessor_storage, _PBRSheenConfiguration_texture_accessor_storage, _PBRSheenConfiguration_useRoughnessFromMainTexture_accessor_storage, _PBRSheenConfiguration_roughness_accessor_storage, _PBRSheenConfiguration_textureRoughness_accessor_storage, _PBRSheenConfiguration_albedoScaling_accessor_storage;
let _classSuper = MaterialPluginBase;
let _isEnabled_decorators;
let _isEnabled_initializers = [];
let _isEnabled_extraInitializers = [];
let _linkSheenWithAlbedo_decorators;
let _linkSheenWithAlbedo_initializers = [];
let _linkSheenWithAlbedo_extraInitializers = [];
let _intensity_decorators;
let _intensity_initializers = [];
let _intensity_extraInitializers = [];
let _color_decorators;
let _color_initializers = [];
let _color_extraInitializers = [];
let _texture_decorators;
let _texture_initializers = [];
let _texture_extraInitializers = [];
let _useRoughnessFromMainTexture_decorators;
let _useRoughnessFromMainTexture_initializers = [];
let _useRoughnessFromMainTexture_extraInitializers = [];
let _roughness_decorators;
let _roughness_initializers = [];
let _roughness_extraInitializers = [];
let _textureRoughness_decorators;
let _textureRoughness_initializers = [];
let _textureRoughness_extraInitializers = [];
let _albedoScaling_decorators;
let _albedoScaling_initializers = [];
let _albedoScaling_extraInitializers = [];
return _a = class PBRSheenConfiguration extends _classSuper {
/**
* Defines if the material uses sheen.
*/
get isEnabled() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_isEnabled_accessor_storage, "f"); }
set isEnabled(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_isEnabled_accessor_storage, value, "f"); }
/**
* Defines if the sheen is linked to the sheen color.
*/
get linkSheenWithAlbedo() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_linkSheenWithAlbedo_accessor_storage, "f"); }
set linkSheenWithAlbedo(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_linkSheenWithAlbedo_accessor_storage, value, "f"); }
/**
* Stores the sheen tint values in a texture.
* rgb is tint
* a is a intensity or roughness if the roughness property has been defined and useRoughnessFromTexture is true (in that case, textureRoughness won't be used)
* If the roughness property has been defined and useRoughnessFromTexture is false then the alpha channel is not used to modulate roughness
*/
get texture() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_texture_accessor_storage, "f"); }
set texture(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_texture_accessor_storage, value, "f"); }
/**
* Indicates that the alpha channel of the texture property will be used for roughness.
* Has no effect if the roughness (and texture!) property is not defined
*/
get useRoughnessFromMainTexture() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_useRoughnessFromMainTexture_accessor_storage, "f"); }
set useRoughnessFromMainTexture(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_useRoughnessFromMainTexture_accessor_storage, value, "f"); }
/**
* Defines the sheen roughness.
* It is not taken into account if linkSheenWithAlbedo is true.
* To stay backward compatible, material roughness is used instead if sheen roughness = null
*/
get roughness() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_roughness_accessor_storage, "f"); }
set roughness(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_roughness_accessor_storage, value, "f"); }
/**
* Stores the sheen roughness in a texture.
* alpha channel is the roughness. This texture won't be used if the texture property is not empty and useRoughnessFromTexture is true
*/
get textureRoughness() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_textureRoughness_accessor_storage, "f"); }
set textureRoughness(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_textureRoughness_accessor_storage, value, "f"); }
/**
* If true, the sheen effect is layered above the base BRDF with the albedo-scaling technique.
* It allows the strength of the sheen effect to not depend on the base color of the material,
* making it easier to setup and tweak the effect
*/
get albedoScaling() { return __classPrivateFieldGet(this, _PBRSheenConfiguration_albedoScaling_accessor_storage, "f"); }
set albedoScaling(value) { __classPrivateFieldSet(this, _PBRSheenConfiguration_albedoScaling_accessor_storage, value, "f"); }
/** @internal */
_markAllSubMeshesAsTexturesDirty() {
this._enable(this._isEnabled);
this._internalMarkAllSubMeshesAsTexturesDirty();
}
/**
* Gets a boolean indicating that the plugin is compatible with a given shader language.
* @returns true if the plugin is compatible with the shader language
*/
isCompatible() {
return true;
}
constructor(material, addToPluginList = true) {
super(material, "Sheen", 120, new MaterialSheenDefines(), addToPluginList);
this._isEnabled = false;
_PBRSheenConfiguration_isEnabled_accessor_storage.set(this, __runInitializers(this, _isEnabled_initializers, false));
this._linkSheenWithAlbedo = (__runInitializers(this, _isEnabled_extraInitializers), false);
_PBRSheenConfiguration_linkSheenWithAlbedo_accessor_storage.set(this, __runInitializers(this, _linkSheenWithAlbedo_initializers, false));
/**
* Defines the sheen intensity.
*/
this.intensity = (__runInitializers(this, _linkSheenWithAlbedo_extraInitializers), __runInitializers(this, _intensity_initializers, 1));
/**
* Defines the sheen color.
*/
this.color = (__runInitializers(this, _intensity_extraInitializers), __runInitializers(this, _color_initializers, Color3.White()));
this._texture = (__runInitializers(this, _color_extraInitializers), null);
_PBRSheenConfiguration_texture_accessor_storage.set(this, __runInitializers(this, _texture_initializers, null));
this._useRoughnessFromMainTexture = (__runInitializers(this, _texture_extraInitializers), true);
_PBRSheenConfiguration_useRoughnessFromMainTexture_accessor_storage.set(this, __runInitializers(this, _useRoughnessFromMainTexture_initializers, true));
this._roughness = (__runInitializers(this, _useRoughnessFromMainTexture_extraInitializers), null);
_PBRSheenConfiguration_roughness_accessor_storage.set(this, __runInitializers(this, _roughness_initializers, null));
this._textureRoughness = (__runInitializers(this, _roughness_extraInitializers), null);
_PBRSheenConfiguration_textureRoughness_accessor_storage.set(this, __runInitializers(this, _textureRoughness_initializers, null));
this._albedoScaling = (__runInitializers(this, _textureRoughness_extraInitializers), false);
_PBRSheenConfiguration_albedoScaling_accessor_storage.set(this, __runInitializers(this, _albedoScaling_initializers, false));
/** @internal */
this._internalMarkAllSubMeshesAsTexturesDirty = __runInitializers(this, _albedoScaling_extraInitializers);
this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];
}
/**
* Checks whether the sheen textures are ready for the sub mesh.
* @param defines defines the material defines to inspect
* @param scene defines the scene to use for readiness checks
* @returns true if sheen is ready
*/
isReadyForSubMesh(defines, scene) {
if (!this._isEnabled) {
return true;
}
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.SheenTextureEnabled) {
if (!this._texture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._textureRoughness && MaterialFlags.SheenTextureEnabled) {
if (!this._textureRoughness.isReadyOrNotBlocking()) {
return false;
}
}
}
}
return true;
}
/**
* Updates shader defines for sheen before attributes are processed.
* @param defines defines the material defines to update
* @param scene defines the scene to use for texture checks
*/
prepareDefinesBeforeAttributes(defines, scene) {
if (this._isEnabled) {
defines.SHEEN = true;
defines.SHEEN_LINKWITHALBEDO = this._linkSheenWithAlbedo;
defines.SHEEN_ROUGHNESS = this._roughness !== null;
defines.SHEEN_ALBEDOSCALING = this._albedoScaling;
defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = this._useRoughnessFromMainTexture;
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.SheenTextureEnabled) {
PrepareDefinesForMergedUV(this._texture, defines, "SHEEN_TEXTURE");
defines.SHEEN_GAMMATEXTURE = this._texture.gammaSpace;
}
else {
defines.SHEEN_TEXTURE = false;
}
if (this._textureRoughness && MaterialFlags.SheenTextureEnabled) {
PrepareDefinesForMergedUV(this._textureRoughness, defines, "SHEEN_TEXTURE_ROUGHNESS");
}
else {
defines.SHEEN_TEXTURE_ROUGHNESS = false;
}
}
}
}
else {
defines.SHEEN = false;
defines.SHEEN_TEXTURE = false;
defines.SHEEN_TEXTURE_ROUGHNESS = false;
defines.SHEEN_LINKWITHALBEDO = false;
defines.SHEEN_ROUGHNESS = false;
defines.SHEEN_ALBEDOSCALING = false;
defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE = false;
defines.SHEEN_GAMMATEXTURE = false;
defines.SHEEN_TEXTUREDIRECTUV = 0;
defines.SHEEN_TEXTURE_ROUGHNESSDIRECTUV = 0;
}
}
/**
* Binds sheen data for a sub mesh.
* @param uniformBuffer defines the uniform buffer to update
* @param scene defines the scene to use for texture binding
* @param engine defines the engine to use for capability checks
* @param subMesh defines the sub mesh being rendered
*/
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
if (!this._isEnabled) {
return;
}
const defines = subMesh.materialDefines;
const isFrozen = this._material.isFrozen;
if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {
if ((this._texture || this._textureRoughness) && MaterialFlags.SheenTextureEnabled) {
uniformBuffer.updateFloat4("vSheenInfos", this._texture?.coordinatesIndex ?? 0, this._texture?.level ?? 0, this._textureRoughness?.coordinatesIndex ?? 0, this._textureRoughness?.level ?? 0);
if (this._texture) {
BindTextureMatrix(this._texture, uniformBuffer, "sheen");
}
if (this._textureRoughness && !defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE) {
BindTextureMatrix(this._textureRoughness, uniformBuffer, "sheenRoughness");
}
}
// Sheen
uniformBuffer.updateFloat4("vSheenColor", this.color.r, this.color.g, this.color.b, this.intensity);
if (this._roughness !== null) {
uniformBuffer.updateFloat("vSheenRoughness", this._roughness);
}
}
// Textures
if (scene.texturesEnabled) {
if (this._texture && MaterialFlags.SheenTextureEnabled) {
uniformBuffer.setTexture("sheenSampler", this._texture);
}
if (this._textureRoughness && !defines.SHEEN_USE_ROUGHNESS_FROM_MAINTEXTURE && MaterialFlags.SheenTextureEnabled) {
uniformBuffer.setTexture("sheenRoughnessSampler", this._textureRoughness);
}
}
}
/**
* Checks whether sheen uses a texture.
* @param texture defines the texture to check
* @returns true if the texture is used by sheen
*/
hasTexture(texture) {
if (this._texture === texture) {
return true;
}
if (this._textureRoughness === texture) {
return true;
}
return false;
}
/**
* Adds the active sheen textures.
* @param activeTextures defines the list of active textures to update
*/
getActiveTextures(activeTextures) {
if (this._texture) {
activeTextures.push(this._texture);
}
if (this._textureRoughness) {
activeTextures.push(this._textureRoughness);
}
}
/**
* Adds the animatable sheen textures.
* @param animatables defines the list of animatables to update
*/
getAnimatables(animatables) {
if (this._texture && this._texture.animations && this._texture.animations.length > 0) {
animatables.push(this._texture);
}
if (this._textureRoughness && this._textureRoughness.animations && this._textureRoughness.animations.length > 0) {
animatables.push(this._textureRoughness);
}
}
/**
* Disposes the sheen textures.
* @param forceDisposeTextures defines whether to dispose the textures
*/
dispose(forceDisposeTextures) {
if (forceDisposeTextures) {
this._texture?.dispose();
this._textureRoughness?.dispose();
}
}
getClassName() {
return "PBRSheenConfiguration";
}
addFallbacks(defines, fallbacks, currentRank) {
if (defines.SHEEN) {
fallbacks.addFallback(currentRank++, "SHEEN");
}
return currentRank;
}
/**
* Adds the sheen sampler names.
* @param samplers defines the list of sampler names to update
*/
getSamplers(samplers) {
samplers.push("sheenSampler", "sheenRoughnessSampler");
}
getUniforms() {
return {
ubo: [
{ name: "vSheenColor", size: 4, type: "vec4" },
{ name: "vSheenRoughness", size: 1, type: "float" },
{ name: "vSheenInfos", size: 4, type: "vec4" },
{ name: "sheenMatrix", size: 16, type: "mat4" },
{ name: "sheenRoughnessMatrix", size: 16, type: "mat4" },
],
};
}
},
_PBRSheenConfiguration_isEnabled_accessor_storage = new WeakMap(),
_PBRSheenConfiguration_linkSheenWithAlbedo_accessor_storage = new WeakMap(),
_PBRSheenConfiguration_texture_accessor_storage = new WeakMap(),
_PBRSheenConfiguration_useRoughnessFromMainTexture_accessor_storage = new WeakMap(),
_PBRSheenConfiguration_roughness_accessor_storage = new WeakMap(),
_PBRSheenConfiguration_textureRoughness_accessor_storage = new WeakMap(),
_PBRSheenConfiguration_albedoScaling_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_isEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_linkSheenWithAlbedo_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_intensity_decorators = [serialize()];
_color_decorators = [serializeAsColor3()];
_texture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_useRoughnessFromMainTexture_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_roughness_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_textureRoughness_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_albedoScaling_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
__esDecorate(_a, null, _isEnabled_decorators, { kind: "accessor", name: "isEnabled", static: false, private: false, access: { has: obj => "isEnabled" in obj, get: obj => obj.isEnabled, set: (obj, value) => { obj.isEnabled = value; } }, metadata: _metadata }, _isEnabled_initializers, _isEnabled_extraInitializers);
__esDecorate(_a, null, _linkSheenWithAlbedo_decorators, { kind: "accessor", name: "linkSheenWithAlbedo", static: false, private: false, access: { has: obj => "linkSheenWithAlbedo" in obj, get: obj => obj.linkSheenWithAlbedo, set: (obj, value) => { obj.linkSheenWithAlbedo = value; } }, metadata: _metadata }, _linkSheenWithAlbedo_initializers, _linkSheenWithAlbedo_extraInitializers);
__esDecorate(_a, null, _texture_decorators, { kind: "accessor", name: "texture", static: false, private: false, access: { has: obj => "texture" in obj, get: obj => obj.texture, set: (obj, value) => { obj.texture = value; } }, metadata: _metadata }, _texture_initializers, _texture_extraInitializers);
__esDecorate(_a, null, _useRoughnessFromMainTexture_decorators, { kind: "accessor", name: "useRoughnessFromMainTexture", static: false, private: false, access: { has: obj => "useRoughnessFromMainTexture" in obj, get: obj => obj.useRoughnessFromMainTexture, set: (obj, value) => { obj.useRoughnessFromMainTexture = value; } }, metadata: _metadata }, _useRoughnessFromMainTexture_initializers, _useRoughnessFromMainTexture_extraInitializers);
__esDecorate(_a, null, _roughness_decorators, { kind: "accessor", name: "roughness", static: false, private: false, access: { has: obj => "roughness" in obj, get: obj => obj.roughness, set: (obj, value) => { obj.roughness = value; } }, metadata: _metadata }, _roughness_initializers, _roughness_extraInitializers);
__esDecorate(_a, null, _textureRoughness_decorators, { kind: "accessor", name: "textureRoughness", static: false, private: false, access: { has: obj => "textureRoughness" in obj, get: obj => obj.textureRoughness, set: (obj, value) => { obj.textureRoughness = value; } }, metadata: _metadata }, _textureRoughness_initializers, _textureRoughness_extraInitializers);
__esDecorate(_a, null, _albedoScaling_decorators, { kind: "accessor", name: "albedoScaling", static: false, private: false, access: { has: obj => "albedoScaling" in obj, get: obj => obj.albedoScaling, set: (obj, value) => { obj.albedoScaling = value; } }, metadata: _metadata }, _albedoScaling_initializers, _albedoScaling_extraInitializers);
__esDecorate(null, null, _intensity_decorators, { kind: "field", name: "intensity", static: false, private: false, access: { has: obj => "intensity" in obj, get: obj => obj.intensity, set: (obj, value) => { obj.intensity = value; } }, metadata: _metadata }, _intensity_initializers, _intensity_extraInitializers);
__esDecorate(null, null, _color_decorators, { kind: "field", name: "color", static: false, private: false, access: { has: obj => "color" in obj, get: obj => obj.color, set: (obj, value) => { obj.color = value; } }, metadata: _metadata }, _color_initializers, _color_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
_a;
})();
/**
* @internal
*/
class MaterialSubSurfaceDefines extends MaterialDefines {
constructor() {
super(...arguments);
this.SUBSURFACE = false;
this.SS_REFRACTION = false;
this.SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS = false;
this.SS_TRANSLUCENCY = false;
this.SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS = false;
this.SS_SCATTERING = false;
this.SS_DISPERSION = false;
this.SS_THICKNESSANDMASK_TEXTURE = false;
this.SS_THICKNESSANDMASK_TEXTUREDIRECTUV = 0;
this.SS_HAS_THICKNESS = false;
this.SS_REFRACTIONINTENSITY_TEXTURE = false;
this.SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV = 0;
this.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;
this.SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV = 0;
this.SS_TRANSLUCENCYCOLOR_TEXTURE = false;
this.SS_TRANSLUCENCYCOLOR_TEXTUREDIRECTUV = 0;
this.SS_TRANSLUCENCYCOLOR_TEXTURE_GAMMA = false;
this.SS_REFRACTIONMAP_3D = false;
this.SS_REFRACTIONMAP_OPPOSITEZ = false;
this.SS_LODINREFRACTIONALPHA = false;
this.SS_GAMMAREFRACTION = false;
this.SS_RGBDREFRACTION = false;
this.SS_LINEARSPECULARREFRACTION = false;
this.SS_LINKREFRACTIONTOTRANSPARENCY = false;
this.SS_ALBEDOFORREFRACTIONTINT = false;
this.SS_ALBEDOFORTRANSLUCENCYTINT = false;
this.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;
this.SS_USE_THICKNESS_AS_DEPTH = false;
this.SS_USE_GLTF_TEXTURES = false;
this.SS_APPLY_ALBEDO_AFTER_SUBSURFACE = false;
this.SS_TRANSLUCENCY_LEGACY = false;
}
}
/**
* Plugin that implements the sub surface component of the PBR material
*/
let PBRSubSurfaceConfiguration = (() => {
var _a, _PBRSubSurfaceConfiguration_isRefractionEnabled_accessor_storage, _PBRSubSurfaceConfiguration_isTranslucencyEnabled_accessor_storage, _PBRSubSurfaceConfiguration_isDispersionEnabled_accessor_storage, _PBRSubSurfaceConfiguration_isScatteringEnabled_accessor_storage, _PBRSubSurfaceConfiguration_useAlbedoToTintRefraction_accessor_storage, _PBRSubSurfaceConfiguration_useAlbedoToTintTranslucency_accessor_storage, _PBRSubSurfaceConfiguration_thicknessTexture_accessor_storage, _PBRSubSurfaceConfiguration_refractionTexture_accessor_storage, _PBRSubSurfaceConfiguration_indexOfRefraction_accessor_storage, _PBRSubSurfaceConfiguration_invertRefractionY_accessor_storage, _PBRSubSurfaceConfiguration_linkRefractionWithTransparency_accessor_storage, _PBRSubSurfaceConfiguration_useMaskFromThicknessTexture_accessor_storage, _PBRSubSurfaceConfiguration_refractionIntensityTexture_accessor_storage, _PBRSubSurfaceConfiguration_translucencyIntensityTexture_accessor_storage, _PBRSubSurfaceConfiguration_translucencyColorTexture_accessor_storage, _PBRSubSurfaceConfiguration_useGltfStyleTextures_accessor_storage;
let _classSuper = MaterialPluginBase;
let _isRefractionEnabled_decorators;
let _isRefractionEnabled_initializers = [];
let _isRefractionEnabled_extraInitializers = [];
let _isTranslucencyEnabled_decorators;
let _isTranslucencyEnabled_initializers = [];
let _isTranslucencyEnabled_extraInitializers = [];
let _isDispersionEnabled_decorators;
let _isDispersionEnabled_initializers = [];
let _isDispersionEnabled_extraInitializers = [];
let _isScatteringEnabled_decorators;
let _isScatteringEnabled_initializers = [];
let _isScatteringEnabled_extraInitializers = [];
let __scatteringDiffusionProfileIndex_decorators;
let __scatteringDiffusionProfileIndex_initializers = [];
let __scatteringDiffusionProfileIndex_extraInitializers = [];
let _refractionIntensity_decorators;
let _refractionIntensity_initializers = [];
let _refractionIntensity_extraInitializers = [];
let _translucencyIntensity_decorators;
let _translucencyIntensity_initializers = [];
let _translucencyIntensity_extraInitializers = [];
let _useAlbedoToTintRefraction_decorators;
let _useAlbedoToTintRefraction_initializers = [];
let _useAlbedoToTintRefraction_extraInitializers = [];
let _useAlbedoToTintTranslucency_decorators;
let _useAlbedoToTintTranslucency_initializers = [];
let _useAlbedoToTintTranslucency_extraInitializers = [];
let _thicknessTexture_decorators;
let _thicknessTexture_initializers = [];
let _thicknessTexture_extraInitializers = [];
let _refractionTexture_decorators;
let _refractionTexture_initializers = [];
let _refractionTexture_extraInitializers = [];
let _indexOfRefraction_decorators;
let _indexOfRefraction_initializers = [];
let _indexOfRefraction_extraInitializers = [];
let __volumeIndexOfRefraction_decorators;
let __volumeIndexOfRefraction_initializers = [];
let __volumeIndexOfRefraction_extraInitializers = [];
let _invertRefractionY_decorators;
let _invertRefractionY_initializers = [];
let _invertRefractionY_extraInitializers = [];
let _linkRefractionWithTransparency_decorators;
let _linkRefractionWithTransparency_initializers = [];
let _linkRefractionWithTransparency_extraInitializers = [];
let _minimumThickness_decorators;
let _minimumThickness_initializers = [];
let _minimumThickness_extraInitializers = [];
let _maximumThickness_decorators;
let _maximumThickness_initializers = [];
let _maximumThickness_extraInitializers = [];
let _useThicknessAsDepth_decorators;
let _useThicknessAsDepth_initializers = [];
let _useThicknessAsDepth_extraInitializers = [];
let _tintColor_decorators;
let _tintColor_initializers = [];
let _tintColor_extraInitializers = [];
let _tintColorAtDistance_decorators;
let _tintColorAtDistance_initializers = [];
let _tintColorAtDistance_extraInitializers = [];
let _dispersion_decorators;
let _dispersion_initializers = [];
let _dispersion_extraInitializers = [];
let _diffusionDistance_decorators;
let _diffusionDistance_initializers = [];
let _diffusionDistance_extraInitializers = [];
let _useMaskFromThicknessTexture_decorators;
let _useMaskFromThicknessTexture_initializers = [];
let _useMaskFromThicknessTexture_extraInitializers = [];
let _refractionIntensityTexture_decorators;
let _refractionIntensityTexture_initializers = [];
let _refractionIntensityTexture_extraInitializers = [];
let _translucencyIntensityTexture_decorators;
let _translucencyIntensityTexture_initializers = [];
let _translucencyIntensityTexture_extraInitializers = [];
let _translucencyColor_decorators;
let _translucencyColor_initializers = [];
let _translucencyColor_extraInitializers = [];
let _translucencyColorTexture_decorators;
let _translucencyColorTexture_initializers = [];
let _translucencyColorTexture_extraInitializers = [];
let _useGltfStyleTextures_decorators;
let _useGltfStyleTextures_initializers = [];
let _useGltfStyleTextures_extraInitializers = [];
let _applyAlbedoAfterSubSurface_decorators;
let _applyAlbedoAfterSubSurface_initializers = [];
let _applyAlbedoAfterSubSurface_extraInitializers = [];
let _legacyTranslucency_decorators;
let _legacyTranslucency_initializers = [];
let _legacyTranslucency_extraInitializers = [];
return _a = class PBRSubSurfaceConfiguration extends _classSuper {
/**
* Defines if the refraction is enabled in the material.
*/
get isRefractionEnabled() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_isRefractionEnabled_accessor_storage, "f"); }
set isRefractionEnabled(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_isRefractionEnabled_accessor_storage, value, "f"); }
/**
* Defines if the translucency is enabled in the material.
*/
get isTranslucencyEnabled() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_isTranslucencyEnabled_accessor_storage, "f"); }
set isTranslucencyEnabled(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_isTranslucencyEnabled_accessor_storage, value, "f"); }
/**
* Defines if dispersion is enabled in the material.
*/
get isDispersionEnabled() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_isDispersionEnabled_accessor_storage, "f"); }
set isDispersionEnabled(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_isDispersionEnabled_accessor_storage, value, "f"); }
/**
* Defines if the sub surface scattering is enabled in the material.
*/
get isScatteringEnabled() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_isScatteringEnabled_accessor_storage, "f"); }
set isScatteringEnabled(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_isScatteringEnabled_accessor_storage, value, "f"); }
/**
* Diffusion profile for subsurface scattering.
* Useful for better scattering in the skins or foliages.
*/
get scatteringDiffusionProfile() {
if (!this._scene.subSurfaceConfiguration) {
return null;
}
return this._scene.subSurfaceConfiguration.ssDiffusionProfileColors[this._scatteringDiffusionProfileIndex];
}
set scatteringDiffusionProfile(c) {
if (!this._scene.enableSubSurfaceForPrePass()) {
// Not supported
return;
}
// addDiffusionProfile automatically checks for doubles
if (c) {
this._scatteringDiffusionProfileIndex = this._scene.subSurfaceConfiguration.addDiffusionProfile(c);
}
}
/**
* When enabled, transparent surfaces will be tinted with the albedo colour (independent of thickness)
*/
get useAlbedoToTintRefraction() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_useAlbedoToTintRefraction_accessor_storage, "f"); }
set useAlbedoToTintRefraction(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_useAlbedoToTintRefraction_accessor_storage, value, "f"); }
/**
* When enabled, translucent surfaces will be tinted with the albedo colour (independent of thickness)
*/
get useAlbedoToTintTranslucency() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_useAlbedoToTintTranslucency_accessor_storage, "f"); }
set useAlbedoToTintTranslucency(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_useAlbedoToTintTranslucency_accessor_storage, value, "f"); }
/**
* Stores the average thickness of a mesh in a texture (The texture is holding the values linearly).
* The red (or green if useGltfStyleTextures=true) channel of the texture should contain the thickness remapped between 0 and 1.
* 0 would mean minimumThickness
* 1 would mean maximumThickness
* The other channels might be use as a mask to vary the different effects intensity.
*/
get thicknessTexture() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_thicknessTexture_accessor_storage, "f"); }
set thicknessTexture(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_thicknessTexture_accessor_storage, value, "f"); }
/**
* Defines the texture to use for refraction.
*/
get refractionTexture() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_refractionTexture_accessor_storage, "f"); }
set refractionTexture(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_refractionTexture_accessor_storage, value, "f"); }
/**
* Index of refraction of the material base layer.
* https://en.wikipedia.org/wiki/List_of_refractive_indices
*
* This does not only impact refraction but also the Base F0 of Dielectric Materials.
*
* From dielectric fresnel rules: F0 = square((iorT - iorI) / (iorT + iorI))
*/
get indexOfRefraction() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_indexOfRefraction_accessor_storage, "f"); }
set indexOfRefraction(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_indexOfRefraction_accessor_storage, value, "f"); }
/**
* Index of refraction of the material's volume.
* https://en.wikipedia.org/wiki/List_of_refractive_indices
*
* This ONLY impacts refraction. If not provided or given a non-valid value,
* the volume will use the same IOR as the surface.
*/
get volumeIndexOfRefraction() {
if (this._volumeIndexOfRefraction >= 1.0) {
return this._volumeIndexOfRefraction;
}
return this._indexOfRefraction;
}
set volumeIndexOfRefraction(value) {
const volumeIndexOfRefraction = value >= 1.0 ? value : -1;
if (this._volumeIndexOfRefraction === volumeIndexOfRefraction) {
return;
}
this._volumeIndexOfRefraction = volumeIndexOfRefraction;
this._markAllSubMeshesAsTexturesDirty();
}
/**
* Controls if refraction needs to be inverted on Y. This could be useful for procedural texture.
*/
get invertRefractionY() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_invertRefractionY_accessor_storage, "f"); }
set invertRefractionY(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_invertRefractionY_accessor_storage, value, "f"); }
/**
* This parameters will make the material used its opacity to control how much it is refracting against not.
* Materials half opaque for instance using refraction could benefit from this control.
*/
get linkRefractionWithTransparency() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_linkRefractionWithTransparency_accessor_storage, "f"); }
set linkRefractionWithTransparency(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_linkRefractionWithTransparency_accessor_storage, value, "f"); }
/**
* Stores the intensity of the different subsurface effects in the thickness texture.
* Note that if refractionIntensityTexture and/or translucencyIntensityTexture is provided it takes precedence over thicknessTexture + useMaskFromThicknessTexture
* * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.
* * the blue (alpha if useGltfStyleTextures = true) channel is the translucency intensity.
*/
get useMaskFromThicknessTexture() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_useMaskFromThicknessTexture_accessor_storage, "f"); }
set useMaskFromThicknessTexture(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_useMaskFromThicknessTexture_accessor_storage, value, "f"); }
/**
* Stores the intensity of the refraction. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture
* * the green (red if useGltfStyleTextures = true) channel is the refraction intensity.
*/
get refractionIntensityTexture() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_refractionIntensityTexture_accessor_storage, "f"); }
set refractionIntensityTexture(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_refractionIntensityTexture_accessor_storage, value, "f"); }
/**
* Stores the intensity of the translucency. If provided, it takes precedence over thicknessTexture + useMaskFromThicknessTexture
* * the blue (alpha if useGltfStyleTextures = true) channel is the translucency intensity.
*/
get translucencyIntensityTexture() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_translucencyIntensityTexture_accessor_storage, "f"); }
set translucencyIntensityTexture(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_translucencyIntensityTexture_accessor_storage, value, "f"); }
/**
* Defines the translucency tint color of the material as a texture.
* This is multiplied against the translucency color to add variety and realism to the material.
* If translucencyColor is not set, the tint color will be used instead.
*/
get translucencyColorTexture() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_translucencyColorTexture_accessor_storage, "f"); }
set translucencyColorTexture(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_translucencyColorTexture_accessor_storage, value, "f"); }
/**
* Use channels layout used by glTF:
* * thicknessTexture: the green (instead of red) channel is the thickness
* * thicknessTexture/refractionIntensityTexture: the red (instead of green) channel is the refraction intensity
* * thicknessTexture/translucencyIntensityTexture: the alpha (instead of blue) channel is the translucency intensity
*/
get useGltfStyleTextures() { return __classPrivateFieldGet(this, _PBRSubSurfaceConfiguration_useGltfStyleTextures_accessor_storage, "f"); }
set useGltfStyleTextures(value) { __classPrivateFieldSet(this, _PBRSubSurfaceConfiguration_useGltfStyleTextures_accessor_storage, value, "f"); }
/**
* Keeping for backward compatibility... Should not be used anymore. It has been replaced by
* the property with the correct spelling.
* @see legacyTranslucency
*/
get legacyTransluceny() {
return this.legacyTranslucency;
}
set legacyTransluceny(value) {
this.legacyTranslucency = value;
}
/** @internal */
_markAllSubMeshesAsTexturesDirty() {
this._enable(this._isRefractionEnabled || this._isTranslucencyEnabled || this._isScatteringEnabled);
this._internalMarkAllSubMeshesAsTexturesDirty();
}
/** @internal */
_markScenePrePassDirty() {
this._enable(this._isRefractionEnabled || this._isTranslucencyEnabled || this._isScatteringEnabled);
this._internalMarkAllSubMeshesAsTexturesDirty();
this._internalMarkScenePrePassDirty();
}
/**
* Gets a boolean indicating that the plugin is compatible with a given shader language.
* @returns true if the plugin is compatible with the shader language
*/
isCompatible() {
return true;
}
constructor(material, addToPluginList = true) {
super(material, "PBRSubSurface", 130, new MaterialSubSurfaceDefines(), addToPluginList);
this._isRefractionEnabled = false;
_PBRSubSurfaceConfiguration_isRefractionEnabled_accessor_storage.set(this, __runInitializers(this, _isRefractionEnabled_initializers, false));
this._isTranslucencyEnabled = (__runInitializers(this, _isRefractionEnabled_extraInitializers), false);
_PBRSubSurfaceConfiguration_isTranslucencyEnabled_accessor_storage.set(this, __runInitializers(this, _isTranslucencyEnabled_initializers, false));
this._isDispersionEnabled = (__runInitializers(this, _isTranslucencyEnabled_extraInitializers), false);
_PBRSubSurfaceConfiguration_isDispersionEnabled_accessor_storage.set(this, __runInitializers(this, _isDispersionEnabled_initializers, false));
this._isScatteringEnabled = (__runInitializers(this, _isDispersionEnabled_extraInitializers), false);
_PBRSubSurfaceConfiguration_isScatteringEnabled_accessor_storage.set(this, __runInitializers(this, _isScatteringEnabled_initializers, false));
this._scatteringDiffusionProfileIndex = (__runInitializers(this, _isScatteringEnabled_extraInitializers), __runInitializers(this, __scatteringDiffusionProfileIndex_initializers, 0));
/**
* Defines the refraction intensity of the material.
* The refraction when enabled replaces the Diffuse part of the material.
* The intensity helps transitioning between diffuse and refraction.
*/
this.refractionIntensity = (__runInitializers(this, __scatteringDiffusionProfileIndex_extraInitializers), __runInitializers(this, _refractionIntensity_initializers, 1));
/**
* Defines the translucency intensity of the material.
* When translucency has been enabled, this defines how much of the "translucency"
* is added to the diffuse part of the material.
*/
this.translucencyIntensity = (__runInitializers(this, _refractionIntensity_extraInitializers), __runInitializers(this, _translucencyIntensity_initializers, 1));
this._useAlbedoToTintRefraction = (__runInitializers(this, _translucencyIntensity_extraInitializers), false);
_PBRSubSurfaceConfiguration_useAlbedoToTintRefraction_accessor_storage.set(this, __runInitializers(this, _useAlbedoToTintRefraction_initializers, false));
this._useAlbedoToTintTranslucency = (__runInitializers(this, _useAlbedoToTintRefraction_extraInitializers), false);
_PBRSubSurfaceConfiguration_useAlbedoToTintTranslucency_accessor_storage.set(this, __runInitializers(this, _useAlbedoToTintTranslucency_initializers, false));
this._thicknessTexture = (__runInitializers(this, _useAlbedoToTintTranslucency_extraInitializers), null);
_PBRSubSurfaceConfiguration_thicknessTexture_accessor_storage.set(this, __runInitializers(this, _thicknessTexture_initializers, null));
this._refractionTexture = (__runInitializers(this, _thicknessTexture_extraInitializers), null);
_PBRSubSurfaceConfiguration_refractionTexture_accessor_storage.set(this, __runInitializers(this, _refractionTexture_initializers, null));
/** @internal */
this._indexOfRefraction = (__runInitializers(this, _refractionTexture_extraInitializers), 1.5);
_PBRSubSurfaceConfiguration_indexOfRefraction_accessor_storage.set(this, __runInitializers(this, _indexOfRefraction_initializers, 1.5));
this._volumeIndexOfRefraction = (__runInitializers(this, _indexOfRefraction_extraInitializers), __runInitializers(this, __volumeIndexOfRefraction_initializers, -1));
this._invertRefractionY = (__runInitializers(this, __volumeIndexOfRefraction_extraInitializers), false);
_PBRSubSurfaceConfiguration_invertRefractionY_accessor_storage.set(this, __runInitializers(this, _invertRefractionY_initializers, false));
/** @internal */
this._linkRefractionWithTransparency = (__runInitializers(this, _invertRefractionY_extraInitializers), false);
_PBRSubSurfaceConfiguration_linkRefractionWithTransparency_accessor_storage.set(this, __runInitializers(this, _linkRefractionWithTransparency_initializers, false));
/**
* Defines the minimum thickness stored in the thickness map.
* If no thickness map is defined, this value will be used to simulate thickness.
*/
this.minimumThickness = (__runInitializers(this, _linkRefractionWithTransparency_extraInitializers), __runInitializers(this, _minimumThickness_initializers, 0));
/**
* Defines the maximum thickness stored in the thickness map.
*/
this.maximumThickness = (__runInitializers(this, _minimumThickness_extraInitializers), __runInitializers(this, _maximumThickness_initializers, 1));
/**
* Defines that the thickness should be used as a measure of the depth volume.
*/
this.useThicknessAsDepth = (__runInitializers(this, _maximumThickness_extraInitializers), __runInitializers(this, _useThicknessAsDepth_initializers, false));
/**
* Defines the volume tint of the material.
* This is used for both translucency and scattering.
*/
this.tintColor = (__runInitializers(this, _useThicknessAsDepth_extraInitializers), __runInitializers(this, _tintColor_initializers, Color3.White()));
/**
* Defines the distance at which the tint color should be found in the media.
* This is used for refraction only.
*/
this.tintColorAtDistance = (__runInitializers(this, _tintColor_extraInitializers), __runInitializers(this, _tintColorAtDistance_initializers, 1));
/**
* Defines the Abbe number for the volume.
*/
this.dispersion = (__runInitializers(this, _tintColorAtDistance_extraInitializers), __runInitializers(this, _dispersion_initializers, 0));
/**
* Defines how far each channel transmit through the media.
* It is defined as a color to simplify it selection.
*/
this.diffusionDistance = (__runInitializers(this, _dispersion_extraInitializers), __runInitializers(this, _diffusionDistance_initializers, Color3.White()));
this._useMaskFromThicknessTexture = (__runInitializers(this, _diffusionDistance_extraInitializers), false);
_PBRSubSurfaceConfiguration_useMaskFromThicknessTexture_accessor_storage.set(this, __runInitializers(this, _useMaskFromThicknessTexture_initializers, false));
this._refractionIntensityTexture = (__runInitializers(this, _useMaskFromThicknessTexture_extraInitializers), null);
_PBRSubSurfaceConfiguration_refractionIntensityTexture_accessor_storage.set(this, __runInitializers(this, _refractionIntensityTexture_initializers, null));
this._translucencyIntensityTexture = (__runInitializers(this, _refractionIntensityTexture_extraInitializers), null);
_PBRSubSurfaceConfiguration_translucencyIntensityTexture_accessor_storage.set(this, __runInitializers(this, _translucencyIntensityTexture_initializers, null));
/**
* Defines the translucency tint of the material.
* If not set, the tint color will be used instead.
*/
this.translucencyColor = (__runInitializers(this, _translucencyIntensityTexture_extraInitializers), __runInitializers(this, _translucencyColor_initializers, null));
this._translucencyColorTexture = (__runInitializers(this, _translucencyColor_extraInitializers), null);
_PBRSubSurfaceConfiguration_translucencyColorTexture_accessor_storage.set(this, __runInitializers(this, _translucencyColorTexture_initializers, null));
this._useGltfStyleTextures = (__runInitializers(this, _translucencyColorTexture_extraInitializers), true);
_PBRSubSurfaceConfiguration_useGltfStyleTextures_accessor_storage.set(this, __runInitializers(this, _useGltfStyleTextures_initializers, true));
/**
* This property only exists for backward compatibility reasons.
* Set it to true if your rendering in 8.0+ is different from that in 7 when you use sub-surface properties (transmission, refraction, etc.). Default is false.
* Note however that the PBR calculation is wrong when this property is set to true, so only use it if you want to mimic the 7.0 behavior.
*/
this.applyAlbedoAfterSubSurface = (__runInitializers(this, _useGltfStyleTextures_extraInitializers), __runInitializers(this, _applyAlbedoAfterSubSurface_initializers, _a.DEFAULT_APPLY_ALBEDO_AFTERSUBSURFACE));
/**
* This property only exists for backward compatibility reasons.
* Set it to true if your rendering in 8.0+ is different from that in 7 when you use sub-surface translucency. Default is false.
*/
this.legacyTranslucency = (__runInitializers(this, _applyAlbedoAfterSubSurface_extraInitializers), __runInitializers(this, _legacyTranslucency_initializers, _a.DEFAULT_LEGACY_TRANSLUCENCY));
this._scene = __runInitializers(this, _legacyTranslucency_extraInitializers);
this._scene = material.getScene();
this.registerForExtraEvents = true;
this._internalMarkAllSubMeshesAsTexturesDirty = material._dirtyCallbacks[Constants.MATERIAL_TextureDirtyFlag];
this._internalMarkScenePrePassDirty = material._dirtyCallbacks[Constants.MATERIAL_PrePassDirtyFlag];
}
/**
* Checks whether the subsurface textures are ready for the sub mesh.
* @param defines defines the material defines to inspect
* @param scene defines the scene to use for readiness checks
* @returns true if subsurface is ready
*/
isReadyForSubMesh(defines, scene) {
if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {
return true;
}
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {
if (!this._thicknessTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled) {
if (!this._refractionIntensityTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._translucencyColorTexture && MaterialFlags.TranslucencyColorTextureEnabled) {
if (!this._translucencyColorTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled) {
if (!this._translucencyIntensityTexture.isReadyOrNotBlocking()) {
return false;
}
}
const refractionTexture = this._getRefractionTexture(scene);
if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {
if (!refractionTexture.isReadyOrNotBlocking()) {
return false;
}
}
}
}
return true;
}
/**
* Updates shader defines for subsurface rendering before attributes are processed.
* @param defines defines the material defines to update
* @param scene defines the scene to use for texture checks
*/
prepareDefinesBeforeAttributes(defines, scene) {
if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {
defines.SUBSURFACE = false;
defines.SS_DISPERSION = false;
defines.SS_TRANSLUCENCY = false;
defines.SS_SCATTERING = false;
defines.SS_REFRACTION = false;
defines.SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS = false;
defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS = false;
defines.SS_THICKNESSANDMASK_TEXTURE = false;
defines.SS_THICKNESSANDMASK_TEXTUREDIRECTUV = 0;
defines.SS_HAS_THICKNESS = false;
defines.SS_REFRACTIONINTENSITY_TEXTURE = false;
defines.SS_REFRACTIONINTENSITY_TEXTUREDIRECTUV = 0;
defines.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;
defines.SS_TRANSLUCENCYINTENSITY_TEXTUREDIRECTUV = 0;
defines.SS_REFRACTIONMAP_3D = false;
defines.SS_REFRACTIONMAP_OPPOSITEZ = false;
defines.SS_LODINREFRACTIONALPHA = false;
defines.SS_GAMMAREFRACTION = false;
defines.SS_RGBDREFRACTION = false;
defines.SS_LINEARSPECULARREFRACTION = false;
defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;
defines.SS_ALBEDOFORREFRACTIONTINT = false;
defines.SS_ALBEDOFORTRANSLUCENCYTINT = false;
defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;
defines.SS_USE_THICKNESS_AS_DEPTH = false;
defines.SS_USE_GLTF_TEXTURES = false;
defines.SS_TRANSLUCENCYCOLOR_TEXTURE = false;
defines.SS_TRANSLUCENCYCOLOR_TEXTUREDIRECTUV = 0;
defines.SS_TRANSLUCENCYCOLOR_TEXTURE_GAMMA = false;
defines.SS_APPLY_ALBEDO_AFTER_SUBSURFACE = false;
return;
}
if (defines._areTexturesDirty) {
defines.SUBSURFACE = true;
defines.SS_DISPERSION = this._isDispersionEnabled;
defines.SS_TRANSLUCENCY = this._isTranslucencyEnabled;
defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS = false;
defines.SS_TRANSLUCENCY_LEGACY = this.legacyTranslucency;
defines.SS_SCATTERING = this._isScatteringEnabled;
defines.SS_THICKNESSANDMASK_TEXTURE = false;
defines.SS_REFRACTIONINTENSITY_TEXTURE = false;
defines.SS_TRANSLUCENCYINTENSITY_TEXTURE = false;
defines.SS_HAS_THICKNESS = false;
defines.SS_USE_GLTF_TEXTURES = false;
defines.SS_REFRACTION = false;
defines.SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS = false;
defines.SS_REFRACTIONMAP_3D = false;
defines.SS_GAMMAREFRACTION = false;
defines.SS_RGBDREFRACTION = false;
defines.SS_LINEARSPECULARREFRACTION = false;
defines.SS_REFRACTIONMAP_OPPOSITEZ = false;
defines.SS_LODINREFRACTIONALPHA = false;
defines.SS_LINKREFRACTIONTOTRANSPARENCY = false;
defines.SS_ALBEDOFORREFRACTIONTINT = false;
defines.SS_ALBEDOFORTRANSLUCENCYTINT = false;
defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = false;
defines.SS_USE_THICKNESS_AS_DEPTH = false;
defines.SS_TRANSLUCENCYCOLOR_TEXTURE = false;
defines.SS_APPLY_ALBEDO_AFTER_SUBSURFACE = this.applyAlbedoAfterSubSurface;
if (defines._areTexturesDirty) {
if (scene.texturesEnabled) {
if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {
PrepareDefinesForMergedUV(this._thicknessTexture, defines, "SS_THICKNESSANDMASK_TEXTURE");
}
if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled) {
PrepareDefinesForMergedUV(this._refractionIntensityTexture, defines, "SS_REFRACTIONINTENSITY_TEXTURE");
}
if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled) {
PrepareDefinesForMergedUV(this._translucencyIntensityTexture, defines, "SS_TRANSLUCENCYINTENSITY_TEXTURE");
}
if (this._translucencyColorTexture && MaterialFlags.TranslucencyColorTextureEnabled) {
PrepareDefinesForMergedUV(this._translucencyColorTexture, defines, "SS_TRANSLUCENCYCOLOR_TEXTURE");
defines.SS_TRANSLUCENCYCOLOR_TEXTURE_GAMMA = this._translucencyColorTexture.gammaSpace;
}
}
}
defines.SS_HAS_THICKNESS = this.maximumThickness - this.minimumThickness !== 0.0;
defines.SS_USE_GLTF_TEXTURES = this._useGltfStyleTextures;
defines.SS_REFRACTION_USE_INTENSITY_FROM_THICKNESS = this._useMaskFromThicknessTexture && !this._refractionIntensityTexture;
defines.SS_TRANSLUCENCY_USE_INTENSITY_FROM_THICKNESS = this._useMaskFromThicknessTexture && !this._translucencyIntensityTexture;
if (this._isRefractionEnabled) {
if (scene.texturesEnabled) {
const refractionTexture = this._getRefractionTexture(scene);
if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {
defines.SS_REFRACTION = true;
defines.SS_REFRACTIONMAP_3D = refractionTexture.isCube;
defines.SS_GAMMAREFRACTION = refractionTexture.gammaSpace;
defines.SS_RGBDREFRACTION = refractionTexture.isRGBD;
defines.SS_LINEARSPECULARREFRACTION = refractionTexture.linearSpecularLOD;
defines.SS_REFRACTIONMAP_OPPOSITEZ = this._scene.useRightHandedSystem && refractionTexture.isCube ? !refractionTexture.invertZ : refractionTexture.invertZ;
defines.SS_LODINREFRACTIONALPHA = refractionTexture.lodLevelInAlpha;
defines.SS_LINKREFRACTIONTOTRANSPARENCY = this._linkRefractionWithTransparency;
defines.SS_ALBEDOFORREFRACTIONTINT = this._useAlbedoToTintRefraction;
defines.SS_USE_LOCAL_REFRACTIONMAP_CUBIC = refractionTexture.isCube && refractionTexture.boundingBoxSize;
defines.SS_USE_THICKNESS_AS_DEPTH = this.useThicknessAsDepth;
}
}
}
if (this._isTranslucencyEnabled) {
defines.SS_ALBEDOFORTRANSLUCENCYTINT = this._useAlbedoToTintTranslucency;
}
}
}
/**
* Binds the material data (this function is called even if mustRebind() returns false)
* @param uniformBuffer defines the Uniform buffer to fill in.
* @param scene defines the scene the material belongs to.
* @param engine defines the engine the material belongs to.
* @param subMesh the submesh to bind data for
*/
hardBindForSubMesh(uniformBuffer, scene, engine, subMesh) {
if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {
return;
}
// If min/max thickness is 0, avoid decompising to determine the scaled thickness (it's always zero).
if (this.maximumThickness === 0.0 && this.minimumThickness === 0.0) {
uniformBuffer.updateFloat2("vThicknessParam", 0, 0);
}
else {
subMesh.getRenderingMesh().getWorldMatrix().decompose(TmpVectors.Vector3[0]);
const thicknessScale = Math.max(Math.abs(TmpVectors.Vector3[0].x), Math.abs(TmpVectors.Vector3[0].y), Math.abs(TmpVectors.Vector3[0].z));
uniformBuffer.updateFloat2("vThicknessParam", this.minimumThickness * thicknessScale, (this.maximumThickness - this.minimumThickness) * thicknessScale);
}
}
/**
* Binds subsurface data for a sub mesh.
* @param uniformBuffer defines the uniform buffer to update
* @param scene defines the scene to use for texture binding
* @param engine defines the engine used for binding
* @param subMesh defines the sub mesh being rendered
*/
bindForSubMesh(uniformBuffer, scene, engine, subMesh) {
if (!this._isRefractionEnabled && !this._isTranslucencyEnabled && !this._isScatteringEnabled) {
return;
}
const defines = subMesh.materialDefines;
const isFrozen = this._material.isFrozen;
const realTimeFiltering = this._material.realTimeFiltering;
const lodBasedMicrosurface = defines.LODBASEDMICROSFURACE;
const refractionTexture = this._getRefractionTexture(scene);
if (!uniformBuffer.useUbo || !isFrozen || !uniformBuffer.isSync) {
if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {
uniformBuffer.updateFloat2("vThicknessInfos", this._thicknessTexture.coordinatesIndex, this._thicknessTexture.level);
BindTextureMatrix(this._thicknessTexture, uniformBuffer, "thickness");
}
if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && defines.SS_REFRACTIONINTENSITY_TEXTURE) {
uniformBuffer.updateFloat2("vRefractionIntensityInfos", this._refractionIntensityTexture.coordinatesIndex, this._refractionIntensityTexture.level);
BindTextureMatrix(this._refractionIntensityTexture, uniformBuffer, "refractionIntensity");
}
if (this._translucencyColorTexture && MaterialFlags.TranslucencyColorTextureEnabled && defines.SS_TRANSLUCENCYCOLOR_TEXTURE) {
uniformBuffer.updateFloat2("vTranslucencyColorInfos", this._translucencyColorTexture.coordinatesIndex, this._translucencyColorTexture.level);
BindTextureMatrix(this._translucencyColorTexture, uniformBuffer, "translucencyColor");
}
if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && defines.SS_TRANSLUCENCYINTENSITY_TEXTURE) {
uniformBuffer.updateFloat2("vTranslucencyIntensityInfos", this._translucencyIntensityTexture.coordinatesIndex, this._translucencyIntensityTexture.level);
BindTextureMatrix(this._translucencyIntensityTexture, uniformBuffer, "translucencyIntensity");
}
if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {
uniformBuffer.updateMatrix("refractionMatrix", refractionTexture.getRefractionTextureMatrix());
let depth = 1.0;
if (!refractionTexture.isCube) {
if (refractionTexture.depth) {
depth = refractionTexture.depth;
}
}
const width = refractionTexture.getSize().width;
const refractionIor = this.volumeIndexOfRefraction;
uniformBuffer.updateFloat4("vRefractionInfos", refractionTexture.level, 1 / refractionIor, depth, this._invertRefractionY ? -1 : 1);
uniformBuffer.updateFloat4("vRefractionMicrosurfaceInfos", width, refractionTexture.lodGenerationScale, refractionTexture.lodGenerationOffset, 1.0 / this.indexOfRefraction);
if (realTimeFiltering) {
uniformBuffer.updateFloat2("vRefractionFilteringInfo", width, Math.log2(width));
}
if (refractionTexture.boundingBoxSize) {
const cubeTexture = refractionTexture;
uniformBuffer.updateVector3("vRefractionPosition", cubeTexture.boundingBoxPosition);
uniformBuffer.updateVector3("vRefractionSize", cubeTexture.boundingBoxSize);
}
}
if (this._isScatteringEnabled) {
uniformBuffer.updateFloat("scatteringDiffusionProfile", this._scatteringDiffusionProfileIndex);
}
uniformBuffer.updateColor3("vDiffusionDistance", this.diffusionDistance);
uniformBuffer.updateFloat4("vTintColor", this.tintColor.r, this.tintColor.g, this.tintColor.b, Math.max(0.00001, this.tintColorAtDistance));
uniformBuffer.updateColor4("vTranslucencyColor", this.translucencyColor ?? this.tintColor, 0);
uniformBuffer.updateFloat3("vSubSurfaceIntensity", this.refractionIntensity, this.translucencyIntensity, 0);
uniformBuffer.updateFloat("dispersion", this.dispersion);
}
// Textures
if (scene.texturesEnabled) {
if (this._thicknessTexture && MaterialFlags.ThicknessTextureEnabled) {
uniformBuffer.setTexture("thicknessSampler", this._thicknessTexture);
}
if (this._refractionIntensityTexture && MaterialFlags.RefractionIntensityTextureEnabled && defines.SS_REFRACTIONINTENSITY_TEXTURE) {
uniformBuffer.setTexture("refractionIntensitySampler", this._refractionIntensityTexture);
}
if (this._translucencyIntensityTexture && MaterialFlags.TranslucencyIntensityTextureEnabled && defines.SS_TRANSLUCENCYINTENSITY_TEXTURE) {
uniformBuffer.setTexture("translucencyIntensitySampler", this._translucencyIntensityTexture);
}
if (this._translucencyColorTexture && MaterialFlags.TranslucencyColorTextureEnabled && defines.SS_TRANSLUCENCYCOLOR_TEXTURE) {
uniformBuffer.setTexture("translucencyColorSampler", this._translucencyColorTexture);
}
if (refractionTexture && MaterialFlags.RefractionTextureEnabled) {
if (lodBasedMicrosurface) {
uniformBuffer.setTexture("refractionSampler", refractionTexture);
}
else {
uniformBuffer.setTexture("refractionSampler", refractionTexture._lodTextureMid || refractionTexture);
uniformBuffer.setTexture("refractionSamplerLow", refractionTexture._lodTextureLow || refractionTexture);
uniformBuffer.setTexture("refractionSamplerHigh", refractionTexture._lodTextureHigh || refractionTexture);
}
}
}
}
/**
* Returns the texture used for refraction or null if none is used.
* @param scene defines the scene the material belongs to.
* @returns - Refraction texture if present. If no refraction texture and refraction
* is linked with transparency, returns environment texture. Otherwise, returns null.
*/
_getRefractionTexture(scene) {
if (this._refractionTexture) {
return this._refractionTexture;
}
if (this._isRefractionEnabled) {
return scene.environmentTexture;
}
return null;
}
/**
* Returns true if alpha blending should be disabled.
*/
get disableAlphaBlending() {
return this._isRefractionEnabled && this._linkRefractionWithTransparency;
}
/**
* Fills the list of render target textures.
* @param renderTargets the list of render targets to update
*/
fillRenderTargetTextures(renderTargets) {
if (MaterialFlags.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {
renderTargets.push(this._refractionTexture);
}
}
/**
* Checks whether subsurface rendering uses a texture.
* @param texture defines the texture to check
* @returns true if the texture is used by subsurface rendering
*/
hasTexture(texture) {
if (this._thicknessTexture === texture) {
return true;
}
if (this._refractionTexture === texture) {
return true;
}
if (this._refractionIntensityTexture === texture) {
return true;
}
if (this._translucencyIntensityTexture === texture) {
return true;
}
if (this._translucencyColorTexture === texture) {
return true;
}
return false;
}
hasRenderTargetTextures() {
if (MaterialFlags.RefractionTextureEnabled && this._refractionTexture && this._refractionTexture.isRenderTarget) {
return true;
}
return false;
}
/**
* Adds the active subsurface textures.
* @param activeTextures defines the list of active textures to update
*/
getActiveTextures(activeTextures) {
if (this._thicknessTexture) {
activeTextures.push(this._thicknessTexture);
}
if (this._refractionTexture) {
activeTextures.push(this._refractionTexture);
}
if (this._refractionIntensityTexture) {
activeTextures.push(this._refractionIntensityTexture);
}
if (this._translucencyColorTexture) {
activeTextures.push(this._translucencyColorTexture);
}
if (this._translucencyIntensityTexture) {
activeTextures.push(this._translucencyIntensityTexture);
}
}
/**
* Adds the animatable subsurface textures.
* @param animatables defines the list of animatables to update
*/
getAnimatables(animatables) {
if (this._thicknessTexture && this._thicknessTexture.animations && this._thicknessTexture.animations.length > 0) {
animatables.push(this._thicknessTexture);
}
if (this._refractionTexture && this._refractionTexture.animations && this._refractionTexture.animations.length > 0) {
animatables.push(this._refractionTexture);
}
if (this._refractionIntensityTexture && this._refractionIntensityTexture.animations && this._refractionIntensityTexture.animations.length > 0) {
animatables.push(this._refractionIntensityTexture);
}
if (this._translucencyColorTexture && this._translucencyColorTexture.animations && this._translucencyColorTexture.animations.length > 0) {
animatables.push(this._translucencyColorTexture);
}
if (this._translucencyIntensityTexture && this._translucencyIntensityTexture.animations && this._translucencyIntensityTexture.animations.length > 0) {
animatables.push(this._translucencyIntensityTexture);
}
}
/**
* Disposes the subsurface textures.
* @param forceDisposeTextures defines whether to dispose the textures
*/
dispose(forceDisposeTextures) {
if (forceDisposeTextures) {
if (this._thicknessTexture) {
this._thicknessTexture.dispose();
}
if (this._refractionTexture) {
this._refractionTexture.dispose();
}
if (this._refractionIntensityTexture) {
this._refractionIntensityTexture.dispose();
}
if (this._translucencyColorTexture) {
this._translucencyColorTexture.dispose();
}
if (this._translucencyIntensityTexture) {
this._translucencyIntensityTexture.dispose();
}
}
}
getClassName() {
return "PBRSubSurfaceConfiguration";
}
addFallbacks(defines, fallbacks, currentRank) {
if (defines.SS_SCATTERING) {
fallbacks.addFallback(currentRank++, "SS_SCATTERING");
}
if (defines.SS_TRANSLUCENCY) {
fallbacks.addFallback(currentRank++, "SS_TRANSLUCENCY");
}
return currentRank;
}
/**
* Adds the subsurface sampler names.
* @param samplers defines the list of sampler names to update
*/
getSamplers(samplers) {
samplers.push("thicknessSampler", "refractionIntensitySampler", "translucencyIntensitySampler", "refractionSampler", "refractionSamplerLow", "refractionSamplerHigh", "translucencyColorSampler");
}
getUniforms() {
return {
ubo: [
{ name: "vRefractionMicrosurfaceInfos", size: 4, type: "vec4" },
{ name: "vRefractionFilteringInfo", size: 2, type: "vec2" },
{ name: "vTranslucencyIntensityInfos", size: 2, type: "vec2" },
{ name: "vRefractionInfos", size: 4, type: "vec4" },
{ name: "refractionMatrix", size: 16, type: "mat4" },
{ name: "vThicknessInfos", size: 2, type: "vec2" },
{ name: "vRefractionIntensityInfos", size: 2, type: "vec2" },
{ name: "thicknessMatrix", size: 16, type: "mat4" },
{ name: "refractionIntensityMatrix", size: 16, type: "mat4" },
{ name: "translucencyIntensityMatrix", size: 16, type: "mat4" },
{ name: "vThicknessParam", size: 2, type: "vec2" },
{ name: "vDiffusionDistance", size: 3, type: "vec3" },
{ name: "vTintColor", size: 4, type: "vec4" },
{ name: "vSubSurfaceIntensity", size: 3, type: "vec3" },
{ name: "vRefractionPosition", size: 3, type: "vec3" },
{ name: "vRefractionSize", size: 3, type: "vec3" },
{ name: "scatteringDiffusionProfile", size: 1, type: "float" },
{ name: "dispersion", size: 1, type: "float" },
{ name: "vTranslucencyColor", size: 4, type: "vec4" },
{ name: "vTranslucencyColorInfos", size: 2, type: "vec2" },
{ name: "translucencyColorMatrix", size: 16, type: "mat4" },
],
};
}
},
_PBRSubSurfaceConfiguration_isRefractionEnabled_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_isTranslucencyEnabled_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_isDispersionEnabled_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_isScatteringEnabled_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_useAlbedoToTintRefraction_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_useAlbedoToTintTranslucency_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_thicknessTexture_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_refractionTexture_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_indexOfRefraction_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_invertRefractionY_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_linkRefractionWithTransparency_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_useMaskFromThicknessTexture_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_refractionIntensityTexture_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_translucencyIntensityTexture_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_translucencyColorTexture_accessor_storage = new WeakMap(),
_PBRSubSurfaceConfiguration_useGltfStyleTextures_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_isRefractionEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_isTranslucencyEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_isDispersionEnabled_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_isScatteringEnabled_decorators = [serialize(), expandToProperty("_markScenePrePassDirty")];
__scatteringDiffusionProfileIndex_decorators = [serialize()];
_refractionIntensity_decorators = [serialize()];
_translucencyIntensity_decorators = [serialize()];
_useAlbedoToTintRefraction_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_useAlbedoToTintTranslucency_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_thicknessTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_refractionTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_indexOfRefraction_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
__volumeIndexOfRefraction_decorators = [serialize()];
_invertRefractionY_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_linkRefractionWithTransparency_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_minimumThickness_decorators = [serialize()];
_maximumThickness_decorators = [serialize()];
_useThicknessAsDepth_decorators = [serialize()];
_tintColor_decorators = [serializeAsColor3()];
_tintColorAtDistance_decorators = [serialize()];
_dispersion_decorators = [serialize()];
_diffusionDistance_decorators = [serializeAsColor3()];
_useMaskFromThicknessTexture_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_refractionIntensityTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_translucencyIntensityTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_translucencyColor_decorators = [serializeAsColor3()];
_translucencyColorTexture_decorators = [serializeAsTexture(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_useGltfStyleTextures_decorators = [serialize(), expandToProperty("_markAllSubMeshesAsTexturesDirty")];
_applyAlbedoAfterSubSurface_decorators = [serialize()];
_legacyTranslucency_decorators = [serialize()];
__esDecorate(_a, null, _isRefractionEnabled_decorators, { kind: "accessor", name: "isRefractionEnabled", static: false, private: false, access: { has: obj => "isRefractionEnabled" in obj, get: obj => obj.isRefractionEnabled, set: (obj, value) => { obj.isRefractionEnabled = value; } }, metadata: _metadata }, _isRefractionEnabled_initializers, _isRefractionEnabled_extraInitializers);
__esDecorate(_a, null, _isTranslucencyEnabled_decorators, { kind: "accessor", name: "isTranslucencyEnabled", static: false, private: false, access: { has: obj => "isTranslucencyEnabled" in obj, get: obj => obj.isTranslucencyEnabled, set: (obj, value) => { obj.isTranslucencyEnabled = value; } }, metadata: _metadata }, _isTranslucencyEnabled_initializers, _isTranslucencyEnabled_extraInitializers);
__esDecorate(_a, null, _isDispersionEnabled_decorators, { kind: "accessor", name: "isDispersionEnabled", static: false, private: false, access: { has: obj => "isDispersionEnabled" in obj, get: obj => obj.isDispersionEnabled, set: (obj, value) => { obj.isDispersionEnabled = value; } }, metadata: _metadata }, _isDispersionEnabled_initializers, _isDispersionEnabled_extraInitializers);
__esDecorate(_a, null, _isScatteringEnabled_decorators, { kind: "accessor", name: "isScatteringEnabled", static: false, private: false, access: { has: obj => "isScatteringEnabled" in obj, get: obj => obj.isScatteringEnabled, set: (obj, value) => { obj.isScatteringEnabled = value; } }, metadata: _metadata }, _isScatteringEnabled_initializers, _isScatteringEnabled_extraInitializers);
__esDecorate(_a, null, _useAlbedoToTintRefraction_decorators, { kind: "accessor", name: "useAlbedoToTintRefraction", static: false, private: false, access: { has: obj => "useAlbedoToTintRefraction" in obj, get: obj => obj.useAlbedoToTintRefraction, set: (obj, value) => { obj.useAlbedoToTintRefraction = value; } }, metadata: _metadata }, _useAlbedoToTintRefraction_initializers, _useAlbedoToTintRefraction_extraInitializers);
__esDecorate(_a, null, _useAlbedoToTintTranslucency_decorators, { kind: "accessor", name: "useAlbedoToTintTranslucency", static: false, private: false, access: { has: obj => "useAlbedoToTintTranslucency" in obj, get: obj => obj.useAlbedoToTintTranslucency, set: (obj, value) => { obj.useAlbedoToTintTranslucency = value; } }, metadata: _metadata }, _useAlbedoToTintTranslucency_initializers, _useAlbedoToTintTranslucency_extraInitializers);
__esDecorate(_a, null, _thicknessTexture_decorators, { kind: "accessor", name: "thicknessTexture", static: false, private: false, access: { has: obj => "thicknessTexture" in obj, get: obj => obj.thicknessTexture, set: (obj, value) => { obj.thicknessTexture = value; } }, metadata: _metadata }, _thicknessTexture_initializers, _thicknessTexture_extraInitializers);
__esDecorate(_a, null, _refractionTexture_decorators, { kind: "accessor", name: "refractionTexture", static: false, private: false, access: { has: obj => "refractionTexture" in obj, get: obj => obj.refractionTexture, set: (obj, value) => { obj.refractionTexture = value; } }, metadata: _metadata }, _refractionTexture_initializers, _refractionTexture_extraInitializers);
__esDecorate(_a, null, _indexOfRefraction_decorators, { kind: "accessor", name: "indexOfRefraction", static: false, private: false, access: { has: obj => "indexOfRefraction" in obj, get: obj => obj.indexOfRefraction, set: (obj, value) => { obj.indexOfRefraction = value; } }, metadata: _metadata }, _indexOfRefraction_initializers, _indexOfRefraction_extraInitializers);
__esDecorate(_a, null, _invertRefractionY_decorators, { kind: "accessor", name: "invertRefractionY", static: false, private: false, access: { has: obj => "invertRefractionY" in obj, get: obj => obj.invertRefractionY, set: (obj, value) => { obj.invertRefractionY = value; } }, metadata: _metadata }, _invertRefractionY_initializers, _invertRefractionY_extraInitializers);
__esDecorate(_a, null, _linkRefractionWithTransparency_decorators, { kind: "accessor", name: "linkRefractionWithTransparency", static: false, private: false, access: { has: obj => "linkRefractionWithTransparency" in obj, get: obj => obj.linkRefractionWithTransparency, set: (obj, value) => { obj.linkRefractionWithTransparency = value; } }, metadata: _metadata }, _linkRefractionWithTransparency_initializers, _linkRefractionWithTransparency_extraInitializers);
__esDecorate(_a, null, _useMaskFromThicknessTexture_decorators, { kind: "accessor", name: "useMaskFromThicknessTexture", static: false, private: false, access: { has: obj => "useMaskFromThicknessTexture" in obj, get: obj => obj.useMaskFromThicknessTexture, set: (obj, value) => { obj.useMaskFromThicknessTexture = value; } }, metadata: _metadata }, _useMaskFromThicknessTexture_initializers, _useMaskFromThicknessTexture_extraInitializers);
__esDecorate(_a, null, _refractionIntensityTexture_decorators, { kind: "accessor", name: "refractionIntensityTexture", static: false, private: false, access: { has: obj => "refractionIntensityTexture" in obj, get: obj => obj.refractionIntensityTexture, set: (obj, value) => { obj.refractionIntensityTexture = value; } }, metadata: _metadata }, _refractionIntensityTexture_initializers, _refractionIntensityTexture_extraInitializers);
__esDecorate(_a, null, _translucencyIntensityTexture_decorators, { kind: "accessor", name: "translucencyIntensityTexture", static: false, private: false, access: { has: obj => "translucencyIntensityTexture" in obj, get: obj => obj.translucencyIntensityTexture, set: (obj, value) => { obj.translucencyIntensityTexture = value; } }, metadata: _metadata }, _translucencyIntensityTexture_initializers, _translucencyIntensityTexture_extraInitializers);
__esDecorate(_a, null, _translucencyColorTexture_decorators, { kind: "accessor", name: "translucencyColorTexture", static: false, private: false, access: { has: obj => "translucencyColorTexture" in obj, get: obj => obj.translucencyColorTexture, set: (obj, value) => { obj.translucencyColorTexture = value; } }, metadata: _metadata }, _translucencyColorTexture_initializers, _translucencyColorTexture_extraInitializers);
__esDecorate(_a, null, _useGltfStyleTextures_decorators, { kind: "accessor", name: "useGltfStyleTextures", static: false, private: false, access: { has: obj => "useGltfStyleTextures" in obj, get: obj => obj.useGltfStyleTextures, set: (obj, value) => { obj.useGltfStyleTextures = value; } }, metadata: _metadata }, _useGltfStyleTextures_initializers, _useGltfStyleTextures_extraInitializers);
__esDecorate(null, null, __scatteringDiffusionProfileIndex_decorators, { kind: "field", name: "_scatteringDiffusionProfileIndex", static: false, private: false, access: { has: obj => "_scatteringDiffusionProfileIndex" in obj, get: obj => obj._scatteringDiffusionProfileIndex, set: (obj, value) => { obj._scatteringDiffusionProfileIndex = value; } }, metadata: _metadata }, __scatteringDiffusionProfileIndex_initializers, __scatteringDiffusionProfileIndex_extraInitializers);
__esDecorate(null, null, _refractionIntensity_decorators, { kind: "field", name: "refractionIntensity", static: false, private: false, access: { has: obj => "refractionIntensity" in obj, get: obj => obj.refractionIntensity, set: (obj, value) => { obj.refractionIntensity = value; } }, metadata: _metadata }, _refractionIntensity_initializers, _refractionIntensity_extraInitializers);
__esDecorate(null, null, _translucencyIntensity_decorators, { kind: "field", name: "translucencyIntensity", static: false, private: false, access: { has: obj => "translucencyIntensity" in obj, get: obj => obj.translucencyIntensity, set: (obj, value) => { obj.translucencyIntensity = value; } }, metadata: _metadata }, _translucencyIntensity_initializers, _translucencyIntensity_extraInitializers);
__esDecorate(null, null, __volumeIndexOfRefraction_decorators, { kind: "field", name: "_volumeIndexOfRefraction", static: false, private: false, access: { has: obj => "_volumeIndexOfRefraction" in obj, get: obj => obj._volumeIndexOfRefraction, set: (obj, value) => { obj._volumeIndexOfRefraction = value; } }, metadata: _metadata }, __volumeIndexOfRefraction_initializers, __volumeIndexOfRefraction_extraInitializers);
__esDecorate(null, null, _minimumThickness_decorators, { kind: "field", name: "minimumThickness", static: false, private: false, access: { has: obj => "minimumThickness" in obj, get: obj => obj.minimumThickness, set: (obj, value) => { obj.minimumThickness = value; } }, metadata: _metadata }, _minimumThickness_initializers, _minimumThickness_extraInitializers);
__esDecorate(null, null, _maximumThickness_decorators, { kind: "field", name: "maximumThickness", static: false, private: false, access: { has: obj => "maximumThickness" in obj, get: obj => obj.maximumThickness, set: (obj, value) => { obj.maximumThickness = value; } }, metadata: _metadata }, _maximumThickness_initializers, _maximumThickness_extraInitializers);
__esDecorate(null, null, _useThicknessAsDepth_decorators, { kind: "field", name: "useThicknessAsDepth", static: false, private: false, access: { has: obj => "useThicknessAsDepth" in obj, get: obj => obj.useThicknessAsDepth, set: (obj, value) => { obj.useThicknessAsDepth = value; } }, metadata: _metadata }, _useThicknessAsDepth_initializers, _useThicknessAsDepth_extraInitializers);
__esDecorate(null, null, _tintColor_decorators, { kind: "field", name: "tintColor", static: false, private: false, access: { has: obj => "tintColor" in obj, get: obj => obj.tintColor, set: (obj, value) => { obj.tintColor = value; } }, metadata: _metadata }, _tintColor_initializers, _tintColor_extraInitializers);
__esDecorate(null, null, _tintColorAtDistance_decorators, { kind: "field", name: "tintColorAtDistance", static: false, private: false, access: { has: obj => "tintColorAtDistance" in obj, get: obj => obj.tintColorAtDistance, set: (obj, value) => { obj.tintColorAtDistance = value; } }, metadata: _metadata }, _tintColorAtDistance_initializers, _tintColorAtDistance_extraInitializers);
__esDecorate(null, null, _dispersion_decorators, { kind: "field", name: "dispersion", static: false, private: false, access: { has: obj => "dispersion" in obj, get: obj => obj.dispersion, set: (obj, value) => { obj.dispersion = value; } }, metadata: _metadata }, _dispersion_initializers, _dispersion_extraInitializers);
__esDecorate(null, null, _diffusionDistance_decorators, { kind: "field", name: "diffusionDistance", static: false, private: false, access: { has: obj => "diffusionDistance" in obj, get: obj => obj.diffusionDistance, set: (obj, value) => { obj.diffusionDistance = value; } }, metadata: _metadata }, _diffusionDistance_initializers, _diffusionDistance_extraInitializers);
__esDecorate(null, null, _translucencyColor_decorators, { kind: "field", name: "translucencyColor", static: false, private: false, access: { has: obj => "translucencyColor" in obj, get: obj => obj.translucencyColor, set: (obj, value) => { obj.translucencyColor = value; } }, metadata: _metadata }, _translucencyColor_initializers, _translucencyColor_extraInitializers);
__esDecorate(null, null, _applyAlbedoAfterSubSurface_decorators, { kind: "field", name: "applyAlbedoAfterSubSurface", static: false, private: false, access: { has: obj => "applyAlbedoAfterSubSurface" in obj, get: obj => obj.applyAlbedoAfterSubSurface, set: (obj, value) => { obj.applyAlbedoAfterSubSurface = value; } }, metadata: _metadata }, _applyAlbedoAfterSubSurface_initializers, _applyAlbedoAfterSubSurface_extraInitializers);
__esDecorate(null, null, _legacyTranslucency_decorators, { kind: "field", name: "legacyTranslucency", static: false, private: false, access: { has: obj => "legacyTranslucency" in obj, get: obj => obj.legacyTranslucency, set: (obj, value) => { obj.legacyTranslucency = value; } }, metadata: _metadata }, _legacyTranslucency_initializers, _legacyTranslucency_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
/**
* Default value used for applyAlbedoAfterSubSurface.
*
* This property only exists for backward compatibility reasons.
* Set it to true if your rendering in 8.0+ is different from that in 7 when you use sub-surface properties (transmission, refraction, etc.). Default is false.
* Note however that the PBR calculation is wrong when this property is set to true, so only use it if you want to mimic the 7.0 behavior.
*/
_a.DEFAULT_APPLY_ALBEDO_AFTERSUBSURFACE = false,
/**
* Default value used for legacyTranslucency.
*
* This property only exists for backward compatibility reasons.
* Set it to true if your rendering in 8.0+ is different from that in 7 when you use sub-surface translucency. Default is false.
*/
_a.DEFAULT_LEGACY_TRANSLUCENCY = false,
_a;
})();
/** This file must only contain pure code and pure imports */
const onCreatedEffectParameters = { effect: null, subMesh: null };
class PBRMaterialDefinesBase extends PrepassDefinesMixin(UVDefinesMixin(MaterialDefines)) {
}
/**
* Manages the defines for the PBR Material.
* @internal
*/
class PBRMaterialDefines extends ImageProcessingDefinesMixin(PBRMaterialDefinesBase) {
/**
* Initializes the PBR Material defines.
* @param externalProperties The external properties
*/
constructor(externalProperties) {
super(externalProperties);
this.PBR = true;
this.NUM_SAMPLES = "0";
this.REALTIME_FILTERING = false;
this.IBL_CDF_FILTERING = false;
this.ALBEDO = false;
this.GAMMAALBEDO = false;
this.ALBEDODIRECTUV = 0;
this.VERTEXCOLOR = false;
this.BASE_WEIGHT = false;
this.BASE_WEIGHTDIRECTUV = 0;
this.BASE_DIFFUSE_ROUGHNESS = false;
this.BASE_DIFFUSE_ROUGHNESSDIRECTUV = 0;
this.BAKED_VERTEX_ANIMATION_TEXTURE = false;
this.AMBIENT = false;
this.AMBIENTDIRECTUV = 0;
this.AMBIENTINGRAYSCALE = false;
this.OPACITY = false;
this.VERTEXALPHA = false;
this.OPACITYDIRECTUV = 0;
this.OPACITYRGB = false;
this.ALPHATEST = false;
this.DEPTHPREPASS = false;
this.ALPHABLEND = false;
this.ALPHAFROMALBEDO = false;
this.ALPHATESTVALUE = "0.5";
this.SPECULAROVERALPHA = false;
this.RADIANCEOVERALPHA = false;
this.ALPHAFRESNEL = false;
this.LINEARALPHAFRESNEL = false;
this.PREMULTIPLYALPHA = false;
this.EMISSIVE = false;
this.EMISSIVEDIRECTUV = 0;
this.GAMMAEMISSIVE = false;
this.REFLECTIVITY = false;
this.REFLECTIVITY_GAMMA = false;
this.REFLECTIVITYDIRECTUV = 0;
this.SPECULARTERM = false;
this.MICROSURFACEFROMREFLECTIVITYMAP = false;
this.MICROSURFACEAUTOMATIC = false;
this.LODBASEDMICROSFURACE = false;
this.MICROSURFACEMAP = false;
this.MICROSURFACEMAPDIRECTUV = 0;
this.METALLICWORKFLOW = false;
this.ROUGHNESSSTOREINMETALMAPALPHA = false;
this.ROUGHNESSSTOREINMETALMAPGREEN = false;
this.METALLNESSSTOREINMETALMAPBLUE = false;
this.AOSTOREINMETALMAPRED = false;
this.METALLIC_REFLECTANCE = false;
this.METALLIC_REFLECTANCE_GAMMA = false;
this.METALLIC_REFLECTANCEDIRECTUV = 0;
this.METALLIC_REFLECTANCE_USE_ALPHA_ONLY = false;
this.REFLECTANCE = false;
this.REFLECTANCE_GAMMA = false;
this.REFLECTANCEDIRECTUV = 0;
this.ENVIRONMENTBRDF = false;
this.ENVIRONMENTBRDF_RGBD = false;
this.NORMAL = false;
this.TANGENT = false;
this.BUMP = false;
this.BUMPDIRECTUV = 0;
this.OBJECTSPACE_NORMALMAP = false;
this.PARALLAX = false;
this.PARALLAX_RHS = false;
this.PARALLAXOCCLUSION = false;
this.NORMALXYSCALE = true;
this.LIGHTMAP = false;
this.LIGHTMAPDIRECTUV = 0;
this.USELIGHTMAPASSHADOWMAP = false;
this.GAMMALIGHTMAP = false;
this.RGBDLIGHTMAP = false;
this.REFLECTION = false;
this.REFLECTIONMAP_3D = false;
this.REFLECTIONMAP_SPHERICAL = false;
this.REFLECTIONMAP_PLANAR = false;
this.REFLECTIONMAP_CUBIC = false;
this.USE_LOCAL_REFLECTIONMAP_CUBIC = false;
this.REFLECTIONMAP_PROJECTION = false;
this.REFLECTIONMAP_SKYBOX = false;
this.REFLECTIONMAP_EXPLICIT = false;
this.REFLECTIONMAP_EQUIRECTANGULAR = false;
this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
this.INVERTCUBICMAP = false;
this.USESPHERICALFROMREFLECTIONMAP = false;
this.USEIRRADIANCEMAP = false;
this.USE_IRRADIANCE_DOMINANT_DIRECTION = false;
this.USESPHERICALINVERTEX = false;
this.REFLECTIONMAP_OPPOSITEZ = false;
this.LODINREFLECTIONALPHA = false;
this.GAMMAREFLECTION = false;
this.RGBDREFLECTION = false;
this.LINEARSPECULARREFLECTION = false;
this.RADIANCEOCCLUSION = false;
this.HORIZONOCCLUSION = false;
this.INSTANCES = false;
this.THIN_INSTANCES = false;
this.INSTANCESCOLOR = false;
this.NUM_BONE_INFLUENCERS = 0;
this.BonesPerMesh = 0;
this.BONETEXTURE = false;
this.BONES_VELOCITY_ENABLED = false;
this.NONUNIFORMSCALING = false;
this.MORPHTARGETS = false;
this.MORPHTARGETS_POSITION = false;
this.MORPHTARGETS_NORMAL = false;
this.MORPHTARGETS_TANGENT = false;
this.MORPHTARGETS_UV = false;
this.MORPHTARGETS_UV2 = false;
this.MORPHTARGETS_COLOR = false;
this.MORPHTARGETTEXTURE_HASPOSITIONS = false;
this.MORPHTARGETTEXTURE_HASNORMALS = false;
this.MORPHTARGETTEXTURE_HASTANGENTS = false;
this.MORPHTARGETTEXTURE_HASUVS = false;
this.MORPHTARGETTEXTURE_HASUV2S = false;
this.MORPHTARGETTEXTURE_HASCOLORS = false;
this.NUM_MORPH_INFLUENCERS = 0;
this.MORPHTARGETS_TEXTURE = false;
this.MULTIVIEW = false;
this.ORDER_INDEPENDENT_TRANSPARENCY = false;
this.ORDER_INDEPENDENT_TRANSPARENCY_16BITS = false;
this.USEPHYSICALLIGHTFALLOFF = false;
this.USEGLTFLIGHTFALLOFF = false;
this.TWOSIDEDLIGHTING = false;
this.MIRRORED = false;
this.SHADOWFLOAT = false;
this.CLIPPLANE = false;
this.CLIPPLANE2 = false;
this.CLIPPLANE3 = false;
this.CLIPPLANE4 = false;
this.CLIPPLANE5 = false;
this.CLIPPLANE6 = false;
this.POINTSIZE = false;
this.FOG = false;
this.LOGARITHMICDEPTH = false;
this.CAMERA_ORTHOGRAPHIC = false;
this.CAMERA_PERSPECTIVE = false;
this.AREALIGHTSUPPORTED = true;
this.FORCENORMALFORWARD = false;
this.SPECULARAA = false;
this.UNLIT = false;
this.DECAL_AFTER_DETAIL = false;
this.TEXTURE_REPETITION_MODE = 0;
this.DEBUGMODE = 0;
this.USE_VERTEX_PULLING = false;
this.VERTEX_PULLING_USE_INDEX_BUFFER = false;
this.VERTEX_PULLING_INDEX_BUFFER_32BITS = false;
this.RIGHT_HANDED = false;
this.CLUSTLIGHT_SLICES = 0;
this.CLUSTLIGHT_BATCH = 0;
this.rebuild();
}
/**
* Resets the PBR Material defines.
*/
reset() {
super.reset();
this.ALPHATESTVALUE = "0.5";
this.PBR = true;
this.NORMALXYSCALE = true;
}
}
class PBRBaseMaterialBase extends ImageProcessingMixin(PushMaterial) {
}
/**
* The Physically based material base class of BJS.
*
* This offers the main features of a standard PBR material.
* For more information, please refer to the documentation :
* https://doc.babylonjs.com/features/featuresDeepDive/materials/using/introToPBR
* @see [WebGL](https://playground.babylonjs.com/#CGHTSM#1)
* @see [WebGPU](https://playground.babylonjs.com/#CGHTSM#2)
*/
let PBRBaseMaterial = (() => {
var _a, _PBRBaseMaterial_debugMode_accessor_storage;
let _classSuper = PBRBaseMaterialBase;
let _debugMode_decorators;
let _debugMode_initializers = [];
let _debugMode_extraInitializers = [];
return _a = class PBRBaseMaterial extends _classSuper {
/**
* Enables realtime filtering on the texture.
*/
get realTimeFiltering() {
return this._realTimeFiltering;
}
set realTimeFiltering(b) {
this._realTimeFiltering = b;
this.markAsDirty(Constants.MATERIAL_TextureDirtyFlag);
}
/**
* Quality switch for realtime filtering
*/
get realTimeFilteringQuality() {
return this._realTimeFilteringQuality;
}
set realTimeFilteringQuality(n) {
this._realTimeFilteringQuality = n;
this.markAsDirty(Constants.MATERIAL_TextureDirtyFlag);
}
/**
* Can this material render to several textures at once
*/
get canRenderToMRT() {
return true;
}
/**
* @internal
* This is reserved for the inspector.
* Defines the material debug mode.
* It helps seeing only some components of the material while troubleshooting.
*/
get debugMode() { return __classPrivateFieldGet(this, _PBRBaseMaterial_debugMode_accessor_storage, "f"); }
set debugMode(value) { __classPrivateFieldSet(this, _PBRBaseMaterial_debugMode_accessor_storage, value, "f"); }
/**
* Instantiates a new PBRMaterial instance.
*
* @param name The material name
* @param scene The scene the material will be use in.
* @param forceGLSL Use the GLSL code generation for the shader (even on WebGPU). Default is false
*/
constructor(name, scene, forceGLSL = false) {
super(name, scene, undefined, forceGLSL || _a.ForceGLSL);
/**
* Intensity of the direct lights e.g. the four lights available in your scene.
* This impacts both the direct diffuse and specular highlights.
* @internal
*/
this._directIntensity = 1.0;
/**
* Intensity of the emissive part of the material.
* This helps controlling the emissive effect without modifying the emissive color.
* @internal
*/
this._emissiveIntensity = 1.0;
/**
* Intensity of the environment e.g. how much the environment will light the object
* either through harmonics for rough material or through the reflection for shiny ones.
* @internal
*/
this._environmentIntensity = 1.0;
/**
* This is a special control allowing the reduction of the specular highlights coming from the
* four lights of the scene. Those highlights may not be needed in full environment lighting.
* @internal
*/
this._specularIntensity = 1.0;
/**
* This stores the direct, emissive, environment, and specular light intensities into a Vector4.
*/
this._lightingInfos = new Vector4(this._directIntensity, this._emissiveIntensity, this._environmentIntensity, this._specularIntensity);
/**
* Debug Control allowing disabling the bump map on this material.
* @internal
*/
this._disableBumpMap = false;
/**
* AKA Diffuse Texture in standard nomenclature.
* @internal
*/
this._albedoTexture = null;
/**
* Base Weight texture (multiplier to the diffuse and metal lobes).
* @internal
*/
this._baseWeightTexture = null;
/**
* Base Diffuse Roughness texture (roughness of the diffuse lobe).
* @internal
*/
this._baseDiffuseRoughnessTexture = null;
/**
* AKA Occlusion Texture in other nomenclature.
* @internal
*/
this._ambientTexture = null;
/**
* AKA Occlusion Texture Intensity in other nomenclature.
* @internal
*/
this._ambientTextureStrength = 1.0;
/**
* Defines how much the AO map is occluding the analytical lights (point spot...).
* 1 means it completely occludes it
* 0 mean it has no impact
* @internal
*/
this._ambientTextureImpactOnAnalyticalLights = _a.DEFAULT_AO_ON_ANALYTICAL_LIGHTS;
/**
* Stores the alpha values in a texture.
* @internal
*/
this._opacityTexture = null;
/**
* Stores the reflection values in a texture.
* @internal
*/
this._reflectionTexture = null;
/**
* Stores the emissive values in a texture.
* @internal
*/
this._emissiveTexture = null;
/**
* AKA Specular texture in other nomenclature.
* @internal
*/
this._reflectivityTexture = null;
/**
* Used to switch from specular/glossiness to metallic/roughness workflow.
* @internal
*/
this._metallicTexture = null;
/**
* Specifies the metallic scalar of the metallic/roughness workflow.
* Can also be used to scale the metalness values of the metallic texture.
* @internal
*/
this._metallic = null;
/**
* Specifies the roughness scalar of the metallic/roughness workflow.
* Can also be used to scale the roughness values of the metallic texture.
* @internal
*/
this._roughness = null;
/**
* In metallic workflow, specifies an F0 factor to help configuring the material F0.
* By default the indexOfrefraction is used to compute F0;
*
* This is used as a factor against the default reflectance at normal incidence to tweak it.
*
* F0 = defaultF0 * metallicF0Factor * metallicReflectanceColor;
* F90 = metallicReflectanceColor;
* @internal
*/
this._metallicF0Factor = 1;
/**
* In metallic workflow, specifies an F0 color.
* By default the F90 is always 1;
*
* Please note that this factor is also used as a factor against the default reflectance at normal incidence.
*
* F0 = defaultF0_from_IOR * metallicF0Factor * metallicReflectanceColor
* F90 = metallicF0Factor;
* @internal
*/
this._metallicReflectanceColor = Color3.White();
/**
* Specifies that only the A channel from _metallicReflectanceTexture should be used.
* If false, both RGB and A channels will be used
* @internal
*/
this._useOnlyMetallicFromMetallicReflectanceTexture = false;
/**
* Defines to store metallicReflectanceColor in RGB and metallicF0Factor in A
* This is multiply against the scalar values defined in the material.
* @internal
*/
this._metallicReflectanceTexture = null;
/**
* Defines to store reflectanceColor in RGB
* This is multiplied against the scalar values defined in the material.
* If both _reflectanceTexture and _metallicReflectanceTexture textures are provided and _useOnlyMetallicFromMetallicReflectanceTexture
* is false, _metallicReflectanceTexture takes precedence and _reflectanceTexture is not used
* @internal
*/
this._reflectanceTexture = null;
/**
* Used to enable roughness/glossiness fetch from a separate channel depending on the current mode.
* Gray Scale represents roughness in metallic mode and glossiness in specular mode.
* @internal
*/
this._microSurfaceTexture = null;
/**
* Stores surface normal data used to displace a mesh in a texture.
* @internal
*/
this._bumpTexture = null;
/**
* Stores the pre-calculated light information of a mesh in a texture.
* @internal
*/
this._lightmapTexture = null;
/**
* The color of a material in ambient lighting.
* @internal
*/
this._ambientColor = new Color3(0, 0, 0);
/**
* AKA Diffuse Color in other nomenclature.
* @internal
*/
this._albedoColor = new Color3(1, 1, 1);
/**
* Base Weight (multiplier to the diffuse and metal lobes).
* @internal
*/
this._baseWeight = 1;
/**
* Base Diffuse Roughness (roughness of the diffuse lobe).
* Can also be used to scale the corresponding texture.
* @internal
*/
this._baseDiffuseRoughness = null;
/**
* AKA Specular Color in other nomenclature.
* @internal
*/
this._reflectivityColor = new Color3(1, 1, 1);
/**
* The color applied when light is reflected from a material.
* @internal
*/
this._reflectionColor = new Color3(1, 1, 1);
/**
* The color applied when light is emitted from a material.
* @internal
*/
this._emissiveColor = new Color3(0, 0, 0);
/**
* AKA Glossiness in other nomenclature.
* @internal
*/
this._microSurface = 0.9;
/**
* Specifies that the material will use the light map as a show map.
* @internal
*/
this._useLightmapAsShadowmap = false;
/**
* This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal
* makes the reflect vector face the model (under horizon).
* @internal
*/
this._useHorizonOcclusion = true;
/**
* This parameters will enable/disable radiance occlusion by preventing the radiance to lit
* too much the area relying on ambient texture to define their ambient occlusion.
* @internal
*/
this._useRadianceOcclusion = true;
/**
* Specifies that the alpha is coming form the albedo channel alpha channel for alpha blending.
* @internal
*/
this._useAlphaFromAlbedoTexture = false;
/**
* Specifies that the material will keeps the specular highlights over a transparent surface (only the most luminous ones).
* A car glass is a good example of that. When sun reflects on it you can not see what is behind.
* @internal
*/
this._useSpecularOverAlpha = true;
/**
* Specifies if the reflectivity texture contains the glossiness information in its alpha channel.
* @internal
*/
this._useMicroSurfaceFromReflectivityMapAlpha = false;
/**
* Specifies if the metallic texture contains the roughness information in its alpha channel.
* @internal
*/
this._useRoughnessFromMetallicTextureAlpha = true;
/**
* Specifies if the metallic texture contains the roughness information in its green channel.
* @internal
*/
this._useRoughnessFromMetallicTextureGreen = false;
/**
* Specifies if the metallic texture contains the metallness information in its blue channel.
* @internal
*/
this._useMetallnessFromMetallicTextureBlue = false;
/**
* Specifies if the metallic texture contains the ambient occlusion information in its red channel.
* @internal
*/
this._useAmbientOcclusionFromMetallicTextureRed = false;
/**
* Specifies if the ambient texture contains the ambient occlusion information in its red channel only.
* @internal
*/
this._useAmbientInGrayScale = false;
/**
* In case the reflectivity map does not contain the microsurface information in its alpha channel,
* The material will try to infer what glossiness each pixel should be.
* @internal
*/
this._useAutoMicroSurfaceFromReflectivityMap = false;
/**
* Defines the falloff type used in this material.
* It by default is Physical.
* @internal
*/
this._lightFalloff = _a.LIGHTFALLOFF_PHYSICAL;
/**
* Specifies that the material will keeps the reflection highlights over a transparent surface (only the most luminous ones).
* A car glass is a good example of that. When the street lights reflects on it you can not see what is behind.
* @internal
*/
this._useRadianceOverAlpha = true;
/**
* Allows using an object space normal map (instead of tangent space).
* @internal
*/
this._useObjectSpaceNormalMap = false;
/**
* Allows using the bump map in parallax mode.
* @internal
*/
this._useParallax = false;
/**
* Allows using the bump map in parallax occlusion mode.
* @internal
*/
this._useParallaxOcclusion = false;
/**
* Controls the scale bias of the parallax mode.
* @internal
*/
this._parallaxScaleBias = 0.05;
/**
* If sets to true, disables all the lights affecting the material.
* @internal
*/
this._disableLighting = false;
/**
* Number of Simultaneous lights allowed on the material.
* @internal
*/
this._maxSimultaneousLights = 4;
/**
* If sets to true, x component of normal map value will be inverted (x = 1.0 - x).
* @internal
*/
this._invertNormalMapX = false;
/**
* If sets to true, y component of normal map value will be inverted (y = 1.0 - y).
* @internal
*/
this._invertNormalMapY = false;
/**
* If sets to true and backfaceCulling is false, normals will be flipped on the backside.
* @internal
*/
this._twoSidedLighting = false;
/**
* Defines the alpha limits in alpha test mode.
* @internal
*/
this._alphaCutOff = 0.4;
/**
* A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
* And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)
* @internal
*/
this._useAlphaFresnel = false;
/**
* A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
* And/Or occlude the blended part. (alpha stays linear to compute the fresnel)
* @internal
*/
this._useLinearAlphaFresnel = false;
/**
* Specifies the environment BRDF texture used to compute the scale and offset roughness values
* from cos theta and roughness:
* http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
* @internal
*/
this._environmentBRDFTexture = null;
/**
* Force the shader to compute irradiance in the fragment shader in order to take bump in account.
* @internal
*/
this._forceIrradianceInFragment = false;
this._realTimeFiltering = false;
this._realTimeFilteringQuality = Constants.TEXTURE_FILTERING_QUALITY_LOW;
/**
* Force normal to face away from face.
* @internal
*/
this._forceNormalForward = false;
/**
* Enables specular anti aliasing in the PBR shader.
* It will both interacts on the Geometry for analytical and IBL lighting.
* It also prefilter the roughness map based on the bump values.
* @internal
*/
this._enableSpecularAntiAliasing = false;
/**
* Stores the available render targets.
*/
this._renderTargets = new SmartArray(16);
/**
* Sets the global ambient color for the material used in lighting calculations.
*/
this._globalAmbientColor = new Color3(0, 0, 0);
/**
* If set to true, no lighting calculations will be applied.
* @internal
*/
this._unlit = false;
/**
* If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)
*/
this._applyDecalMapAfterDetailMap = false;
this._debugMode = 0;
this._shadersLoaded = false;
this._breakShaderLoadedCheck = false;
this._vertexPullingMetadata = null;
_PBRBaseMaterial_debugMode_accessor_storage.set(this, __runInitializers(this, _debugMode_initializers, 0));
/**
* @internal
* This is reserved for the inspector.
* Specify from where on screen the debug mode should start.
* The value goes from -1 (full screen) to 1 (not visible)
* It helps with side by side comparison against the final render
* This defaults to -1
*/
this.debugLimit = (__runInitializers(this, _debugMode_extraInitializers), -1);
/**
* @internal
* This is reserved for the inspector.
* As the default viewing range might not be enough (if the ambient is really small for instance)
* You can use the factor to better multiply the final value.
*/
this.debugFactor = 1;
this._cacheHasRenderTargetTextures = false;
this.brdf = new PBRBRDFConfiguration(this);
this.clearCoat = new PBRClearCoatConfiguration(this);
this.iridescence = new PBRIridescenceConfiguration(this);
this.anisotropy = new PBRAnisotropicConfiguration(this);
this.sheen = new PBRSheenConfiguration(this);
this.subSurface = new PBRSubSurfaceConfiguration(this);
this.detailMap = new DetailMapConfiguration(this);
// Setup the default processing configuration to the scene.
this._attachImageProcessingConfiguration(null);
this.getRenderTargetTextures = () => {
this._renderTargets.reset();
if (MaterialFlags.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
this._renderTargets.push(this._reflectionTexture);
}
this._eventInfo.renderTargets = this._renderTargets;
this._callbackPluginEventFillRenderTargetTextures(this._eventInfo);
return this._renderTargets;
};
this._environmentBRDFTexture = GetEnvironmentBRDFTexture(this.getScene());
this.prePassConfiguration = new PrePassConfiguration();
}
/**
* Gets a boolean indicating that current material needs to register RTT
*/
get hasRenderTargetTextures() {
if (MaterialFlags.ReflectionTextureEnabled && this._reflectionTexture && this._reflectionTexture.isRenderTarget) {
return true;
}
return this._cacheHasRenderTargetTextures;
}
/**
* Can this material render to prepass
*/
get isPrePassCapable() {
return !this.disableDepthWrite;
}
/**
* @returns the name of the material class.
*/
getClassName() {
return "PBRBaseMaterial";
}
/**
* Returns true if alpha blending should be disabled.
*/
get _disableAlphaBlending() {
return (this._transparencyMode === _a.PBRMATERIAL_OPAQUE ||
this._transparencyMode === _a.PBRMATERIAL_ALPHATEST ||
this.subSurface?.disableAlphaBlending);
}
/**
* @returns whether or not this material should be rendered in alpha blend mode.
*/
needAlphaBlending() {
if (this._hasTransparencyMode) {
return this._transparencyModeIsBlend;
}
if (this._disableAlphaBlending) {
return false;
}
return this.alpha < 1.0 || this._opacityTexture != null || this._shouldUseAlphaFromAlbedoTexture();
}
/**
* @returns whether or not this material should be rendered in alpha test mode.
*/
needAlphaTesting() {
if (this._hasTransparencyMode) {
return this._transparencyModeIsTest;
}
if (this.subSurface?.disableAlphaBlending) {
return false;
}
return this._hasAlphaChannel() && (this._transparencyMode == null || this._transparencyMode === _a.PBRMATERIAL_ALPHATEST);
}
/**
* @returns whether or not the alpha value of the albedo texture should be used for alpha blending.
*/
_shouldUseAlphaFromAlbedoTexture() {
return this._albedoTexture != null && this._albedoTexture.hasAlpha && this._useAlphaFromAlbedoTexture && this._transparencyMode !== _a.PBRMATERIAL_OPAQUE;
}
/**
* @returns whether or not there is a usable alpha channel for transparency.
*/
_hasAlphaChannel() {
return (this._albedoTexture != null && this._albedoTexture.hasAlpha) || this._opacityTexture != null;
}
/**
* @returns the texture used for the alpha test.
*/
getAlphaTestTexture() {
return this._albedoTexture;
}
/**
* Specifies that the submesh is ready to be used.
* @param mesh - BJS mesh.
* @param subMesh - A submesh of the BJS mesh. Used to check if it is ready.
* @param useInstances - Specifies that instances should be used.
* @returns - boolean indicating that the submesh is ready or not.
*/
isReadyForSubMesh(mesh, subMesh, useInstances) {
if (!this._uniformBufferLayoutBuilt) {
this.buildUniformLayout();
}
const drawWrapper = subMesh._drawWrapper;
if (drawWrapper.effect && this.isFrozen) {
if (drawWrapper._wasPreviouslyReady && drawWrapper._wasPreviouslyUsingInstances === useInstances) {
return true;
}
}
if (!subMesh.materialDefines) {
this._callbackPluginEventGeneric(4 /* MaterialPluginEvent.GetDefineNames */, this._eventInfo);
subMesh.materialDefines = new PBRMaterialDefines(this._eventInfo.defineNames);
}
const defines = subMesh.materialDefines;
if (this._isReadyForSubMesh(subMesh)) {
return true;
}
const scene = this.getScene();
const engine = scene.getEngine();
if (defines._areTexturesDirty) {
this._eventInfo.hasRenderTargetTextures = false;
this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);
this._cacheHasRenderTargetTextures = this._eventInfo.hasRenderTargetTextures;
if (scene.texturesEnabled) {
if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {
if (!this._albedoTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._baseWeightTexture && MaterialFlags.BaseWeightTextureEnabled) {
if (!this._baseWeightTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) {
if (!this._baseDiffuseRoughnessTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {
if (!this._ambientTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
if (!this._opacityTexture.isReadyOrNotBlocking()) {
return false;
}
}
const reflectionTexture = this._getReflectionTexture();
if (reflectionTexture && MaterialFlags.ReflectionTextureEnabled) {
if (!reflectionTexture.isReadyOrNotBlocking()) {
return false;
}
if (reflectionTexture.irradianceTexture) {
if (!reflectionTexture.irradianceTexture.isReadyOrNotBlocking()) {
return false;
}
}
else {
// Not ready until spherical are ready too.
if (!reflectionTexture.sphericalPolynomial && reflectionTexture.getInternalTexture()?._sphericalPolynomialPromise) {
return false;
}
}
}
if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {
if (!this._lightmapTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {
if (!this._emissiveTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (MaterialFlags.SpecularTextureEnabled) {
if (this._metallicTexture) {
if (!this._metallicTexture.isReadyOrNotBlocking()) {
return false;
}
}
else if (this._reflectivityTexture) {
if (!this._reflectivityTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._metallicReflectanceTexture) {
if (!this._metallicReflectanceTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._reflectanceTexture) {
if (!this._reflectanceTexture.isReadyOrNotBlocking()) {
return false;
}
}
if (this._microSurfaceTexture) {
if (!this._microSurfaceTexture.isReadyOrNotBlocking()) {
return false;
}
}
}
if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {
// Bump texture cannot be not blocking.
if (!this._bumpTexture.isReady()) {
return false;
}
}
if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {
// This is blocking.
if (!this._environmentBRDFTexture.isReady()) {
return false;
}
}
}
}
this._eventInfo.isReadyForSubMesh = true;
this._eventInfo.defines = defines;
this._eventInfo.subMesh = subMesh;
this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);
if (!this._eventInfo.isReadyForSubMesh) {
return false;
}
if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {
if (!this._imageProcessingConfiguration.isReady()) {
return false;
}
}
// Check if Area Lights have LTC texture.
if (defines["AREALIGHTUSED"] || defines["CLUSTLIGHT_BATCH"]) {
for (let index = 0; index < mesh.lightSources.length; index++) {
if (!mesh.lightSources[index]._isReady()) {
return false;
}
}
}
if (!engine.getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
mesh.createNormals(true);
Logger.Warn("PBRMaterial: Normals have been created for the mesh: " + mesh.name);
}
if (!AreLightsTexturesReady(scene, mesh, this._maxSimultaneousLights, this._disableLighting)) {
return false;
}
const previousEffect = subMesh.effect;
const lightDisposed = defines._areLightsDisposed;
const effect = this._prepareEffect(mesh, subMesh.getRenderingMesh(), defines, this.onCompiled, this.onError, useInstances, null);
let forceWasNotReadyPreviously = false;
if (effect) {
if (this._onEffectCreatedObservable) {
onCreatedEffectParameters.effect = effect;
onCreatedEffectParameters.subMesh = subMesh;
this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);
}
// Use previous effect while new one is compiling
if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {
defines.markAsUnprocessed();
forceWasNotReadyPreviously = this.isFrozen;
if (lightDisposed) {
// re register in case it takes more than one frame.
defines._areLightsDisposed = true;
return false;
}
}
else {
scene.resetCachedMaterial();
subMesh.setEffect(effect, defines, this._materialContext);
}
}
if (!subMesh.effect || !subMesh.effect.isReady()) {
return false;
}
defines._renderId = scene.getRenderId();
drawWrapper._wasPreviouslyReady = forceWasNotReadyPreviously ? false : true;
drawWrapper._wasPreviouslyUsingInstances = !!useInstances;
this._checkScenePerformancePriority();
return true;
}
/**
* Specifies if the material uses metallic roughness workflow.
* @returns boolean specifying if the material uses metallic roughness workflow.
*/
isMetallicWorkflow() {
if (this._metallic != null || this._roughness != null || this._metallicTexture) {
return true;
}
return false;
}
_prepareEffect(mesh, renderingMesh, defines, onCompiled = null, onError = null, useInstances = null, useClipPlane = null) {
this._prepareDefines(mesh, renderingMesh, defines, useInstances, useClipPlane);
if (!defines.isDirty) {
return null;
}
defines.markAsProcessed();
const scene = this.getScene();
const engine = scene.getEngine();
// Fallbacks
const fallbacks = new EffectFallbacks();
let fallbackRank = 0;
if (defines.USESPHERICALINVERTEX) {
fallbacks.addFallback(fallbackRank++, "USESPHERICALINVERTEX");
}
if (defines.FOG) {
fallbacks.addFallback(fallbackRank, "FOG");
}
if (defines.SPECULARAA) {
fallbacks.addFallback(fallbackRank, "SPECULARAA");
}
if (defines.POINTSIZE) {
fallbacks.addFallback(fallbackRank, "POINTSIZE");
}
if (defines.LOGARITHMICDEPTH) {
fallbacks.addFallback(fallbackRank, "LOGARITHMICDEPTH");
}
if (defines.PARALLAX) {
fallbacks.addFallback(fallbackRank, "PARALLAX");
}
if (defines.PARALLAX_RHS) {
fallbacks.addFallback(fallbackRank, "PARALLAX_RHS");
}
if (defines.PARALLAXOCCLUSION) {
fallbacks.addFallback(fallbackRank++, "PARALLAXOCCLUSION");
}
if (defines.ENVIRONMENTBRDF) {
fallbacks.addFallback(fallbackRank++, "ENVIRONMENTBRDF");
}
if (defines.TANGENT) {
fallbacks.addFallback(fallbackRank++, "TANGENT");
}
if (defines.BUMP) {
fallbacks.addFallback(fallbackRank++, "BUMP");
}
fallbackRank = HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights, fallbackRank);
if (defines.SPECULARTERM) {
fallbacks.addFallback(fallbackRank++, "SPECULARTERM");
}
if (defines.USESPHERICALFROMREFLECTIONMAP) {
fallbacks.addFallback(fallbackRank++, "USESPHERICALFROMREFLECTIONMAP");
}
if (defines.USEIRRADIANCEMAP) {
fallbacks.addFallback(fallbackRank++, "USEIRRADIANCEMAP");
}
if (defines.LIGHTMAP) {
fallbacks.addFallback(fallbackRank++, "LIGHTMAP");
}
if (defines.NORMAL) {
fallbacks.addFallback(fallbackRank++, "NORMAL");
}
if (defines.AMBIENT) {
fallbacks.addFallback(fallbackRank++, "AMBIENT");
}
if (defines.EMISSIVE) {
fallbacks.addFallback(fallbackRank++, "EMISSIVE");
}
if (defines.VERTEXCOLOR) {
fallbacks.addFallback(fallbackRank++, "VERTEXCOLOR");
}
if (defines.MORPHTARGETS) {
fallbacks.addFallback(fallbackRank++, "MORPHTARGETS");
}
if (defines.MULTIVIEW) {
fallbacks.addFallback(0, "MULTIVIEW");
}
//Attributes
const attribs = [VertexBuffer.PositionKind];
if (defines.NORMAL) {
attribs.push(VertexBuffer.NormalKind);
}
if (defines.TANGENT) {
attribs.push(VertexBuffer.TangentKind);
}
for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {
if (defines["UV" + i]) {
attribs.push(`uv${i === 1 ? "" : i}`);
}
}
if (defines.VERTEXCOLOR) {
attribs.push(VertexBuffer.ColorKind);
}
PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
PrepareAttributesForInstances(attribs, defines);
PrepareAttributesForMorphTargets(attribs, mesh, defines);
PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);
let shaderName = "pbr";
const uniforms = [
"world",
"view",
"viewProjection",
"vEyePosition",
"vLightsType",
"vAmbientColor",
"vAlbedoColor",
"baseWeight",
"baseDiffuseRoughness",
"vReflectivityColor",
"vMetallicReflectanceFactors",
"vEmissiveColor",
"visibility",
"vFogInfos",
"vFogColor",
"pointSize",
"vAlbedoInfos",
"vBaseWeightInfos",
"vBaseDiffuseRoughnessInfos",
"vAmbientInfos",
"vOpacityInfos",
"vEmissiveInfos",
"vReflectivityInfos",
"vMetallicReflectanceInfos",
"vReflectanceInfos",
"vMicroSurfaceSamplerInfos",
"vBumpInfos",
"vLightmapInfos",
"mBones",
"albedoMatrix",
"baseWeightMatrix",
"baseDiffuseRoughnessMatrix",
"ambientMatrix",
"opacityMatrix",
"emissiveMatrix",
"reflectivityMatrix",
"normalMatrix",
"microSurfaceSamplerMatrix",
"bumpMatrix",
"lightmapMatrix",
"metallicReflectanceMatrix",
"reflectanceMatrix",
"vLightingIntensity",
"logarithmicDepthConstant",
"vTangentSpaceParams",
"boneTextureInfo",
"vDebugMode",
"morphTargetTextureInfo",
"morphTargetTextureIndices",
"cameraInfo",
"vTextureRepetitionHexTilingParams",
];
const samplers = [
"albedoSampler",
"baseWeightSampler",
"baseDiffuseRoughnessSampler",
"reflectivitySampler",
"ambientSampler",
"emissiveSampler",
"bumpSampler",
"lightmapSampler",
"opacitySampler",
"microSurfaceSampler",
"environmentBrdfSampler",
"boneSampler",
"metallicReflectanceSampler",
"reflectanceSampler",
"morphTargets",
"oitDepthSampler",
"oitFrontColorSampler",
"areaLightsLTC1Sampler",
"areaLightsLTC2Sampler",
];
PrepareUniformsAndSamplersForIBL(uniforms, samplers, true);
const uniformBuffers = ["Material", "Scene", "Mesh"];
const indexParameters = { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS };
this._eventInfo.fallbacks = fallbacks;
this._eventInfo.fallbackRank = fallbackRank;
this._eventInfo.defines = defines;
this._eventInfo.uniforms = uniforms;
this._eventInfo.attributes = attribs;
this._eventInfo.samplers = samplers;
this._eventInfo.uniformBuffersNames = uniformBuffers;
this._eventInfo.customCode = undefined;
this._eventInfo.mesh = mesh;
this._eventInfo.indexParameters = indexParameters;
this._callbackPluginEventGeneric(128 /* MaterialPluginEvent.PrepareEffect */, this._eventInfo);
MaterialHelperGeometryRendering.AddUniformsAndSamplers(uniforms, samplers);
PrePassConfiguration.AddUniforms(uniforms);
AddClipPlaneUniforms(uniforms);
// Vertex pulling metadata uniforms
if (this._useVertexPulling) {
const geometry = renderingMesh?.geometry;
if (geometry) {
this._vertexPullingMetadata = PrepareVertexPullingUniforms(geometry);
if (this._vertexPullingMetadata) {
this._vertexPullingMetadata.forEach((_, attribute) => {
uniforms.push(`vp_${attribute}_info`);
});
}
}
}
else {
this._vertexPullingMetadata = null;
}
if (ImageProcessingConfiguration) {
ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
}
PrepareUniformsAndSamplersList({
uniformsNames: uniforms,
uniformBuffersNames: uniformBuffers,
samplers: samplers,
defines: defines,
maxSimultaneousLights: this._maxSimultaneousLights,
shaderLanguage: this._shaderLanguage,
});
const csnrOptions = {};
if (this.customShaderNameResolve) {
shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs, csnrOptions);
}
const join = defines.toString();
const effect = engine.createEffect(shaderName, {
attributes: attribs,
uniformsNames: uniforms,
uniformBuffersNames: uniformBuffers,
samplers: samplers,
defines: join,
fallbacks: fallbacks,
onCompiled: onCompiled,
onError: onError,
indexParameters,
processFinalCode: csnrOptions.processFinalCode,
processCodeAfterIncludes: this._eventInfo.customCode,
multiTarget: defines.PREPASS,
shaderLanguage: this._shaderLanguage,
extraInitializationsAsync: this._shadersLoaded
? undefined
: async () => {
if (this.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
await Promise.all([import('./pbr.vertex-DbkbmZiG.esm.js'), import('./pbr.fragment-cSse4OHC.esm.js')]);
}
else {
await Promise.all([import('./pbr.vertex-RLD_H3tY.esm.js'), import('./pbr.fragment-Bgd8XsYL.esm.js')]);
}
this._shadersLoaded = true;
},
}, engine);
this._eventInfo.customCode = undefined;
return effect;
}
_prepareDefines(mesh, renderingMesh, defines, useInstances = null, useClipPlane = null) {
const useThinInstances = renderingMesh.hasThinInstances;
const scene = this.getScene();
const engine = scene.getEngine();
// Lights
PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
defines._needNormals = true;
// Multiview
PrepareDefinesForMultiview(scene, defines);
// PrePass
const oit = this.needAlphaBlendingForMesh(mesh) && this.getScene().useOrderIndependentTransparency;
PrepareDefinesForPrePass(scene, defines, this.canRenderToMRT && !oit);
// Order independant transparency
PrepareDefinesForOIT(scene, defines, oit);
MaterialHelperGeometryRendering.PrepareDefines(engine.currentRenderPassId, mesh, defines);
// Textures
defines.METALLICWORKFLOW = this.isMetallicWorkflow();
if (defines._areTexturesDirty) {
defines._needUVs = false;
for (let i = 1; i <= Constants.MAX_SUPPORTED_UV_SETS; ++i) {
defines["MAINUV" + i] = false;
}
if (scene.texturesEnabled) {
defines.ALBEDODIRECTUV = 0;
defines.BASE_WEIGHTDIRECTUV = 0;
defines.BASE_DIFFUSE_ROUGHNESSDIRECTUV = 0;
defines.AMBIENTDIRECTUV = 0;
defines.OPACITYDIRECTUV = 0;
defines.EMISSIVEDIRECTUV = 0;
defines.REFLECTIVITYDIRECTUV = 0;
defines.MICROSURFACEMAPDIRECTUV = 0;
defines.METALLIC_REFLECTANCEDIRECTUV = 0;
defines.REFLECTANCEDIRECTUV = 0;
defines.BUMPDIRECTUV = 0;
defines.LIGHTMAPDIRECTUV = 0;
if (engine.getCaps().textureLOD) {
defines.LODBASEDMICROSFURACE = true;
}
if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {
PrepareDefinesForMergedUV(this._albedoTexture, defines, "ALBEDO");
defines.GAMMAALBEDO = this._albedoTexture.gammaSpace;
}
else {
defines.ALBEDO = false;
}
if (this._baseWeightTexture && MaterialFlags.BaseWeightTextureEnabled) {
PrepareDefinesForMergedUV(this._baseWeightTexture, defines, "BASE_WEIGHT");
}
else {
defines.BASE_WEIGHT = false;
}
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) {
PrepareDefinesForMergedUV(this._baseDiffuseRoughnessTexture, defines, "BASE_DIFFUSE_ROUGHNESS");
}
else {
defines.BASE_DIFFUSE_ROUGHNESS = false;
}
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {
PrepareDefinesForMergedUV(this._ambientTexture, defines, "AMBIENT");
defines.AMBIENTINGRAYSCALE = this._useAmbientInGrayScale;
}
else {
defines.AMBIENT = false;
}
if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
PrepareDefinesForMergedUV(this._opacityTexture, defines, "OPACITY");
defines.OPACITYRGB = this._opacityTexture.getAlphaFromRGB;
}
else {
defines.OPACITY = false;
}
const reflectionTexture = this._getReflectionTexture();
const useSHInFragment = this._forceIrradianceInFragment ||
this.realTimeFiltering ||
this._twoSidedLighting ||
engine.getCaps().maxVaryingVectors <= 8 ||
this._baseDiffuseRoughnessTexture != null;
PrepareDefinesForIBL(scene, reflectionTexture, defines, this.realTimeFiltering, this.realTimeFilteringQuality, !useSHInFragment);
if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {
PrepareDefinesForMergedUV(this._lightmapTexture, defines, "LIGHTMAP");
defines.USELIGHTMAPASSHADOWMAP = this._useLightmapAsShadowmap;
defines.GAMMALIGHTMAP = this._lightmapTexture.gammaSpace;
defines.RGBDLIGHTMAP = this._lightmapTexture.isRGBD;
}
else {
defines.LIGHTMAP = false;
}
if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {
PrepareDefinesForMergedUV(this._emissiveTexture, defines, "EMISSIVE");
defines.GAMMAEMISSIVE = this._emissiveTexture.gammaSpace;
}
else {
defines.EMISSIVE = false;
}
if (MaterialFlags.SpecularTextureEnabled) {
if (this._metallicTexture) {
PrepareDefinesForMergedUV(this._metallicTexture, defines, "REFLECTIVITY");
defines.ROUGHNESSSTOREINMETALMAPALPHA = this._useRoughnessFromMetallicTextureAlpha;
defines.ROUGHNESSSTOREINMETALMAPGREEN = !this._useRoughnessFromMetallicTextureAlpha && this._useRoughnessFromMetallicTextureGreen;
defines.METALLNESSSTOREINMETALMAPBLUE = this._useMetallnessFromMetallicTextureBlue;
defines.AOSTOREINMETALMAPRED = this._useAmbientOcclusionFromMetallicTextureRed;
defines.REFLECTIVITY_GAMMA = false;
}
else if (this._reflectivityTexture) {
PrepareDefinesForMergedUV(this._reflectivityTexture, defines, "REFLECTIVITY");
defines.MICROSURFACEFROMREFLECTIVITYMAP = this._useMicroSurfaceFromReflectivityMapAlpha;
defines.MICROSURFACEAUTOMATIC = this._useAutoMicroSurfaceFromReflectivityMap;
defines.REFLECTIVITY_GAMMA = this._reflectivityTexture.gammaSpace;
}
else {
defines.REFLECTIVITY = false;
}
if (this._metallicReflectanceTexture || this._reflectanceTexture) {
defines.METALLIC_REFLECTANCE_USE_ALPHA_ONLY = this._useOnlyMetallicFromMetallicReflectanceTexture;
if (this._metallicReflectanceTexture) {
PrepareDefinesForMergedUV(this._metallicReflectanceTexture, defines, "METALLIC_REFLECTANCE");
defines.METALLIC_REFLECTANCE_GAMMA = this._metallicReflectanceTexture.gammaSpace;
}
else {
defines.METALLIC_REFLECTANCE = false;
}
if (this._reflectanceTexture &&
(!this._metallicReflectanceTexture || (this._metallicReflectanceTexture && this._useOnlyMetallicFromMetallicReflectanceTexture))) {
PrepareDefinesForMergedUV(this._reflectanceTexture, defines, "REFLECTANCE");
defines.REFLECTANCE_GAMMA = this._reflectanceTexture.gammaSpace;
}
else {
defines.REFLECTANCE = false;
}
}
else {
defines.METALLIC_REFLECTANCE = false;
defines.REFLECTANCE = false;
}
if (this._microSurfaceTexture) {
PrepareDefinesForMergedUV(this._microSurfaceTexture, defines, "MICROSURFACEMAP");
}
else {
defines.MICROSURFACEMAP = false;
}
}
else {
defines.REFLECTIVITY = false;
defines.MICROSURFACEMAP = false;
}
if (engine.getCaps().standardDerivatives && this._bumpTexture && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {
PrepareDefinesForMergedUV(this._bumpTexture, defines, "BUMP");
if (this._useParallax && this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {
defines.PARALLAX = true;
defines.PARALLAX_RHS = scene.useRightHandedSystem;
defines.PARALLAXOCCLUSION = !!this._useParallaxOcclusion;
}
else {
defines.PARALLAX = false;
}
defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;
}
else {
defines.BUMP = false;
defines.PARALLAX = false;
defines.PARALLAX_RHS = false;
defines.PARALLAXOCCLUSION = false;
defines.OBJECTSPACE_NORMALMAP = false;
}
if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {
defines.ENVIRONMENTBRDF = true;
defines.ENVIRONMENTBRDF_RGBD = this._environmentBRDFTexture.isRGBD;
}
else {
defines.ENVIRONMENTBRDF = false;
defines.ENVIRONMENTBRDF_RGBD = false;
}
if (this._shouldUseAlphaFromAlbedoTexture()) {
defines.ALPHAFROMALBEDO = true;
}
else {
defines.ALPHAFROMALBEDO = false;
}
}
defines.SPECULAROVERALPHA = this._useSpecularOverAlpha;
if (this._lightFalloff === _a.LIGHTFALLOFF_STANDARD) {
defines.USEPHYSICALLIGHTFALLOFF = false;
defines.USEGLTFLIGHTFALLOFF = false;
}
else if (this._lightFalloff === _a.LIGHTFALLOFF_GLTF) {
defines.USEPHYSICALLIGHTFALLOFF = false;
defines.USEGLTFLIGHTFALLOFF = true;
}
else {
defines.USEPHYSICALLIGHTFALLOFF = true;
defines.USEGLTFLIGHTFALLOFF = false;
}
defines.RADIANCEOVERALPHA = this._useRadianceOverAlpha;
if (!this.backFaceCulling && this._twoSidedLighting) {
defines.TWOSIDEDLIGHTING = true;
}
else {
defines.TWOSIDEDLIGHTING = false;
}
// We need it to not invert normals in two sided lighting mode (based on the winding of the face)
defines.MIRRORED = !!scene._mirroredCameraPosition;
defines.SPECULARAA = engine.getCaps().standardDerivatives && this._enableSpecularAntiAliasing;
}
if (defines._areTexturesDirty || defines._areMiscDirty) {
defines.ALPHATESTVALUE = `${this._alphaCutOff}${this._alphaCutOff % 1 === 0 ? "." : ""}`;
defines.PREMULTIPLYALPHA = this.alphaMode === Constants.ALPHA_PREMULTIPLIED || this.alphaMode === Constants.ALPHA_PREMULTIPLIED_PORTERDUFF;
defines.ALPHABLEND = this.needAlphaBlendingForMesh(mesh);
defines.ALPHAFRESNEL = this._useAlphaFresnel || this._useLinearAlphaFresnel;
defines.LINEARALPHAFRESNEL = this._useLinearAlphaFresnel;
}
if (defines._areTexturesDirty) {
defines.TEXTURE_REPETITION_MODE = engine.version > 1 || engine.isWebGPU ? this.textureRepetitionMode : 0;
}
if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {
this._imageProcessingConfiguration.prepareDefines(defines);
}
defines.FORCENORMALFORWARD = this._forceNormalForward;
defines.RADIANCEOCCLUSION = this._useRadianceOcclusion;
defines.HORIZONOCCLUSION = this._useHorizonOcclusion;
// Misc.
if (defines._areMiscDirty) {
PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines, this._applyDecalMapAfterDetailMap, this._useVertexPulling, renderingMesh, this._isVertexOutputInvariant);
defines.UNLIT = this._unlit || ((this.pointsCloud || this.wireframe) && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind));
defines.DEBUGMODE = this._debugMode;
}
// Values that need to be evaluated on every frame
PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false, useClipPlane, useThinInstances);
// External config
this._eventInfo.defines = defines;
this._eventInfo.mesh = mesh;
this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);
// Attribs
PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== _a.PBRMATERIAL_OPAQUE);
// External config
this._callbackPluginEventPrepareDefines(this._eventInfo);
}
/**
* Force shader compilation
* @param mesh - Define the mesh we want to force the compilation for
* @param onCompiled - Define a callback triggered when the compilation completes
* @param options - Define the options used to create the compilation
*/
forceCompilation(mesh, onCompiled, options) {
const localOptions = {
clipPlane: false,
useInstances: false,
...options,
};
if (!this._uniformBufferLayoutBuilt) {
this.buildUniformLayout();
}
this._callbackPluginEventGeneric(4 /* MaterialPluginEvent.GetDefineNames */, this._eventInfo);
const checkReady = () => {
if (this._breakShaderLoadedCheck) {
return;
}
const defines = new PBRMaterialDefines(this._eventInfo.defineNames);
const effect = this._prepareEffect(mesh, mesh, defines, undefined, undefined, localOptions.useInstances, localOptions.clipPlane);
if (this._onEffectCreatedObservable) {
onCreatedEffectParameters.effect = effect;
onCreatedEffectParameters.subMesh = null;
this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);
}
if (effect.isReady()) {
if (onCompiled) {
onCompiled(this);
}
}
else {
effect.onCompileObservable.add(() => {
if (onCompiled) {
onCompiled(this);
}
});
}
};
checkReady();
}
/**
* Initializes the uniform buffer layout for the shader.
*/
buildUniformLayout() {
// Order is important !
const ubo = this._uniformBuffer;
ubo.addUniform("vAlbedoInfos", 2);
ubo.addUniform("vBaseWeightInfos", 2);
ubo.addUniform("vBaseDiffuseRoughnessInfos", 2);
ubo.addUniform("vAmbientInfos", 4);
ubo.addUniform("vOpacityInfos", 2);
ubo.addUniform("vEmissiveInfos", 2);
ubo.addUniform("vLightmapInfos", 2);
ubo.addUniform("vReflectivityInfos", 3);
ubo.addUniform("vMicroSurfaceSamplerInfos", 2);
ubo.addUniform("vBumpInfos", 3);
ubo.addUniform("albedoMatrix", 16);
ubo.addUniform("baseWeightMatrix", 16);
ubo.addUniform("baseDiffuseRoughnessMatrix", 16);
ubo.addUniform("ambientMatrix", 16);
ubo.addUniform("opacityMatrix", 16);
ubo.addUniform("emissiveMatrix", 16);
ubo.addUniform("lightmapMatrix", 16);
ubo.addUniform("reflectivityMatrix", 16);
ubo.addUniform("microSurfaceSamplerMatrix", 16);
ubo.addUniform("bumpMatrix", 16);
ubo.addUniform("vTangentSpaceParams", 2);
ubo.addUniform("vAlbedoColor", 4);
ubo.addUniform("baseWeight", 1);
ubo.addUniform("baseDiffuseRoughness", 1);
ubo.addUniform("vLightingIntensity", 4);
ubo.addUniform("pointSize", 1);
ubo.addUniform("vReflectivityColor", 4);
ubo.addUniform("vEmissiveColor", 3);
ubo.addUniform("vAmbientColor", 3);
ubo.addUniform("vDebugMode", 2);
ubo.addUniform("vMetallicReflectanceFactors", 4);
ubo.addUniform("vMetallicReflectanceInfos", 2);
ubo.addUniform("metallicReflectanceMatrix", 16);
ubo.addUniform("vReflectanceInfos", 2);
ubo.addUniform("reflectanceMatrix", 16);
ubo.addUniform("cameraInfo", 4);
ubo.addUniform("vTextureRepetitionHexTilingParams", 4);
PrepareUniformLayoutForIBL(ubo, true, true, true, true, true);
super.buildUniformLayout();
}
/**
* Binds the submesh data.
* @param world - The world matrix.
* @param mesh - The BJS mesh.
* @param subMesh - A submesh of the BJS mesh.
*/
bindForSubMesh(world, mesh, subMesh) {
const scene = this.getScene();
const defines = subMesh.materialDefines;
if (!defines) {
return;
}
const effect = subMesh.effect;
if (!effect) {
return;
}
this._activeEffect = effect;
// Matrices Mesh.
mesh.getMeshUniformBuffer().bindToEffect(effect, "Mesh");
mesh.transferToEffect(world);
const engine = scene.getEngine();
// Binding unconditionally
this._uniformBuffer.bindToEffect(effect, "Material");
this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);
MaterialHelperGeometryRendering.Bind(engine.currentRenderPassId, this._activeEffect, mesh, world, this);
const camera = scene.activeCamera;
if (camera) {
this._uniformBuffer.updateFloat4("cameraInfo", camera.minZ, camera.maxZ, 0, 0);
}
else {
this._uniformBuffer.updateFloat4("cameraInfo", 0, 0, 0, 0);
}
const hexParams = this.textureRepetitionHexTilingParams;
this._uniformBuffer.updateFloat4("vTextureRepetitionHexTilingParams", hexParams[0], hexParams[1], hexParams[2], hexParams[3]);
this._eventInfo.subMesh = subMesh;
this._callbackPluginEventHardBindForSubMesh(this._eventInfo);
// Normal Matrix
if (defines.OBJECTSPACE_NORMALMAP) {
world.toNormalMatrix(this._normalMatrix);
this.bindOnlyNormalMatrix(this._normalMatrix);
}
const mustRebind = this._mustRebind(scene, effect, subMesh, mesh.visibility);
const needToAlwaysBindUniformBuffers = engine._features.needToAlwaysBindUniformBuffers;
// Bones
BindBonesParameters(mesh, this._activeEffect, this.prePassConfiguration);
// Vertex pulling
if (this._vertexPullingMetadata) {
BindVertexPullingUniforms(this._activeEffect, this._vertexPullingMetadata);
}
let reflectionTexture = null;
const ubo = this._uniformBuffer;
if (mustRebind) {
this.bindViewProjection(effect);
reflectionTexture = this._getReflectionTexture();
if (!ubo.useUbo || !this.isFrozen || !ubo.isSync || subMesh._drawWrapper._forceRebindOnNextCall) {
// Texture uniforms
if (scene.texturesEnabled) {
if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {
ubo.updateFloat2("vAlbedoInfos", this._albedoTexture.coordinatesIndex, this._albedoTexture.level);
BindTextureMatrix(this._albedoTexture, ubo, "albedo");
}
if (this._baseWeightTexture && MaterialFlags.BaseWeightTextureEnabled) {
ubo.updateFloat2("vBaseWeightInfos", this._baseWeightTexture.coordinatesIndex, this._baseWeightTexture.level);
BindTextureMatrix(this._baseWeightTexture, ubo, "baseWeight");
}
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) {
ubo.updateFloat2("vBaseDiffuseRoughnessInfos", this._baseDiffuseRoughnessTexture.coordinatesIndex, this._baseDiffuseRoughnessTexture.level);
BindTextureMatrix(this._baseDiffuseRoughnessTexture, ubo, "baseDiffuseRoughness");
}
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {
ubo.updateFloat4("vAmbientInfos", this._ambientTexture.coordinatesIndex, this._ambientTexture.level, this._ambientTextureStrength, this._ambientTextureImpactOnAnalyticalLights);
BindTextureMatrix(this._ambientTexture, ubo, "ambient");
}
if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
ubo.updateFloat2("vOpacityInfos", this._opacityTexture.coordinatesIndex, this._opacityTexture.level);
BindTextureMatrix(this._opacityTexture, ubo, "opacity");
}
if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {
ubo.updateFloat2("vEmissiveInfos", this._emissiveTexture.coordinatesIndex, this._emissiveTexture.level);
BindTextureMatrix(this._emissiveTexture, ubo, "emissive");
}
if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {
ubo.updateFloat2("vLightmapInfos", this._lightmapTexture.coordinatesIndex, this._lightmapTexture.level);
BindTextureMatrix(this._lightmapTexture, ubo, "lightmap");
}
if (MaterialFlags.SpecularTextureEnabled) {
if (this._metallicTexture) {
ubo.updateFloat3("vReflectivityInfos", this._metallicTexture.coordinatesIndex, this._metallicTexture.level, this._ambientTextureStrength);
BindTextureMatrix(this._metallicTexture, ubo, "reflectivity");
}
else if (this._reflectivityTexture) {
ubo.updateFloat3("vReflectivityInfos", this._reflectivityTexture.coordinatesIndex, this._reflectivityTexture.level, 1.0);
BindTextureMatrix(this._reflectivityTexture, ubo, "reflectivity");
}
if (this._metallicReflectanceTexture) {
ubo.updateFloat2("vMetallicReflectanceInfos", this._metallicReflectanceTexture.coordinatesIndex, this._metallicReflectanceTexture.level);
BindTextureMatrix(this._metallicReflectanceTexture, ubo, "metallicReflectance");
}
if (this._reflectanceTexture && defines.REFLECTANCE) {
ubo.updateFloat2("vReflectanceInfos", this._reflectanceTexture.coordinatesIndex, this._reflectanceTexture.level);
BindTextureMatrix(this._reflectanceTexture, ubo, "reflectance");
}
if (this._microSurfaceTexture) {
ubo.updateFloat2("vMicroSurfaceSamplerInfos", this._microSurfaceTexture.coordinatesIndex, this._microSurfaceTexture.level);
BindTextureMatrix(this._microSurfaceTexture, ubo, "microSurfaceSampler");
}
}
if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {
ubo.updateFloat3("vBumpInfos", this._bumpTexture.coordinatesIndex, this._bumpTexture.level, this._parallaxScaleBias);
BindTextureMatrix(this._bumpTexture, ubo, "bump");
if (scene._mirroredCameraPosition) {
ubo.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? 1.0 : -1, this._invertNormalMapY ? 1.0 : -1);
}
else {
ubo.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? -1 : 1.0, this._invertNormalMapY ? -1 : 1.0);
}
}
BindIBLParameters(scene, defines, ubo, this._reflectionColor, reflectionTexture, this.realTimeFiltering, true, true, true, true, true);
}
// Point size
if (this.pointsCloud) {
ubo.updateFloat("pointSize", this.pointSize);
}
// Colors
if (defines.METALLICWORKFLOW) {
TmpColors.Color4[0].r = this._metallic === undefined || this._metallic === null ? 1 : this._metallic;
TmpColors.Color4[0].g = this._roughness === undefined || this._roughness === null ? 1 : this._roughness;
const ior = this.subSurface?._indexOfRefraction ?? 1.5;
const outsideIOR = 1; // consider air as clear coat and other layers would remap in the shader.
TmpColors.Color4[0].b = ior;
// We are here deriving our default reflectance from a common value for none metallic surface.
// Based of the schlick fresnel approximation model
// for dielectrics.
const f0 = Math.pow((ior - outsideIOR) / (ior + outsideIOR), 2);
TmpColors.Color4[0].a = f0;
ubo.updateDirectColor4("vReflectivityColor", TmpColors.Color4[0]);
ubo.updateColor4("vMetallicReflectanceFactors", this._metallicReflectanceColor, this._metallicF0Factor);
}
else {
ubo.updateColor4("vReflectivityColor", this._reflectivityColor, this._microSurface);
}
ubo.updateColor3("vEmissiveColor", MaterialFlags.EmissiveTextureEnabled ? this._emissiveColor : Color3.BlackReadOnly);
if (!defines.SS_REFRACTION && this.subSurface?._linkRefractionWithTransparency) {
ubo.updateColor4("vAlbedoColor", this._albedoColor, 1);
}
else {
ubo.updateColor4("vAlbedoColor", this._albedoColor, this.alpha);
}
ubo.updateFloat("baseWeight", this._baseWeight);
ubo.updateFloat("baseDiffuseRoughness", this._baseDiffuseRoughness || 0.0);
// Misc
this._lightingInfos.x = this._directIntensity;
this._lightingInfos.y = this._emissiveIntensity;
this._lightingInfos.z = this._environmentIntensity * scene.environmentIntensity;
this._lightingInfos.w = this._specularIntensity;
ubo.updateVector4("vLightingIntensity", this._lightingInfos);
// Colors
scene.ambientColor.multiplyToRef(this._ambientColor, this._globalAmbientColor);
ubo.updateColor3("vAmbientColor", this._globalAmbientColor);
ubo.updateFloat2("vDebugMode", this.debugLimit, this.debugFactor);
}
// Textures
if (scene.texturesEnabled) {
if (this._albedoTexture && MaterialFlags.DiffuseTextureEnabled) {
ubo.setTexture("albedoSampler", this._albedoTexture);
}
if (this._baseWeightTexture && MaterialFlags.BaseWeightTextureEnabled) {
ubo.setTexture("baseWeightSampler", this._baseWeightTexture);
}
if (this._baseDiffuseRoughnessTexture && MaterialFlags.BaseDiffuseRoughnessTextureEnabled) {
ubo.setTexture("baseDiffuseRoughnessSampler", this._baseDiffuseRoughnessTexture);
}
if (this._ambientTexture && MaterialFlags.AmbientTextureEnabled) {
ubo.setTexture("ambientSampler", this._ambientTexture);
}
if (this._opacityTexture && MaterialFlags.OpacityTextureEnabled) {
ubo.setTexture("opacitySampler", this._opacityTexture);
}
BindIBLSamplers(scene, defines, ubo, reflectionTexture, this.realTimeFiltering);
if (defines.ENVIRONMENTBRDF) {
ubo.setTexture("environmentBrdfSampler", this._environmentBRDFTexture);
}
if (this._emissiveTexture && MaterialFlags.EmissiveTextureEnabled) {
ubo.setTexture("emissiveSampler", this._emissiveTexture);
}
if (this._lightmapTexture && MaterialFlags.LightmapTextureEnabled) {
ubo.setTexture("lightmapSampler", this._lightmapTexture);
}
if (MaterialFlags.SpecularTextureEnabled) {
if (this._metallicTexture) {
ubo.setTexture("reflectivitySampler", this._metallicTexture);
}
else if (this._reflectivityTexture) {
ubo.setTexture("reflectivitySampler", this._reflectivityTexture);
}
if (this._metallicReflectanceTexture) {
ubo.setTexture("metallicReflectanceSampler", this._metallicReflectanceTexture);
}
if (this._reflectanceTexture && defines.REFLECTANCE) {
ubo.setTexture("reflectanceSampler", this._reflectanceTexture);
}
if (this._microSurfaceTexture) {
ubo.setTexture("microSurfaceSampler", this._microSurfaceTexture);
}
}
if (this._bumpTexture && engine.getCaps().standardDerivatives && MaterialFlags.BumpTextureEnabled && !this._disableBumpMap) {
ubo.setTexture("bumpSampler", this._bumpTexture);
}
}
// OIT with depth peeling
if (this.getScene().useOrderIndependentTransparency && this.needAlphaBlendingForMesh(mesh)) {
this.getScene().depthPeelingRenderer.bind(effect);
}
this._eventInfo.subMesh = subMesh;
this._callbackPluginEventBindForSubMesh(this._eventInfo);
// Clip plane
BindClipPlane(this._activeEffect, this, scene);
this.bindEyePosition(effect);
}
else if (needToAlwaysBindUniformBuffers) {
this._needToBindSceneUbo = true;
}
// Lights
if ((mustRebind || !this.isFrozen || needToAlwaysBindUniformBuffers) && scene.lightsEnabled && !this._disableLighting) {
BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
}
if (mustRebind || !this.isFrozen) {
// View
if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) ||
reflectionTexture ||
this.subSurface.refractionTexture ||
mesh.receiveShadows ||
defines.PREPASS ||
defines["CLUSTLIGHT_BATCH"]) {
this.bindView(effect);
}
// Fog
BindFogParameters(scene, mesh, this._activeEffect, true);
// Morph targets
if (defines.NUM_MORPH_INFLUENCERS) {
BindMorphTargetParameters(mesh, this._activeEffect);
}
if (defines.BAKED_VERTEX_ANIMATION_TEXTURE) {
mesh.bakedVertexAnimationManager?.bind(effect, defines.INSTANCES);
}
// image processing
this._imageProcessingConfiguration.bind(this._activeEffect);
// Log. depth
BindLogDepth(defines, this._activeEffect, scene);
}
this._afterBind(mesh, this._activeEffect, subMesh);
ubo.update();
}
/**
* Returns the animatable textures.
* If material have animatable metallic texture, then reflectivity texture will not be returned, even if it has animations.
* @returns - Array of animatable textures.
*/
getAnimatables() {
const results = super.getAnimatables();
if (this._albedoTexture && this._albedoTexture.animations && this._albedoTexture.animations.length > 0) {
results.push(this._albedoTexture);
}
if (this._baseWeightTexture && this._baseWeightTexture.animations && this._baseWeightTexture.animations.length > 0) {
results.push(this._baseWeightTexture);
}
if (this._baseDiffuseRoughnessTexture && this._baseDiffuseRoughnessTexture.animations && this._baseDiffuseRoughnessTexture.animations.length > 0) {
results.push(this._baseDiffuseRoughnessTexture);
}
if (this._ambientTexture && this._ambientTexture.animations && this._ambientTexture.animations.length > 0) {
results.push(this._ambientTexture);
}
if (this._opacityTexture && this._opacityTexture.animations && this._opacityTexture.animations.length > 0) {
results.push(this._opacityTexture);
}
if (this._reflectionTexture && this._reflectionTexture.animations && this._reflectionTexture.animations.length > 0) {
results.push(this._reflectionTexture);
}
if (this._emissiveTexture && this._emissiveTexture.animations && this._emissiveTexture.animations.length > 0) {
results.push(this._emissiveTexture);
}
if (this._metallicTexture && this._metallicTexture.animations && this._metallicTexture.animations.length > 0) {
results.push(this._metallicTexture);
}
else if (this._reflectivityTexture && this._reflectivityTexture.animations && this._reflectivityTexture.animations.length > 0) {
results.push(this._reflectivityTexture);
}
if (this._bumpTexture && this._bumpTexture.animations && this._bumpTexture.animations.length > 0) {
results.push(this._bumpTexture);
}
if (this._lightmapTexture && this._lightmapTexture.animations && this._lightmapTexture.animations.length > 0) {
results.push(this._lightmapTexture);
}
if (this._metallicReflectanceTexture && this._metallicReflectanceTexture.animations && this._metallicReflectanceTexture.animations.length > 0) {
results.push(this._metallicReflectanceTexture);
}
if (this._reflectanceTexture && this._reflectanceTexture.animations && this._reflectanceTexture.animations.length > 0) {
results.push(this._reflectanceTexture);
}
if (this._microSurfaceTexture && this._microSurfaceTexture.animations && this._microSurfaceTexture.animations.length > 0) {
results.push(this._microSurfaceTexture);
}
return results;
}
/**
* Returns the texture used for reflections.
* @returns - Reflection texture if present. Otherwise, returns the environment texture.
*/
_getReflectionTexture() {
if (this._reflectionTexture) {
return this._reflectionTexture;
}
return this.getScene().environmentTexture;
}
/**
* Returns an array of the actively used textures.
* @returns - Array of BaseTextures
*/
getActiveTextures() {
const activeTextures = super.getActiveTextures();
if (this._albedoTexture) {
activeTextures.push(this._albedoTexture);
}
if (this._baseWeightTexture) {
activeTextures.push(this._baseWeightTexture);
}
if (this._baseDiffuseRoughnessTexture) {
activeTextures.push(this._baseDiffuseRoughnessTexture);
}
if (this._ambientTexture) {
activeTextures.push(this._ambientTexture);
}
if (this._opacityTexture) {
activeTextures.push(this._opacityTexture);
}
if (this._reflectionTexture) {
activeTextures.push(this._reflectionTexture);
}
if (this._emissiveTexture) {
activeTextures.push(this._emissiveTexture);
}
if (this._reflectivityTexture) {
activeTextures.push(this._reflectivityTexture);
}
if (this._metallicTexture) {
activeTextures.push(this._metallicTexture);
}
if (this._metallicReflectanceTexture) {
activeTextures.push(this._metallicReflectanceTexture);
}
if (this._reflectanceTexture) {
activeTextures.push(this._reflectanceTexture);
}
if (this._microSurfaceTexture) {
activeTextures.push(this._microSurfaceTexture);
}
if (this._bumpTexture) {
activeTextures.push(this._bumpTexture);
}
if (this._lightmapTexture) {
activeTextures.push(this._lightmapTexture);
}
return activeTextures;
}
/**
* Checks to see if a texture is used in the material.
* @param texture - Base texture to use.
* @returns - Boolean specifying if a texture is used in the material.
*/
hasTexture(texture) {
if (super.hasTexture(texture)) {
return true;
}
if (this._albedoTexture === texture) {
return true;
}
if (this._baseWeightTexture === texture) {
return true;
}
if (this._baseDiffuseRoughnessTexture === texture) {
return true;
}
if (this._ambientTexture === texture) {
return true;
}
if (this._opacityTexture === texture) {
return true;
}
if (this._reflectionTexture === texture) {
return true;
}
if (this._emissiveTexture === texture) {
return true;
}
if (this._reflectivityTexture === texture) {
return true;
}
if (this._metallicTexture === texture) {
return true;
}
if (this._metallicReflectanceTexture === texture) {
return true;
}
if (this._reflectanceTexture === texture) {
return true;
}
if (this._microSurfaceTexture === texture) {
return true;
}
if (this._bumpTexture === texture) {
return true;
}
if (this._lightmapTexture === texture) {
return true;
}
return false;
}
/**
* Sets the required values to the prepass renderer.
* It can't be sets when subsurface scattering of this material is disabled.
* When scene have ability to enable subsurface prepass effect, it will enable.
* @returns - If prepass is enabled or not.
*/
setPrePassRenderer() {
if (!this.subSurface?.isScatteringEnabled) {
return false;
}
const subSurfaceConfiguration = this.getScene().enableSubSurfaceForPrePass();
if (subSurfaceConfiguration) {
subSurfaceConfiguration.enabled = true;
}
return true;
}
/**
* Disposes the resources of the material.
* @param forceDisposeEffect - Forces the disposal of effects.
* @param forceDisposeTextures - Forces the disposal of all textures.
*/
dispose(forceDisposeEffect, forceDisposeTextures) {
this._breakShaderLoadedCheck = true;
if (forceDisposeTextures) {
if (this._environmentBRDFTexture && this.getScene().environmentBRDFTexture !== this._environmentBRDFTexture) {
this._environmentBRDFTexture.dispose();
}
this._albedoTexture?.dispose();
this._baseWeightTexture?.dispose();
this._baseDiffuseRoughnessTexture?.dispose();
this._ambientTexture?.dispose();
this._opacityTexture?.dispose();
this._reflectionTexture?.dispose();
this._emissiveTexture?.dispose();
this._metallicTexture?.dispose();
this._reflectivityTexture?.dispose();
this._bumpTexture?.dispose();
this._lightmapTexture?.dispose();
this._metallicReflectanceTexture?.dispose();
this._reflectanceTexture?.dispose();
this._microSurfaceTexture?.dispose();
}
this._renderTargets.dispose();
if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
}
super.dispose(forceDisposeEffect, forceDisposeTextures);
}
},
_PBRBaseMaterial_debugMode_accessor_storage = new WeakMap(),
(() => {
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(_classSuper[Symbol.metadata] ?? null) : void 0;
_debugMode_decorators = [expandToProperty("_markAllSubMeshesAsMiscDirty")];
__esDecorate(_a, null, _debugMode_decorators, { kind: "accessor", name: "debugMode", static: false, private: false, access: { has: obj => "debugMode" in obj, get: obj => obj.debugMode, set: (obj, value) => { obj.debugMode = value; } }, metadata: _metadata }, _debugMode_initializers, _debugMode_extraInitializers);
if (_metadata) Object.defineProperty(_a, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
})(),
/**
* PBRMaterialTransparencyMode: No transparency mode, Alpha channel is not use.
*/
_a.PBRMATERIAL_OPAQUE = Material.MATERIAL_OPAQUE,
/**
* PBRMaterialTransparencyMode: Alpha Test mode, pixel are discarded below a certain threshold defined by the alpha cutoff value.
*/
_a.PBRMATERIAL_ALPHATEST = Material.MATERIAL_ALPHATEST,
/**
* PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.
*/
_a.PBRMATERIAL_ALPHABLEND = Material.MATERIAL_ALPHABLEND,
/**
* PBRMaterialTransparencyMode: Pixels are blended (according to the alpha mode) with the already drawn pixels in the current frame buffer.
* They are also discarded below the alpha cutoff threshold to improve performances.
*/
_a.PBRMATERIAL_ALPHATESTANDBLEND = Material.MATERIAL_ALPHATESTANDBLEND,
/**
* Defines the default value of how much AO map is occluding the analytical lights
* (point spot...).
*/
_a.DEFAULT_AO_ON_ANALYTICAL_LIGHTS = 0,
/**
* PBRMaterialLightFalloff Physical: light is falling off following the inverse squared distance law.
*/
_a.LIGHTFALLOFF_PHYSICAL = 0,
/**
* PBRMaterialLightFalloff gltf: light is falling off as described in the gltf moving to PBR document
* to enhance interoperability with other engines.
*/
_a.LIGHTFALLOFF_GLTF = 1,
/**
* PBRMaterialLightFalloff Standard: light is falling off like in the standard material
* to enhance interoperability with other materials.
*/
_a.LIGHTFALLOFF_STANDARD = 2,
/**
* Force all the PBR materials to compile to glsl even on WebGPU engines.
* False by default. This is mostly meant for backward compatibility.
*/
_a.ForceGLSL = false,
_a;
})();
if (!Object.getOwnPropertyDescriptor(PBRBaseMaterial.prototype, "decalMap")) {
Object.defineProperty(PBRBaseMaterial.prototype, "decalMap", _MissingSideEffectProperty("PBRBaseMaterial", "decalMap"));
}
// #endregion GENERATED_SIDE_EFFECT_STUBS
export { PBRBaseMaterial as P };
//# sourceMappingURL=pbrBaseMaterial.pure-5Eirh_Zs.esm.js.map