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