UNPKG

@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.

670 lines (668 loc) 296 kB
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-MZPybX0H.esm.js'; import { G as GetEnvironmentBRDFTexture } from './brdfTextureTools-DrHgFJ85.esm.js'; import { M as MaterialPluginBase, D as DetailMapConfiguration } from './material.detailMapConfiguration-CHgbrJ-3.esm.js'; import { P as PrePassConfiguration, M as MaterialHelperGeometryRendering, a as PrepassDefinesMixin, U as UVDefinesMixin } from './prepass.defines-D50C_zO6.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?.di