babylon.pbrMaterial.ts 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. module BABYLON {
  3. var maxSimultaneousLights = 4;
  4. class PBRMaterialDefines extends MaterialDefines {
  5. public DIFFUSE = false;
  6. public AMBIENT = false;
  7. public OPACITY = false;
  8. public OPACITYRGB = false;
  9. public REFLECTION = false;
  10. public EMISSIVE = false;
  11. public SPECULAR = false;
  12. public BUMP = false;
  13. public SPECULAROVERALPHA = false;
  14. public CLIPPLANE = false;
  15. public ALPHATEST = false;
  16. public ALPHAFROMDIFFUSE = false;
  17. public POINTSIZE = false;
  18. public FOG = false;
  19. public LIGHT0 = false;
  20. public LIGHT1 = false;
  21. public LIGHT2 = false;
  22. public LIGHT3 = false;
  23. public SPOTLIGHT0 = false;
  24. public SPOTLIGHT1 = false;
  25. public SPOTLIGHT2 = false;
  26. public SPOTLIGHT3 = false;
  27. public HEMILIGHT0 = false;
  28. public HEMILIGHT1 = false;
  29. public HEMILIGHT2 = false;
  30. public HEMILIGHT3 = false;
  31. public POINTLIGHT0 = false;
  32. public POINTLIGHT1 = false;
  33. public POINTLIGHT2 = false;
  34. public POINTLIGHT3 = false;
  35. public DIRLIGHT0 = false;
  36. public DIRLIGHT1 = false;
  37. public DIRLIGHT2 = false;
  38. public DIRLIGHT3 = false;
  39. public SPECULARTERM = false;
  40. public SHADOW0 = false;
  41. public SHADOW1 = false;
  42. public SHADOW2 = false;
  43. public SHADOW3 = false;
  44. public SHADOWS = false;
  45. public SHADOWVSM0 = false;
  46. public SHADOWVSM1 = false;
  47. public SHADOWVSM2 = false;
  48. public SHADOWVSM3 = false;
  49. public SHADOWPCF0 = false;
  50. public SHADOWPCF1 = false;
  51. public SHADOWPCF2 = false;
  52. public SHADOWPCF3 = false;
  53. public OPACITYFRESNEL = false;
  54. public EMISSIVEFRESNEL = false;
  55. public FRESNEL = false;
  56. public NORMAL = false;
  57. public UV1 = false;
  58. public UV2 = false;
  59. public VERTEXCOLOR = false;
  60. public VERTEXALPHA = false;
  61. public NUM_BONE_INFLUENCERS = 0;
  62. public BonesPerMesh = 0;
  63. public INSTANCES = false;
  64. public GLOSSINESSFROMSPECULARMAP = false;
  65. public EMISSIVEASILLUMINATION = false;
  66. public LINKEMISSIVEWITHDIFFUSE = false;
  67. public LIGHTMAP = false;
  68. public USELIGHTMAPASSHADOWMAP = false;
  69. public REFLECTIONMAP_3D = false;
  70. public REFLECTIONMAP_SPHERICAL = false;
  71. public REFLECTIONMAP_PLANAR = false;
  72. public REFLECTIONMAP_CUBIC = false;
  73. public REFLECTIONMAP_PROJECTION = false;
  74. public REFLECTIONMAP_SKYBOX = false;
  75. public REFLECTIONMAP_EXPLICIT = false;
  76. public REFLECTIONMAP_EQUIRECTANGULAR = false;
  77. public INVERTCUBICMAP = false;
  78. public LOGARITHMICDEPTH = false;
  79. public CAMERATONEMAP = false;
  80. public CAMERACONTRAST = false;
  81. public OVERLOADEDVALUES = false;
  82. constructor() {
  83. super();
  84. this._keys = Object.keys(this);
  85. }
  86. }
  87. export class PBRMaterial extends BABYLON.Material {
  88. public directIntensity: number = 1.0;
  89. public emissiveIntensity: number = 1.0;
  90. public environmentIntensity: number = 1.0;
  91. private _lightingInfos: Vector4 = new Vector4(this.directIntensity, this.emissiveIntensity, this.environmentIntensity, 0.0);
  92. public shadowIntensity: number = 1.0;
  93. public shadeIntensity: number = 1.0;
  94. private _shadowInfos: Vector4 = new Vector4(this.shadowIntensity, this.shadeIntensity, 0.0, 0.0);
  95. public cameraExposure: number = 1.0;
  96. public cameraContrast: number = 1.0;
  97. private _cameraInfos: Vector4 = new Vector4(1.0, 1.0, 0.0, 0.0);
  98. public overloadedAmbientIntensity: number = 0.0;
  99. public overloadedDiffuseIntensity: number = 0.0;
  100. public overloadedSpecularIntensity: number = 0.0;
  101. public overloadedEmissiveIntensity: number = 0.0;
  102. private _overloadedIntensity: Vector4 = new Vector4(this.overloadedAmbientIntensity, this.overloadedDiffuseIntensity, this.overloadedSpecularIntensity, this.overloadedEmissiveIntensity);
  103. public overloadedAmbient: Color3 = BABYLON.Color3.White();
  104. public overloadedDiffuse: Color3 = BABYLON.Color3.White();
  105. public overloadedSpecular: Color3 = BABYLON.Color3.White();
  106. public overloadedEmissive: Color3 = BABYLON.Color3.White();
  107. public overloadedSmoothness: number = 0.0;
  108. public overloadedSmoothnessIntensity: number = 0.0;
  109. private _overloadedSmoothness: Vector3 = new Vector3(this.overloadedSmoothness, this.overloadedSmoothnessIntensity, 0.0);
  110. public disableBumpMap: boolean = false;
  111. public diffuseTexture: BaseTexture;
  112. public ambientTexture: BaseTexture;
  113. public opacityTexture: BaseTexture;
  114. public reflectionTexture: BaseTexture;
  115. public emissiveTexture: BaseTexture;
  116. public specularTexture: BaseTexture;
  117. public bumpTexture: BaseTexture;
  118. public lightmapTexture: BaseTexture;
  119. public ambientColor = new Color3(0, 0, 0);
  120. public diffuseColor = new Color3(1, 1, 1);
  121. public specularColor = new Color3(1, 1, 1);
  122. public reflectionColor = new Color3(0.5, 0.5, 0.5);
  123. public glossiness = 0.5;
  124. public emissiveColor = new Color3(0, 0, 0);
  125. public useAlphaFromDiffuseTexture = false;
  126. public useEmissiveAsIllumination = false;
  127. public linkEmissiveWithDiffuse = false;
  128. public useSpecularOverAlpha = true;
  129. public disableLighting = false;
  130. public useLightmapAsShadowmap = false;
  131. public opacityFresnelParameters: FresnelParameters;
  132. public emissiveFresnelParameters: FresnelParameters;
  133. public useGlossinessFromSpecularMapAlpha = false;
  134. private _renderTargets = new SmartArray<RenderTargetTexture>(16);
  135. private _worldViewProjectionMatrix = Matrix.Zero();
  136. private _globalAmbientColor = new Color3(0, 0, 0);
  137. private _tempColor = new Color3();
  138. private _renderId: number;
  139. private _defines = new PBRMaterialDefines();
  140. private _cachedDefines = new PBRMaterialDefines();
  141. private _useLogarithmicDepth: boolean;
  142. constructor(name: string, scene: Scene) {
  143. super(name, scene);
  144. this._cachedDefines.BonesPerMesh = -1;
  145. this.getRenderTargetTextures = (): SmartArray<RenderTargetTexture> => {
  146. this._renderTargets.reset();
  147. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  148. this._renderTargets.push(this.reflectionTexture);
  149. }
  150. return this._renderTargets;
  151. }
  152. }
  153. public get useLogarithmicDepth(): boolean {
  154. return this._useLogarithmicDepth;
  155. }
  156. public set useLogarithmicDepth(value: boolean) {
  157. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  158. }
  159. public needAlphaBlending(): boolean {
  160. return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromDiffuseTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
  161. }
  162. public needAlphaTesting(): boolean {
  163. return this.diffuseTexture != null && this.diffuseTexture.hasAlpha;
  164. }
  165. private _shouldUseAlphaFromDiffuseTexture(): boolean {
  166. return this.diffuseTexture != null && this.diffuseTexture.hasAlpha && this.useAlphaFromDiffuseTexture;
  167. }
  168. public getAlphaTestTexture(): BaseTexture {
  169. return this.diffuseTexture;
  170. }
  171. private _checkCache(scene: Scene, mesh?: AbstractMesh, useInstances?: boolean): boolean {
  172. if (!mesh) {
  173. return true;
  174. }
  175. if (this._defines.INSTANCES !== useInstances) {
  176. return false;
  177. }
  178. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  179. return true;
  180. }
  181. return false;
  182. }
  183. public static PrepareDefinesForLights(scene: Scene, mesh: AbstractMesh, defines: MaterialDefines): boolean {
  184. var lightIndex = 0;
  185. var needNormals = false;
  186. for (var index = 0; index < scene.lights.length; index++) {
  187. var light = scene.lights[index];
  188. if (!light.isEnabled()) {
  189. continue;
  190. }
  191. // Excluded check
  192. if (light._excludedMeshesIds.length > 0) {
  193. for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
  194. var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
  195. if (excludedMesh) {
  196. light.excludedMeshes.push(excludedMesh);
  197. }
  198. }
  199. light._excludedMeshesIds = [];
  200. }
  201. // Included check
  202. if (light._includedOnlyMeshesIds.length > 0) {
  203. for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
  204. var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
  205. if (includedOnlyMesh) {
  206. light.includedOnlyMeshes.push(includedOnlyMesh);
  207. }
  208. }
  209. light._includedOnlyMeshesIds = [];
  210. }
  211. if (!light.canAffectMesh(mesh)) {
  212. continue;
  213. }
  214. needNormals = true;
  215. defines["LIGHT" + lightIndex] = true;
  216. var type;
  217. if (light instanceof SpotLight) {
  218. type = "SPOTLIGHT" + lightIndex;
  219. } else if (light instanceof HemisphericLight) {
  220. type = "HEMILIGHT" + lightIndex;
  221. } else if (light instanceof PointLight) {
  222. type = "POINTLIGHT" + lightIndex;
  223. } else {
  224. type = "DIRLIGHT" + lightIndex;
  225. }
  226. defines[type] = true;
  227. // Specular
  228. if (!light.specular.equalsFloats(0, 0, 0)) {
  229. defines["SPECULARTERM"] = true;
  230. }
  231. // Shadows
  232. if (scene.shadowsEnabled) {
  233. var shadowGenerator = light.getShadowGenerator();
  234. if (mesh && mesh.receiveShadows && shadowGenerator) {
  235. defines["SHADOW" + lightIndex] = true;
  236. defines["SHADOWS"] = true;
  237. if (shadowGenerator.useVarianceShadowMap || shadowGenerator.useBlurVarianceShadowMap) {
  238. defines["SHADOWVSM" + lightIndex] = true;
  239. }
  240. if (shadowGenerator.usePoissonSampling) {
  241. defines["SHADOWPCF" + lightIndex] = true;
  242. }
  243. }
  244. }
  245. lightIndex++;
  246. if (lightIndex === maxSimultaneousLights)
  247. break;
  248. }
  249. return needNormals;
  250. }
  251. private static _scaledDiffuse = new Color3();
  252. private static _scaledSpecular = new Color3();
  253. private static _scaledEmissive = new Color3();
  254. private static _scaledReflection = new Color3();
  255. public static BindLights(scene: Scene, mesh: AbstractMesh, effect: Effect, defines: MaterialDefines) {
  256. var lightIndex = 0;
  257. for (var index = 0; index < scene.lights.length; index++) {
  258. var light = scene.lights[index];
  259. if (!light.isEnabled()) {
  260. continue;
  261. }
  262. if (!light.canAffectMesh(mesh)) {
  263. continue;
  264. }
  265. if (light instanceof PointLight) {
  266. // Point Light
  267. light.transferToEffect(effect, "vLightData" + lightIndex);
  268. } else if (light instanceof DirectionalLight) {
  269. // Directional Light
  270. light.transferToEffect(effect, "vLightData" + lightIndex);
  271. } else if (light instanceof SpotLight) {
  272. // Spot Light
  273. light.transferToEffect(effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
  274. } else if (light instanceof HemisphericLight) {
  275. // Hemispheric Light
  276. light.transferToEffect(effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
  277. }
  278. // GAMMA CORRECTION.
  279. light.diffuse.toLinearSpaceToRef(PBRMaterial._scaledDiffuse);
  280. PBRMaterial._scaledDiffuse.scaleToRef(light.intensity, PBRMaterial._scaledDiffuse);
  281. light.diffuse.scaleToRef(light.intensity, PBRMaterial._scaledDiffuse);
  282. effect.setColor4("vLightDiffuse" + lightIndex, PBRMaterial._scaledDiffuse, light.range);
  283. if (defines["SPECULARTERM"]) {
  284. light.specular.toLinearSpaceToRef(PBRMaterial._scaledSpecular);
  285. PBRMaterial._scaledSpecular.scaleToRef(light.intensity, PBRMaterial._scaledSpecular);
  286. effect.setColor3("vLightSpecular" + lightIndex, PBRMaterial._scaledSpecular);
  287. }
  288. // Shadows
  289. if (scene.shadowsEnabled) {
  290. var shadowGenerator = light.getShadowGenerator();
  291. if (mesh.receiveShadows && shadowGenerator) {
  292. if (!(<any>light).needCube()) {
  293. effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
  294. }
  295. effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
  296. effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
  297. }
  298. }
  299. lightIndex++;
  300. if (lightIndex === maxSimultaneousLights)
  301. break;
  302. }
  303. }
  304. public isReady(mesh?: AbstractMesh, useInstances?: boolean): boolean {
  305. if (this.checkReadyOnlyOnce) {
  306. if (this._wasPreviouslyReady) {
  307. return true;
  308. }
  309. }
  310. var scene = this.getScene();
  311. if (!this.checkReadyOnEveryCall) {
  312. if (this._renderId === scene.getRenderId()) {
  313. if (this._checkCache(scene, mesh, useInstances)) {
  314. return true;
  315. }
  316. }
  317. }
  318. var engine = scene.getEngine();
  319. var needNormals = false;
  320. var needUVs = false;
  321. this._defines.reset();
  322. // Textures
  323. if (scene.texturesEnabled) {
  324. if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
  325. if (!this.diffuseTexture.isReady()) {
  326. return false;
  327. } else {
  328. needUVs = true;
  329. this._defines.DIFFUSE = true;
  330. }
  331. }
  332. if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
  333. if (!this.ambientTexture.isReady()) {
  334. return false;
  335. } else {
  336. needUVs = true;
  337. this._defines.AMBIENT = true;
  338. }
  339. }
  340. if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
  341. if (!this.opacityTexture.isReady()) {
  342. return false;
  343. } else {
  344. needUVs = true;
  345. this._defines.OPACITY = true;
  346. if (this.opacityTexture.getAlphaFromRGB) {
  347. this._defines.OPACITYRGB = true;
  348. }
  349. }
  350. }
  351. if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
  352. if (!this.reflectionTexture.isReady()) {
  353. return false;
  354. } else {
  355. needNormals = true;
  356. this._defines.REFLECTION = true;
  357. if (this.reflectionTexture.coordinatesMode === Texture.INVCUBIC_MODE) {
  358. this._defines.INVERTCUBICMAP = true;
  359. }
  360. this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
  361. switch (this.reflectionTexture.coordinatesMode) {
  362. case Texture.CUBIC_MODE:
  363. case Texture.INVCUBIC_MODE:
  364. this._defines.REFLECTIONMAP_CUBIC = true;
  365. break;
  366. case Texture.EXPLICIT_MODE:
  367. this._defines.REFLECTIONMAP_EXPLICIT = true;
  368. break;
  369. case Texture.PLANAR_MODE:
  370. this._defines.REFLECTIONMAP_PLANAR = true;
  371. break;
  372. case Texture.PROJECTION_MODE:
  373. this._defines.REFLECTIONMAP_PROJECTION = true;
  374. break;
  375. case Texture.SKYBOX_MODE:
  376. this._defines.REFLECTIONMAP_SKYBOX = true;
  377. break;
  378. case Texture.SPHERICAL_MODE:
  379. this._defines.REFLECTIONMAP_SPHERICAL = true;
  380. break;
  381. case Texture.EQUIRECTANGULAR_MODE:
  382. this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
  383. break;
  384. }
  385. }
  386. }
  387. if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
  388. if (!this.lightmapTexture.isReady()) {
  389. return false;
  390. } else {
  391. needUVs = true;
  392. this._defines.LIGHTMAP = true;
  393. this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
  394. }
  395. }
  396. if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
  397. if (!this.emissiveTexture.isReady()) {
  398. return false;
  399. } else {
  400. needUVs = true;
  401. this._defines.EMISSIVE = true;
  402. }
  403. }
  404. if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
  405. if (!this.specularTexture.isReady()) {
  406. return false;
  407. } else {
  408. needUVs = true;
  409. this._defines.SPECULAR = true;
  410. this._defines.GLOSSINESSFROMSPECULARMAP = this.useGlossinessFromSpecularMapAlpha;
  411. }
  412. }
  413. }
  414. if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  415. if (!this.bumpTexture.isReady()) {
  416. return false;
  417. } else {
  418. needUVs = true;
  419. this._defines.BUMP = true;
  420. }
  421. }
  422. // Effect
  423. if (scene.clipPlane) {
  424. this._defines.CLIPPLANE = true;
  425. }
  426. if (engine.getAlphaTesting()) {
  427. this._defines.ALPHATEST = true;
  428. }
  429. if (this._shouldUseAlphaFromDiffuseTexture()) {
  430. this._defines.ALPHAFROMDIFFUSE = true;
  431. }
  432. if (this.useEmissiveAsIllumination) {
  433. this._defines.EMISSIVEASILLUMINATION = true;
  434. }
  435. if (this.linkEmissiveWithDiffuse) {
  436. this._defines.LINKEMISSIVEWITHDIFFUSE = true;
  437. }
  438. if (this.useLogarithmicDepth) {
  439. this._defines.LOGARITHMICDEPTH = true;
  440. }
  441. if (this.cameraContrast != 1) {
  442. this._defines.CAMERACONTRAST = true;
  443. }
  444. if (this.cameraExposure != 1) {
  445. this._defines.CAMERATONEMAP = true;
  446. }
  447. if (this.overloadedSmoothnessIntensity > 0 ||
  448. this.overloadedEmissiveIntensity > 0 ||
  449. this.overloadedSpecularIntensity > 0 ||
  450. this.overloadedDiffuseIntensity > 0 ||
  451. this.overloadedAmbientIntensity > 0) {
  452. this._defines.OVERLOADEDVALUES = true;
  453. }
  454. // Point size
  455. if (this.pointsCloud || scene.forcePointsCloud) {
  456. this._defines.POINTSIZE = true;
  457. }
  458. // Fog
  459. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== Scene.FOGMODE_NONE && this.fogEnabled) {
  460. this._defines.FOG = true;
  461. }
  462. if (scene.lightsEnabled && !this.disableLighting) {
  463. needNormals = PBRMaterial.PrepareDefinesForLights(scene, mesh, this._defines);
  464. }
  465. if (StandardMaterial.FresnelEnabled) {
  466. // Fresnel
  467. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled ||
  468. this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  469. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  470. this._defines.OPACITYFRESNEL = true;
  471. }
  472. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  473. this._defines.EMISSIVEFRESNEL = true;
  474. }
  475. needNormals = true;
  476. this._defines.FRESNEL = true;
  477. }
  478. }
  479. if (this._defines.SPECULARTERM && this.useSpecularOverAlpha) {
  480. this._defines.SPECULAROVERALPHA = true;
  481. }
  482. // Attribs
  483. if (mesh) {
  484. if (needNormals && mesh.isVerticesDataPresent(VertexBuffer.NormalKind)) {
  485. this._defines.NORMAL = true;
  486. }
  487. if (needUVs) {
  488. if (mesh.isVerticesDataPresent(VertexBuffer.UVKind)) {
  489. this._defines.UV1 = true;
  490. }
  491. if (mesh.isVerticesDataPresent(VertexBuffer.UV2Kind)) {
  492. this._defines.UV2 = true;
  493. }
  494. }
  495. if (mesh.useVertexColors && mesh.isVerticesDataPresent(VertexBuffer.ColorKind)) {
  496. this._defines.VERTEXCOLOR = true;
  497. if (mesh.hasVertexAlpha) {
  498. this._defines.VERTEXALPHA = true;
  499. }
  500. }
  501. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  502. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  503. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  504. }
  505. // Instances
  506. if (useInstances) {
  507. this._defines.INSTANCES = true;
  508. }
  509. }
  510. // Get correct effect
  511. if (!this._defines.isEqual(this._cachedDefines)) {
  512. this._defines.cloneTo(this._cachedDefines);
  513. scene.resetCachedMaterial();
  514. // Fallbacks
  515. var fallbacks = new EffectFallbacks();
  516. if (this._defines.REFLECTION) {
  517. fallbacks.addFallback(0, "REFLECTION");
  518. }
  519. if (this._defines.SPECULAR) {
  520. fallbacks.addFallback(0, "SPECULAR");
  521. }
  522. if (this._defines.BUMP) {
  523. fallbacks.addFallback(0, "BUMP");
  524. }
  525. if (this._defines.SPECULAROVERALPHA) {
  526. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  527. }
  528. if (this._defines.FOG) {
  529. fallbacks.addFallback(1, "FOG");
  530. }
  531. if (this._defines.POINTSIZE) {
  532. fallbacks.addFallback(0, "POINTSIZE");
  533. }
  534. if (this._defines.LOGARITHMICDEPTH) {
  535. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  536. }
  537. for (let lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
  538. if (!this._defines["LIGHT" + lightIndex]) {
  539. continue;
  540. }
  541. if (lightIndex > 0) {
  542. fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
  543. }
  544. if (this._defines["SHADOW" + lightIndex]) {
  545. fallbacks.addFallback(0, "SHADOW" + lightIndex);
  546. }
  547. if (this._defines["SHADOWPCF" + lightIndex]) {
  548. fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
  549. }
  550. if (this._defines["SHADOWVSM" + lightIndex]) {
  551. fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
  552. }
  553. }
  554. if (this._defines.SPECULARTERM) {
  555. fallbacks.addFallback(0, "SPECULARTERM");
  556. }
  557. if (this._defines.OPACITYFRESNEL) {
  558. fallbacks.addFallback(1, "OPACITYFRESNEL");
  559. }
  560. if (this._defines.EMISSIVEFRESNEL) {
  561. fallbacks.addFallback(2, "EMISSIVEFRESNEL");
  562. }
  563. if (this._defines.FRESNEL) {
  564. fallbacks.addFallback(3, "FRESNEL");
  565. }
  566. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  567. fallbacks.addCPUSkinningFallback(0, mesh);
  568. }
  569. //Attributes
  570. var attribs = [VertexBuffer.PositionKind];
  571. if (this._defines.NORMAL) {
  572. attribs.push(VertexBuffer.NormalKind);
  573. }
  574. if (this._defines.UV1) {
  575. attribs.push(VertexBuffer.UVKind);
  576. }
  577. if (this._defines.UV2) {
  578. attribs.push(VertexBuffer.UV2Kind);
  579. }
  580. if (this._defines.VERTEXCOLOR) {
  581. attribs.push(VertexBuffer.ColorKind);
  582. }
  583. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  584. attribs.push(VertexBuffer.MatricesIndicesKind);
  585. attribs.push(VertexBuffer.MatricesWeightsKind);
  586. if (this._defines.NUM_BONE_INFLUENCERS > 4) {
  587. attribs.push(VertexBuffer.MatricesIndicesExtraKind);
  588. attribs.push(VertexBuffer.MatricesWeightsExtraKind);
  589. }
  590. }
  591. if (this._defines.INSTANCES) {
  592. attribs.push("world0");
  593. attribs.push("world1");
  594. attribs.push("world2");
  595. attribs.push("world3");
  596. }
  597. // Legacy browser patch
  598. var shaderName = "pbr";
  599. if (!scene.getEngine().getCaps().standardDerivatives) {
  600. shaderName = "legacypbr";
  601. }
  602. var join = this._defines.toString();
  603. this._effect = scene.getEngine().createEffect(shaderName,
  604. attribs,
  605. ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vDiffuseColor", "vSpecularColor", "vEmissiveColor", "vReflectionColor",
  606. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  607. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  608. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  609. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  610. "vFogInfos", "vFogColor", "pointSize",
  611. "vDiffuseInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vSpecularInfos", "vBumpInfos", "vLightmapInfos",
  612. "mBones",
  613. "vClipPlane", "diffuseMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "specularMatrix", "bumpMatrix", "lightmapMatrix",
  614. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
  615. "opacityParts", "emissiveLeftColor", "emissiveRightColor",
  616. "vLightingIntensity", "vShadowIntensity", "vOverloadedIntensity", "vCameraInfos", "vOverloadedDiffuse", "vOverloadedSpecular", "vOverloadedEmissive", "vOverloadedSmoothness",
  617. "logarithmicDepthConstant"
  618. ],
  619. ["diffuseSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "specularSampler", "bumpSampler", "lightmapSampler",
  620. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
  621. ],
  622. join, fallbacks, this.onCompiled, this.onError);
  623. }
  624. if (!this._effect.isReady()) {
  625. return false;
  626. }
  627. this._renderId = scene.getRenderId();
  628. this._wasPreviouslyReady = true;
  629. if (mesh) {
  630. if (!mesh._materialDefines) {
  631. mesh._materialDefines = new PBRMaterialDefines();
  632. }
  633. this._defines.cloneTo(mesh._materialDefines);
  634. }
  635. return true;
  636. }
  637. public unbind(): void {
  638. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  639. this._effect.setTexture("reflection2DSampler", null);
  640. }
  641. super.unbind();
  642. }
  643. public bindOnlyWorldMatrix(world: Matrix): void {
  644. this._effect.setMatrix("world", world);
  645. }
  646. private _myScene: BABYLON.Scene = null;
  647. private _myShadowGenerator: BABYLON.ShadowGenerator = null;
  648. public bind(world: Matrix, mesh?: Mesh): void {
  649. this._myScene = this.getScene();
  650. // Matrices
  651. this.bindOnlyWorldMatrix(world);
  652. this._effect.setMatrix("viewProjection", this._myScene.getTransformMatrix());
  653. // Bones
  654. if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
  655. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices());
  656. }
  657. if (this._myScene.getCachedMaterial() !== (<BABYLON.Material>this)) {
  658. if (StandardMaterial.FresnelEnabled) {
  659. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  660. this._effect.setColor4("opacityParts", new Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  661. }
  662. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  663. this._effect.setColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  664. this._effect.setColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  665. }
  666. }
  667. // Textures
  668. if (this.diffuseTexture && StandardMaterial.DiffuseTextureEnabled) {
  669. this._effect.setTexture("diffuseSampler", this.diffuseTexture);
  670. this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  671. this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  672. }
  673. if (this.ambientTexture && StandardMaterial.AmbientTextureEnabled) {
  674. this._effect.setTexture("ambientSampler", this.ambientTexture);
  675. this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
  676. this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
  677. }
  678. if (this.opacityTexture && StandardMaterial.OpacityTextureEnabled) {
  679. this._effect.setTexture("opacitySampler", this.opacityTexture);
  680. this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
  681. this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
  682. }
  683. if (this.reflectionTexture && StandardMaterial.ReflectionTextureEnabled) {
  684. if (this.reflectionTexture.isCube) {
  685. this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
  686. } else {
  687. this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
  688. }
  689. this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
  690. this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
  691. }
  692. if (this.emissiveTexture && StandardMaterial.EmissiveTextureEnabled) {
  693. this._effect.setTexture("emissiveSampler", this.emissiveTexture);
  694. this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
  695. this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
  696. }
  697. if (this.lightmapTexture && StandardMaterial.LightmapEnabled) {
  698. this._effect.setTexture("lightmapSampler", this.lightmapTexture);
  699. this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
  700. this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
  701. }
  702. if (this.specularTexture && StandardMaterial.SpecularTextureEnabled) {
  703. this._effect.setTexture("specularSampler", this.specularTexture);
  704. this._effect.setFloat2("vSpecularInfos", this.specularTexture.coordinatesIndex, this.specularTexture.level);
  705. this._effect.setMatrix("specularMatrix", this.specularTexture.getTextureMatrix());
  706. }
  707. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  708. this._effect.setTexture("bumpSampler", this.bumpTexture);
  709. this._effect.setFloat2("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level);
  710. this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
  711. }
  712. // Clip plane
  713. if (this._myScene.clipPlane) {
  714. this._effect.setFloat4("vClipPlane", this._myScene.clipPlane.normal.x,
  715. this._myScene.clipPlane.normal.y,
  716. this._myScene.clipPlane.normal.z,
  717. this._myScene.clipPlane.d);
  718. }
  719. // Point size
  720. if (this.pointsCloud) {
  721. this._effect.setFloat("pointSize", this.pointSize);
  722. }
  723. // Colors
  724. this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  725. // GAMMA CORRECTION.
  726. this.specularColor.toLinearSpaceToRef(PBRMaterial._scaledSpecular);
  727. this._effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
  728. this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
  729. if (this._defines.SPECULARTERM) {
  730. this._effect.setColor4("vSpecularColor", PBRMaterial._scaledSpecular, this.glossiness);
  731. }
  732. // GAMMA CORRECTION.
  733. this.emissiveColor.toLinearSpaceToRef(PBRMaterial._scaledEmissive);
  734. this._effect.setColor3("vEmissiveColor", PBRMaterial._scaledEmissive);
  735. // GAMMA CORRECTION.
  736. this.reflectionColor.toLinearSpaceToRef(PBRMaterial._scaledReflection);
  737. this._effect.setColor3("vReflectionColor", PBRMaterial._scaledReflection);
  738. }
  739. // GAMMA CORRECTION.
  740. this.diffuseColor.toLinearSpaceToRef(PBRMaterial._scaledDiffuse);
  741. this._effect.setColor4("vDiffuseColor", PBRMaterial._scaledDiffuse, this.alpha * mesh.visibility);
  742. // Lights
  743. if (this._myScene.lightsEnabled && !this.disableLighting) {
  744. PBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines);
  745. }
  746. // View
  747. if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== Scene.FOGMODE_NONE || this.reflectionTexture) {
  748. this._effect.setMatrix("view", this._myScene.getViewMatrix());
  749. }
  750. // Fog
  751. if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== Scene.FOGMODE_NONE) {
  752. this._effect.setFloat4("vFogInfos", this._myScene.fogMode, this._myScene.fogStart, this._myScene.fogEnd, this._myScene.fogDensity);
  753. this._effect.setColor3("vFogColor", this._myScene.fogColor);
  754. }
  755. this._lightingInfos.x = this.directIntensity;
  756. this._lightingInfos.y = this.emissiveIntensity;
  757. this._lightingInfos.z = this.environmentIntensity;
  758. this._effect.setVector4("vLightingIntensity", this._lightingInfos);
  759. this._shadowInfos.x = this.shadowIntensity;
  760. this._shadowInfos.y = this.shadeIntensity;
  761. this._effect.setVector4("vShadowIntensity", this._shadowInfos);
  762. this._cameraInfos.x = this.cameraExposure;
  763. this._cameraInfos.y = this.cameraContrast;
  764. this._effect.setVector4("vCameraInfos", this._cameraInfos);
  765. this._overloadedIntensity.x = this.overloadedAmbientIntensity;
  766. this._overloadedIntensity.y = this.overloadedDiffuseIntensity;
  767. this._overloadedIntensity.z = this.overloadedSpecularIntensity;
  768. this._overloadedIntensity.w = this.overloadedEmissiveIntensity;
  769. this._effect.setVector4("vOverloadedIntensity", this._overloadedIntensity);
  770. this.overloadedAmbient.toLinearSpaceToRef(this._tempColor);
  771. this._effect.setColor3("vOverloadedAmbient", this._tempColor);
  772. this.overloadedDiffuse.toLinearSpaceToRef(this._tempColor);
  773. this._effect.setColor3("vOverloadedDiffuse", this._tempColor);
  774. this.overloadedSpecular.toLinearSpaceToRef(this._tempColor);
  775. this._effect.setColor3("vOverloadedSpecular", this._tempColor);
  776. this.overloadedEmissive.toLinearSpaceToRef(this._tempColor);
  777. this._effect.setColor3("vOverloadedEmissive", this._tempColor);
  778. this._overloadedSmoothness.x = this.overloadedSmoothness;
  779. this._overloadedSmoothness.y = this.overloadedSmoothnessIntensity;
  780. this._effect.setVector3("vOverloadedSmoothness", this._overloadedSmoothness);
  781. // Log. depth
  782. if (this._defines.LOGARITHMICDEPTH) {
  783. this._effect.setFloat("logarithmicDepthConstant", 2.0 / (Math.log(this._myScene.activeCamera.maxZ + 1.0) / Math.LN2));
  784. }
  785. super.bind(world, mesh);
  786. this._myScene = null;
  787. }
  788. public getAnimatables(): IAnimatable[] {
  789. var results = [];
  790. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  791. results.push(this.diffuseTexture);
  792. }
  793. if (this.ambientTexture && this.ambientTexture.animations && this.ambientTexture.animations.length > 0) {
  794. results.push(this.ambientTexture);
  795. }
  796. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  797. results.push(this.opacityTexture);
  798. }
  799. if (this.reflectionTexture && this.reflectionTexture.animations && this.reflectionTexture.animations.length > 0) {
  800. results.push(this.reflectionTexture);
  801. }
  802. if (this.emissiveTexture && this.emissiveTexture.animations && this.emissiveTexture.animations.length > 0) {
  803. results.push(this.emissiveTexture);
  804. }
  805. if (this.specularTexture && this.specularTexture.animations && this.specularTexture.animations.length > 0) {
  806. results.push(this.specularTexture);
  807. }
  808. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  809. results.push(this.bumpTexture);
  810. }
  811. return results;
  812. }
  813. public dispose(forceDisposeEffect?: boolean): void {
  814. if (this.diffuseTexture) {
  815. this.diffuseTexture.dispose();
  816. }
  817. if (this.ambientTexture) {
  818. this.ambientTexture.dispose();
  819. }
  820. if (this.opacityTexture) {
  821. this.opacityTexture.dispose();
  822. }
  823. if (this.reflectionTexture) {
  824. this.reflectionTexture.dispose();
  825. }
  826. if (this.emissiveTexture) {
  827. this.emissiveTexture.dispose();
  828. }
  829. if (this.specularTexture) {
  830. this.specularTexture.dispose();
  831. }
  832. if (this.bumpTexture) {
  833. this.bumpTexture.dispose();
  834. }
  835. super.dispose(forceDisposeEffect);
  836. }
  837. public clone(name: string): PBRMaterial {
  838. var newPBRMaterial = new PBRMaterial(name, this.getScene());
  839. // Base material
  840. this.copyTo(newPBRMaterial);
  841. newPBRMaterial.directIntensity = this.directIntensity;
  842. newPBRMaterial.emissiveIntensity = this.emissiveIntensity;
  843. newPBRMaterial.environmentIntensity = this.environmentIntensity;
  844. newPBRMaterial.shadowIntensity = this.shadowIntensity;
  845. newPBRMaterial.shadeIntensity = this.shadeIntensity;
  846. newPBRMaterial.cameraExposure = this.cameraExposure;
  847. newPBRMaterial.cameraContrast = this.cameraContrast;
  848. newPBRMaterial.overloadedAmbientIntensity = this.overloadedAmbientIntensity;
  849. newPBRMaterial.overloadedDiffuseIntensity = this.overloadedDiffuseIntensity;
  850. newPBRMaterial.overloadedSpecularIntensity = this.overloadedSpecularIntensity;
  851. newPBRMaterial.overloadedEmissiveIntensity = this.overloadedEmissiveIntensity;
  852. newPBRMaterial.overloadedAmbient = this.overloadedAmbient;
  853. newPBRMaterial.overloadedDiffuse = this.overloadedDiffuse;
  854. newPBRMaterial.overloadedSpecular = this.overloadedSpecular;
  855. newPBRMaterial.overloadedEmissive = this.overloadedEmissive;
  856. newPBRMaterial.overloadedSmoothness = this.overloadedSmoothness;
  857. newPBRMaterial.overloadedSmoothnessIntensity = this.overloadedSmoothnessIntensity;
  858. newPBRMaterial.disableBumpMap = this.disableBumpMap;
  859. // Standard material
  860. if (this.diffuseTexture && this.diffuseTexture.clone) {
  861. newPBRMaterial.diffuseTexture = this.diffuseTexture.clone();
  862. }
  863. if (this.ambientTexture && this.ambientTexture.clone) {
  864. newPBRMaterial.ambientTexture = this.ambientTexture.clone();
  865. }
  866. if (this.opacityTexture && this.opacityTexture.clone) {
  867. newPBRMaterial.opacityTexture = this.opacityTexture.clone();
  868. }
  869. if (this.reflectionTexture && this.reflectionTexture.clone) {
  870. newPBRMaterial.reflectionTexture = this.reflectionTexture.clone();
  871. }
  872. if (this.emissiveTexture && this.emissiveTexture.clone) {
  873. newPBRMaterial.emissiveTexture = this.emissiveTexture.clone();
  874. }
  875. if (this.specularTexture && this.specularTexture.clone) {
  876. newPBRMaterial.specularTexture = this.specularTexture.clone();
  877. }
  878. if (this.bumpTexture && this.bumpTexture.clone) {
  879. newPBRMaterial.bumpTexture = this.bumpTexture.clone();
  880. }
  881. if (this.lightmapTexture && this.lightmapTexture.clone) {
  882. newPBRMaterial.lightmapTexture = this.lightmapTexture.clone();
  883. newPBRMaterial.useLightmapAsShadowmap = this.useLightmapAsShadowmap;
  884. }
  885. newPBRMaterial.ambientColor = this.ambientColor.clone();
  886. newPBRMaterial.diffuseColor = this.diffuseColor.clone();
  887. newPBRMaterial.specularColor = this.specularColor.clone();
  888. newPBRMaterial.reflectionColor = this.reflectionColor.clone();
  889. newPBRMaterial.glossiness = this.glossiness;
  890. newPBRMaterial.emissiveColor = this.emissiveColor.clone();
  891. newPBRMaterial.useAlphaFromDiffuseTexture = this.useAlphaFromDiffuseTexture;
  892. newPBRMaterial.useEmissiveAsIllumination = this.useEmissiveAsIllumination;
  893. newPBRMaterial.useGlossinessFromSpecularMapAlpha = this.useGlossinessFromSpecularMapAlpha;
  894. newPBRMaterial.useSpecularOverAlpha = this.useSpecularOverAlpha;
  895. newPBRMaterial.emissiveFresnelParameters = this.emissiveFresnelParameters.clone();
  896. newPBRMaterial.opacityFresnelParameters = this.opacityFresnelParameters.clone();
  897. return newPBRMaterial;
  898. }
  899. }
  900. }