@babylonjs/materials 5.0.0-rc.6 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/cell/cell.fragment.d.ts +17 -17
  2. package/cell/cell.fragment.js +20 -20
  3. package/cell/cell.vertex.d.ts +18 -18
  4. package/cell/cell.vertex.js +21 -21
  5. package/cell/cellMaterial.d.ts +37 -37
  6. package/cell/cellMaterial.js +304 -304
  7. package/cell/cellMaterial.js.map +1 -1
  8. package/cell/index.d.ts +1 -1
  9. package/cell/index.js +1 -1
  10. package/custom/customMaterial.d.ts +69 -69
  11. package/custom/customMaterial.js +216 -216
  12. package/custom/customMaterial.js.map +1 -1
  13. package/custom/index.d.ts +2 -2
  14. package/custom/index.js +2 -2
  15. package/custom/pbrCustomMaterial.d.ts +71 -71
  16. package/custom/pbrCustomMaterial.js +241 -241
  17. package/custom/pbrCustomMaterial.js.map +1 -1
  18. package/fire/fire.fragment.d.ts +11 -11
  19. package/fire/fire.fragment.js +14 -14
  20. package/fire/fire.vertex.d.ts +15 -15
  21. package/fire/fire.vertex.js +18 -18
  22. package/fire/fireMaterial.d.ts +38 -38
  23. package/fire/fireMaterial.js +342 -342
  24. package/fire/fireMaterial.js.map +1 -1
  25. package/fire/index.d.ts +1 -1
  26. package/fire/index.js +1 -1
  27. package/fur/fur.fragment.d.ts +17 -17
  28. package/fur/fur.fragment.js +20 -20
  29. package/fur/fur.vertex.d.ts +18 -18
  30. package/fur/fur.vertex.js +21 -21
  31. package/fur/furMaterial.d.ts +57 -56
  32. package/fur/furMaterial.js +500 -500
  33. package/fur/furMaterial.js.map +1 -1
  34. package/fur/index.d.ts +1 -1
  35. package/fur/index.js +1 -1
  36. package/gradient/gradient.fragment.d.ts +17 -17
  37. package/gradient/gradient.fragment.js +20 -20
  38. package/gradient/gradient.vertex.d.ts +18 -18
  39. package/gradient/gradient.vertex.js +21 -21
  40. package/gradient/gradientMaterial.d.ts +37 -37
  41. package/gradient/gradientMaterial.js +275 -275
  42. package/gradient/gradientMaterial.js.map +1 -1
  43. package/gradient/index.d.ts +1 -1
  44. package/gradient/index.js +1 -1
  45. package/grid/grid.fragment.d.ts +8 -8
  46. package/grid/grid.fragment.js +11 -11
  47. package/grid/grid.vertex.d.ts +9 -9
  48. package/grid/grid.vertex.js +12 -12
  49. package/grid/gridMaterial.d.ts +78 -77
  50. package/grid/gridMaterial.js +276 -276
  51. package/grid/gridMaterial.js.map +1 -1
  52. package/grid/index.d.ts +1 -1
  53. package/grid/index.js +1 -1
  54. package/index.d.ts +15 -15
  55. package/index.js +16 -15
  56. package/index.js.map +1 -1
  57. package/lava/index.d.ts +1 -1
  58. package/lava/index.js +1 -1
  59. package/lava/lava.fragment.d.ts +17 -17
  60. package/lava/lava.fragment.js +20 -20
  61. package/lava/lava.vertex.d.ts +18 -18
  62. package/lava/lava.vertex.js +21 -21
  63. package/lava/lavaMaterial.d.ts +45 -45
  64. package/lava/lavaMaterial.js +394 -394
  65. package/lava/lavaMaterial.js.map +1 -1
  66. package/legacy/legacy-cell.d.ts +1 -1
  67. package/legacy/legacy-cell.js +13 -12
  68. package/legacy/legacy-cell.js.map +1 -1
  69. package/legacy/legacy-custom.d.ts +1 -1
  70. package/legacy/legacy-custom.js +13 -12
  71. package/legacy/legacy-custom.js.map +1 -1
  72. package/legacy/legacy-fire.d.ts +1 -1
  73. package/legacy/legacy-fire.js +13 -12
  74. package/legacy/legacy-fire.js.map +1 -1
  75. package/legacy/legacy-fur.d.ts +1 -1
  76. package/legacy/legacy-fur.js +13 -12
  77. package/legacy/legacy-fur.js.map +1 -1
  78. package/legacy/legacy-gradient.d.ts +1 -1
  79. package/legacy/legacy-gradient.js +13 -12
  80. package/legacy/legacy-gradient.js.map +1 -1
  81. package/legacy/legacy-grid.d.ts +1 -1
  82. package/legacy/legacy-grid.js +13 -12
  83. package/legacy/legacy-grid.js.map +1 -1
  84. package/legacy/legacy-lava.d.ts +1 -1
  85. package/legacy/legacy-lava.js +13 -12
  86. package/legacy/legacy-lava.js.map +1 -1
  87. package/legacy/legacy-mix.d.ts +1 -1
  88. package/legacy/legacy-mix.js +13 -12
  89. package/legacy/legacy-mix.js.map +1 -1
  90. package/legacy/legacy-normal.d.ts +1 -1
  91. package/legacy/legacy-normal.js +13 -12
  92. package/legacy/legacy-normal.js.map +1 -1
  93. package/legacy/legacy-shadowOnly.d.ts +1 -1
  94. package/legacy/legacy-shadowOnly.js +13 -12
  95. package/legacy/legacy-shadowOnly.js.map +1 -1
  96. package/legacy/legacy-simple.d.ts +1 -1
  97. package/legacy/legacy-simple.js +13 -12
  98. package/legacy/legacy-simple.js.map +1 -1
  99. package/legacy/legacy-sky.d.ts +1 -1
  100. package/legacy/legacy-sky.js +13 -12
  101. package/legacy/legacy-sky.js.map +1 -1
  102. package/legacy/legacy-terrain.d.ts +1 -1
  103. package/legacy/legacy-terrain.js +13 -12
  104. package/legacy/legacy-terrain.js.map +1 -1
  105. package/legacy/legacy-triPlanar.d.ts +1 -1
  106. package/legacy/legacy-triPlanar.js +13 -12
  107. package/legacy/legacy-triPlanar.js.map +1 -1
  108. package/legacy/legacy-water.d.ts +1 -1
  109. package/legacy/legacy-water.js +13 -12
  110. package/legacy/legacy-water.js.map +1 -1
  111. package/legacy/legacy.d.ts +1 -1
  112. package/legacy/legacy.js +16 -15
  113. package/legacy/legacy.js.map +1 -1
  114. package/license.md +71 -0
  115. package/mix/index.d.ts +1 -1
  116. package/mix/index.js +1 -1
  117. package/mix/mix.fragment.d.ts +17 -17
  118. package/mix/mix.fragment.js +20 -20
  119. package/mix/mix.vertex.d.ts +18 -18
  120. package/mix/mix.vertex.js +21 -21
  121. package/mix/mixMaterial.d.ts +65 -65
  122. package/mix/mixMaterial.js +510 -510
  123. package/mix/mixMaterial.js.map +1 -1
  124. package/normal/index.d.ts +1 -1
  125. package/normal/index.js +1 -1
  126. package/normal/normal.fragment.d.ts +17 -17
  127. package/normal/normal.fragment.js +20 -20
  128. package/normal/normal.vertex.d.ts +18 -18
  129. package/normal/normal.vertex.js +21 -21
  130. package/normal/normalMaterial.d.ts +36 -36
  131. package/normal/normalMaterial.js +336 -336
  132. package/normal/normalMaterial.js.map +1 -1
  133. package/package.json +24 -5
  134. package/shadowOnly/index.d.ts +1 -1
  135. package/shadowOnly/index.js +1 -1
  136. package/shadowOnly/shadowOnly.fragment.d.ts +16 -16
  137. package/shadowOnly/shadowOnly.fragment.js +19 -19
  138. package/shadowOnly/shadowOnly.vertex.d.ts +18 -18
  139. package/shadowOnly/shadowOnly.vertex.js +21 -21
  140. package/shadowOnly/shadowOnlyMaterial.d.ts +30 -30
  141. package/shadowOnly/shadowOnlyMaterial.js +254 -254
  142. package/shadowOnly/shadowOnlyMaterial.js.map +1 -1
  143. package/simple/index.d.ts +1 -1
  144. package/simple/index.js +1 -1
  145. package/simple/simple.fragment.d.ts +17 -17
  146. package/simple/simple.fragment.js +20 -20
  147. package/simple/simple.vertex.d.ts +18 -18
  148. package/simple/simple.vertex.js +21 -21
  149. package/simple/simpleMaterial.d.ts +35 -35
  150. package/simple/simpleMaterial.js +295 -295
  151. package/simple/simpleMaterial.js.map +1 -1
  152. package/sky/index.d.ts +1 -1
  153. package/sky/index.js +1 -1
  154. package/sky/sky.fragment.d.ts +10 -10
  155. package/sky/sky.fragment.js +13 -13
  156. package/sky/sky.vertex.d.ts +9 -9
  157. package/sky/sky.vertex.js +12 -12
  158. package/sky/skyMaterial.d.ts +147 -146
  159. package/sky/skyMaterial.js +359 -359
  160. package/sky/skyMaterial.js.map +1 -1
  161. package/terrain/index.d.ts +1 -1
  162. package/terrain/index.js +1 -1
  163. package/terrain/terrain.fragment.d.ts +17 -17
  164. package/terrain/terrain.fragment.js +20 -20
  165. package/terrain/terrain.vertex.d.ts +18 -18
  166. package/terrain/terrain.vertex.js +21 -21
  167. package/terrain/terrainMaterial.d.ts +50 -50
  168. package/terrain/terrainMaterial.js +426 -426
  169. package/terrain/terrainMaterial.js.map +1 -1
  170. package/triPlanar/index.d.ts +1 -1
  171. package/triPlanar/index.js +1 -1
  172. package/triPlanar/triPlanarMaterial.d.ts +49 -49
  173. package/triPlanar/triPlanarMaterial.js +403 -403
  174. package/triPlanar/triPlanarMaterial.js.map +1 -1
  175. package/triPlanar/triplanar.fragment.d.ts +17 -17
  176. package/triPlanar/triplanar.fragment.js +20 -20
  177. package/triPlanar/triplanar.vertex.d.ts +18 -18
  178. package/triPlanar/triplanar.vertex.js +21 -21
  179. package/water/index.d.ts +1 -1
  180. package/water/index.js +1 -1
  181. package/water/water.fragment.d.ts +19 -19
  182. package/water/water.fragment.js +22 -22
  183. package/water/water.vertex.d.ts +20 -20
  184. package/water/water.vertex.js +23 -23
  185. package/water/waterMaterial.d.ts +135 -135
  186. package/water/waterMaterial.js +736 -736
  187. package/water/waterMaterial.js.map +1 -1
@@ -1,296 +1,296 @@
1
- import { __decorate, __extends } from "tslib";
2
- import { serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
- import { Color3 } from "@babylonjs/core/Maths/math.color.js";
4
- import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
5
- import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
6
- import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
7
- import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
8
- import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
9
- import { Scene } from "@babylonjs/core/scene.js";
10
- import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
11
- import "./simple.fragment.js";
12
- import "./simple.vertex.js";
13
- import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
14
- var SimpleMaterialDefines = /** @class */ (function (_super) {
15
- __extends(SimpleMaterialDefines, _super);
16
- function SimpleMaterialDefines() {
17
- var _this = _super.call(this) || this;
18
- _this.DIFFUSE = false;
19
- _this.CLIPPLANE = false;
20
- _this.CLIPPLANE2 = false;
21
- _this.CLIPPLANE3 = false;
22
- _this.CLIPPLANE4 = false;
23
- _this.CLIPPLANE5 = false;
24
- _this.CLIPPLANE6 = false;
25
- _this.ALPHATEST = false;
26
- _this.DEPTHPREPASS = false;
27
- _this.POINTSIZE = false;
28
- _this.FOG = false;
29
- _this.NORMAL = false;
30
- _this.UV1 = false;
31
- _this.UV2 = false;
32
- _this.VERTEXCOLOR = false;
33
- _this.VERTEXALPHA = false;
34
- _this.NUM_BONE_INFLUENCERS = 0;
35
- _this.BonesPerMesh = 0;
36
- _this.INSTANCES = false;
37
- _this.INSTANCESCOLOR = false;
38
- _this.IMAGEPROCESSINGPOSTPROCESS = false;
39
- _this.SKIPFINALCOLORCLAMP = false;
40
- _this.rebuild();
41
- return _this;
42
- }
43
- return SimpleMaterialDefines;
44
- }(MaterialDefines));
45
- var SimpleMaterial = /** @class */ (function (_super) {
46
- __extends(SimpleMaterial, _super);
47
- function SimpleMaterial(name, scene) {
48
- var _this = _super.call(this, name, scene) || this;
49
- _this.diffuseColor = new Color3(1, 1, 1);
50
- _this._disableLighting = false;
51
- _this._maxSimultaneousLights = 4;
52
- return _this;
53
- }
54
- SimpleMaterial.prototype.needAlphaBlending = function () {
55
- return this.alpha < 1.0;
56
- };
57
- SimpleMaterial.prototype.needAlphaTesting = function () {
58
- return false;
59
- };
60
- SimpleMaterial.prototype.getAlphaTestTexture = function () {
61
- return null;
62
- };
63
- // Methods
64
- SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
65
- if (this.isFrozen) {
66
- if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
67
- return true;
68
- }
69
- }
70
- if (!subMesh.materialDefines) {
71
- subMesh.materialDefines = new SimpleMaterialDefines();
72
- }
73
- var defines = subMesh.materialDefines;
74
- var scene = this.getScene();
75
- if (this._isReadyForSubMesh(subMesh)) {
76
- return true;
77
- }
78
- var engine = scene.getEngine();
79
- // Textures
80
- if (defines._areTexturesDirty) {
81
- defines._needUVs = false;
82
- if (scene.texturesEnabled) {
83
- if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
84
- if (!this._diffuseTexture.isReady()) {
85
- return false;
86
- }
87
- else {
88
- defines._needUVs = true;
89
- defines.DIFFUSE = true;
90
- }
91
- }
92
- }
93
- }
94
- // Misc.
95
- MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
96
- // Lights
97
- defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
98
- // Values that need to be evaluated on every frame
99
- MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
100
- // Attribs
101
- MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
102
- // Get correct effect
103
- if (defines.isDirty) {
104
- defines.markAsProcessed();
105
- scene.resetCachedMaterial();
106
- // Fallbacks
107
- var fallbacks = new EffectFallbacks();
108
- if (defines.FOG) {
109
- fallbacks.addFallback(1, "FOG");
110
- }
111
- MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
112
- if (defines.NUM_BONE_INFLUENCERS > 0) {
113
- fallbacks.addCPUSkinningFallback(0, mesh);
114
- }
115
- defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
116
- //Attributes
117
- var attribs = [VertexBuffer.PositionKind];
118
- if (defines.NORMAL) {
119
- attribs.push(VertexBuffer.NormalKind);
120
- }
121
- if (defines.UV1) {
122
- attribs.push(VertexBuffer.UVKind);
123
- }
124
- if (defines.UV2) {
125
- attribs.push(VertexBuffer.UV2Kind);
126
- }
127
- if (defines.VERTEXCOLOR) {
128
- attribs.push(VertexBuffer.ColorKind);
129
- }
130
- MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
131
- MaterialHelper.PrepareAttributesForInstances(attribs, defines);
132
- var shaderName = "simple";
133
- var join = defines.toString();
134
- var uniforms = [
135
- "world",
136
- "view",
137
- "viewProjection",
138
- "vEyePosition",
139
- "vLightsType",
140
- "vDiffuseColor",
141
- "vFogInfos",
142
- "vFogColor",
143
- "pointSize",
144
- "vDiffuseInfos",
145
- "mBones",
146
- "vClipPlane",
147
- "vClipPlane2",
148
- "vClipPlane3",
149
- "vClipPlane4",
150
- "vClipPlane5",
151
- "vClipPlane6",
152
- "diffuseMatrix",
153
- ];
154
- var samplers = ["diffuseSampler"];
155
- var uniformBuffers = new Array();
156
- MaterialHelper.PrepareUniformsAndSamplersList({
157
- uniformsNames: uniforms,
158
- uniformBuffersNames: uniformBuffers,
159
- samplers: samplers,
160
- defines: defines,
161
- maxSimultaneousLights: this.maxSimultaneousLights,
162
- });
163
- subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
164
- attributes: attribs,
165
- uniformsNames: uniforms,
166
- uniformBuffersNames: uniformBuffers,
167
- samplers: samplers,
168
- defines: join,
169
- fallbacks: fallbacks,
170
- onCompiled: this.onCompiled,
171
- onError: this.onError,
172
- indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 },
173
- }, engine), defines, this._materialContext);
174
- }
175
- if (!subMesh.effect || !subMesh.effect.isReady()) {
176
- return false;
177
- }
178
- defines._renderId = scene.getRenderId();
179
- subMesh.effect._wasPreviouslyReady = true;
180
- return true;
181
- };
182
- SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
183
- var scene = this.getScene();
184
- var defines = subMesh.materialDefines;
185
- if (!defines) {
186
- return;
187
- }
188
- var effect = subMesh.effect;
189
- if (!effect) {
190
- return;
191
- }
192
- this._activeEffect = effect;
193
- // Matrices
194
- this.bindOnlyWorldMatrix(world);
195
- this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
196
- // Bones
197
- MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
198
- if (this._mustRebind(scene, effect)) {
199
- // Textures
200
- if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
201
- this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
202
- this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
203
- this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
204
- }
205
- // Clip plane
206
- MaterialHelper.BindClipPlane(this._activeEffect, scene);
207
- // Point size
208
- if (this.pointsCloud) {
209
- this._activeEffect.setFloat("pointSize", this.pointSize);
210
- }
211
- scene.bindEyePosition(effect);
212
- }
213
- this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
214
- // Lights
215
- if (scene.lightsEnabled && !this.disableLighting) {
216
- MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
217
- }
218
- // View
219
- if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
220
- this._activeEffect.setMatrix("view", scene.getViewMatrix());
221
- }
222
- // Fog
223
- MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
224
- this._afterBind(mesh, this._activeEffect);
225
- };
226
- SimpleMaterial.prototype.getAnimatables = function () {
227
- var results = [];
228
- if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
229
- results.push(this._diffuseTexture);
230
- }
231
- return results;
232
- };
233
- SimpleMaterial.prototype.getActiveTextures = function () {
234
- var activeTextures = _super.prototype.getActiveTextures.call(this);
235
- if (this._diffuseTexture) {
236
- activeTextures.push(this._diffuseTexture);
237
- }
238
- return activeTextures;
239
- };
240
- SimpleMaterial.prototype.hasTexture = function (texture) {
241
- if (_super.prototype.hasTexture.call(this, texture)) {
242
- return true;
243
- }
244
- if (this.diffuseTexture === texture) {
245
- return true;
246
- }
247
- return false;
248
- };
249
- SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
250
- if (this._diffuseTexture) {
251
- this._diffuseTexture.dispose();
252
- }
253
- _super.prototype.dispose.call(this, forceDisposeEffect);
254
- };
255
- SimpleMaterial.prototype.clone = function (name) {
256
- var _this = this;
257
- return SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
258
- };
259
- SimpleMaterial.prototype.serialize = function () {
260
- var serializationObject = _super.prototype.serialize.call(this);
261
- serializationObject.customType = "BABYLON.SimpleMaterial";
262
- return serializationObject;
263
- };
264
- SimpleMaterial.prototype.getClassName = function () {
265
- return "SimpleMaterial";
266
- };
267
- // Statics
268
- SimpleMaterial.Parse = function (source, scene, rootUrl) {
269
- return SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
270
- };
271
- __decorate([
272
- serializeAsTexture("diffuseTexture")
273
- ], SimpleMaterial.prototype, "_diffuseTexture", void 0);
274
- __decorate([
275
- expandToProperty("_markAllSubMeshesAsTexturesDirty")
276
- ], SimpleMaterial.prototype, "diffuseTexture", void 0);
277
- __decorate([
278
- serializeAsColor3("diffuse")
279
- ], SimpleMaterial.prototype, "diffuseColor", void 0);
280
- __decorate([
281
- serialize("disableLighting")
282
- ], SimpleMaterial.prototype, "_disableLighting", void 0);
283
- __decorate([
284
- expandToProperty("_markAllSubMeshesAsLightsDirty")
285
- ], SimpleMaterial.prototype, "disableLighting", void 0);
286
- __decorate([
287
- serialize("maxSimultaneousLights")
288
- ], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
289
- __decorate([
290
- expandToProperty("_markAllSubMeshesAsLightsDirty")
291
- ], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
292
- return SimpleMaterial;
293
- }(PushMaterial));
294
- export { SimpleMaterial };
295
- RegisterClass("BABYLON.SimpleMaterial", SimpleMaterial);
1
+ import { __decorate, __extends } from "tslib";
2
+ import { serializeAsTexture, serialize, expandToProperty, serializeAsColor3, SerializationHelper } from "@babylonjs/core/Misc/decorators.js";
3
+ import { Color3 } from "@babylonjs/core/Maths/math.color.js";
4
+ import { MaterialDefines } from "@babylonjs/core/Materials/materialDefines.js";
5
+ import { MaterialHelper } from "@babylonjs/core/Materials/materialHelper.js";
6
+ import { PushMaterial } from "@babylonjs/core/Materials/pushMaterial.js";
7
+ import { MaterialFlags } from "@babylonjs/core/Materials/materialFlags.js";
8
+ import { VertexBuffer } from "@babylonjs/core/Buffers/buffer.js";
9
+ import { Scene } from "@babylonjs/core/scene.js";
10
+ import { RegisterClass } from "@babylonjs/core/Misc/typeStore.js";
11
+ import "./simple.fragment.js";
12
+ import "./simple.vertex.js";
13
+ import { EffectFallbacks } from "@babylonjs/core/Materials/effectFallbacks.js";
14
+ var SimpleMaterialDefines = /** @class */ (function (_super) {
15
+ __extends(SimpleMaterialDefines, _super);
16
+ function SimpleMaterialDefines() {
17
+ var _this = _super.call(this) || this;
18
+ _this.DIFFUSE = false;
19
+ _this.CLIPPLANE = false;
20
+ _this.CLIPPLANE2 = false;
21
+ _this.CLIPPLANE3 = false;
22
+ _this.CLIPPLANE4 = false;
23
+ _this.CLIPPLANE5 = false;
24
+ _this.CLIPPLANE6 = false;
25
+ _this.ALPHATEST = false;
26
+ _this.DEPTHPREPASS = false;
27
+ _this.POINTSIZE = false;
28
+ _this.FOG = false;
29
+ _this.NORMAL = false;
30
+ _this.UV1 = false;
31
+ _this.UV2 = false;
32
+ _this.VERTEXCOLOR = false;
33
+ _this.VERTEXALPHA = false;
34
+ _this.NUM_BONE_INFLUENCERS = 0;
35
+ _this.BonesPerMesh = 0;
36
+ _this.INSTANCES = false;
37
+ _this.INSTANCESCOLOR = false;
38
+ _this.IMAGEPROCESSINGPOSTPROCESS = false;
39
+ _this.SKIPFINALCOLORCLAMP = false;
40
+ _this.rebuild();
41
+ return _this;
42
+ }
43
+ return SimpleMaterialDefines;
44
+ }(MaterialDefines));
45
+ var SimpleMaterial = /** @class */ (function (_super) {
46
+ __extends(SimpleMaterial, _super);
47
+ function SimpleMaterial(name, scene) {
48
+ var _this = _super.call(this, name, scene) || this;
49
+ _this.diffuseColor = new Color3(1, 1, 1);
50
+ _this._disableLighting = false;
51
+ _this._maxSimultaneousLights = 4;
52
+ return _this;
53
+ }
54
+ SimpleMaterial.prototype.needAlphaBlending = function () {
55
+ return this.alpha < 1.0;
56
+ };
57
+ SimpleMaterial.prototype.needAlphaTesting = function () {
58
+ return false;
59
+ };
60
+ SimpleMaterial.prototype.getAlphaTestTexture = function () {
61
+ return null;
62
+ };
63
+ // Methods
64
+ SimpleMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
65
+ if (this.isFrozen) {
66
+ if (subMesh.effect && subMesh.effect._wasPreviouslyReady) {
67
+ return true;
68
+ }
69
+ }
70
+ if (!subMesh.materialDefines) {
71
+ subMesh.materialDefines = new SimpleMaterialDefines();
72
+ }
73
+ var defines = subMesh.materialDefines;
74
+ var scene = this.getScene();
75
+ if (this._isReadyForSubMesh(subMesh)) {
76
+ return true;
77
+ }
78
+ var engine = scene.getEngine();
79
+ // Textures
80
+ if (defines._areTexturesDirty) {
81
+ defines._needUVs = false;
82
+ if (scene.texturesEnabled) {
83
+ if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
84
+ if (!this._diffuseTexture.isReady()) {
85
+ return false;
86
+ }
87
+ else {
88
+ defines._needUVs = true;
89
+ defines.DIFFUSE = true;
90
+ }
91
+ }
92
+ }
93
+ }
94
+ // Misc.
95
+ MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
96
+ // Lights
97
+ defines._needNormals = MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
98
+ // Values that need to be evaluated on every frame
99
+ MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
100
+ // Attribs
101
+ MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
102
+ // Get correct effect
103
+ if (defines.isDirty) {
104
+ defines.markAsProcessed();
105
+ scene.resetCachedMaterial();
106
+ // Fallbacks
107
+ var fallbacks = new EffectFallbacks();
108
+ if (defines.FOG) {
109
+ fallbacks.addFallback(1, "FOG");
110
+ }
111
+ MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
112
+ if (defines.NUM_BONE_INFLUENCERS > 0) {
113
+ fallbacks.addCPUSkinningFallback(0, mesh);
114
+ }
115
+ defines.IMAGEPROCESSINGPOSTPROCESS = scene.imageProcessingConfiguration.applyByPostProcess;
116
+ //Attributes
117
+ var attribs = [VertexBuffer.PositionKind];
118
+ if (defines.NORMAL) {
119
+ attribs.push(VertexBuffer.NormalKind);
120
+ }
121
+ if (defines.UV1) {
122
+ attribs.push(VertexBuffer.UVKind);
123
+ }
124
+ if (defines.UV2) {
125
+ attribs.push(VertexBuffer.UV2Kind);
126
+ }
127
+ if (defines.VERTEXCOLOR) {
128
+ attribs.push(VertexBuffer.ColorKind);
129
+ }
130
+ MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
131
+ MaterialHelper.PrepareAttributesForInstances(attribs, defines);
132
+ var shaderName = "simple";
133
+ var join = defines.toString();
134
+ var uniforms = [
135
+ "world",
136
+ "view",
137
+ "viewProjection",
138
+ "vEyePosition",
139
+ "vLightsType",
140
+ "vDiffuseColor",
141
+ "vFogInfos",
142
+ "vFogColor",
143
+ "pointSize",
144
+ "vDiffuseInfos",
145
+ "mBones",
146
+ "vClipPlane",
147
+ "vClipPlane2",
148
+ "vClipPlane3",
149
+ "vClipPlane4",
150
+ "vClipPlane5",
151
+ "vClipPlane6",
152
+ "diffuseMatrix",
153
+ ];
154
+ var samplers = ["diffuseSampler"];
155
+ var uniformBuffers = new Array();
156
+ MaterialHelper.PrepareUniformsAndSamplersList({
157
+ uniformsNames: uniforms,
158
+ uniformBuffersNames: uniformBuffers,
159
+ samplers: samplers,
160
+ defines: defines,
161
+ maxSimultaneousLights: this.maxSimultaneousLights,
162
+ });
163
+ subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
164
+ attributes: attribs,
165
+ uniformsNames: uniforms,
166
+ uniformBuffersNames: uniformBuffers,
167
+ samplers: samplers,
168
+ defines: join,
169
+ fallbacks: fallbacks,
170
+ onCompiled: this.onCompiled,
171
+ onError: this.onError,
172
+ indexParameters: { maxSimultaneousLights: this._maxSimultaneousLights - 1 },
173
+ }, engine), defines, this._materialContext);
174
+ }
175
+ if (!subMesh.effect || !subMesh.effect.isReady()) {
176
+ return false;
177
+ }
178
+ defines._renderId = scene.getRenderId();
179
+ subMesh.effect._wasPreviouslyReady = true;
180
+ return true;
181
+ };
182
+ SimpleMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
183
+ var scene = this.getScene();
184
+ var defines = subMesh.materialDefines;
185
+ if (!defines) {
186
+ return;
187
+ }
188
+ var effect = subMesh.effect;
189
+ if (!effect) {
190
+ return;
191
+ }
192
+ this._activeEffect = effect;
193
+ // Matrices
194
+ this.bindOnlyWorldMatrix(world);
195
+ this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
196
+ // Bones
197
+ MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
198
+ if (this._mustRebind(scene, effect)) {
199
+ // Textures
200
+ if (this._diffuseTexture && MaterialFlags.DiffuseTextureEnabled) {
201
+ this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
202
+ this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
203
+ this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
204
+ }
205
+ // Clip plane
206
+ MaterialHelper.BindClipPlane(this._activeEffect, scene);
207
+ // Point size
208
+ if (this.pointsCloud) {
209
+ this._activeEffect.setFloat("pointSize", this.pointSize);
210
+ }
211
+ scene.bindEyePosition(effect);
212
+ }
213
+ this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
214
+ // Lights
215
+ if (scene.lightsEnabled && !this.disableLighting) {
216
+ MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
217
+ }
218
+ // View
219
+ if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE) {
220
+ this._activeEffect.setMatrix("view", scene.getViewMatrix());
221
+ }
222
+ // Fog
223
+ MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
224
+ this._afterBind(mesh, this._activeEffect);
225
+ };
226
+ SimpleMaterial.prototype.getAnimatables = function () {
227
+ var results = [];
228
+ if (this._diffuseTexture && this._diffuseTexture.animations && this._diffuseTexture.animations.length > 0) {
229
+ results.push(this._diffuseTexture);
230
+ }
231
+ return results;
232
+ };
233
+ SimpleMaterial.prototype.getActiveTextures = function () {
234
+ var activeTextures = _super.prototype.getActiveTextures.call(this);
235
+ if (this._diffuseTexture) {
236
+ activeTextures.push(this._diffuseTexture);
237
+ }
238
+ return activeTextures;
239
+ };
240
+ SimpleMaterial.prototype.hasTexture = function (texture) {
241
+ if (_super.prototype.hasTexture.call(this, texture)) {
242
+ return true;
243
+ }
244
+ if (this.diffuseTexture === texture) {
245
+ return true;
246
+ }
247
+ return false;
248
+ };
249
+ SimpleMaterial.prototype.dispose = function (forceDisposeEffect) {
250
+ if (this._diffuseTexture) {
251
+ this._diffuseTexture.dispose();
252
+ }
253
+ _super.prototype.dispose.call(this, forceDisposeEffect);
254
+ };
255
+ SimpleMaterial.prototype.clone = function (name) {
256
+ var _this = this;
257
+ return SerializationHelper.Clone(function () { return new SimpleMaterial(name, _this.getScene()); }, this);
258
+ };
259
+ SimpleMaterial.prototype.serialize = function () {
260
+ var serializationObject = _super.prototype.serialize.call(this);
261
+ serializationObject.customType = "BABYLON.SimpleMaterial";
262
+ return serializationObject;
263
+ };
264
+ SimpleMaterial.prototype.getClassName = function () {
265
+ return "SimpleMaterial";
266
+ };
267
+ // Statics
268
+ SimpleMaterial.Parse = function (source, scene, rootUrl) {
269
+ return SerializationHelper.Parse(function () { return new SimpleMaterial(source.name, scene); }, source, scene, rootUrl);
270
+ };
271
+ __decorate([
272
+ serializeAsTexture("diffuseTexture")
273
+ ], SimpleMaterial.prototype, "_diffuseTexture", void 0);
274
+ __decorate([
275
+ expandToProperty("_markAllSubMeshesAsTexturesDirty")
276
+ ], SimpleMaterial.prototype, "diffuseTexture", void 0);
277
+ __decorate([
278
+ serializeAsColor3("diffuse")
279
+ ], SimpleMaterial.prototype, "diffuseColor", void 0);
280
+ __decorate([
281
+ serialize("disableLighting")
282
+ ], SimpleMaterial.prototype, "_disableLighting", void 0);
283
+ __decorate([
284
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
285
+ ], SimpleMaterial.prototype, "disableLighting", void 0);
286
+ __decorate([
287
+ serialize("maxSimultaneousLights")
288
+ ], SimpleMaterial.prototype, "_maxSimultaneousLights", void 0);
289
+ __decorate([
290
+ expandToProperty("_markAllSubMeshesAsLightsDirty")
291
+ ], SimpleMaterial.prototype, "maxSimultaneousLights", void 0);
292
+ return SimpleMaterial;
293
+ }(PushMaterial));
294
+ export { SimpleMaterial };
295
+ RegisterClass("BABYLON.SimpleMaterial", SimpleMaterial);
296
296
  //# sourceMappingURL=simpleMaterial.js.map