babylon.pbrMaterial.ts 47 KB

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