@onerjs/core 8.26.4 → 8.26.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (151) hide show
  1. package/Engines/abstractEngine.js +2 -2
  2. package/Engines/abstractEngine.js.map +1 -1
  3. package/FrameGraph/Tasks/Rendering/objectRendererTask.js +6 -0
  4. package/FrameGraph/Tasks/Rendering/objectRendererTask.js.map +1 -1
  5. package/FrameGraph/frameGraphContext.d.ts +2 -1
  6. package/FrameGraph/frameGraphContext.js +4 -1
  7. package/FrameGraph/frameGraphContext.js.map +1 -1
  8. package/Lights/Clustered/clusteredLightContainer.d.ts +1 -1
  9. package/Lights/Clustered/clusteredLightContainer.js +4 -5
  10. package/Lights/Clustered/clusteredLightContainer.js.map +1 -1
  11. package/Lights/pointLight.js +4 -4
  12. package/Lights/pointLight.js.map +1 -1
  13. package/Lights/rectAreaLight.js +4 -4
  14. package/Lights/rectAreaLight.js.map +1 -1
  15. package/Lights/spotLight.js +2 -2
  16. package/Lights/spotLight.js.map +1 -1
  17. package/Materials/Background/backgroundMaterial.d.ts +19 -91
  18. package/Materials/Background/backgroundMaterial.js +17 -245
  19. package/Materials/Background/backgroundMaterial.js.map +1 -1
  20. package/Materials/Node/Blocks/Dual/currentScreenBlock.d.ts +3 -1
  21. package/Materials/Node/Blocks/Dual/currentScreenBlock.js +15 -6
  22. package/Materials/Node/Blocks/Dual/currentScreenBlock.js.map +1 -1
  23. package/Materials/Node/Blocks/Dual/imageSourceBlock.js +1 -1
  24. package/Materials/Node/Blocks/Dual/imageSourceBlock.js.map +1 -1
  25. package/Materials/Node/Blocks/Dual/lightBlock.js +15 -4
  26. package/Materials/Node/Blocks/Dual/lightBlock.js.map +1 -1
  27. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.d.ts +20 -0
  28. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.js +41 -3
  29. package/Materials/Node/Blocks/Dual/smartFilterTextureBlock.js.map +1 -1
  30. package/Materials/Node/Blocks/Fragment/smartFilterFragmentOutputBlock.js +0 -1
  31. package/Materials/Node/Blocks/Fragment/smartFilterFragmentOutputBlock.js.map +1 -1
  32. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js +28 -5
  33. package/Materials/Node/Blocks/PBR/pbrMetallicRoughnessBlock.js.map +1 -1
  34. package/Materials/Node/nodeMaterial.d.ts +57 -69
  35. package/Materials/Node/nodeMaterial.js +9 -86
  36. package/Materials/Node/nodeMaterial.js.map +1 -1
  37. package/Materials/Node/nodeMaterialBuildState.d.ts +3 -1
  38. package/Materials/Node/nodeMaterialBuildState.js +35 -15
  39. package/Materials/Node/nodeMaterialBuildState.js.map +1 -1
  40. package/Materials/PBR/index.d.ts +5 -0
  41. package/Materials/PBR/index.js +5 -0
  42. package/Materials/PBR/index.js.map +1 -1
  43. package/Materials/PBR/openPbrMaterial.d.ts +998 -0
  44. package/Materials/PBR/openPbrMaterial.js +2069 -0
  45. package/Materials/PBR/openPbrMaterial.js.map +1 -0
  46. package/Materials/PBR/pbrBaseMaterial.d.ts +65 -43
  47. package/Materials/PBR/pbrBaseMaterial.js +37 -308
  48. package/Materials/PBR/pbrBaseMaterial.js.map +1 -1
  49. package/Materials/PBR/pbrMaterial.d.ts +0 -78
  50. package/Materials/PBR/pbrMaterial.js +0 -110
  51. package/Materials/PBR/pbrMaterial.js.map +1 -1
  52. package/Materials/floatingOriginMatrixOverrides.d.ts +3 -0
  53. package/Materials/floatingOriginMatrixOverrides.js +91 -0
  54. package/Materials/floatingOriginMatrixOverrides.js.map +1 -0
  55. package/Materials/imageProcessing.d.ts +65 -0
  56. package/Materials/imageProcessing.js +162 -0
  57. package/Materials/imageProcessing.js.map +1 -0
  58. package/Materials/imageProcessingConfiguration.defines.d.ts +25 -0
  59. package/Materials/imageProcessingConfiguration.defines.js +27 -0
  60. package/Materials/imageProcessingConfiguration.defines.js.map +1 -1
  61. package/Materials/index.d.ts +2 -0
  62. package/Materials/index.js +2 -0
  63. package/Materials/index.js.map +1 -1
  64. package/Materials/material.d.ts +14 -0
  65. package/Materials/material.js +14 -0
  66. package/Materials/material.js.map +1 -1
  67. package/Materials/materialHelper.functions.d.ts +53 -0
  68. package/Materials/materialHelper.functions.js +297 -0
  69. package/Materials/materialHelper.functions.js.map +1 -1
  70. package/Materials/standardMaterial.d.ts +57 -121
  71. package/Materials/standardMaterial.js +21 -250
  72. package/Materials/standardMaterial.js.map +1 -1
  73. package/Materials/uv.defines.d.ts +22 -0
  74. package/Materials/uv.defines.js +24 -0
  75. package/Materials/uv.defines.js.map +1 -0
  76. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js +1 -0
  77. package/Meshes/GaussianSplatting/gaussianSplattingMesh.js.map +1 -1
  78. package/Misc/decorators.d.ts +7 -0
  79. package/Misc/decorators.js +34 -0
  80. package/Misc/decorators.js.map +1 -1
  81. package/Particles/Node/Blocks/Emitters/createParticleBlock.js +10 -1
  82. package/Particles/Node/Blocks/Emitters/createParticleBlock.js.map +1 -1
  83. package/Particles/Node/Blocks/index.d.ts +2 -0
  84. package/Particles/Node/Blocks/index.js +2 -0
  85. package/Particles/Node/Blocks/index.js.map +1 -1
  86. package/Particles/Node/Blocks/particleInputBlock.js +4 -1
  87. package/Particles/Node/Blocks/particleInputBlock.js.map +1 -1
  88. package/Particles/Node/Blocks/particleLocalVariableBlock.d.ts +38 -0
  89. package/Particles/Node/Blocks/particleLocalVariableBlock.js +108 -0
  90. package/Particles/Node/Blocks/particleLocalVariableBlock.js.map +1 -0
  91. package/Particles/Node/Blocks/particleVectorLengthBlock.d.ts +26 -0
  92. package/Particles/Node/Blocks/particleVectorLengthBlock.js +50 -0
  93. package/Particles/Node/Blocks/particleVectorLengthBlock.js.map +1 -0
  94. package/Rendering/IBLShadows/iblShadowsPluginMaterial.d.ts +2 -1
  95. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js +45 -0
  96. package/Rendering/IBLShadows/iblShadowsPluginMaterial.js.map +1 -1
  97. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js +2 -1
  98. package/Rendering/IBLShadows/iblShadowsRenderPipeline.js.map +1 -1
  99. package/Rendering/geometryBufferRenderer.js +6 -4
  100. package/Rendering/geometryBufferRenderer.js.map +1 -1
  101. package/Rendering/iblCdfGenerator.js +28 -20
  102. package/Rendering/iblCdfGenerator.js.map +1 -1
  103. package/Rendering/reflectiveShadowMap.d.ts +3 -3
  104. package/Shaders/ShadersInclude/backgroundUboDeclaration.js +1 -1
  105. package/Shaders/ShadersInclude/backgroundUboDeclaration.js.map +1 -1
  106. package/Shaders/ShadersInclude/clusteredLightingFunctions.js +3 -1
  107. package/Shaders/ShadersInclude/clusteredLightingFunctions.js.map +1 -1
  108. package/Shaders/ShadersInclude/defaultUboDeclaration.js +1 -1
  109. package/Shaders/ShadersInclude/defaultUboDeclaration.js.map +1 -1
  110. package/Shaders/ShadersInclude/hdrFilteringFunctions.js +34 -0
  111. package/Shaders/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  112. package/Shaders/ShadersInclude/helperFunctions.js +1 -1
  113. package/Shaders/ShadersInclude/helperFunctions.js.map +1 -1
  114. package/Shaders/ShadersInclude/importanceSampling.js +4 -0
  115. package/Shaders/ShadersInclude/importanceSampling.js.map +1 -1
  116. package/Shaders/ShadersInclude/lightsFragmentFunctions.js +1 -0
  117. package/Shaders/ShadersInclude/lightsFragmentFunctions.js.map +1 -1
  118. package/Shaders/ShadersInclude/pbrBRDFFunctions.js +1 -1
  119. package/Shaders/ShadersInclude/pbrBRDFFunctions.js.map +1 -1
  120. package/Shaders/ShadersInclude/pbrClusteredLightingFunctions.js +1 -0
  121. package/Shaders/ShadersInclude/pbrClusteredLightingFunctions.js.map +1 -1
  122. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js +3 -1
  123. package/Shaders/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  124. package/Shaders/ShadersInclude/pbrHelperFunctions.js +2 -0
  125. package/Shaders/ShadersInclude/pbrHelperFunctions.js.map +1 -1
  126. package/Shaders/ShadersInclude/pbrUboDeclaration.js +1 -1
  127. package/Shaders/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  128. package/Shaders/openpbr.vertex.js +1 -1
  129. package/Shaders/openpbr.vertex.js.map +1 -1
  130. package/ShadersWGSL/ShadersInclude/backgroundUboDeclaration.js +1 -1
  131. package/ShadersWGSL/ShadersInclude/backgroundUboDeclaration.js.map +1 -1
  132. package/ShadersWGSL/ShadersInclude/defaultUboDeclaration.js +1 -1
  133. package/ShadersWGSL/ShadersInclude/defaultUboDeclaration.js.map +1 -1
  134. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js +28 -0
  135. package/ShadersWGSL/ShadersInclude/hdrFilteringFunctions.js.map +1 -1
  136. package/ShadersWGSL/ShadersInclude/importanceSampling.js +4 -0
  137. package/ShadersWGSL/ShadersInclude/importanceSampling.js.map +1 -1
  138. package/ShadersWGSL/ShadersInclude/pbrBRDFFunctions.js +1 -1
  139. package/ShadersWGSL/ShadersInclude/pbrBRDFFunctions.js.map +1 -1
  140. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js +3 -1
  141. package/ShadersWGSL/ShadersInclude/pbrDirectLightingFunctions.js.map +1 -1
  142. package/ShadersWGSL/ShadersInclude/pbrHelperFunctions.js +2 -0
  143. package/ShadersWGSL/ShadersInclude/pbrHelperFunctions.js.map +1 -1
  144. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js +1 -1
  145. package/ShadersWGSL/ShadersInclude/pbrUboDeclaration.js.map +1 -1
  146. package/ShadersWGSL/openpbr.vertex.js +1 -1
  147. package/ShadersWGSL/openpbr.vertex.js.map +1 -1
  148. package/package.json +1 -1
  149. package/scene.d.ts +21 -0
  150. package/scene.js +29 -3
  151. package/scene.js.map +1 -1
@@ -0,0 +1,2069 @@
1
+ import { __decorate } from "../../tslib.es6.js";
2
+ /* eslint-disable @typescript-eslint/naming-convention */
3
+ import { serialize, expandToProperty, addAccessorsForMaterialProperty } from "../../Misc/decorators.js";
4
+ import { GetEnvironmentBRDFTexture } from "../../Misc/brdfTextureTools.js";
5
+ import { Scene } from "../../scene.js";
6
+ import { Color3 } from "../../Maths/math.color.js";
7
+ import { ImageProcessingConfiguration } from "../imageProcessingConfiguration.js";
8
+ import { Texture } from "../../Materials/Textures/texture.js";
9
+ import { RegisterClass } from "../../Misc/typeStore.js";
10
+ import { Material } from "../material.js";
11
+ import { SerializationHelper } from "../../Misc/decorators.serialization.js";
12
+ import { MaterialDefines } from "../materialDefines.js";
13
+ import { ImageProcessingDefinesMixin } from "../imageProcessingConfiguration.defines.js";
14
+ import { EffectFallbacks } from "../effectFallbacks.js";
15
+ import { AddClipPlaneUniforms, BindClipPlane } from "../clipPlaneMaterialHelper.js";
16
+ import { BindBonesParameters, BindFogParameters, BindLights, BindLogDepth, BindMorphTargetParameters, BindTextureMatrix, BindIBLParameters, BindIBLSamplers, HandleFallbacksForShadows, PrepareAttributesForBakedVertexAnimation, PrepareAttributesForBones, PrepareAttributesForInstances, PrepareAttributesForMorphTargets, PrepareDefinesForAttributes, PrepareDefinesForFrameBoundValues, PrepareDefinesForLights, PrepareDefinesForIBL, PrepareDefinesForMergedUV, PrepareDefinesForMisc, PrepareDefinesForMultiview, PrepareDefinesForOIT, PrepareDefinesForPrePass, PrepareUniformsAndSamplersList, PrepareUniformsAndSamplersForIBL, PrepareUniformLayoutForIBL, } from "../materialHelper.functions.js";
17
+
18
+ import { VertexBuffer } from "../../Buffers/buffer.js";
19
+ import { MaterialHelperGeometryRendering } from "../materialHelper.geometryrendering.js";
20
+ import { PrePassConfiguration } from "../prePassConfiguration.js";
21
+ import { MaterialFlags } from "../materialFlags.js";
22
+ import { Logger } from "../../Misc/logger.js";
23
+ import { UVDefinesMixin } from "../uv.defines.js";
24
+ import { Vector2, Vector4, TmpVectors } from "../../Maths/math.vector.js";
25
+ import { ImageProcessingMixin } from "../imageProcessing.js";
26
+ import { PushMaterial } from "../pushMaterial.js";
27
+ import { SmartArray } from "../../Misc/smartArray.js";
28
+ const onCreatedEffectParameters = { effect: null, subMesh: null };
29
+ class Uniform {
30
+ populateVectorFromLinkedProperties(vector) {
31
+ const destinationSize = vector.dimension[0];
32
+ for (const propKey in this.linkedProperties) {
33
+ const prop = this.linkedProperties[propKey];
34
+ const sourceSize = prop.numComponents;
35
+ if (destinationSize < sourceSize || prop.targetUniformComponentOffset > destinationSize - sourceSize) {
36
+ if (sourceSize == 1) {
37
+ Logger.Error(`Float property ${prop.name} has an offset that is too large.`);
38
+ }
39
+ else {
40
+ Logger.Error(`Vector${sourceSize} property ${prop.name} won't fit in Vector${destinationSize} or has an offset that is too large.`);
41
+ }
42
+ return;
43
+ }
44
+ if (typeof prop.value === "number") {
45
+ Uniform._tmpArray[prop.targetUniformComponentOffset] = prop.value;
46
+ }
47
+ else {
48
+ prop.value.toArray(Uniform._tmpArray, prop.targetUniformComponentOffset);
49
+ }
50
+ }
51
+ vector.fromArray(Uniform._tmpArray);
52
+ }
53
+ constructor(name, componentNum) {
54
+ this.linkedProperties = {};
55
+ this.name = name;
56
+ this.numComponents = componentNum;
57
+ }
58
+ }
59
+ Uniform._tmpArray = [0, 0, 0, 0];
60
+ /**
61
+ * Defines a property for the OpenPBRMaterial.
62
+ */
63
+ class Property {
64
+ /**
65
+ * Creates a new Property instance.
66
+ * @param name The name of the property in the shader
67
+ * @param defaultValue The default value of the property
68
+ * @param targetUniformName The name of the property in the shader uniform block
69
+ * @param targetUniformComponentNum The number of components in the target uniform. All properties that are
70
+ * packed into the same uniform must agree on the size of the target uniform.
71
+ * @param targetUniformComponentOffset The offset in the uniform where this property will be packed.
72
+ */
73
+ constructor(name, defaultValue, targetUniformName, targetUniformComponentNum, targetUniformComponentOffset = 0) {
74
+ // public includeAlphaFromProp: string = "";
75
+ /**
76
+ * If not given a type, there will be no uniform defined for this property and
77
+ * it will be assumed that the value will be packed into the already existing "uniformName" uniform.
78
+ */
79
+ this.targetUniformComponentNum = 4; // Default to vec4
80
+ this.targetUniformComponentOffset = 0;
81
+ this.name = name;
82
+ this.targetUniformName = targetUniformName;
83
+ this.defaultValue = defaultValue;
84
+ this.value = defaultValue;
85
+ this.targetUniformComponentNum = targetUniformComponentNum;
86
+ this.targetUniformComponentOffset = targetUniformComponentOffset;
87
+ }
88
+ /**
89
+ * Returns the number of components of the property based on its default value type.
90
+ */
91
+ get numComponents() {
92
+ if (typeof this.defaultValue === "number") {
93
+ return 1;
94
+ }
95
+ return this.defaultValue.dimension[0];
96
+ }
97
+ }
98
+ class Sampler {
99
+ /**
100
+ * The name of the sampler used in the shader.
101
+ * If this naming changes, we'll also need to change:
102
+ * - samplerFragmentDeclaration.fx
103
+ * - openpbr.fragment.fx
104
+ */
105
+ get samplerName() {
106
+ return this.samplerPrefix + "Sampler";
107
+ }
108
+ /**
109
+ * The name of the sampler info used in the shader.
110
+ * If this naming changes, we'll also need to change:
111
+ * - openpbr.vertex.fx
112
+ * - openpbr.fragment.fx
113
+ */
114
+ get samplerInfoName() {
115
+ return "v" + this.samplerPrefix.charAt(0).toUpperCase() + this.samplerPrefix.slice(1) + "Infos";
116
+ }
117
+ /**
118
+ * The name of the matrix used for this sampler in the shader.
119
+ * If this naming changes, we'll also need to change:
120
+ * - materialHelper.functions.BindTextureMatrix
121
+ * - samplerVertexImplementation.fx
122
+ * - openpbr.fragment.fx
123
+ */
124
+ get samplerMatrixName() {
125
+ return this.samplerPrefix + "Matrix";
126
+ }
127
+ /**
128
+ * Creates a new Sampler instance.
129
+ * @param name The name of the texture property
130
+ * @param samplerPrefix The prefix used for the name of the sampler in the shader
131
+ * @param textureDefine The define used in the shader for this sampler
132
+ */
133
+ constructor(name, samplerPrefix, textureDefine) {
134
+ this.value = null; // Texture value, default to null
135
+ this.samplerPrefix = ""; // The name of the sampler in the shader
136
+ this.textureDefine = ""; // The define used in the shader for this sampler
137
+ this.name = name;
138
+ this.samplerPrefix = samplerPrefix;
139
+ this.textureDefine = textureDefine;
140
+ }
141
+ }
142
+ class OpenPBRMaterialDefinesBase extends UVDefinesMixin(MaterialDefines) {
143
+ }
144
+ /**
145
+ * Manages the defines for the PBR Material.
146
+ * @internal
147
+ */
148
+ export class OpenPBRMaterialDefines extends ImageProcessingDefinesMixin(OpenPBRMaterialDefinesBase) {
149
+ /**
150
+ * Initializes the PBR Material defines.
151
+ * @param externalProperties The external properties
152
+ */
153
+ constructor(externalProperties) {
154
+ super(externalProperties);
155
+ this.NUM_SAMPLES = "0";
156
+ this.REALTIME_FILTERING = false;
157
+ this.IBL_CDF_FILTERING = false;
158
+ this.VERTEXCOLOR = false;
159
+ this.BAKED_VERTEX_ANIMATION_TEXTURE = false;
160
+ this.VERTEXALPHA = false;
161
+ this.ALPHATEST = false;
162
+ this.DEPTHPREPASS = false;
163
+ this.ALPHABLEND = false;
164
+ this.ALPHA_FROM_BASE_COLOR_TEXTURE = false;
165
+ this.ALPHATESTVALUE = "0.5";
166
+ this.PREMULTIPLYALPHA = false;
167
+ this.REFLECTIVITY_GAMMA = false;
168
+ this.REFLECTIVITYDIRECTUV = 0;
169
+ this.SPECULARTERM = false;
170
+ this.LODBASEDMICROSFURACE = true;
171
+ this.METALLICWORKFLOW = true;
172
+ this.ROUGHNESSSTOREINMETALMAPALPHA = false;
173
+ this.ROUGHNESSSTOREINMETALMAPGREEN = false;
174
+ this.METALLNESSSTOREINMETALMAPBLUE = false;
175
+ this.AOSTOREINMETALMAPRED = false;
176
+ this.SPECULAR_WEIGHT_IN_ALPHA = false;
177
+ this.SPECULAR_WEIGHT_FROM_SPECULAR_COLOR_TEXTURE = false;
178
+ this.SPECULAR_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE = false;
179
+ this.COAT_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE = false;
180
+ this.USE_GLTF_STYLE_ANISOTROPY = false;
181
+ this.ENVIRONMENTBRDF = false;
182
+ this.ENVIRONMENTBRDF_RGBD = false;
183
+ this.NORMAL = false;
184
+ this.TANGENT = false;
185
+ this.OBJECTSPACE_NORMALMAP = false;
186
+ this.PARALLAX = false;
187
+ this.PARALLAX_RHS = false;
188
+ this.PARALLAXOCCLUSION = false;
189
+ this.NORMALXYSCALE = true;
190
+ this.ANISOTROPIC = false; // Enables anisotropic logic. Still needed because it's used in pbrHelperFunctions
191
+ this.ANISOTROPIC_OPENPBR = true; // Tells the shader to use OpenPBR's anisotropic roughness remapping
192
+ this.ANISOTROPIC_BASE = false; // Tells the shader to apply anisotropy to the base layer
193
+ this.ANISOTROPIC_COAT = false; // Tells the shader to apply anisotropy to the coat layer
194
+ this.REFLECTION = false;
195
+ this.REFLECTIONMAP_3D = false;
196
+ this.REFLECTIONMAP_SPHERICAL = false;
197
+ this.REFLECTIONMAP_PLANAR = false;
198
+ this.REFLECTIONMAP_CUBIC = false;
199
+ this.USE_LOCAL_REFLECTIONMAP_CUBIC = false;
200
+ this.REFLECTIONMAP_PROJECTION = false;
201
+ this.REFLECTIONMAP_SKYBOX = false;
202
+ this.REFLECTIONMAP_EXPLICIT = false;
203
+ this.REFLECTIONMAP_EQUIRECTANGULAR = false;
204
+ this.REFLECTIONMAP_EQUIRECTANGULAR_FIXED = false;
205
+ this.REFLECTIONMAP_MIRROREDEQUIRECTANGULAR_FIXED = false;
206
+ this.INVERTCUBICMAP = false;
207
+ this.USESPHERICALFROMREFLECTIONMAP = false;
208
+ this.USEIRRADIANCEMAP = false;
209
+ this.USE_IRRADIANCE_DOMINANT_DIRECTION = false;
210
+ this.USESPHERICALINVERTEX = false;
211
+ this.REFLECTIONMAP_OPPOSITEZ = false;
212
+ this.LODINREFLECTIONALPHA = false;
213
+ this.GAMMAREFLECTION = false;
214
+ this.RGBDREFLECTION = false;
215
+ this.RADIANCEOCCLUSION = false;
216
+ this.HORIZONOCCLUSION = false;
217
+ this.INSTANCES = false;
218
+ this.THIN_INSTANCES = false;
219
+ this.INSTANCESCOLOR = false;
220
+ this.PREPASS = false;
221
+ this.PREPASS_COLOR = false;
222
+ this.PREPASS_COLOR_INDEX = -1;
223
+ this.PREPASS_IRRADIANCE = false;
224
+ this.PREPASS_IRRADIANCE_INDEX = -1;
225
+ this.PREPASS_ALBEDO = false;
226
+ this.PREPASS_ALBEDO_INDEX = -1;
227
+ this.PREPASS_ALBEDO_SQRT = false;
228
+ this.PREPASS_ALBEDO_SQRT_INDEX = -1;
229
+ this.PREPASS_DEPTH = false;
230
+ this.PREPASS_DEPTH_INDEX = -1;
231
+ this.PREPASS_SCREENSPACE_DEPTH = false;
232
+ this.PREPASS_SCREENSPACE_DEPTH_INDEX = -1;
233
+ this.PREPASS_NORMALIZED_VIEW_DEPTH = false;
234
+ this.PREPASS_NORMALIZED_VIEW_DEPTH_INDEX = -1;
235
+ this.PREPASS_NORMAL = false;
236
+ this.PREPASS_NORMAL_INDEX = -1;
237
+ this.PREPASS_NORMAL_WORLDSPACE = false;
238
+ this.PREPASS_WORLD_NORMAL = false;
239
+ this.PREPASS_WORLD_NORMAL_INDEX = -1;
240
+ this.PREPASS_POSITION = false;
241
+ this.PREPASS_POSITION_INDEX = -1;
242
+ this.PREPASS_LOCAL_POSITION = false;
243
+ this.PREPASS_LOCAL_POSITION_INDEX = -1;
244
+ this.PREPASS_VELOCITY = false;
245
+ this.PREPASS_VELOCITY_INDEX = -1;
246
+ this.PREPASS_VELOCITY_LINEAR = false;
247
+ this.PREPASS_VELOCITY_LINEAR_INDEX = -1;
248
+ this.PREPASS_REFLECTIVITY = false;
249
+ this.PREPASS_REFLECTIVITY_INDEX = -1;
250
+ this.SCENE_MRT_COUNT = 0;
251
+ this.NUM_BONE_INFLUENCERS = 0;
252
+ this.BonesPerMesh = 0;
253
+ this.BONETEXTURE = false;
254
+ this.BONES_VELOCITY_ENABLED = false;
255
+ this.NONUNIFORMSCALING = false;
256
+ this.MORPHTARGETS = false;
257
+ this.MORPHTARGETS_POSITION = false;
258
+ this.MORPHTARGETS_NORMAL = false;
259
+ this.MORPHTARGETS_TANGENT = false;
260
+ this.MORPHTARGETS_UV = false;
261
+ this.MORPHTARGETS_UV2 = false;
262
+ this.MORPHTARGETS_COLOR = false;
263
+ this.MORPHTARGETTEXTURE_HASPOSITIONS = false;
264
+ this.MORPHTARGETTEXTURE_HASNORMALS = false;
265
+ this.MORPHTARGETTEXTURE_HASTANGENTS = false;
266
+ this.MORPHTARGETTEXTURE_HASUVS = false;
267
+ this.MORPHTARGETTEXTURE_HASUV2S = false;
268
+ this.MORPHTARGETTEXTURE_HASCOLORS = false;
269
+ this.NUM_MORPH_INFLUENCERS = 0;
270
+ this.MORPHTARGETS_TEXTURE = false;
271
+ this.USEPHYSICALLIGHTFALLOFF = false;
272
+ this.USEGLTFLIGHTFALLOFF = false;
273
+ this.TWOSIDEDLIGHTING = false;
274
+ this.MIRRORED = false;
275
+ this.SHADOWFLOAT = false;
276
+ this.CLIPPLANE = false;
277
+ this.CLIPPLANE2 = false;
278
+ this.CLIPPLANE3 = false;
279
+ this.CLIPPLANE4 = false;
280
+ this.CLIPPLANE5 = false;
281
+ this.CLIPPLANE6 = false;
282
+ this.POINTSIZE = false;
283
+ this.FOG = false;
284
+ this.LOGARITHMICDEPTH = false;
285
+ this.CAMERA_ORTHOGRAPHIC = false;
286
+ this.CAMERA_PERSPECTIVE = false;
287
+ this.AREALIGHTSUPPORTED = true;
288
+ this.FORCENORMALFORWARD = false;
289
+ this.SPECULARAA = false;
290
+ this.UNLIT = false;
291
+ this.DECAL_AFTER_DETAIL = false;
292
+ this.DEBUGMODE = 0;
293
+ // BRDF defines
294
+ this.BRDF_V_HEIGHT_CORRELATED = true;
295
+ this.MS_BRDF_ENERGY_CONSERVATION = true;
296
+ this.SPHERICAL_HARMONICS = true;
297
+ this.SPECULAR_GLOSSINESS_ENERGY_CONSERVATION = true;
298
+ this.MIX_IBL_RADIANCE_WITH_IRRADIANCE = true;
299
+ this.LEGACY_SPECULAR_ENERGY_CONSERVATION = false;
300
+ this.BASE_DIFFUSE_MODEL = 0;
301
+ this.DIELECTRIC_SPECULAR_MODEL = 1;
302
+ this.CONDUCTOR_SPECULAR_MODEL = 1;
303
+ this.rebuild();
304
+ }
305
+ /**
306
+ * Resets the PBR Material defines.
307
+ */
308
+ reset() {
309
+ super.reset();
310
+ this.ALPHATESTVALUE = "0.5";
311
+ this.NORMALXYSCALE = true;
312
+ }
313
+ }
314
+ class OpenPBRMaterialBase extends ImageProcessingMixin(PushMaterial) {
315
+ }
316
+ /**
317
+ * A Physically based material that follows the specification of OpenPBR.
318
+ *
319
+ * For more information, please refer to the documentation :
320
+ * https://academysoftwarefoundation.github.io/OpenPBR/index.html
321
+ */
322
+ export class OpenPBRMaterial extends OpenPBRMaterialBase {
323
+ /**
324
+ * Defines the angle of the tangent of the material's geometry. Used only for anisotropic reflections.
325
+ * See OpenPBR's specs for geometry_tangent
326
+ */
327
+ get geometryTangentAngle() {
328
+ return Math.atan2(this.geometryTangent.y, this.geometryTangent.x);
329
+ }
330
+ set geometryTangentAngle(value) {
331
+ this.geometryTangent = new Vector2(Math.cos(value), Math.sin(value));
332
+ }
333
+ /**
334
+ * Defines the angle of the tangent of the material's coat layer.
335
+ */
336
+ get geometryCoatTangentAngle() {
337
+ return Math.atan2(this.geometryCoatTangent.y, this.geometryCoatTangent.x);
338
+ }
339
+ /**
340
+ * Defines the angle of the tangent of the material's coat layer.
341
+ */
342
+ set geometryCoatTangentAngle(value) {
343
+ this.geometryCoatTangent = new Vector2(Math.cos(value), Math.sin(value));
344
+ }
345
+ /**
346
+ * BJS is using an hardcoded light falloff based on a manually sets up range.
347
+ * In PBR, one way to represents the falloff is to use the inverse squared root algorithm.
348
+ * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.
349
+ */
350
+ get usePhysicalLightFalloff() {
351
+ return this._lightFalloff === Material.LIGHTFALLOFF_PHYSICAL;
352
+ }
353
+ /**
354
+ * BJS is using an hardcoded light falloff based on a manually sets up range.
355
+ * In PBR, one way to represents the falloff is to use the inverse squared root algorithm.
356
+ * This parameter can help you switch back to the BJS mode in order to create scenes using both materials.
357
+ */
358
+ set usePhysicalLightFalloff(value) {
359
+ if (value !== this.usePhysicalLightFalloff) {
360
+ // Ensure the effect will be rebuilt.
361
+ this._markAllSubMeshesAsTexturesDirty();
362
+ if (value) {
363
+ this._lightFalloff = Material.LIGHTFALLOFF_PHYSICAL;
364
+ }
365
+ else {
366
+ this._lightFalloff = Material.LIGHTFALLOFF_STANDARD;
367
+ }
368
+ }
369
+ }
370
+ /**
371
+ * In order to support the falloff compatibility with gltf, a special mode has been added
372
+ * to reproduce the gltf light falloff.
373
+ */
374
+ get useGLTFLightFalloff() {
375
+ return this._lightFalloff === Material.LIGHTFALLOFF_GLTF;
376
+ }
377
+ /**
378
+ * In order to support the falloff compatibility with gltf, a special mode has been added
379
+ * to reproduce the gltf light falloff.
380
+ */
381
+ set useGLTFLightFalloff(value) {
382
+ if (value !== this.useGLTFLightFalloff) {
383
+ // Ensure the effect will be rebuilt.
384
+ this._markAllSubMeshesAsTexturesDirty();
385
+ if (value) {
386
+ this._lightFalloff = Material.LIGHTFALLOFF_GLTF;
387
+ }
388
+ else {
389
+ this._lightFalloff = Material.LIGHTFALLOFF_STANDARD;
390
+ }
391
+ }
392
+ }
393
+ /**
394
+ * Enables realtime filtering on the texture.
395
+ */
396
+ get realTimeFiltering() {
397
+ return this._realTimeFiltering;
398
+ }
399
+ set realTimeFiltering(b) {
400
+ this._realTimeFiltering = b;
401
+ this.markAsDirty(1);
402
+ }
403
+ /**
404
+ * Quality switch for realtime filtering
405
+ */
406
+ get realTimeFilteringQuality() {
407
+ return this._realTimeFilteringQuality;
408
+ }
409
+ set realTimeFilteringQuality(n) {
410
+ this._realTimeFilteringQuality = n;
411
+ this.markAsDirty(1);
412
+ }
413
+ /**
414
+ * Can this material render to several textures at once
415
+ */
416
+ get canRenderToMRT() {
417
+ return true;
418
+ }
419
+ /**
420
+ * Instantiates a new OpenPBRMaterial instance.
421
+ *
422
+ * @param name The material name
423
+ * @param scene The scene the material will be use in.
424
+ * @param forceGLSL Use the GLSL code generation for the shader (even on WebGPU). Default is false
425
+ */
426
+ constructor(name, scene, forceGLSL = false) {
427
+ super(name, scene, undefined, forceGLSL || OpenPBRMaterial.ForceGLSL);
428
+ this._baseWeight = new Property("base_weight", 1, "vBaseWeight", 1);
429
+ this._baseWeightTexture = new Sampler("base_weight", "baseWeight", "BASE_WEIGHT");
430
+ this._baseColor = new Property("base_color", Color3.White(), "vBaseColor", 4);
431
+ this._baseColorTexture = new Sampler("base_color", "baseColor", "BASE_COLOR");
432
+ this._baseDiffuseRoughness = new Property("base_diffuse_roughness", 0, "vBaseDiffuseRoughness", 1);
433
+ this._baseDiffuseRoughnessTexture = new Sampler("base_diffuse_roughness", "baseDiffuseRoughness", "BASE_DIFFUSE_ROUGHNESS");
434
+ this._baseMetalness = new Property("base_metalness", 0, "vReflectanceInfo", 4, 0);
435
+ this._baseMetalnessTexture = new Sampler("base_metalness", "baseMetalness", "BASE_METALNESS");
436
+ this._specularWeight = new Property("specular_weight", 1, "vReflectanceInfo", 4, 3);
437
+ this._specularWeightTexture = new Sampler("specular_weight", "specularWeight", "SPECULAR_WEIGHT");
438
+ this._specularColor = new Property("specular_color", Color3.White(), "vSpecularColor", 4);
439
+ this._specularColorTexture = new Sampler("specular_color", "specularColor", "SPECULAR_COLOR");
440
+ this._specularRoughness = new Property("specular_roughness", 0.3, "vReflectanceInfo", 4, 1);
441
+ this._specularRoughnessTexture = new Sampler("specular_roughness", "specularRoughness", "SPECULAR_ROUGHNESS");
442
+ this._specularRoughnessAnisotropy = new Property("specular_roughness_anisotropy", 0, "vSpecularAnisotropy", 3, 2);
443
+ this._specularRoughnessAnisotropyTexture = new Sampler("specular_roughness_anisotropy", "specularRoughnessAnisotropy", "SPECULAR_ROUGHNESS_ANISOTROPY");
444
+ this._specularIor = new Property("specular_ior", 1.5, "vReflectanceInfo", 4, 2);
445
+ this._coatWeight = new Property("coat_weight", 0.0, "vCoatWeight", 1, 0);
446
+ this._coatWeightTexture = new Sampler("coat_weight", "coatWeight", "COAT_WEIGHT");
447
+ this._coatColor = new Property("coat_color", Color3.White(), "vCoatColor", 3, 0);
448
+ this._coatColorTexture = new Sampler("coat_color", "coatColor", "COAT_COLOR");
449
+ this._coatRoughness = new Property("coat_roughness", 0.0, "vCoatRoughness", 1, 0);
450
+ this._coatRoughnessTexture = new Sampler("coat_roughness", "coatRoughness", "COAT_ROUGHNESS");
451
+ this._coatRoughnessAnisotropy = new Property("coat_roughness_anisotropy", 0, "vCoatRoughnessAnisotropy", 1);
452
+ this._coatRoughnessAnisotropyTexture = new Sampler("coat_roughness_anisotropy", "coatRoughnessAnisotropy", "COAT_ROUGHNESS_ANISOTROPY");
453
+ this._coatIor = new Property("coat_ior", 1.5, "vCoatIor", 1, 0);
454
+ this._coatDarkening = new Property("coat_darkening", 1.0, "vCoatDarkening", 1, 0);
455
+ this._coatDarkeningTexture = new Sampler("coat_darkening", "coatDarkening", "COAT_DARKENING");
456
+ /**
457
+ * Specifies whether the coat roughness is taken from the
458
+ * same texture as the coat_weight.
459
+ */
460
+ this.useCoatRoughnessFromWeightTexture = false;
461
+ this._geometryNormalTexture = new Sampler("geometry_normal", "geometryNormal", "GEOMETRY_NORMAL");
462
+ this._geometryTangent = new Property("geometry_tangent", new Vector2(1, 0), "vSpecularAnisotropy", 3, 0);
463
+ this._geometryTangentTexture = new Sampler("geometry_tangent", "geometryTangent", "GEOMETRY_TANGENT");
464
+ this._geometryCoatNormalTexture = new Sampler("geometry_coat_normal", "geometryCoatNormal", "GEOMETRY_COAT_NORMAL");
465
+ this._geometryCoatTangent = new Property("geometry_coat_tangent", new Vector2(1, 0), "vGeometryCoatTangent", 2, 0);
466
+ this._geometryCoatTangentTexture = new Sampler("geometry_coat_tangent", "geometryCoatTangent", "GEOMETRY_COAT_TANGENT");
467
+ this._geometryOpacity = new Property("geometry_opacity", 1.0, "vBaseColor", 4, 3);
468
+ this._geometryOpacityTexture = new Sampler("geometry_opacity", "geometryOpacity", "GEOMETRY_OPACITY");
469
+ this._emissionLuminance = new Property("emission_luminance", 1.0, "vLightingIntensity", 4, 1);
470
+ this._emissionColor = new Property("emission_color", Color3.Black(), "vEmissionColor", 3);
471
+ this._emissionColorTexture = new Sampler("emission_color", "emissionColor", "EMISSION_COLOR");
472
+ this._ambientOcclusionTexture = new Sampler("ambient_occlusion", "ambientOcclusion", "AMBIENT_OCCLUSION");
473
+ this._uniformsList = {};
474
+ this._samplersList = {};
475
+ this._samplerDefines = {};
476
+ /**
477
+ * Intensity of the direct lights e.g. the four lights available in your scene.
478
+ * This impacts both the direct diffuse and specular highlights.
479
+ */
480
+ this.directIntensity = 1.0;
481
+ /**
482
+ * Intensity of the environment e.g. how much the environment will light the object
483
+ * either through harmonics for rough material or through the reflection for shiny ones.
484
+ */
485
+ this.environmentIntensity = 1.0;
486
+ /**
487
+ * Specifies that the specular weight is stored in the alpha channel of the specular weight texture.
488
+ */
489
+ this.useSpecularWeightFromTextureAlpha = false;
490
+ /**
491
+ * Enforces alpha test in opaque or blend mode in order to improve the performances of some situations.
492
+ */
493
+ this.forceAlphaTest = false;
494
+ /**
495
+ * Defines the alpha limits in alpha test mode.
496
+ */
497
+ this.alphaCutOff = 0.4;
498
+ /**
499
+ * Specifies if the metallic texture contains the ambient occlusion information in its red channel.
500
+ */
501
+ this.useAmbientOcclusionFromMetallicTextureRed = false;
502
+ /**
503
+ * Specifies if the ambient texture contains the ambient occlusion information in its red channel only.
504
+ */
505
+ this.useAmbientInGrayScale = false;
506
+ /**
507
+ * Allows using an object space normal map (instead of tangent space).
508
+ */
509
+ this.useObjectSpaceNormalMap = false;
510
+ /**
511
+ * Allows using the normal map in parallax mode.
512
+ */
513
+ this.useParallax = false;
514
+ /**
515
+ * Allows using the normal map in parallax occlusion mode.
516
+ */
517
+ this.useParallaxOcclusion = false;
518
+ /**
519
+ * Controls the scale bias of the parallax mode.
520
+ */
521
+ this.parallaxScaleBias = 0.05;
522
+ /**
523
+ * If sets to true, disables all the lights affecting the material.
524
+ */
525
+ this.disableLighting = false;
526
+ /**
527
+ * Force the shader to compute irradiance in the fragment shader in order to take normal mapping into account.
528
+ */
529
+ this.forceIrradianceInFragment = false;
530
+ /**
531
+ * Number of Simultaneous lights allowed on the material.
532
+ */
533
+ this.maxSimultaneousLights = 4;
534
+ /**
535
+ * If sets to true, x component of normal map value will invert (x = 1.0 - x).
536
+ */
537
+ this.invertNormalMapX = false;
538
+ /**
539
+ * If sets to true, y component of normal map value will invert (y = 1.0 - y).
540
+ */
541
+ this.invertNormalMapY = false;
542
+ /**
543
+ * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
544
+ */
545
+ this.twoSidedLighting = false;
546
+ /**
547
+ * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
548
+ * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)
549
+ */
550
+ this.useAlphaFresnel = false;
551
+ /**
552
+ * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
553
+ * And/Or occlude the blended part. (alpha stays linear to compute the fresnel)
554
+ */
555
+ this.useLinearAlphaFresnel = false;
556
+ /**
557
+ * Let user defines the brdf lookup texture used for IBL.
558
+ * A default 8bit version is embedded but you could point at :
559
+ * * Default texture: https://assets.babylonjs.com/environments/correlatedMSBRDF_RGBD.png
560
+ * * Default 16bit pixel depth texture: https://assets.babylonjs.com/environments/correlatedMSBRDF.dds
561
+ * * LEGACY Default None correlated https://assets.babylonjs.com/environments/uncorrelatedBRDF_RGBD.png
562
+ * * LEGACY Default None correlated 16bit pixel depth https://assets.babylonjs.com/environments/uncorrelatedBRDF.dds
563
+ */
564
+ this.environmentBRDFTexture = null;
565
+ /**
566
+ * Force normal to face away from face.
567
+ */
568
+ this.forceNormalForward = false;
569
+ /**
570
+ * Enables specular anti aliasing in the PBR shader.
571
+ * It will both interacts on the Geometry for analytical and IBL lighting.
572
+ * It also prefilter the roughness map based on the normalmap values.
573
+ */
574
+ this.enableSpecularAntiAliasing = false;
575
+ /**
576
+ * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal
577
+ * makes the reflect vector face the model (under horizon).
578
+ */
579
+ this.useHorizonOcclusion = true;
580
+ /**
581
+ * This parameters will enable/disable radiance occlusion by preventing the radiance to lit
582
+ * too much the area relying on ambient texture to define their ambient occlusion.
583
+ */
584
+ this.useRadianceOcclusion = true;
585
+ /**
586
+ * If set to true, no lighting calculations will be applied.
587
+ */
588
+ this.unlit = false;
589
+ /**
590
+ * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)
591
+ */
592
+ this.applyDecalMapAfterDetailMap = false;
593
+ /**
594
+ * This stores the direct, emissive, environment, and specular light intensities into a Vector4.
595
+ */
596
+ this._lightingInfos = new Vector4(this.directIntensity, 1.0, this.environmentIntensity, 1.0);
597
+ /**
598
+ * Stores the radiance (and, possibly, irradiance) values in a texture.
599
+ * @internal
600
+ */
601
+ this._radianceTexture = null;
602
+ /**
603
+ * Specifies that the specular weight will be read from the alpha channel.
604
+ * This is for compatibility with glTF's KHR_materials_specular extension.
605
+ * @internal
606
+ */
607
+ this._useSpecularWeightFromAlpha = false;
608
+ /**
609
+ * Specifies that the specular weight will be read from the alpha channel of the specular color texture.
610
+ * This is for compatibility with glTF's KHR_materials_specular extension.
611
+ * @internal
612
+ */
613
+ this._useSpecularWeightFromSpecularColorTexture = false;
614
+ /**
615
+ * Specifies if the material uses anisotropy weight read from the geometry tangent texture's blue channel.
616
+ * This is for compatibility with glTF's anisotropy extension.
617
+ * @internal
618
+ */
619
+ this._useSpecularRoughnessAnisotropyFromTangentTexture = false;
620
+ /**
621
+ * Specifies if the material uses coat anisotropy weight read from the coat's geometry tangent texture's blue channel.
622
+ * This is for compatibility with glTF's clearcoat_anisotropy extension.
623
+ * @internal
624
+ */
625
+ this._useCoatRoughnessAnisotropyFromTangentTexture = false;
626
+ /**
627
+ * Assume the anisotropy data is stored in the format specified by
628
+ * KHR_materials_anisotropy.
629
+ * @internal
630
+ */
631
+ this._useGltfStyleAnisotropy = false;
632
+ /**
633
+ * This parameters will enable/disable Horizon occlusion to prevent normal maps to look shiny when the normal
634
+ * makes the reflect vector face the model (under horizon).
635
+ * @internal
636
+ */
637
+ this._useHorizonOcclusion = true;
638
+ /**
639
+ * This parameters will enable/disable radiance occlusion by preventing the radiance to lit
640
+ * too much the area relying on ambient texture to define their ambient occlusion.
641
+ * @internal
642
+ */
643
+ this._useRadianceOcclusion = true;
644
+ /**
645
+ * Specifies that the alpha is coming from the base color texture's alpha channel.
646
+ * This is for compatibility with glTF.
647
+ * @internal
648
+ */
649
+ this._useAlphaFromBaseColorTexture = false;
650
+ /**
651
+ * Specifies if the metallic texture contains the ambient occlusion information in its red channel.
652
+ * This is for compatibility with glTF.
653
+ * @internal
654
+ */
655
+ this._useAmbientOcclusionFromMetallicTextureRed = false;
656
+ /**
657
+ * Specifies if the metallic texture contains the roughness information in its green channel.
658
+ * This is for compatibility with glTF.
659
+ * @internal
660
+ */
661
+ this._useRoughnessFromMetallicTextureGreen = false;
662
+ /**
663
+ * Specifies if the metallic texture contains the metallic information in its blue channel.
664
+ * This is for compatibility with glTF.
665
+ * @internal
666
+ */
667
+ this._useMetallicFromMetallicTextureBlue = false;
668
+ /**
669
+ * Defines the falloff type used in this material.
670
+ * It by default is Physical.
671
+ * @internal
672
+ */
673
+ this._lightFalloff = Material.LIGHTFALLOFF_PHYSICAL;
674
+ /**
675
+ * Allows using an object space normal map (instead of tangent space).
676
+ * @internal
677
+ */
678
+ this._useObjectSpaceNormalMap = false;
679
+ /**
680
+ * Allows using the normal map in parallax mode.
681
+ * @internal
682
+ */
683
+ this._useParallax = false;
684
+ /**
685
+ * Allows using the normal map in parallax occlusion mode.
686
+ * @internal
687
+ */
688
+ this._useParallaxOcclusion = false;
689
+ /**
690
+ * Controls the scale bias of the parallax mode.
691
+ * @internal
692
+ */
693
+ this._parallaxScaleBias = 0.05;
694
+ /**
695
+ * If sets to true, disables all the lights affecting the material.
696
+ * @internal
697
+ */
698
+ this._disableLighting = false;
699
+ /**
700
+ * Number of Simultaneous lights allowed on the material.
701
+ * @internal
702
+ */
703
+ this._maxSimultaneousLights = 4;
704
+ /**
705
+ * If sets to true, x component of normal map value will be inverted (x = 1.0 - x).
706
+ * @internal
707
+ */
708
+ this._invertNormalMapX = false;
709
+ /**
710
+ * If sets to true, y component of normal map value will be inverted (y = 1.0 - y).
711
+ * @internal
712
+ */
713
+ this._invertNormalMapY = false;
714
+ /**
715
+ * If sets to true and backfaceCulling is false, normals will be flipped on the backside.
716
+ * @internal
717
+ */
718
+ this._twoSidedLighting = false;
719
+ /**
720
+ * Defines the alpha limits in alpha test mode.
721
+ * @internal
722
+ */
723
+ this._alphaCutOff = 0.4;
724
+ /**
725
+ * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
726
+ * And/Or occlude the blended part. (alpha is converted to gamma to compute the fresnel)
727
+ * @internal
728
+ */
729
+ this._useAlphaFresnel = false;
730
+ /**
731
+ * A fresnel is applied to the alpha of the model to ensure grazing angles edges are not alpha tested.
732
+ * And/Or occlude the blended part. (alpha stays linear to compute the fresnel)
733
+ * @internal
734
+ */
735
+ this._useLinearAlphaFresnel = false;
736
+ /**
737
+ * Specifies the environment BRDF texture used to compute the scale and offset roughness values
738
+ * from cos theta and roughness:
739
+ * http://blog.selfshadow.com/publications/s2013-shading-course/karis/s2013_pbs_epic_notes_v2.pdf
740
+ * @internal
741
+ */
742
+ this._environmentBRDFTexture = null;
743
+ /**
744
+ * Force the shader to compute irradiance in the fragment shader in order to take normal mapping into account.
745
+ * @internal
746
+ */
747
+ this._forceIrradianceInFragment = false;
748
+ this._realTimeFiltering = false;
749
+ this._realTimeFilteringQuality = 8;
750
+ /**
751
+ * Force normal to face away from face.
752
+ * @internal
753
+ */
754
+ this._forceNormalForward = false;
755
+ /**
756
+ * Enables specular anti aliasing in the PBR shader.
757
+ * It will both interacts on the Geometry for analytical and IBL lighting.
758
+ * It also prefilter the roughness map based on the normalmap values.
759
+ * @internal
760
+ */
761
+ this._enableSpecularAntiAliasing = false;
762
+ /**
763
+ * Stores the available render targets.
764
+ */
765
+ this._renderTargets = new SmartArray(16);
766
+ /**
767
+ * If set to true, no lighting calculations will be applied.
768
+ */
769
+ this._unlit = false;
770
+ /**
771
+ * If sets to true, the decal map will be applied after the detail map. Else, it is applied before (default: false)
772
+ */
773
+ this._applyDecalMapAfterDetailMap = false;
774
+ this._debugMode = 0;
775
+ this._shadersLoaded = false;
776
+ this._breakShaderLoadedCheck = false;
777
+ /**
778
+ * @internal
779
+ * This is reserved for the inspector.
780
+ * Defines the material debug mode.
781
+ * It helps seeing only some components of the material while troubleshooting.
782
+ */
783
+ this.debugMode = 0;
784
+ /**
785
+ * @internal
786
+ * This is reserved for the inspector.
787
+ * Specify from where on screen the debug mode should start.
788
+ * The value goes from -1 (full screen) to 1 (not visible)
789
+ * It helps with side by side comparison against the final render
790
+ * This defaults to -1
791
+ */
792
+ this.debugLimit = -1;
793
+ /**
794
+ * @internal
795
+ * This is reserved for the inspector.
796
+ * As the default viewing range might not be enough (if the ambient is really small for instance)
797
+ * You can use the factor to better multiply the final value.
798
+ */
799
+ this.debugFactor = 1;
800
+ this._cacheHasRenderTargetTextures = false;
801
+ this._transparencyMode = Material.MATERIAL_OPAQUE;
802
+ // TODO: Check if we're running WebGL 2.0 or above
803
+ if (this.getScene() && !this.getScene()?.getEngine().isWebGPU && this.getScene().getEngine().webGLVersion < 2) {
804
+ Logger.Error("OpenPBRMaterial: WebGL 2.0 or above is required for this material.");
805
+ }
806
+ if (!OpenPBRMaterial._noiseTextures[this.getScene().uniqueId]) {
807
+ OpenPBRMaterial._noiseTextures[this.getScene().uniqueId] = new Texture("https://assets.babylonjs.com/textures/blue_noise/blue_noise_rgb.png", this.getScene(), false, true, 1);
808
+ this.getScene().onDisposeObservable.addOnce(() => {
809
+ OpenPBRMaterial._noiseTextures[this.getScene().uniqueId]?.dispose();
810
+ delete OpenPBRMaterial._noiseTextures[this.getScene().uniqueId];
811
+ });
812
+ }
813
+ // Setup the default processing configuration to the scene.
814
+ this._attachImageProcessingConfiguration(null);
815
+ this.getRenderTargetTextures = () => {
816
+ this._renderTargets.reset();
817
+ if (MaterialFlags.ReflectionTextureEnabled && this._radianceTexture && this._radianceTexture.isRenderTarget) {
818
+ this._renderTargets.push(this._radianceTexture);
819
+ }
820
+ this._eventInfo.renderTargets = this._renderTargets;
821
+ this._callbackPluginEventFillRenderTargetTextures(this._eventInfo);
822
+ return this._renderTargets;
823
+ };
824
+ this._environmentBRDFTexture = GetEnvironmentBRDFTexture(this.getScene());
825
+ this.prePassConfiguration = new PrePassConfiguration();
826
+ // Build the internal property list that can be used to generate and update the uniform buffer
827
+ this._propertyList = {};
828
+ for (const key of Object.getOwnPropertyNames(this)) {
829
+ const value = this[key];
830
+ if (value instanceof Property) {
831
+ this._propertyList[key] = value;
832
+ }
833
+ }
834
+ // Build the internal uniforms list that is used for combining and updating
835
+ // property values in the uniform buffer
836
+ const propertyKeys = Object.keys(this._propertyList);
837
+ propertyKeys.forEach((key) => {
838
+ const prop = this._propertyList[key];
839
+ let uniform = this._uniformsList[prop.targetUniformName];
840
+ if (!uniform) {
841
+ uniform = new Uniform(prop.targetUniformName, prop.targetUniformComponentNum);
842
+ this._uniformsList[prop.targetUniformName] = uniform;
843
+ }
844
+ else if (uniform.numComponents !== prop.targetUniformComponentNum) {
845
+ Logger.Error(`Uniform ${prop.targetUniformName} already exists of size ${uniform.numComponents}, but trying to set it to ${prop.targetUniformComponentNum}.`);
846
+ }
847
+ uniform.linkedProperties[prop.name] = prop;
848
+ });
849
+ // Build the internal list of samplers
850
+ this._samplersList = {};
851
+ for (const key of Object.getOwnPropertyNames(this)) {
852
+ const value = this[key];
853
+ if (value instanceof Sampler) {
854
+ this._samplersList[key] = value;
855
+ }
856
+ }
857
+ // For each sampler in _samplersList, add defines to be added to OpenPBRMaterialDefines
858
+ for (const samplerKey in this._samplersList) {
859
+ const sampler = this._samplersList[samplerKey];
860
+ const defineName = sampler.textureDefine;
861
+ this._samplerDefines[defineName] = { type: "boolean", default: false };
862
+ this._samplerDefines[defineName + "DIRECTUV"] = { type: "number", default: 0 };
863
+ this._samplerDefines[defineName + "_GAMMA"] = { type: "boolean", default: false };
864
+ }
865
+ // Arg. Why do I have to add these references to get rid of the linting errors?
866
+ this._baseWeight;
867
+ this._baseWeightTexture;
868
+ this._baseColor;
869
+ this._baseColorTexture;
870
+ this._baseDiffuseRoughness;
871
+ this._baseDiffuseRoughnessTexture;
872
+ this._baseMetalness;
873
+ this._baseMetalnessTexture;
874
+ this._specularWeight;
875
+ this._specularWeightTexture;
876
+ this._specularColor;
877
+ this._specularColorTexture;
878
+ this._specularRoughness;
879
+ this._specularIor;
880
+ this._specularRoughnessTexture;
881
+ this._specularRoughnessAnisotropy;
882
+ this._specularRoughnessAnisotropyTexture;
883
+ this._coatWeight;
884
+ this._coatWeightTexture;
885
+ this._coatColor;
886
+ this._coatColorTexture;
887
+ this._coatRoughness;
888
+ this._coatRoughnessTexture;
889
+ this._coatRoughnessAnisotropy;
890
+ this._coatRoughnessAnisotropyTexture;
891
+ this._coatIor;
892
+ this._coatDarkening;
893
+ this._coatDarkeningTexture;
894
+ this._geometryNormalTexture;
895
+ this._geometryTangent;
896
+ this._geometryTangentTexture;
897
+ this._geometryCoatNormalTexture;
898
+ this._geometryCoatTangent;
899
+ this._geometryCoatTangentTexture;
900
+ this._geometryOpacity;
901
+ this._geometryOpacityTexture;
902
+ this._emissionLuminance;
903
+ this._emissionColor;
904
+ this._emissionColorTexture;
905
+ this._ambientOcclusionTexture;
906
+ }
907
+ /**
908
+ * Gets a boolean indicating that current material needs to register RTT
909
+ */
910
+ get hasRenderTargetTextures() {
911
+ if (MaterialFlags.ReflectionTextureEnabled && this._radianceTexture && this._radianceTexture.isRenderTarget) {
912
+ return true;
913
+ }
914
+ return this._cacheHasRenderTargetTextures;
915
+ }
916
+ /**
917
+ * Can this material render to prepass
918
+ */
919
+ get isPrePassCapable() {
920
+ return !this.disableDepthWrite;
921
+ }
922
+ /**
923
+ * @returns the name of the material class.
924
+ */
925
+ getClassName() {
926
+ return "OpenPBRMaterial";
927
+ }
928
+ get transparencyMode() {
929
+ return this._transparencyMode;
930
+ }
931
+ set transparencyMode(value) {
932
+ if (this._transparencyMode === value) {
933
+ return;
934
+ }
935
+ this._transparencyMode = value;
936
+ this._markAllSubMeshesAsTexturesAndMiscDirty();
937
+ }
938
+ /**
939
+ * @returns whether or not the alpha value of the albedo texture should be used for alpha blending.
940
+ */
941
+ _shouldUseAlphaFromBaseColorTexture() {
942
+ return this._hasAlphaChannel() && this._transparencyMode !== Material.MATERIAL_OPAQUE && !this.geometryOpacityTexture;
943
+ }
944
+ /**
945
+ * @returns whether or not there is a usable alpha channel for transparency.
946
+ */
947
+ _hasAlphaChannel() {
948
+ return (this.baseColorTexture != null && this.baseColorTexture.hasAlpha && this._useAlphaFromBaseColorTexture) || this.geometryOpacityTexture != null;
949
+ }
950
+ /**
951
+ * Makes a duplicate of the current material.
952
+ * @param name - name to use for the new material.
953
+ * @param cloneTexturesOnlyOnce - if a texture is used in more than one channel (e.g baseColor and opacity), only clone it once and reuse it on the other channels. Default false.
954
+ * @param rootUrl defines the root URL to use to load textures
955
+ * @returns cloned material instance
956
+ */
957
+ clone(name, cloneTexturesOnlyOnce = true, rootUrl = "") {
958
+ const clone = SerializationHelper.Clone(() => new OpenPBRMaterial(name, this.getScene()), this, { cloneTexturesOnlyOnce });
959
+ clone.id = name;
960
+ clone.name = name;
961
+ this.stencil.copyTo(clone.stencil);
962
+ this._clonePlugins(clone, rootUrl);
963
+ return clone;
964
+ }
965
+ /**
966
+ * Serializes this PBR Material.
967
+ * @returns - An object with the serialized material.
968
+ */
969
+ serialize() {
970
+ const serializationObject = super.serialize();
971
+ serializationObject.customType = "BABYLON.OpenPBRMaterial";
972
+ return serializationObject;
973
+ }
974
+ // Statics
975
+ /**
976
+ * Parses a PBR Material from a serialized object.
977
+ * @param source - Serialized object.
978
+ * @param scene - BJS scene instance.
979
+ * @param rootUrl - url for the scene object
980
+ * @returns - OpenPBRMaterial
981
+ */
982
+ static Parse(source, scene, rootUrl) {
983
+ const material = SerializationHelper.Parse(() => new OpenPBRMaterial(source.name, scene), source, scene, rootUrl);
984
+ if (source.stencil) {
985
+ material.stencil.parse(source.stencil, scene, rootUrl);
986
+ }
987
+ Material._ParsePlugins(source, material, scene, rootUrl);
988
+ return material;
989
+ }
990
+ /**
991
+ * Force shader compilation
992
+ * @param mesh - Define the mesh we want to force the compilation for
993
+ * @param onCompiled - Define a callback triggered when the compilation completes
994
+ * @param options - Define the options used to create the compilation
995
+ */
996
+ forceCompilation(mesh, onCompiled, options) {
997
+ const localOptions = {
998
+ clipPlane: false,
999
+ useInstances: false,
1000
+ ...options,
1001
+ };
1002
+ if (!this._uniformBufferLayoutBuilt) {
1003
+ this.buildUniformLayout();
1004
+ }
1005
+ this._callbackPluginEventGeneric(4 /* MaterialPluginEvent.GetDefineNames */, this._eventInfo);
1006
+ const checkReady = () => {
1007
+ if (this._breakShaderLoadedCheck) {
1008
+ return;
1009
+ }
1010
+ const defines = new OpenPBRMaterialDefines({
1011
+ ...(this._eventInfo.defineNames || {}),
1012
+ ...(this._samplerDefines || {}),
1013
+ });
1014
+ const effect = this._prepareEffect(mesh, defines, undefined, undefined, localOptions.useInstances, localOptions.clipPlane, mesh.hasThinInstances);
1015
+ if (this._onEffectCreatedObservable) {
1016
+ onCreatedEffectParameters.effect = effect;
1017
+ onCreatedEffectParameters.subMesh = null;
1018
+ this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);
1019
+ }
1020
+ if (effect.isReady()) {
1021
+ if (onCompiled) {
1022
+ onCompiled(this);
1023
+ }
1024
+ }
1025
+ else {
1026
+ effect.onCompileObservable.add(() => {
1027
+ if (onCompiled) {
1028
+ onCompiled(this);
1029
+ }
1030
+ });
1031
+ }
1032
+ };
1033
+ checkReady();
1034
+ }
1035
+ /**
1036
+ * Specifies that the submesh is ready to be used.
1037
+ * @param mesh - BJS mesh.
1038
+ * @param subMesh - A submesh of the BJS mesh. Used to check if it is ready.
1039
+ * @param useInstances - Specifies that instances should be used.
1040
+ * @returns - boolean indicating that the submesh is ready or not.
1041
+ */
1042
+ isReadyForSubMesh(mesh, subMesh, useInstances) {
1043
+ if (!this._uniformBufferLayoutBuilt) {
1044
+ this.buildUniformLayout();
1045
+ }
1046
+ const drawWrapper = subMesh._drawWrapper;
1047
+ if (drawWrapper.effect && this.isFrozen) {
1048
+ if (drawWrapper._wasPreviouslyReady && drawWrapper._wasPreviouslyUsingInstances === useInstances) {
1049
+ return true;
1050
+ }
1051
+ }
1052
+ if (!subMesh.materialDefines) {
1053
+ this._callbackPluginEventGeneric(4 /* MaterialPluginEvent.GetDefineNames */, this._eventInfo);
1054
+ subMesh.materialDefines = new OpenPBRMaterialDefines({
1055
+ ...(this._eventInfo.defineNames || {}),
1056
+ ...(this._samplerDefines || {}),
1057
+ });
1058
+ }
1059
+ const defines = subMesh.materialDefines;
1060
+ if (this._isReadyForSubMesh(subMesh)) {
1061
+ return true;
1062
+ }
1063
+ const scene = this.getScene();
1064
+ const engine = scene.getEngine();
1065
+ if (defines._areTexturesDirty) {
1066
+ this._eventInfo.hasRenderTargetTextures = false;
1067
+ this._callbackPluginEventHasRenderTargetTextures(this._eventInfo);
1068
+ this._cacheHasRenderTargetTextures = this._eventInfo.hasRenderTargetTextures;
1069
+ if (scene.texturesEnabled) {
1070
+ // Loop through samplers, check MaterialFlag and whether the texture is ready or not.
1071
+ for (const key in this._samplersList) {
1072
+ const sampler = this._samplersList[key];
1073
+ if (sampler.value) {
1074
+ if (!sampler.value.isReadyOrNotBlocking()) {
1075
+ return false;
1076
+ }
1077
+ }
1078
+ }
1079
+ const radianceTexture = this._getRadianceTexture();
1080
+ if (radianceTexture && MaterialFlags.ReflectionTextureEnabled) {
1081
+ if (!radianceTexture.isReadyOrNotBlocking()) {
1082
+ return false;
1083
+ }
1084
+ if (radianceTexture.irradianceTexture) {
1085
+ if (!radianceTexture.irradianceTexture.isReadyOrNotBlocking()) {
1086
+ return false;
1087
+ }
1088
+ }
1089
+ else {
1090
+ // Not ready until spherical are ready too.
1091
+ if (!radianceTexture.sphericalPolynomial && radianceTexture.getInternalTexture()?._sphericalPolynomialPromise) {
1092
+ return false;
1093
+ }
1094
+ }
1095
+ }
1096
+ if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {
1097
+ // This is blocking.
1098
+ if (!this._environmentBRDFTexture.isReady()) {
1099
+ return false;
1100
+ }
1101
+ }
1102
+ if (OpenPBRMaterial._noiseTextures[scene.uniqueId]) {
1103
+ if (!OpenPBRMaterial._noiseTextures[scene.uniqueId].isReady()) {
1104
+ return false;
1105
+ }
1106
+ }
1107
+ }
1108
+ }
1109
+ this._eventInfo.isReadyForSubMesh = true;
1110
+ this._eventInfo.defines = defines;
1111
+ this._eventInfo.subMesh = subMesh;
1112
+ this._callbackPluginEventIsReadyForSubMesh(this._eventInfo);
1113
+ if (!this._eventInfo.isReadyForSubMesh) {
1114
+ return false;
1115
+ }
1116
+ if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {
1117
+ if (!this._imageProcessingConfiguration.isReady()) {
1118
+ return false;
1119
+ }
1120
+ }
1121
+ // Check if Area Lights have LTC texture.
1122
+ if (defines["AREALIGHTUSED"]) {
1123
+ for (let index = 0; index < mesh.lightSources.length; index++) {
1124
+ if (!mesh.lightSources[index]._isReady()) {
1125
+ return false;
1126
+ }
1127
+ }
1128
+ }
1129
+ if (!engine.getCaps().standardDerivatives && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
1130
+ mesh.createNormals(true);
1131
+ Logger.Warn("OpenPBRMaterial: Normals have been created for the mesh: " + mesh.name);
1132
+ }
1133
+ const previousEffect = subMesh.effect;
1134
+ const lightDisposed = defines._areLightsDisposed;
1135
+ let effect = this._prepareEffect(mesh, defines, this.onCompiled, this.onError, useInstances, null, subMesh.getRenderingMesh().hasThinInstances);
1136
+ let forceWasNotReadyPreviously = false;
1137
+ if (effect) {
1138
+ if (this._onEffectCreatedObservable) {
1139
+ onCreatedEffectParameters.effect = effect;
1140
+ onCreatedEffectParameters.subMesh = subMesh;
1141
+ this._onEffectCreatedObservable.notifyObservers(onCreatedEffectParameters);
1142
+ }
1143
+ // Use previous effect while new one is compiling
1144
+ if (this.allowShaderHotSwapping && previousEffect && !effect.isReady()) {
1145
+ effect = previousEffect;
1146
+ defines.markAsUnprocessed();
1147
+ forceWasNotReadyPreviously = this.isFrozen;
1148
+ if (lightDisposed) {
1149
+ // re register in case it takes more than one frame.
1150
+ defines._areLightsDisposed = true;
1151
+ return false;
1152
+ }
1153
+ }
1154
+ else {
1155
+ scene.resetCachedMaterial();
1156
+ subMesh.setEffect(effect, defines, this._materialContext);
1157
+ }
1158
+ }
1159
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
1160
+ return false;
1161
+ }
1162
+ defines._renderId = scene.getRenderId();
1163
+ drawWrapper._wasPreviouslyReady = forceWasNotReadyPreviously ? false : true;
1164
+ drawWrapper._wasPreviouslyUsingInstances = !!useInstances;
1165
+ this._checkScenePerformancePriority();
1166
+ return true;
1167
+ }
1168
+ /**
1169
+ * Initializes the uniform buffer layout for the shader.
1170
+ */
1171
+ buildUniformLayout() {
1172
+ // Order is important !
1173
+ const ubo = this._uniformBuffer;
1174
+ ubo.addUniform("vTangentSpaceParams", 2);
1175
+ ubo.addUniform("vLightingIntensity", 4);
1176
+ ubo.addUniform("pointSize", 1);
1177
+ ubo.addUniform("vDebugMode", 2);
1178
+ ubo.addUniform("cameraInfo", 4);
1179
+ PrepareUniformLayoutForIBL(ubo, true, true, true, true, true);
1180
+ Object.values(this._uniformsList).forEach((uniform) => {
1181
+ ubo.addUniform(uniform.name, uniform.numComponents);
1182
+ });
1183
+ Object.values(this._samplersList).forEach((sampler) => {
1184
+ ubo.addUniform(sampler.samplerInfoName, 2);
1185
+ ubo.addUniform(sampler.samplerMatrixName, 16);
1186
+ });
1187
+ super.buildUniformLayout();
1188
+ }
1189
+ /**
1190
+ * Binds the submesh data.
1191
+ * @param world - The world matrix.
1192
+ * @param mesh - The BJS mesh.
1193
+ * @param subMesh - A submesh of the BJS mesh.
1194
+ */
1195
+ bindForSubMesh(world, mesh, subMesh) {
1196
+ const scene = this.getScene();
1197
+ const defines = subMesh.materialDefines;
1198
+ if (!defines) {
1199
+ return;
1200
+ }
1201
+ const effect = subMesh.effect;
1202
+ if (!effect) {
1203
+ return;
1204
+ }
1205
+ this._activeEffect = effect;
1206
+ // Matrices Mesh.
1207
+ mesh.getMeshUniformBuffer().bindToEffect(effect, "Mesh");
1208
+ mesh.transferToEffect(world);
1209
+ const engine = scene.getEngine();
1210
+ // Binding unconditionally
1211
+ this._uniformBuffer.bindToEffect(effect, "Material");
1212
+ this.prePassConfiguration.bindForSubMesh(this._activeEffect, scene, mesh, world, this.isFrozen);
1213
+ MaterialHelperGeometryRendering.Bind(engine.currentRenderPassId, this._activeEffect, mesh, world, this);
1214
+ const camera = scene.activeCamera;
1215
+ if (camera) {
1216
+ this._uniformBuffer.updateFloat4("cameraInfo", camera.minZ, camera.maxZ, 0, 0);
1217
+ }
1218
+ else {
1219
+ this._uniformBuffer.updateFloat4("cameraInfo", 0, 0, 0, 0);
1220
+ }
1221
+ this._eventInfo.subMesh = subMesh;
1222
+ this._callbackPluginEventHardBindForSubMesh(this._eventInfo);
1223
+ // Normal Matrix
1224
+ if (defines.OBJECTSPACE_NORMALMAP) {
1225
+ world.toNormalMatrix(this._normalMatrix);
1226
+ this.bindOnlyNormalMatrix(this._normalMatrix);
1227
+ }
1228
+ const mustRebind = this._mustRebind(scene, effect, subMesh, mesh.visibility);
1229
+ // Bones
1230
+ BindBonesParameters(mesh, this._activeEffect, this.prePassConfiguration);
1231
+ let radianceTexture = null;
1232
+ const ubo = this._uniformBuffer;
1233
+ if (mustRebind) {
1234
+ this.bindViewProjection(effect);
1235
+ radianceTexture = this._getRadianceTexture();
1236
+ if (!ubo.useUbo || !this.isFrozen || !ubo.isSync || subMesh._drawWrapper._forceRebindOnNextCall) {
1237
+ // Texture uniforms
1238
+ if (scene.texturesEnabled) {
1239
+ // Loop through samplers and bind info and matrix for each texture.
1240
+ for (const key in this._samplersList) {
1241
+ const sampler = this._samplersList[key];
1242
+ if (sampler.value) {
1243
+ ubo.updateFloat2(sampler.samplerInfoName, sampler.value.coordinatesIndex, sampler.value.level);
1244
+ BindTextureMatrix(sampler.value, ubo, sampler.samplerPrefix);
1245
+ }
1246
+ }
1247
+ if (this.geometryNormalTexture) {
1248
+ if (scene._mirroredCameraPosition) {
1249
+ ubo.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? 1.0 : -1.0, this._invertNormalMapY ? 1.0 : -1.0);
1250
+ }
1251
+ else {
1252
+ ubo.updateFloat2("vTangentSpaceParams", this._invertNormalMapX ? -1.0 : 1.0, this._invertNormalMapY ? -1.0 : 1.0);
1253
+ }
1254
+ }
1255
+ BindIBLParameters(scene, defines, ubo, radianceTexture, this.realTimeFiltering, true, true, true, true, true, Color3.White());
1256
+ }
1257
+ // Point size
1258
+ if (this.pointsCloud) {
1259
+ ubo.updateFloat("pointSize", this.pointSize);
1260
+ }
1261
+ Object.values(this._uniformsList).forEach((uniform) => {
1262
+ // If the property actually defines a uniform, update it.
1263
+ if (uniform.numComponents === 4) {
1264
+ uniform.populateVectorFromLinkedProperties(TmpVectors.Vector4[0]);
1265
+ ubo.updateVector4(uniform.name, TmpVectors.Vector4[0]);
1266
+ }
1267
+ else if (uniform.numComponents === 3) {
1268
+ uniform.populateVectorFromLinkedProperties(TmpVectors.Vector3[0]);
1269
+ ubo.updateVector3(uniform.name, TmpVectors.Vector3[0]);
1270
+ }
1271
+ else if (uniform.numComponents === 2) {
1272
+ uniform.populateVectorFromLinkedProperties(TmpVectors.Vector2[0]);
1273
+ ubo.updateFloat2(uniform.name, TmpVectors.Vector2[0].x, TmpVectors.Vector2[0].y);
1274
+ }
1275
+ else if (uniform.numComponents === 1) {
1276
+ ubo.updateFloat(uniform.name, uniform.linkedProperties[Object.keys(uniform.linkedProperties)[0]].value);
1277
+ }
1278
+ });
1279
+ // Misc
1280
+ this._lightingInfos.x = this.directIntensity;
1281
+ this._lightingInfos.y = this.emissionLuminance;
1282
+ this._lightingInfos.z = this.environmentIntensity * scene.environmentIntensity;
1283
+ this._lightingInfos.w = 1.0; // This is used to be _specularIntensity.
1284
+ ubo.updateVector4("vLightingIntensity", this._lightingInfos);
1285
+ ubo.updateFloat2("vDebugMode", this.debugLimit, this.debugFactor);
1286
+ }
1287
+ // Textures
1288
+ if (scene.texturesEnabled) {
1289
+ // Loop through samplers and set textures
1290
+ for (const key in this._samplersList) {
1291
+ const sampler = this._samplersList[key];
1292
+ if (sampler.value) {
1293
+ ubo.setTexture(sampler.samplerName, sampler.value);
1294
+ }
1295
+ }
1296
+ BindIBLSamplers(scene, defines, ubo, radianceTexture, this.realTimeFiltering);
1297
+ if (defines.ENVIRONMENTBRDF) {
1298
+ ubo.setTexture("environmentBrdfSampler", this._environmentBRDFTexture);
1299
+ }
1300
+ if (defines.ANISOTROPIC) {
1301
+ ubo.setTexture("blueNoiseSampler", OpenPBRMaterial._noiseTextures[this.getScene().uniqueId]);
1302
+ }
1303
+ }
1304
+ // OIT with depth peeling
1305
+ if (this.getScene().useOrderIndependentTransparency && this.needAlphaBlendingForMesh(mesh)) {
1306
+ this.getScene().depthPeelingRenderer.bind(effect);
1307
+ }
1308
+ this._eventInfo.subMesh = subMesh;
1309
+ this._callbackPluginEventBindForSubMesh(this._eventInfo);
1310
+ // Clip plane
1311
+ BindClipPlane(this._activeEffect, this, scene);
1312
+ this.bindEyePosition(effect);
1313
+ }
1314
+ else if (scene.getEngine()._features.needToAlwaysBindUniformBuffers) {
1315
+ this._needToBindSceneUbo = true;
1316
+ }
1317
+ if (mustRebind || !this.isFrozen) {
1318
+ // Lights
1319
+ if (scene.lightsEnabled && !this._disableLighting) {
1320
+ BindLights(scene, mesh, this._activeEffect, defines, this._maxSimultaneousLights);
1321
+ }
1322
+ // View
1323
+ if ((scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) || radianceTexture || mesh.receiveShadows || defines.PREPASS) {
1324
+ this.bindView(effect);
1325
+ }
1326
+ // Fog
1327
+ BindFogParameters(scene, mesh, this._activeEffect, true);
1328
+ // Morph targets
1329
+ if (defines.NUM_MORPH_INFLUENCERS) {
1330
+ BindMorphTargetParameters(mesh, this._activeEffect);
1331
+ }
1332
+ if (defines.BAKED_VERTEX_ANIMATION_TEXTURE) {
1333
+ mesh.bakedVertexAnimationManager?.bind(effect, defines.INSTANCES);
1334
+ }
1335
+ // image processing
1336
+ this._imageProcessingConfiguration.bind(this._activeEffect);
1337
+ // Log. depth
1338
+ BindLogDepth(defines, this._activeEffect, scene);
1339
+ }
1340
+ this._afterBind(mesh, this._activeEffect, subMesh);
1341
+ ubo.update();
1342
+ }
1343
+ /**
1344
+ * Returns the animatable textures.
1345
+ * If material have animatable metallic texture, then reflectivity texture will not be returned, even if it has animations.
1346
+ * @returns - Array of animatable textures.
1347
+ */
1348
+ getAnimatables() {
1349
+ const results = super.getAnimatables();
1350
+ // Loop through samplers and push animated textures to list.
1351
+ for (const key in this._samplersList) {
1352
+ const sampler = this._samplersList[key];
1353
+ if (sampler.value && sampler.value.animations && sampler.value.animations.length > 0) {
1354
+ results.push(sampler.value);
1355
+ }
1356
+ }
1357
+ if (this._radianceTexture && this._radianceTexture.animations && this._radianceTexture.animations.length > 0) {
1358
+ results.push(this._radianceTexture);
1359
+ }
1360
+ return results;
1361
+ }
1362
+ /**
1363
+ * Returns an array of the actively used textures.
1364
+ * @returns - Array of BaseTextures
1365
+ */
1366
+ getActiveTextures() {
1367
+ const activeTextures = super.getActiveTextures();
1368
+ // Loop through samplers and push active textures
1369
+ for (const key in this._samplersList) {
1370
+ const sampler = this._samplersList[key];
1371
+ if (sampler.value) {
1372
+ activeTextures.push(sampler.value);
1373
+ }
1374
+ }
1375
+ if (this._radianceTexture) {
1376
+ activeTextures.push(this._radianceTexture);
1377
+ }
1378
+ return activeTextures;
1379
+ }
1380
+ /**
1381
+ * Checks to see if a texture is used in the material.
1382
+ * @param texture - Base texture to use.
1383
+ * @returns - Boolean specifying if a texture is used in the material.
1384
+ */
1385
+ hasTexture(texture) {
1386
+ if (super.hasTexture(texture)) {
1387
+ return true;
1388
+ }
1389
+ // Loop through samplers and check each texture for equality
1390
+ for (const key in this._samplersList) {
1391
+ const sampler = this._samplersList[key];
1392
+ if (sampler.value === texture) {
1393
+ return true;
1394
+ }
1395
+ }
1396
+ if (this._radianceTexture === texture) {
1397
+ return true;
1398
+ }
1399
+ return false;
1400
+ }
1401
+ /**
1402
+ * Sets the required values to the prepass renderer.
1403
+ * It can't be sets when subsurface scattering of this material is disabled.
1404
+ * When scene have ability to enable subsurface prepass effect, it will enable.
1405
+ * @returns - If prepass is enabled or not.
1406
+ */
1407
+ setPrePassRenderer() {
1408
+ return false;
1409
+ }
1410
+ /**
1411
+ * Disposes the resources of the material.
1412
+ * @param forceDisposeEffect - Forces the disposal of effects.
1413
+ * @param forceDisposeTextures - Forces the disposal of all textures.
1414
+ */
1415
+ dispose(forceDisposeEffect, forceDisposeTextures) {
1416
+ this._breakShaderLoadedCheck = true;
1417
+ if (forceDisposeTextures) {
1418
+ if (this._environmentBRDFTexture && this.getScene().environmentBRDFTexture !== this._environmentBRDFTexture) {
1419
+ this._environmentBRDFTexture.dispose();
1420
+ }
1421
+ // Loop through samplers and dispose the textures
1422
+ for (const key in this._samplersList) {
1423
+ const sampler = this._samplersList[key];
1424
+ sampler.value?.dispose();
1425
+ }
1426
+ this._radianceTexture?.dispose();
1427
+ }
1428
+ this._renderTargets.dispose();
1429
+ if (this._imageProcessingConfiguration && this._imageProcessingObserver) {
1430
+ this._imageProcessingConfiguration.onUpdateParameters.remove(this._imageProcessingObserver);
1431
+ }
1432
+ super.dispose(forceDisposeEffect, forceDisposeTextures);
1433
+ }
1434
+ /**
1435
+ * Returns the texture used for reflections.
1436
+ * @returns - Reflection texture if present. Otherwise, returns the environment texture.
1437
+ */
1438
+ _getRadianceTexture() {
1439
+ if (this._radianceTexture) {
1440
+ return this._radianceTexture;
1441
+ }
1442
+ return this.getScene().environmentTexture;
1443
+ }
1444
+ _prepareEffect(mesh, defines, onCompiled = null, onError = null, useInstances = null, useClipPlane = null, useThinInstances) {
1445
+ this._prepareDefines(mesh, defines, useInstances, useClipPlane, useThinInstances);
1446
+ if (!defines.isDirty) {
1447
+ return null;
1448
+ }
1449
+ defines.markAsProcessed();
1450
+ const scene = this.getScene();
1451
+ const engine = scene.getEngine();
1452
+ // Fallbacks
1453
+ const fallbacks = new EffectFallbacks();
1454
+ let fallbackRank = 0;
1455
+ if (defines.USESPHERICALINVERTEX) {
1456
+ fallbacks.addFallback(fallbackRank++, "USESPHERICALINVERTEX");
1457
+ }
1458
+ if (defines.FOG) {
1459
+ fallbacks.addFallback(fallbackRank, "FOG");
1460
+ }
1461
+ if (defines.SPECULARAA) {
1462
+ fallbacks.addFallback(fallbackRank, "SPECULARAA");
1463
+ }
1464
+ if (defines.POINTSIZE) {
1465
+ fallbacks.addFallback(fallbackRank, "POINTSIZE");
1466
+ }
1467
+ if (defines.LOGARITHMICDEPTH) {
1468
+ fallbacks.addFallback(fallbackRank, "LOGARITHMICDEPTH");
1469
+ }
1470
+ if (defines.PARALLAX) {
1471
+ fallbacks.addFallback(fallbackRank, "PARALLAX");
1472
+ }
1473
+ if (defines.PARALLAX_RHS) {
1474
+ fallbacks.addFallback(fallbackRank, "PARALLAX_RHS");
1475
+ }
1476
+ if (defines.PARALLAXOCCLUSION) {
1477
+ fallbacks.addFallback(fallbackRank++, "PARALLAXOCCLUSION");
1478
+ }
1479
+ if (defines.ENVIRONMENTBRDF) {
1480
+ fallbacks.addFallback(fallbackRank++, "ENVIRONMENTBRDF");
1481
+ }
1482
+ if (defines.TANGENT) {
1483
+ fallbacks.addFallback(fallbackRank++, "TANGENT");
1484
+ }
1485
+ fallbackRank = HandleFallbacksForShadows(defines, fallbacks, this._maxSimultaneousLights, fallbackRank++);
1486
+ if (defines.SPECULARTERM) {
1487
+ fallbacks.addFallback(fallbackRank++, "SPECULARTERM");
1488
+ }
1489
+ if (defines.USESPHERICALFROMREFLECTIONMAP) {
1490
+ fallbacks.addFallback(fallbackRank++, "USESPHERICALFROMREFLECTIONMAP");
1491
+ }
1492
+ if (defines.USEIRRADIANCEMAP) {
1493
+ fallbacks.addFallback(fallbackRank++, "USEIRRADIANCEMAP");
1494
+ }
1495
+ if (defines.NORMAL) {
1496
+ fallbacks.addFallback(fallbackRank++, "NORMAL");
1497
+ }
1498
+ if (defines.VERTEXCOLOR) {
1499
+ fallbacks.addFallback(fallbackRank++, "VERTEXCOLOR");
1500
+ }
1501
+ if (defines.MORPHTARGETS) {
1502
+ fallbacks.addFallback(fallbackRank++, "MORPHTARGETS");
1503
+ }
1504
+ if (defines.MULTIVIEW) {
1505
+ fallbacks.addFallback(0, "MULTIVIEW");
1506
+ }
1507
+ //Attributes
1508
+ const attribs = [VertexBuffer.PositionKind];
1509
+ if (defines.NORMAL) {
1510
+ attribs.push(VertexBuffer.NormalKind);
1511
+ }
1512
+ if (defines.TANGENT) {
1513
+ attribs.push(VertexBuffer.TangentKind);
1514
+ }
1515
+ for (let i = 1; i <= 6; ++i) {
1516
+ if (defines["UV" + i]) {
1517
+ attribs.push(`uv${i === 1 ? "" : i}`);
1518
+ }
1519
+ }
1520
+ if (defines.VERTEXCOLOR) {
1521
+ attribs.push(VertexBuffer.ColorKind);
1522
+ }
1523
+ PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
1524
+ PrepareAttributesForInstances(attribs, defines);
1525
+ PrepareAttributesForMorphTargets(attribs, mesh, defines);
1526
+ PrepareAttributesForBakedVertexAnimation(attribs, mesh, defines);
1527
+ let shaderName = "openpbr";
1528
+ const uniforms = [
1529
+ "world",
1530
+ "view",
1531
+ "viewProjection",
1532
+ "vEyePosition",
1533
+ "vLightsType",
1534
+ "visibility",
1535
+ "vFogInfos",
1536
+ "vFogColor",
1537
+ "pointSize",
1538
+ "mBones",
1539
+ "normalMatrix",
1540
+ "vLightingIntensity",
1541
+ "logarithmicDepthConstant",
1542
+ "vTangentSpaceParams",
1543
+ "boneTextureWidth",
1544
+ "vDebugMode",
1545
+ "morphTargetTextureInfo",
1546
+ "morphTargetTextureIndices",
1547
+ "cameraInfo",
1548
+ ];
1549
+ for (const uniformName in this._uniformsList) {
1550
+ uniforms.push(uniformName);
1551
+ }
1552
+ const samplers = [
1553
+ "environmentBrdfSampler",
1554
+ "blueNoiseSampler",
1555
+ "boneSampler",
1556
+ "morphTargets",
1557
+ "oitDepthSampler",
1558
+ "oitFrontColorSampler",
1559
+ "areaLightsLTC1Sampler",
1560
+ "areaLightsLTC2Sampler",
1561
+ ];
1562
+ for (const key in this._samplersList) {
1563
+ const sampler = this._samplersList[key];
1564
+ samplers.push(sampler.samplerName);
1565
+ // Push uniforms for texture infos and matrix
1566
+ uniforms.push(sampler.samplerInfoName);
1567
+ uniforms.push(sampler.samplerMatrixName);
1568
+ }
1569
+ PrepareUniformsAndSamplersForIBL(uniforms, samplers, true);
1570
+ const uniformBuffers = ["Material", "Scene", "Mesh"];
1571
+ const indexParameters = { maxSimultaneousLights: this._maxSimultaneousLights, maxSimultaneousMorphTargets: defines.NUM_MORPH_INFLUENCERS };
1572
+ this._eventInfo.fallbacks = fallbacks;
1573
+ this._eventInfo.fallbackRank = fallbackRank;
1574
+ this._eventInfo.defines = defines;
1575
+ this._eventInfo.uniforms = uniforms;
1576
+ this._eventInfo.attributes = attribs;
1577
+ this._eventInfo.samplers = samplers;
1578
+ this._eventInfo.uniformBuffersNames = uniformBuffers;
1579
+ this._eventInfo.customCode = undefined;
1580
+ this._eventInfo.mesh = mesh;
1581
+ this._eventInfo.indexParameters = indexParameters;
1582
+ this._callbackPluginEventGeneric(128 /* MaterialPluginEvent.PrepareEffect */, this._eventInfo);
1583
+ MaterialHelperGeometryRendering.AddUniformsAndSamplers(uniforms, samplers);
1584
+ PrePassConfiguration.AddUniforms(uniforms);
1585
+ PrePassConfiguration.AddSamplers(samplers);
1586
+ AddClipPlaneUniforms(uniforms);
1587
+ if (ImageProcessingConfiguration) {
1588
+ ImageProcessingConfiguration.PrepareUniforms(uniforms, defines);
1589
+ ImageProcessingConfiguration.PrepareSamplers(samplers, defines);
1590
+ }
1591
+ PrepareUniformsAndSamplersList({
1592
+ uniformsNames: uniforms,
1593
+ uniformBuffersNames: uniformBuffers,
1594
+ samplers: samplers,
1595
+ defines: defines,
1596
+ maxSimultaneousLights: this._maxSimultaneousLights,
1597
+ });
1598
+ const csnrOptions = {};
1599
+ if (this.customShaderNameResolve) {
1600
+ shaderName = this.customShaderNameResolve(shaderName, uniforms, uniformBuffers, samplers, defines, attribs, csnrOptions);
1601
+ }
1602
+ const join = defines.toString();
1603
+ const effect = engine.createEffect(shaderName, {
1604
+ attributes: attribs,
1605
+ uniformsNames: uniforms,
1606
+ uniformBuffersNames: uniformBuffers,
1607
+ samplers: samplers,
1608
+ defines: join,
1609
+ fallbacks: fallbacks,
1610
+ onCompiled: onCompiled,
1611
+ onError: onError,
1612
+ indexParameters,
1613
+ processFinalCode: csnrOptions.processFinalCode,
1614
+ processCodeAfterIncludes: this._eventInfo.customCode,
1615
+ multiTarget: defines.PREPASS,
1616
+ shaderLanguage: this._shaderLanguage,
1617
+ extraInitializationsAsync: this._shadersLoaded
1618
+ ? undefined
1619
+ : async () => {
1620
+ if (this.shaderLanguage === 1 /* ShaderLanguage.WGSL */) {
1621
+ await Promise.all([import("../../ShadersWGSL/openpbr.vertex.js"), import("../../ShadersWGSL/openpbr.fragment.js")]);
1622
+ }
1623
+ else {
1624
+ await Promise.all([import("../../Shaders/openpbr.vertex.js"), import("../../Shaders/openpbr.fragment.js")]);
1625
+ }
1626
+ this._shadersLoaded = true;
1627
+ },
1628
+ }, engine);
1629
+ this._eventInfo.customCode = undefined;
1630
+ return effect;
1631
+ }
1632
+ _prepareDefines(mesh, defines, useInstances = null, useClipPlane = null, useThinInstances = false) {
1633
+ const scene = this.getScene();
1634
+ const engine = scene.getEngine();
1635
+ // Lights
1636
+ PrepareDefinesForLights(scene, mesh, defines, true, this._maxSimultaneousLights, this._disableLighting);
1637
+ defines._needNormals = true;
1638
+ // Multiview
1639
+ PrepareDefinesForMultiview(scene, defines);
1640
+ // PrePass
1641
+ const oit = this.needAlphaBlendingForMesh(mesh) && this.getScene().useOrderIndependentTransparency;
1642
+ PrepareDefinesForPrePass(scene, defines, this.canRenderToMRT && !oit);
1643
+ // Order independant transparency
1644
+ PrepareDefinesForOIT(scene, defines, oit);
1645
+ MaterialHelperGeometryRendering.PrepareDefines(engine.currentRenderPassId, mesh, defines);
1646
+ // Textures
1647
+ defines.METALLICWORKFLOW = true;
1648
+ if (defines._areTexturesDirty) {
1649
+ defines._needUVs = false;
1650
+ for (let i = 1; i <= 6; ++i) {
1651
+ defines["MAINUV" + i] = false;
1652
+ }
1653
+ if (scene.texturesEnabled) {
1654
+ // Loop through samplers and prepare defines for each texture
1655
+ for (const key in this._samplersList) {
1656
+ const sampler = this._samplersList[key];
1657
+ if (sampler.value) {
1658
+ PrepareDefinesForMergedUV(sampler.value, defines, sampler.textureDefine);
1659
+ defines[sampler.textureDefine + "_GAMMA"] = sampler.value.gammaSpace;
1660
+ }
1661
+ else {
1662
+ defines[sampler.textureDefine] = false;
1663
+ }
1664
+ }
1665
+ const radianceTexture = this._getRadianceTexture();
1666
+ const useSHInFragment = this._forceIrradianceInFragment ||
1667
+ this.realTimeFiltering ||
1668
+ this._twoSidedLighting ||
1669
+ engine.getCaps().maxVaryingVectors <= 8 ||
1670
+ this._baseDiffuseRoughnessTexture != null;
1671
+ PrepareDefinesForIBL(scene, radianceTexture, defines, this.realTimeFiltering, this.realTimeFilteringQuality, !useSHInFragment);
1672
+ if (this._baseMetalnessTexture) {
1673
+ defines.AOSTOREINMETALMAPRED = this._useAmbientOcclusionFromMetallicTextureRed;
1674
+ }
1675
+ defines.SPECULAR_WEIGHT_IN_ALPHA = this._useSpecularWeightFromAlpha;
1676
+ defines.SPECULAR_WEIGHT_FROM_SPECULAR_COLOR_TEXTURE = this._useSpecularWeightFromSpecularColorTexture;
1677
+ defines.SPECULAR_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE = this._useSpecularRoughnessAnisotropyFromTangentTexture;
1678
+ defines.COAT_ROUGHNESS_ANISOTROPY_FROM_TANGENT_TEXTURE = this._useCoatRoughnessAnisotropyFromTangentTexture;
1679
+ defines.ROUGHNESSSTOREINMETALMAPGREEN = this._useRoughnessFromMetallicTextureGreen;
1680
+ defines.METALLNESSSTOREINMETALMAPBLUE = this._useMetallicFromMetallicTextureBlue;
1681
+ if (this.geometryNormalTexture) {
1682
+ if (this._useParallax && this.baseColorTexture && MaterialFlags.DiffuseTextureEnabled) {
1683
+ defines.PARALLAX = true;
1684
+ defines.PARALLAX_RHS = scene.useRightHandedSystem;
1685
+ defines.PARALLAXOCCLUSION = !!this._useParallaxOcclusion;
1686
+ }
1687
+ else {
1688
+ defines.PARALLAX = false;
1689
+ }
1690
+ defines.OBJECTSPACE_NORMALMAP = this._useObjectSpaceNormalMap;
1691
+ }
1692
+ else {
1693
+ defines.PARALLAX = false;
1694
+ defines.PARALLAX_RHS = false;
1695
+ defines.PARALLAXOCCLUSION = false;
1696
+ defines.OBJECTSPACE_NORMALMAP = false;
1697
+ }
1698
+ if (this._environmentBRDFTexture && MaterialFlags.ReflectionTextureEnabled) {
1699
+ defines.ENVIRONMENTBRDF = true;
1700
+ defines.ENVIRONMENTBRDF_RGBD = this._environmentBRDFTexture.isRGBD;
1701
+ }
1702
+ else {
1703
+ defines.ENVIRONMENTBRDF = false;
1704
+ defines.ENVIRONMENTBRDF_RGBD = false;
1705
+ }
1706
+ if (this._shouldUseAlphaFromBaseColorTexture()) {
1707
+ defines.ALPHA_FROM_BASE_COLOR_TEXTURE = true;
1708
+ }
1709
+ else {
1710
+ defines.ALPHA_FROM_BASE_COLOR_TEXTURE = false;
1711
+ }
1712
+ }
1713
+ if (this._lightFalloff === Material.LIGHTFALLOFF_STANDARD) {
1714
+ defines.USEPHYSICALLIGHTFALLOFF = false;
1715
+ defines.USEGLTFLIGHTFALLOFF = false;
1716
+ }
1717
+ else if (this._lightFalloff === Material.LIGHTFALLOFF_GLTF) {
1718
+ defines.USEPHYSICALLIGHTFALLOFF = false;
1719
+ defines.USEGLTFLIGHTFALLOFF = true;
1720
+ }
1721
+ else {
1722
+ defines.USEPHYSICALLIGHTFALLOFF = true;
1723
+ defines.USEGLTFLIGHTFALLOFF = false;
1724
+ }
1725
+ if (!this.backFaceCulling && this._twoSidedLighting) {
1726
+ defines.TWOSIDEDLIGHTING = true;
1727
+ }
1728
+ else {
1729
+ defines.TWOSIDEDLIGHTING = false;
1730
+ }
1731
+ // We need it to not invert normals in two sided lighting mode (based on the winding of the face)
1732
+ defines.MIRRORED = !!scene._mirroredCameraPosition;
1733
+ defines.SPECULARAA = engine.getCaps().standardDerivatives && this._enableSpecularAntiAliasing;
1734
+ }
1735
+ if (defines._areTexturesDirty || defines._areMiscDirty) {
1736
+ defines.ALPHATESTVALUE = `${this._alphaCutOff}${this._alphaCutOff % 1 === 0 ? "." : ""}`;
1737
+ defines.PREMULTIPLYALPHA = this.alphaMode === 7 || this.alphaMode === 8;
1738
+ defines.ALPHABLEND = this.needAlphaBlendingForMesh(mesh);
1739
+ }
1740
+ if (defines._areImageProcessingDirty && this._imageProcessingConfiguration) {
1741
+ this._imageProcessingConfiguration.prepareDefines(defines);
1742
+ }
1743
+ defines.FORCENORMALFORWARD = this._forceNormalForward;
1744
+ defines.RADIANCEOCCLUSION = this._useRadianceOcclusion;
1745
+ defines.HORIZONOCCLUSION = this._useHorizonOcclusion;
1746
+ if ((this.specularRoughnessAnisotropy > 0.0 || this.coatRoughnessAnisotropy > 0.0) &&
1747
+ OpenPBRMaterial._noiseTextures[scene.uniqueId] &&
1748
+ MaterialFlags.ReflectionTextureEnabled) {
1749
+ // ANISOTROPIC is used to include common shader functions needed for anisotropy
1750
+ // ANISOTROPIC_BASE is used to process anisotropy for the base layer
1751
+ // ANISOTROPIC_COAT is used to process anisotropy for the coat layer
1752
+ defines.ANISOTROPIC = true;
1753
+ if (!mesh.isVerticesDataPresent(VertexBuffer.TangentKind)) {
1754
+ defines._needUVs = true;
1755
+ defines.MAINUV1 = true;
1756
+ }
1757
+ if (this._useGltfStyleAnisotropy) {
1758
+ defines.USE_GLTF_STYLE_ANISOTROPY = true;
1759
+ }
1760
+ defines.ANISOTROPIC_BASE = this.specularRoughnessAnisotropy > 0.0;
1761
+ defines.ANISOTROPIC_COAT = this.coatRoughnessAnisotropy > 0.0;
1762
+ }
1763
+ else {
1764
+ defines.ANISOTROPIC = false;
1765
+ defines.USE_GLTF_STYLE_ANISOTROPY = false;
1766
+ defines.ANISOTROPIC_BASE = false;
1767
+ defines.ANISOTROPIC_COAT = false;
1768
+ }
1769
+ // Misc.
1770
+ if (defines._areMiscDirty) {
1771
+ PrepareDefinesForMisc(mesh, scene, this._useLogarithmicDepth, this.pointsCloud, this.fogEnabled, this.needAlphaTestingForMesh(mesh), defines, this._applyDecalMapAfterDetailMap);
1772
+ defines.UNLIT = this._unlit || ((this.pointsCloud || this.wireframe) && !mesh.isVerticesDataPresent(VertexBuffer.NormalKind));
1773
+ defines.DEBUGMODE = this._debugMode;
1774
+ }
1775
+ // Values that need to be evaluated on every frame
1776
+ PrepareDefinesForFrameBoundValues(scene, engine, this, defines, useInstances ? true : false, useClipPlane, useThinInstances);
1777
+ // External config
1778
+ this._eventInfo.defines = defines;
1779
+ this._eventInfo.mesh = mesh;
1780
+ this._callbackPluginEventPrepareDefinesBeforeAttributes(this._eventInfo);
1781
+ // Attribs
1782
+ PrepareDefinesForAttributes(mesh, defines, true, true, true, this._transparencyMode !== Material.MATERIAL_OPAQUE);
1783
+ // External config
1784
+ this._callbackPluginEventPrepareDefines(this._eventInfo);
1785
+ }
1786
+ }
1787
+ OpenPBRMaterial._noiseTextures = {};
1788
+ /**
1789
+ * Force all the PBR materials to compile to glsl even on WebGPU engines.
1790
+ * False by default. This is mostly meant for backward compatibility.
1791
+ */
1792
+ OpenPBRMaterial.ForceGLSL = false;
1793
+ __decorate([
1794
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseWeight")
1795
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1796
+ ], OpenPBRMaterial.prototype, "_baseWeight", void 0);
1797
+ __decorate([
1798
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseWeightTexture")
1799
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1800
+ ], OpenPBRMaterial.prototype, "_baseWeightTexture", void 0);
1801
+ __decorate([
1802
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseColor")
1803
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1804
+ ], OpenPBRMaterial.prototype, "_baseColor", void 0);
1805
+ __decorate([
1806
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseColorTexture")
1807
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1808
+ ], OpenPBRMaterial.prototype, "_baseColorTexture", void 0);
1809
+ __decorate([
1810
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseDiffuseRoughness")
1811
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1812
+ ], OpenPBRMaterial.prototype, "_baseDiffuseRoughness", void 0);
1813
+ __decorate([
1814
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseDiffuseRoughnessTexture")
1815
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1816
+ ], OpenPBRMaterial.prototype, "_baseDiffuseRoughnessTexture", void 0);
1817
+ __decorate([
1818
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseMetalness")
1819
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1820
+ ], OpenPBRMaterial.prototype, "_baseMetalness", void 0);
1821
+ __decorate([
1822
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "baseMetalnessTexture")
1823
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1824
+ ], OpenPBRMaterial.prototype, "_baseMetalnessTexture", void 0);
1825
+ __decorate([
1826
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularWeight")
1827
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1828
+ ], OpenPBRMaterial.prototype, "_specularWeight", void 0);
1829
+ __decorate([
1830
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularWeightTexture")
1831
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1832
+ ], OpenPBRMaterial.prototype, "_specularWeightTexture", void 0);
1833
+ __decorate([
1834
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularColor")
1835
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1836
+ ], OpenPBRMaterial.prototype, "_specularColor", void 0);
1837
+ __decorate([
1838
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularColorTexture")
1839
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1840
+ ], OpenPBRMaterial.prototype, "_specularColorTexture", void 0);
1841
+ __decorate([
1842
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularRoughness")
1843
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1844
+ ], OpenPBRMaterial.prototype, "_specularRoughness", void 0);
1845
+ __decorate([
1846
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularRoughnessTexture")
1847
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1848
+ ], OpenPBRMaterial.prototype, "_specularRoughnessTexture", void 0);
1849
+ __decorate([
1850
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularRoughnessAnisotropy")
1851
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1852
+ ], OpenPBRMaterial.prototype, "_specularRoughnessAnisotropy", void 0);
1853
+ __decorate([
1854
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularRoughnessAnisotropyTexture")
1855
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1856
+ ], OpenPBRMaterial.prototype, "_specularRoughnessAnisotropyTexture", void 0);
1857
+ __decorate([
1858
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "specularIor")
1859
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1860
+ ], OpenPBRMaterial.prototype, "_specularIor", void 0);
1861
+ __decorate([
1862
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatWeight")
1863
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1864
+ ], OpenPBRMaterial.prototype, "_coatWeight", void 0);
1865
+ __decorate([
1866
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatWeightTexture")
1867
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1868
+ ], OpenPBRMaterial.prototype, "_coatWeightTexture", void 0);
1869
+ __decorate([
1870
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatColor")
1871
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1872
+ ], OpenPBRMaterial.prototype, "_coatColor", void 0);
1873
+ __decorate([
1874
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatColorTexture")
1875
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1876
+ ], OpenPBRMaterial.prototype, "_coatColorTexture", void 0);
1877
+ __decorate([
1878
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatRoughness")
1879
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1880
+ ], OpenPBRMaterial.prototype, "_coatRoughness", void 0);
1881
+ __decorate([
1882
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatRoughnessTexture")
1883
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1884
+ ], OpenPBRMaterial.prototype, "_coatRoughnessTexture", void 0);
1885
+ __decorate([
1886
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatRoughnessAnisotropy")
1887
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1888
+ ], OpenPBRMaterial.prototype, "_coatRoughnessAnisotropy", void 0);
1889
+ __decorate([
1890
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatRoughnessAnisotropyTexture")
1891
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1892
+ ], OpenPBRMaterial.prototype, "_coatRoughnessAnisotropyTexture", void 0);
1893
+ __decorate([
1894
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatIor")
1895
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1896
+ ], OpenPBRMaterial.prototype, "_coatIor", void 0);
1897
+ __decorate([
1898
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatDarkening")
1899
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1900
+ ], OpenPBRMaterial.prototype, "_coatDarkening", void 0);
1901
+ __decorate([
1902
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "coatDarkeningTexture")
1903
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1904
+ ], OpenPBRMaterial.prototype, "_coatDarkeningTexture", void 0);
1905
+ __decorate([
1906
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryNormalTexture")
1907
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1908
+ ], OpenPBRMaterial.prototype, "_geometryNormalTexture", void 0);
1909
+ __decorate([
1910
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryTangent")
1911
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1912
+ ], OpenPBRMaterial.prototype, "_geometryTangent", void 0);
1913
+ __decorate([
1914
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryTangentTexture")
1915
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1916
+ ], OpenPBRMaterial.prototype, "_geometryTangentTexture", void 0);
1917
+ __decorate([
1918
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryCoatNormalTexture")
1919
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1920
+ ], OpenPBRMaterial.prototype, "_geometryCoatNormalTexture", void 0);
1921
+ __decorate([
1922
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryCoatTangent")
1923
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1924
+ ], OpenPBRMaterial.prototype, "_geometryCoatTangent", void 0);
1925
+ __decorate([
1926
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryCoatTangentTexture")
1927
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1928
+ ], OpenPBRMaterial.prototype, "_geometryCoatTangentTexture", void 0);
1929
+ __decorate([
1930
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryOpacity")
1931
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1932
+ ], OpenPBRMaterial.prototype, "_geometryOpacity", void 0);
1933
+ __decorate([
1934
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "geometryOpacityTexture")
1935
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1936
+ ], OpenPBRMaterial.prototype, "_geometryOpacityTexture", void 0);
1937
+ __decorate([
1938
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "emissionLuminance")
1939
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1940
+ ], OpenPBRMaterial.prototype, "_emissionLuminance", void 0);
1941
+ __decorate([
1942
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "emissionColor")
1943
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1944
+ ], OpenPBRMaterial.prototype, "_emissionColor", void 0);
1945
+ __decorate([
1946
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "emissionColorTexture")
1947
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1948
+ ], OpenPBRMaterial.prototype, "_emissionColorTexture", void 0);
1949
+ __decorate([
1950
+ addAccessorsForMaterialProperty("_markAllSubMeshesAsTexturesDirty", "ambientOcclusionTexture")
1951
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
1952
+ ], OpenPBRMaterial.prototype, "_ambientOcclusionTexture", void 0);
1953
+ __decorate([
1954
+ serialize(),
1955
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1956
+ ], OpenPBRMaterial.prototype, "directIntensity", void 0);
1957
+ __decorate([
1958
+ serialize(),
1959
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1960
+ ], OpenPBRMaterial.prototype, "environmentIntensity", void 0);
1961
+ __decorate([
1962
+ serialize(),
1963
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1964
+ ], OpenPBRMaterial.prototype, "useSpecularWeightFromTextureAlpha", void 0);
1965
+ __decorate([
1966
+ serialize(),
1967
+ expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")
1968
+ ], OpenPBRMaterial.prototype, "forceAlphaTest", void 0);
1969
+ __decorate([
1970
+ serialize(),
1971
+ expandToProperty("_markAllSubMeshesAsTexturesAndMiscDirty")
1972
+ ], OpenPBRMaterial.prototype, "alphaCutOff", void 0);
1973
+ __decorate([
1974
+ serialize(),
1975
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1976
+ ], OpenPBRMaterial.prototype, "useAmbientOcclusionFromMetallicTextureRed", void 0);
1977
+ __decorate([
1978
+ serialize(),
1979
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1980
+ ], OpenPBRMaterial.prototype, "useAmbientInGrayScale", void 0);
1981
+ __decorate([
1982
+ serialize()
1983
+ ], OpenPBRMaterial.prototype, "usePhysicalLightFalloff", null);
1984
+ __decorate([
1985
+ serialize()
1986
+ ], OpenPBRMaterial.prototype, "useGLTFLightFalloff", null);
1987
+ __decorate([
1988
+ serialize(),
1989
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1990
+ ], OpenPBRMaterial.prototype, "useObjectSpaceNormalMap", void 0);
1991
+ __decorate([
1992
+ serialize(),
1993
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1994
+ ], OpenPBRMaterial.prototype, "useParallax", void 0);
1995
+ __decorate([
1996
+ serialize(),
1997
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
1998
+ ], OpenPBRMaterial.prototype, "useParallaxOcclusion", void 0);
1999
+ __decorate([
2000
+ serialize(),
2001
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2002
+ ], OpenPBRMaterial.prototype, "parallaxScaleBias", void 0);
2003
+ __decorate([
2004
+ serialize(),
2005
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
2006
+ ], OpenPBRMaterial.prototype, "disableLighting", void 0);
2007
+ __decorate([
2008
+ serialize(),
2009
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2010
+ ], OpenPBRMaterial.prototype, "forceIrradianceInFragment", void 0);
2011
+ __decorate([
2012
+ serialize(),
2013
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
2014
+ ], OpenPBRMaterial.prototype, "maxSimultaneousLights", void 0);
2015
+ __decorate([
2016
+ serialize(),
2017
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2018
+ ], OpenPBRMaterial.prototype, "invertNormalMapX", void 0);
2019
+ __decorate([
2020
+ serialize(),
2021
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2022
+ ], OpenPBRMaterial.prototype, "invertNormalMapY", void 0);
2023
+ __decorate([
2024
+ serialize(),
2025
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2026
+ ], OpenPBRMaterial.prototype, "twoSidedLighting", void 0);
2027
+ __decorate([
2028
+ serialize(),
2029
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2030
+ ], OpenPBRMaterial.prototype, "useAlphaFresnel", void 0);
2031
+ __decorate([
2032
+ serialize(),
2033
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2034
+ ], OpenPBRMaterial.prototype, "useLinearAlphaFresnel", void 0);
2035
+ __decorate([
2036
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2037
+ ], OpenPBRMaterial.prototype, "environmentBRDFTexture", void 0);
2038
+ __decorate([
2039
+ serialize(),
2040
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2041
+ ], OpenPBRMaterial.prototype, "forceNormalForward", void 0);
2042
+ __decorate([
2043
+ serialize(),
2044
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2045
+ ], OpenPBRMaterial.prototype, "enableSpecularAntiAliasing", void 0);
2046
+ __decorate([
2047
+ serialize(),
2048
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2049
+ ], OpenPBRMaterial.prototype, "useHorizonOcclusion", void 0);
2050
+ __decorate([
2051
+ serialize(),
2052
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
2053
+ ], OpenPBRMaterial.prototype, "useRadianceOcclusion", void 0);
2054
+ __decorate([
2055
+ serialize(),
2056
+ expandToProperty("_markAllSubMeshesAsMiscDirty")
2057
+ ], OpenPBRMaterial.prototype, "unlit", void 0);
2058
+ __decorate([
2059
+ serialize(),
2060
+ expandToProperty("_markAllSubMeshesAsMiscDirty")
2061
+ ], OpenPBRMaterial.prototype, "applyDecalMapAfterDetailMap", void 0);
2062
+ __decorate([
2063
+ expandToProperty("_markAllSubMeshesAsMiscDirty")
2064
+ ], OpenPBRMaterial.prototype, "debugMode", void 0);
2065
+ __decorate([
2066
+ serialize()
2067
+ ], OpenPBRMaterial.prototype, "transparencyMode", null);
2068
+ RegisterClass("BABYLON.OpenPBRMaterial", OpenPBRMaterial);
2069
+ //# sourceMappingURL=openPbrMaterial.js.map