babylon.pbrMaterial.js 117 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  3. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") return Reflect.decorate(decorators, target, key, desc);
  4. switch (arguments.length) {
  5. case 2: return decorators.reduceRight(function(o, d) { return (d && d(o)) || o; }, target);
  6. case 3: return decorators.reduceRight(function(o, d) { return (d && d(target, key)), void 0; }, void 0);
  7. case 4: return decorators.reduceRight(function(o, d) { return (d && d(target, key, o)) || o; }, desc);
  8. }
  9. };
  10. var BABYLON;
  11. (function (BABYLON) {
  12. var maxSimultaneousLights = 4;
  13. var PBRMaterialDefines = (function (_super) {
  14. __extends(PBRMaterialDefines, _super);
  15. function PBRMaterialDefines() {
  16. _super.call(this);
  17. this.ALBEDO = false;
  18. this.AMBIENT = false;
  19. this.OPACITY = false;
  20. this.OPACITYRGB = false;
  21. this.REFLECTION = false;
  22. this.EMISSIVE = false;
  23. this.REFLECTIVITY = false;
  24. this.BUMP = false;
  25. this.PARALLAX = false;
  26. this.PARALLAXOCCLUSION = false;
  27. this.SPECULAROVERALPHA = false;
  28. this.CLIPPLANE = false;
  29. this.ALPHATEST = false;
  30. this.ALPHAFROMALBEDO = false;
  31. this.POINTSIZE = false;
  32. this.FOG = false;
  33. this.LIGHT0 = false;
  34. this.LIGHT1 = false;
  35. this.LIGHT2 = false;
  36. this.LIGHT3 = false;
  37. this.SPOTLIGHT0 = false;
  38. this.SPOTLIGHT1 = false;
  39. this.SPOTLIGHT2 = false;
  40. this.SPOTLIGHT3 = false;
  41. this.HEMILIGHT0 = false;
  42. this.HEMILIGHT1 = false;
  43. this.HEMILIGHT2 = false;
  44. this.HEMILIGHT3 = false;
  45. this.POINTLIGHT0 = false;
  46. this.POINTLIGHT1 = false;
  47. this.POINTLIGHT2 = false;
  48. this.POINTLIGHT3 = false;
  49. this.DIRLIGHT0 = false;
  50. this.DIRLIGHT1 = false;
  51. this.DIRLIGHT2 = false;
  52. this.DIRLIGHT3 = false;
  53. this.SPECULARTERM = false;
  54. this.SHADOW0 = false;
  55. this.SHADOW1 = false;
  56. this.SHADOW2 = false;
  57. this.SHADOW3 = false;
  58. this.SHADOWS = false;
  59. this.SHADOWVSM0 = false;
  60. this.SHADOWVSM1 = false;
  61. this.SHADOWVSM2 = false;
  62. this.SHADOWVSM3 = false;
  63. this.SHADOWPCF0 = false;
  64. this.SHADOWPCF1 = false;
  65. this.SHADOWPCF2 = false;
  66. this.SHADOWPCF3 = false;
  67. this.OPACITYFRESNEL = false;
  68. this.EMISSIVEFRESNEL = false;
  69. this.FRESNEL = false;
  70. this.NORMAL = false;
  71. this.UV1 = false;
  72. this.UV2 = false;
  73. this.VERTEXCOLOR = false;
  74. this.VERTEXALPHA = false;
  75. this.NUM_BONE_INFLUENCERS = 0;
  76. this.BonesPerMesh = 0;
  77. this.INSTANCES = false;
  78. this.MICROSURFACEFROMREFLECTIVITYMAP = false;
  79. this.MICROSURFACEAUTOMATIC = false;
  80. this.EMISSIVEASILLUMINATION = false;
  81. this.LINKEMISSIVEWITHALBEDO = false;
  82. this.LIGHTMAP = false;
  83. this.USELIGHTMAPASSHADOWMAP = false;
  84. this.REFLECTIONMAP_3D = false;
  85. this.REFLECTIONMAP_SPHERICAL = false;
  86. this.REFLECTIONMAP_PLANAR = false;
  87. this.REFLECTIONMAP_CUBIC = false;
  88. this.REFLECTIONMAP_PROJECTION = false;
  89. this.REFLECTIONMAP_SKYBOX = false;
  90. this.REFLECTIONMAP_EXPLICIT = false;
  91. this.REFLECTIONMAP_EQUIRECTANGULAR = false;
  92. this.INVERTCUBICMAP = false;
  93. this.LOGARITHMICDEPTH = false;
  94. this.CAMERATONEMAP = false;
  95. this.CAMERACONTRAST = false;
  96. this.OVERLOADEDVALUES = false;
  97. this.OVERLOADEDSHADOWVALUES = false;
  98. this.USESPHERICALFROMREFLECTIONMAP = false;
  99. this.REFRACTION = false;
  100. this.REFRACTIONMAP_3D = false;
  101. this.LINKREFRACTIONTOTRANSPARENCY = false;
  102. this.REFRACTIONMAPINLINEARSPACE = false;
  103. this.LODBASEDMICROSFURACE = false;
  104. this.USEPHYSICALLIGHTFALLOFF = false;
  105. this.RADIANCEOVERALPHA = false;
  106. this.USEPMREMREFLECTION = false;
  107. this.USEPMREMREFRACTION = false;
  108. this._keys = Object.keys(this);
  109. }
  110. return PBRMaterialDefines;
  111. })(BABYLON.MaterialDefines);
  112. var PBRMaterial = (function (_super) {
  113. __extends(PBRMaterial, _super);
  114. function PBRMaterial(name, scene) {
  115. var _this = this;
  116. _super.call(this, name, scene);
  117. this.directIntensity = 1.0;
  118. this.emissiveIntensity = 1.0;
  119. this.environmentIntensity = 1.0;
  120. this.specularIntensity = 1.0;
  121. this._lightingInfos = new BABYLON.Vector4(this.directIntensity, this.emissiveIntensity, this.environmentIntensity, this.specularIntensity);
  122. this.overloadedShadowIntensity = 1.0;
  123. this.overloadedShadeIntensity = 1.0;
  124. this._overloadedShadowInfos = new BABYLON.Vector4(this.overloadedShadowIntensity, this.overloadedShadeIntensity, 0.0, 0.0);
  125. this.cameraExposure = 1.0;
  126. this.cameraContrast = 1.0;
  127. this._cameraInfos = new BABYLON.Vector4(1.0, 1.0, 0.0, 0.0);
  128. this._microsurfaceTextureLods = new BABYLON.Vector2(0.0, 0.0);
  129. this.overloadedAmbientIntensity = 0.0;
  130. this.overloadedAlbedoIntensity = 0.0;
  131. this.overloadedReflectivityIntensity = 0.0;
  132. this.overloadedEmissiveIntensity = 0.0;
  133. this._overloadedIntensity = new BABYLON.Vector4(this.overloadedAmbientIntensity, this.overloadedAlbedoIntensity, this.overloadedReflectivityIntensity, this.overloadedEmissiveIntensity);
  134. this.overloadedAmbient = BABYLON.Color3.White();
  135. this.overloadedAlbedo = BABYLON.Color3.White();
  136. this.overloadedReflectivity = BABYLON.Color3.White();
  137. this.overloadedEmissive = BABYLON.Color3.White();
  138. this.overloadedReflection = BABYLON.Color3.White();
  139. this.overloadedMicroSurface = 0.0;
  140. this.overloadedMicroSurfaceIntensity = 0.0;
  141. this.overloadedReflectionIntensity = 0.0;
  142. this._overloadedMicroSurface = new BABYLON.Vector3(this.overloadedMicroSurface, this.overloadedMicroSurfaceIntensity, this.overloadedReflectionIntensity);
  143. this.disableBumpMap = false;
  144. this.ambientColor = new BABYLON.Color3(0, 0, 0);
  145. this.albedoColor = new BABYLON.Color3(1, 1, 1);
  146. this.reflectivityColor = new BABYLON.Color3(1, 1, 1);
  147. this.reflectionColor = new BABYLON.Color3(0.5, 0.5, 0.5);
  148. this.emissiveColor = new BABYLON.Color3(0, 0, 0);
  149. this.microSurface = 0.5;
  150. this.indexOfRefraction = 0.66;
  151. this.invertRefractionY = false;
  152. this.linkRefractionWithTransparency = false;
  153. this.linkEmissiveWithAlbedo = false;
  154. this.useLightmapAsShadowmap = false;
  155. this.useEmissiveAsIllumination = false;
  156. this.useAlphaFromAlbedoTexture = false;
  157. this.useSpecularOverAlpha = true;
  158. this.useMicroSurfaceFromReflectivityMapAlpha = false;
  159. this.useAutoMicroSurfaceFromReflectivityMap = false;
  160. this.useScalarInLinearSpace = false;
  161. this.usePhysicalLightFalloff = true;
  162. this.useRadianceOverAlpha = true;
  163. this.useParallax = false;
  164. this.useParallaxOcclusion = false;
  165. this.parallaxScaleBias = 0.05;
  166. this.disableLighting = false;
  167. this._renderTargets = new BABYLON.SmartArray(16);
  168. this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  169. this._globalAmbientColor = new BABYLON.Color3(0, 0, 0);
  170. this._tempColor = new BABYLON.Color3();
  171. this._defines = new PBRMaterialDefines();
  172. this._cachedDefines = new PBRMaterialDefines();
  173. this._myScene = null;
  174. this._myShadowGenerator = null;
  175. this._cachedDefines.BonesPerMesh = -1;
  176. this.getRenderTargetTextures = function () {
  177. _this._renderTargets.reset();
  178. if (_this.reflectionTexture && _this.reflectionTexture.isRenderTarget) {
  179. _this._renderTargets.push(_this.reflectionTexture);
  180. }
  181. if (_this.refractionTexture && _this.refractionTexture.isRenderTarget) {
  182. _this._renderTargets.push(_this.refractionTexture);
  183. }
  184. return _this._renderTargets;
  185. };
  186. }
  187. Object.defineProperty(PBRMaterial.prototype, "useLogarithmicDepth", {
  188. get: function () {
  189. return this._useLogarithmicDepth;
  190. },
  191. set: function (value) {
  192. this._useLogarithmicDepth = value && this.getScene().getEngine().getCaps().fragmentDepthSupported;
  193. },
  194. enumerable: true,
  195. configurable: true
  196. });
  197. PBRMaterial.prototype.needAlphaBlending = function () {
  198. if (this.linkRefractionWithTransparency) {
  199. return false;
  200. }
  201. return (this.alpha < 1.0) || (this.opacityTexture != null) || this._shouldUseAlphaFromAlbedoTexture() || this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled;
  202. };
  203. PBRMaterial.prototype.needAlphaTesting = function () {
  204. if (this.linkRefractionWithTransparency) {
  205. return false;
  206. }
  207. return this.albedoTexture != null && this.albedoTexture.hasAlpha;
  208. };
  209. PBRMaterial.prototype._shouldUseAlphaFromAlbedoTexture = function () {
  210. return this.albedoTexture != null && this.albedoTexture.hasAlpha && this.useAlphaFromAlbedoTexture;
  211. };
  212. PBRMaterial.prototype.getAlphaTestTexture = function () {
  213. return this.albedoTexture;
  214. };
  215. PBRMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  216. if (!mesh) {
  217. return true;
  218. }
  219. if (this._defines.INSTANCES !== useInstances) {
  220. return false;
  221. }
  222. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  223. return true;
  224. }
  225. return false;
  226. };
  227. PBRMaterial.prototype.convertColorToLinearSpaceToRef = function (color, ref) {
  228. PBRMaterial.convertColorToLinearSpaceToRef(color, ref, this.useScalarInLinearSpace);
  229. };
  230. PBRMaterial.convertColorToLinearSpaceToRef = function (color, ref, useScalarInLinear) {
  231. if (!useScalarInLinear) {
  232. color.toLinearSpaceToRef(ref);
  233. }
  234. else {
  235. ref.r = color.r;
  236. ref.g = color.g;
  237. ref.b = color.b;
  238. }
  239. };
  240. PBRMaterial.BindLights = function (scene, mesh, effect, defines, useScalarInLinearSpace) {
  241. var lightIndex = 0;
  242. var depthValuesAlreadySet = false;
  243. for (var index = 0; index < scene.lights.length; index++) {
  244. var light = scene.lights[index];
  245. if (!light.isEnabled()) {
  246. continue;
  247. }
  248. if (!light.canAffectMesh(mesh)) {
  249. continue;
  250. }
  251. this._lightRadiuses[lightIndex] = light.radius;
  252. BABYLON.MaterialHelper.BindLightProperties(light, effect, lightIndex);
  253. // GAMMA CORRECTION.
  254. this.convertColorToLinearSpaceToRef(light.diffuse, PBRMaterial._scaledAlbedo, useScalarInLinearSpace);
  255. PBRMaterial._scaledAlbedo.scaleToRef(light.intensity, PBRMaterial._scaledAlbedo);
  256. effect.setColor4("vLightDiffuse" + lightIndex, PBRMaterial._scaledAlbedo, light.range);
  257. if (defines["SPECULARTERM"]) {
  258. this.convertColorToLinearSpaceToRef(light.specular, PBRMaterial._scaledReflectivity, useScalarInLinearSpace);
  259. PBRMaterial._scaledReflectivity.scaleToRef(light.intensity, PBRMaterial._scaledReflectivity);
  260. effect.setColor3("vLightSpecular" + lightIndex, PBRMaterial._scaledReflectivity);
  261. }
  262. // Shadows
  263. if (scene.shadowsEnabled) {
  264. depthValuesAlreadySet = BABYLON.MaterialHelper.BindLightShadow(light, scene, mesh, lightIndex, effect, depthValuesAlreadySet);
  265. }
  266. lightIndex++;
  267. if (lightIndex === maxSimultaneousLights)
  268. break;
  269. }
  270. effect.setFloat4("vLightRadiuses", this._lightRadiuses[0], this._lightRadiuses[1], this._lightRadiuses[2], this._lightRadiuses[3]);
  271. };
  272. PBRMaterial.prototype.isReady = function (mesh, useInstances) {
  273. if (this.checkReadyOnlyOnce) {
  274. if (this._wasPreviouslyReady) {
  275. return true;
  276. }
  277. }
  278. var scene = this.getScene();
  279. if (!this.checkReadyOnEveryCall) {
  280. if (this._renderId === scene.getRenderId()) {
  281. if (this._checkCache(scene, mesh, useInstances)) {
  282. return true;
  283. }
  284. }
  285. }
  286. var engine = scene.getEngine();
  287. var needNormals = false;
  288. var needUVs = false;
  289. this._defines.reset();
  290. if (scene.texturesEnabled) {
  291. // Textures
  292. if (scene.texturesEnabled) {
  293. if (scene.getEngine().getCaps().textureLOD) {
  294. this._defines.LODBASEDMICROSFURACE = true;
  295. }
  296. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  297. if (!this.albedoTexture.isReady()) {
  298. return false;
  299. }
  300. else {
  301. needUVs = true;
  302. this._defines.ALBEDO = true;
  303. }
  304. }
  305. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  306. if (!this.ambientTexture.isReady()) {
  307. return false;
  308. }
  309. else {
  310. needUVs = true;
  311. this._defines.AMBIENT = true;
  312. }
  313. }
  314. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  315. if (!this.opacityTexture.isReady()) {
  316. return false;
  317. }
  318. else {
  319. needUVs = true;
  320. this._defines.OPACITY = true;
  321. if (this.opacityTexture.getAlphaFromRGB) {
  322. this._defines.OPACITYRGB = true;
  323. }
  324. }
  325. }
  326. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  327. if (!this.reflectionTexture.isReady()) {
  328. return false;
  329. }
  330. else {
  331. needNormals = true;
  332. this._defines.REFLECTION = true;
  333. if (this.reflectionTexture.coordinatesMode === BABYLON.Texture.INVCUBIC_MODE) {
  334. this._defines.INVERTCUBICMAP = true;
  335. }
  336. this._defines.REFLECTIONMAP_3D = this.reflectionTexture.isCube;
  337. switch (this.reflectionTexture.coordinatesMode) {
  338. case BABYLON.Texture.CUBIC_MODE:
  339. case BABYLON.Texture.INVCUBIC_MODE:
  340. this._defines.REFLECTIONMAP_CUBIC = true;
  341. break;
  342. case BABYLON.Texture.EXPLICIT_MODE:
  343. this._defines.REFLECTIONMAP_EXPLICIT = true;
  344. break;
  345. case BABYLON.Texture.PLANAR_MODE:
  346. this._defines.REFLECTIONMAP_PLANAR = true;
  347. break;
  348. case BABYLON.Texture.PROJECTION_MODE:
  349. this._defines.REFLECTIONMAP_PROJECTION = true;
  350. break;
  351. case BABYLON.Texture.SKYBOX_MODE:
  352. this._defines.REFLECTIONMAP_SKYBOX = true;
  353. break;
  354. case BABYLON.Texture.SPHERICAL_MODE:
  355. this._defines.REFLECTIONMAP_SPHERICAL = true;
  356. break;
  357. case BABYLON.Texture.EQUIRECTANGULAR_MODE:
  358. this._defines.REFLECTIONMAP_EQUIRECTANGULAR = true;
  359. break;
  360. }
  361. if (this.reflectionTexture instanceof BABYLON.HDRCubeTexture && this.reflectionTexture) {
  362. this._defines.USESPHERICALFROMREFLECTIONMAP = true;
  363. needNormals = true;
  364. if (this.reflectionTexture.isPMREM) {
  365. this._defines.USEPMREMREFLECTION = true;
  366. }
  367. }
  368. }
  369. }
  370. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  371. if (!this.lightmapTexture.isReady()) {
  372. return false;
  373. }
  374. else {
  375. needUVs = true;
  376. this._defines.LIGHTMAP = true;
  377. this._defines.USELIGHTMAPASSHADOWMAP = this.useLightmapAsShadowmap;
  378. }
  379. }
  380. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  381. if (!this.emissiveTexture.isReady()) {
  382. return false;
  383. }
  384. else {
  385. needUVs = true;
  386. this._defines.EMISSIVE = true;
  387. }
  388. }
  389. if (this.reflectivityTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
  390. if (!this.reflectivityTexture.isReady()) {
  391. return false;
  392. }
  393. else {
  394. needUVs = true;
  395. this._defines.REFLECTIVITY = true;
  396. this._defines.MICROSURFACEFROMREFLECTIVITYMAP = this.useMicroSurfaceFromReflectivityMapAlpha;
  397. this._defines.MICROSURFACEAUTOMATIC = this.useAutoMicroSurfaceFromReflectivityMap;
  398. }
  399. }
  400. }
  401. if (scene.getEngine().getCaps().standardDerivatives && this.bumpTexture && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  402. if (!this.bumpTexture.isReady()) {
  403. return false;
  404. }
  405. else {
  406. needUVs = true;
  407. this._defines.BUMP = true;
  408. if (this.useParallax) {
  409. this._defines.PARALLAX = true;
  410. if (this.useParallaxOcclusion) {
  411. this._defines.PARALLAXOCCLUSION = true;
  412. }
  413. }
  414. }
  415. }
  416. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  417. if (!this.refractionTexture.isReady()) {
  418. return false;
  419. }
  420. else {
  421. needUVs = true;
  422. this._defines.REFRACTION = true;
  423. this._defines.REFRACTIONMAP_3D = this.refractionTexture.isCube;
  424. if (this.linkRefractionWithTransparency) {
  425. this._defines.LINKREFRACTIONTOTRANSPARENCY = true;
  426. }
  427. if (this.refractionTexture instanceof BABYLON.HDRCubeTexture) {
  428. this._defines.REFRACTIONMAPINLINEARSPACE = true;
  429. if (this.refractionTexture.isPMREM) {
  430. this._defines.USEPMREMREFRACTION = true;
  431. }
  432. }
  433. }
  434. }
  435. }
  436. // Effect
  437. if (scene.clipPlane) {
  438. this._defines.CLIPPLANE = true;
  439. }
  440. if (engine.getAlphaTesting()) {
  441. this._defines.ALPHATEST = true;
  442. }
  443. if (this._shouldUseAlphaFromAlbedoTexture()) {
  444. this._defines.ALPHAFROMALBEDO = true;
  445. }
  446. if (this.useEmissiveAsIllumination) {
  447. this._defines.EMISSIVEASILLUMINATION = true;
  448. }
  449. if (this.linkEmissiveWithAlbedo) {
  450. this._defines.LINKEMISSIVEWITHALBEDO = true;
  451. }
  452. if (this.useLogarithmicDepth) {
  453. this._defines.LOGARITHMICDEPTH = true;
  454. }
  455. if (this.cameraContrast != 1) {
  456. this._defines.CAMERACONTRAST = true;
  457. }
  458. if (this.cameraExposure != 1) {
  459. this._defines.CAMERATONEMAP = true;
  460. }
  461. if (this.overloadedShadeIntensity != 1 ||
  462. this.overloadedShadowIntensity != 1) {
  463. this._defines.OVERLOADEDSHADOWVALUES = true;
  464. }
  465. if (this.overloadedMicroSurfaceIntensity > 0 ||
  466. this.overloadedEmissiveIntensity > 0 ||
  467. this.overloadedReflectivityIntensity > 0 ||
  468. this.overloadedAlbedoIntensity > 0 ||
  469. this.overloadedAmbientIntensity > 0 ||
  470. this.overloadedReflectionIntensity > 0) {
  471. this._defines.OVERLOADEDVALUES = true;
  472. }
  473. // Point size
  474. if (this.pointsCloud || scene.forcePointsCloud) {
  475. this._defines.POINTSIZE = true;
  476. }
  477. // Fog
  478. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  479. this._defines.FOG = true;
  480. }
  481. if (scene.lightsEnabled && !this.disableLighting) {
  482. needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, this._defines) || needNormals;
  483. }
  484. if (BABYLON.StandardMaterial.FresnelEnabled) {
  485. // Fresnel
  486. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled ||
  487. this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  488. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  489. this._defines.OPACITYFRESNEL = true;
  490. }
  491. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  492. this._defines.EMISSIVEFRESNEL = true;
  493. }
  494. needNormals = true;
  495. this._defines.FRESNEL = true;
  496. }
  497. }
  498. if (this._defines.SPECULARTERM && this.useSpecularOverAlpha) {
  499. this._defines.SPECULAROVERALPHA = true;
  500. }
  501. if (this.usePhysicalLightFalloff) {
  502. this._defines.USEPHYSICALLIGHTFALLOFF = true;
  503. }
  504. if (this.useRadianceOverAlpha) {
  505. this._defines.RADIANCEOVERALPHA = true;
  506. }
  507. // Attribs
  508. if (mesh) {
  509. if (needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  510. this._defines.NORMAL = true;
  511. }
  512. if (needUVs) {
  513. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  514. this._defines.UV1 = true;
  515. }
  516. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  517. this._defines.UV2 = true;
  518. }
  519. }
  520. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  521. this._defines.VERTEXCOLOR = true;
  522. if (mesh.hasVertexAlpha) {
  523. this._defines.VERTEXALPHA = true;
  524. }
  525. }
  526. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  527. this._defines.NUM_BONE_INFLUENCERS = mesh.numBoneInfluencers;
  528. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  529. }
  530. // Instances
  531. if (useInstances) {
  532. this._defines.INSTANCES = true;
  533. }
  534. }
  535. // Get correct effect
  536. if (!this._defines.isEqual(this._cachedDefines)) {
  537. this._defines.cloneTo(this._cachedDefines);
  538. scene.resetCachedMaterial();
  539. // Fallbacks
  540. var fallbacks = new BABYLON.EffectFallbacks();
  541. if (this._defines.REFLECTION) {
  542. fallbacks.addFallback(0, "REFLECTION");
  543. }
  544. if (this._defines.REFRACTION) {
  545. fallbacks.addFallback(0, "REFRACTION");
  546. }
  547. if (this._defines.REFLECTIVITY) {
  548. fallbacks.addFallback(0, "REFLECTIVITY");
  549. }
  550. if (this._defines.BUMP) {
  551. fallbacks.addFallback(0, "BUMP");
  552. }
  553. if (this._defines.PARALLAX) {
  554. fallbacks.addFallback(1, "PARALLAX");
  555. }
  556. if (this._defines.PARALLAXOCCLUSION) {
  557. fallbacks.addFallback(0, "PARALLAXOCCLUSION");
  558. }
  559. if (this._defines.SPECULAROVERALPHA) {
  560. fallbacks.addFallback(0, "SPECULAROVERALPHA");
  561. }
  562. if (this._defines.FOG) {
  563. fallbacks.addFallback(1, "FOG");
  564. }
  565. if (this._defines.POINTSIZE) {
  566. fallbacks.addFallback(0, "POINTSIZE");
  567. }
  568. if (this._defines.LOGARITHMICDEPTH) {
  569. fallbacks.addFallback(0, "LOGARITHMICDEPTH");
  570. }
  571. BABYLON.MaterialHelper.HandleFallbacksForShadows(this._defines, fallbacks);
  572. if (this._defines.SPECULARTERM) {
  573. fallbacks.addFallback(0, "SPECULARTERM");
  574. }
  575. if (this._defines.OPACITYFRESNEL) {
  576. fallbacks.addFallback(1, "OPACITYFRESNEL");
  577. }
  578. if (this._defines.EMISSIVEFRESNEL) {
  579. fallbacks.addFallback(2, "EMISSIVEFRESNEL");
  580. }
  581. if (this._defines.FRESNEL) {
  582. fallbacks.addFallback(3, "FRESNEL");
  583. }
  584. if (this._defines.NUM_BONE_INFLUENCERS > 0) {
  585. fallbacks.addCPUSkinningFallback(0, mesh);
  586. }
  587. //Attributes
  588. var attribs = [BABYLON.VertexBuffer.PositionKind];
  589. if (this._defines.NORMAL) {
  590. attribs.push(BABYLON.VertexBuffer.NormalKind);
  591. }
  592. if (this._defines.UV1) {
  593. attribs.push(BABYLON.VertexBuffer.UVKind);
  594. }
  595. if (this._defines.UV2) {
  596. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  597. }
  598. if (this._defines.VERTEXCOLOR) {
  599. attribs.push(BABYLON.VertexBuffer.ColorKind);
  600. }
  601. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, this._defines, fallbacks);
  602. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, this._defines);
  603. // Legacy browser patch
  604. var shaderName = "pbr";
  605. if (!scene.getEngine().getCaps().standardDerivatives) {
  606. shaderName = "legacypbr";
  607. }
  608. var join = this._defines.toString();
  609. this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vAmbientColor", "vAlbedoColor", "vReflectivityColor", "vEmissiveColor", "vReflectionColor",
  610. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  611. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  612. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  613. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  614. "vFogInfos", "vFogColor", "pointSize",
  615. "vAlbedoInfos", "vAmbientInfos", "vOpacityInfos", "vReflectionInfos", "vEmissiveInfos", "vReflectivityInfos", "vBumpInfos", "vLightmapInfos", "vRefractionInfos",
  616. "mBones",
  617. "vClipPlane", "albedoMatrix", "ambientMatrix", "opacityMatrix", "reflectionMatrix", "emissiveMatrix", "reflectivityMatrix", "bumpMatrix", "lightmapMatrix", "refractionMatrix",
  618. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3", "depthValues",
  619. "opacityParts", "emissiveLeftColor", "emissiveRightColor",
  620. "vLightingIntensity", "vOverloadedShadowIntensity", "vOverloadedIntensity", "vCameraInfos", "vOverloadedAlbedo", "vOverloadedReflection", "vOverloadedReflectivity", "vOverloadedEmissive", "vOverloadedMicroSurface",
  621. "logarithmicDepthConstant",
  622. "vSphericalX", "vSphericalY", "vSphericalZ",
  623. "vSphericalXX", "vSphericalYY", "vSphericalZZ",
  624. "vSphericalXY", "vSphericalYZ", "vSphericalZX",
  625. "vMicrosurfaceTextureLods", "vLightRadiuses"
  626. ], ["albedoSampler", "ambientSampler", "opacitySampler", "reflectionCubeSampler", "reflection2DSampler", "emissiveSampler", "reflectivitySampler", "bumpSampler", "lightmapSampler", "refractionCubeSampler", "refraction2DSampler",
  627. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3"
  628. ], join, fallbacks, this.onCompiled, this.onError);
  629. }
  630. if (!this._effect.isReady()) {
  631. return false;
  632. }
  633. this._renderId = scene.getRenderId();
  634. this._wasPreviouslyReady = true;
  635. if (mesh) {
  636. if (!mesh._materialDefines) {
  637. mesh._materialDefines = new PBRMaterialDefines();
  638. }
  639. this._defines.cloneTo(mesh._materialDefines);
  640. }
  641. return true;
  642. };
  643. PBRMaterial.prototype.unbind = function () {
  644. if (this.reflectionTexture && this.reflectionTexture.isRenderTarget) {
  645. this._effect.setTexture("reflection2DSampler", null);
  646. }
  647. if (this.refractionTexture && this.refractionTexture.isRenderTarget) {
  648. this._effect.setTexture("refraction2DSampler", null);
  649. }
  650. _super.prototype.unbind.call(this);
  651. };
  652. PBRMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  653. this._effect.setMatrix("world", world);
  654. };
  655. PBRMaterial.prototype.bind = function (world, mesh) {
  656. this._myScene = this.getScene();
  657. // Matrices
  658. this.bindOnlyWorldMatrix(world);
  659. // Bones
  660. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._effect);
  661. if (this._myScene.getCachedMaterial() !== this) {
  662. this._effect.setMatrix("viewProjection", this._myScene.getTransformMatrix());
  663. if (BABYLON.StandardMaterial.FresnelEnabled) {
  664. if (this.opacityFresnelParameters && this.opacityFresnelParameters.isEnabled) {
  665. this._effect.setColor4("opacityParts", new BABYLON.Color3(this.opacityFresnelParameters.leftColor.toLuminance(), this.opacityFresnelParameters.rightColor.toLuminance(), this.opacityFresnelParameters.bias), this.opacityFresnelParameters.power);
  666. }
  667. if (this.emissiveFresnelParameters && this.emissiveFresnelParameters.isEnabled) {
  668. this._effect.setColor4("emissiveLeftColor", this.emissiveFresnelParameters.leftColor, this.emissiveFresnelParameters.power);
  669. this._effect.setColor4("emissiveRightColor", this.emissiveFresnelParameters.rightColor, this.emissiveFresnelParameters.bias);
  670. }
  671. }
  672. // Textures
  673. if (this._myScene.texturesEnabled) {
  674. if (this.albedoTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  675. this._effect.setTexture("albedoSampler", this.albedoTexture);
  676. this._effect.setFloat2("vAlbedoInfos", this.albedoTexture.coordinatesIndex, this.albedoTexture.level);
  677. this._effect.setMatrix("albedoMatrix", this.albedoTexture.getTextureMatrix());
  678. }
  679. if (this.ambientTexture && BABYLON.StandardMaterial.AmbientTextureEnabled) {
  680. this._effect.setTexture("ambientSampler", this.ambientTexture);
  681. this._effect.setFloat2("vAmbientInfos", this.ambientTexture.coordinatesIndex, this.ambientTexture.level);
  682. this._effect.setMatrix("ambientMatrix", this.ambientTexture.getTextureMatrix());
  683. }
  684. if (this.opacityTexture && BABYLON.StandardMaterial.OpacityTextureEnabled) {
  685. this._effect.setTexture("opacitySampler", this.opacityTexture);
  686. this._effect.setFloat2("vOpacityInfos", this.opacityTexture.coordinatesIndex, this.opacityTexture.level);
  687. this._effect.setMatrix("opacityMatrix", this.opacityTexture.getTextureMatrix());
  688. }
  689. if (this.reflectionTexture && BABYLON.StandardMaterial.ReflectionTextureEnabled) {
  690. this._microsurfaceTextureLods.x = Math.round(Math.log(this.reflectionTexture.getSize().width) * Math.LOG2E);
  691. if (this.reflectionTexture.isCube) {
  692. this._effect.setTexture("reflectionCubeSampler", this.reflectionTexture);
  693. }
  694. else {
  695. this._effect.setTexture("reflection2DSampler", this.reflectionTexture);
  696. }
  697. this._effect.setMatrix("reflectionMatrix", this.reflectionTexture.getReflectionTextureMatrix());
  698. this._effect.setFloat2("vReflectionInfos", this.reflectionTexture.level, 0);
  699. if (this._defines.USESPHERICALFROMREFLECTIONMAP) {
  700. this._effect.setFloat3("vSphericalX", this.reflectionTexture.sphericalPolynomial.x.x, this.reflectionTexture.sphericalPolynomial.x.y, this.reflectionTexture.sphericalPolynomial.x.z);
  701. this._effect.setFloat3("vSphericalY", this.reflectionTexture.sphericalPolynomial.y.x, this.reflectionTexture.sphericalPolynomial.y.y, this.reflectionTexture.sphericalPolynomial.y.z);
  702. this._effect.setFloat3("vSphericalZ", this.reflectionTexture.sphericalPolynomial.z.x, this.reflectionTexture.sphericalPolynomial.z.y, this.reflectionTexture.sphericalPolynomial.z.z);
  703. this._effect.setFloat3("vSphericalXX", this.reflectionTexture.sphericalPolynomial.xx.x, this.reflectionTexture.sphericalPolynomial.xx.y, this.reflectionTexture.sphericalPolynomial.xx.z);
  704. this._effect.setFloat3("vSphericalYY", this.reflectionTexture.sphericalPolynomial.yy.x, this.reflectionTexture.sphericalPolynomial.yy.y, this.reflectionTexture.sphericalPolynomial.yy.z);
  705. this._effect.setFloat3("vSphericalZZ", this.reflectionTexture.sphericalPolynomial.zz.x, this.reflectionTexture.sphericalPolynomial.zz.y, this.reflectionTexture.sphericalPolynomial.zz.z);
  706. this._effect.setFloat3("vSphericalXY", this.reflectionTexture.sphericalPolynomial.xy.x, this.reflectionTexture.sphericalPolynomial.xy.y, this.reflectionTexture.sphericalPolynomial.xy.z);
  707. this._effect.setFloat3("vSphericalYZ", this.reflectionTexture.sphericalPolynomial.yz.x, this.reflectionTexture.sphericalPolynomial.yz.y, this.reflectionTexture.sphericalPolynomial.yz.z);
  708. this._effect.setFloat3("vSphericalZX", this.reflectionTexture.sphericalPolynomial.zx.x, this.reflectionTexture.sphericalPolynomial.zx.y, this.reflectionTexture.sphericalPolynomial.zx.z);
  709. }
  710. }
  711. if (this.emissiveTexture && BABYLON.StandardMaterial.EmissiveTextureEnabled) {
  712. this._effect.setTexture("emissiveSampler", this.emissiveTexture);
  713. this._effect.setFloat2("vEmissiveInfos", this.emissiveTexture.coordinatesIndex, this.emissiveTexture.level);
  714. this._effect.setMatrix("emissiveMatrix", this.emissiveTexture.getTextureMatrix());
  715. }
  716. if (this.lightmapTexture && BABYLON.StandardMaterial.LightmapTextureEnabled) {
  717. this._effect.setTexture("lightmapSampler", this.lightmapTexture);
  718. this._effect.setFloat2("vLightmapInfos", this.lightmapTexture.coordinatesIndex, this.lightmapTexture.level);
  719. this._effect.setMatrix("lightmapMatrix", this.lightmapTexture.getTextureMatrix());
  720. }
  721. if (this.reflectivityTexture && BABYLON.StandardMaterial.SpecularTextureEnabled) {
  722. this._effect.setTexture("reflectivitySampler", this.reflectivityTexture);
  723. this._effect.setFloat2("vReflectivityInfos", this.reflectivityTexture.coordinatesIndex, this.reflectivityTexture.level);
  724. this._effect.setMatrix("reflectivityMatrix", this.reflectivityTexture.getTextureMatrix());
  725. }
  726. if (this.bumpTexture && this._myScene.getEngine().getCaps().standardDerivatives && BABYLON.StandardMaterial.BumpTextureEnabled && !this.disableBumpMap) {
  727. this._effect.setTexture("bumpSampler", this.bumpTexture);
  728. this._effect.setFloat3("vBumpInfos", this.bumpTexture.coordinatesIndex, 1.0 / this.bumpTexture.level, this.parallaxScaleBias);
  729. this._effect.setMatrix("bumpMatrix", this.bumpTexture.getTextureMatrix());
  730. }
  731. if (this.refractionTexture && BABYLON.StandardMaterial.RefractionTextureEnabled) {
  732. this._microsurfaceTextureLods.y = Math.round(Math.log(this.refractionTexture.getSize().width) * Math.LOG2E);
  733. var depth = 1.0;
  734. if (this.refractionTexture.isCube) {
  735. this._effect.setTexture("refractionCubeSampler", this.refractionTexture);
  736. }
  737. else {
  738. this._effect.setTexture("refraction2DSampler", this.refractionTexture);
  739. this._effect.setMatrix("refractionMatrix", this.refractionTexture.getReflectionTextureMatrix());
  740. if (this.refractionTexture.depth) {
  741. depth = this.refractionTexture.depth;
  742. }
  743. }
  744. this._effect.setFloat4("vRefractionInfos", this.refractionTexture.level, this.indexOfRefraction, depth, this.invertRefractionY ? -1 : 1);
  745. }
  746. if ((this.reflectionTexture || this.refractionTexture)) {
  747. this._effect.setFloat2("vMicrosurfaceTextureLods", this._microsurfaceTextureLods.x, this._microsurfaceTextureLods.y);
  748. }
  749. }
  750. // Clip plane
  751. BABYLON.MaterialHelper.BindClipPlane(this._effect, this._myScene);
  752. // Point size
  753. if (this.pointsCloud) {
  754. this._effect.setFloat("pointSize", this.pointSize);
  755. }
  756. // Colors
  757. this._myScene.ambientColor.multiplyToRef(this.ambientColor, this._globalAmbientColor);
  758. // GAMMA CORRECTION.
  759. this.convertColorToLinearSpaceToRef(this.reflectivityColor, PBRMaterial._scaledReflectivity);
  760. this._effect.setVector3("vEyePosition", this._myScene._mirroredCameraPosition ? this._myScene._mirroredCameraPosition : this._myScene.activeCamera.position);
  761. this._effect.setColor3("vAmbientColor", this._globalAmbientColor);
  762. this._effect.setColor4("vReflectivityColor", PBRMaterial._scaledReflectivity, this.microSurface);
  763. // GAMMA CORRECTION.
  764. this.convertColorToLinearSpaceToRef(this.emissiveColor, PBRMaterial._scaledEmissive);
  765. this._effect.setColor3("vEmissiveColor", PBRMaterial._scaledEmissive);
  766. // GAMMA CORRECTION.
  767. this.convertColorToLinearSpaceToRef(this.reflectionColor, PBRMaterial._scaledReflection);
  768. this._effect.setColor3("vReflectionColor", PBRMaterial._scaledReflection);
  769. }
  770. if (this._myScene.getCachedMaterial() !== this || !this.isFrozen) {
  771. // GAMMA CORRECTION.
  772. this.convertColorToLinearSpaceToRef(this.albedoColor, PBRMaterial._scaledAlbedo);
  773. this._effect.setColor4("vAlbedoColor", PBRMaterial._scaledAlbedo, this.alpha * mesh.visibility);
  774. // Lights
  775. if (this._myScene.lightsEnabled && !this.disableLighting) {
  776. PBRMaterial.BindLights(this._myScene, mesh, this._effect, this._defines, this.useScalarInLinearSpace);
  777. }
  778. // View
  779. if (this._myScene.fogEnabled && mesh.applyFog && this._myScene.fogMode !== BABYLON.Scene.FOGMODE_NONE || this.reflectionTexture) {
  780. this._effect.setMatrix("view", this._myScene.getViewMatrix());
  781. }
  782. // Fog
  783. BABYLON.MaterialHelper.BindFogParameters(this._myScene, mesh, this._effect);
  784. this._lightingInfos.x = this.directIntensity;
  785. this._lightingInfos.y = this.emissiveIntensity;
  786. this._lightingInfos.z = this.environmentIntensity;
  787. this._lightingInfos.w = this.specularIntensity;
  788. this._effect.setVector4("vLightingIntensity", this._lightingInfos);
  789. this._overloadedShadowInfos.x = this.overloadedShadowIntensity;
  790. this._overloadedShadowInfos.y = this.overloadedShadeIntensity;
  791. this._effect.setVector4("vOverloadedShadowIntensity", this._overloadedShadowInfos);
  792. this._cameraInfos.x = this.cameraExposure;
  793. this._cameraInfos.y = this.cameraContrast;
  794. this._effect.setVector4("vCameraInfos", this._cameraInfos);
  795. this._overloadedIntensity.x = this.overloadedAmbientIntensity;
  796. this._overloadedIntensity.y = this.overloadedAlbedoIntensity;
  797. this._overloadedIntensity.z = this.overloadedReflectivityIntensity;
  798. this._overloadedIntensity.w = this.overloadedEmissiveIntensity;
  799. this._effect.setVector4("vOverloadedIntensity", this._overloadedIntensity);
  800. this.convertColorToLinearSpaceToRef(this.overloadedAmbient, this._tempColor);
  801. this._effect.setColor3("vOverloadedAmbient", this._tempColor);
  802. this.convertColorToLinearSpaceToRef(this.overloadedAlbedo, this._tempColor);
  803. this._effect.setColor3("vOverloadedAlbedo", this._tempColor);
  804. this.convertColorToLinearSpaceToRef(this.overloadedReflectivity, this._tempColor);
  805. this._effect.setColor3("vOverloadedReflectivity", this._tempColor);
  806. this.convertColorToLinearSpaceToRef(this.overloadedEmissive, this._tempColor);
  807. this._effect.setColor3("vOverloadedEmissive", this._tempColor);
  808. this.convertColorToLinearSpaceToRef(this.overloadedReflection, this._tempColor);
  809. this._effect.setColor3("vOverloadedReflection", this._tempColor);
  810. this._overloadedMicroSurface.x = this.overloadedMicroSurface;
  811. this._overloadedMicroSurface.y = this.overloadedMicroSurfaceIntensity;
  812. this._overloadedMicroSurface.z = this.overloadedReflectionIntensity;
  813. this._effect.setVector3("vOverloadedMicroSurface", this._overloadedMicroSurface);
  814. // Log. depth
  815. BABYLON.MaterialHelper.BindLogDepth(this._defines, this._effect, this._myScene);
  816. }
  817. _super.prototype.bind.call(this, world, mesh);
  818. this._myScene = null;
  819. };
  820. PBRMaterial.prototype.getAnimatables = function () {
  821. var results = [];
  822. if (this.albedoTexture && this.albedoTexture.animations && this.albedoTexture.animations.length > 0) {
  823. results.push(this.albedoTexture);
  824. }
  825. if (this.ambientTexture && this.ambientTexture.animations && this.ambientTexture.animations.length > 0) {
  826. results.push(this.ambientTexture);
  827. }
  828. if (this.opacityTexture && this.opacityTexture.animations && this.opacityTexture.animations.length > 0) {
  829. results.push(this.opacityTexture);
  830. }
  831. if (this.reflectionTexture && this.reflectionTexture.animations && this.reflectionTexture.animations.length > 0) {
  832. results.push(this.reflectionTexture);
  833. }
  834. if (this.emissiveTexture && this.emissiveTexture.animations && this.emissiveTexture.animations.length > 0) {
  835. results.push(this.emissiveTexture);
  836. }
  837. if (this.reflectivityTexture && this.reflectivityTexture.animations && this.reflectivityTexture.animations.length > 0) {
  838. results.push(this.reflectivityTexture);
  839. }
  840. if (this.bumpTexture && this.bumpTexture.animations && this.bumpTexture.animations.length > 0) {
  841. results.push(this.bumpTexture);
  842. }
  843. if (this.lightmapTexture && this.lightmapTexture.animations && this.lightmapTexture.animations.length > 0) {
  844. results.push(this.lightmapTexture);
  845. }
  846. if (this.refractionTexture && this.refractionTexture.animations && this.refractionTexture.animations.length > 0) {
  847. results.push(this.refractionTexture);
  848. }
  849. return results;
  850. };
  851. PBRMaterial.prototype.dispose = function (forceDisposeEffect) {
  852. if (this.albedoTexture) {
  853. this.albedoTexture.dispose();
  854. }
  855. if (this.ambientTexture) {
  856. this.ambientTexture.dispose();
  857. }
  858. if (this.opacityTexture) {
  859. this.opacityTexture.dispose();
  860. }
  861. if (this.reflectionTexture) {
  862. this.reflectionTexture.dispose();
  863. }
  864. if (this.emissiveTexture) {
  865. this.emissiveTexture.dispose();
  866. }
  867. if (this.reflectivityTexture) {
  868. this.reflectivityTexture.dispose();
  869. }
  870. if (this.bumpTexture) {
  871. this.bumpTexture.dispose();
  872. }
  873. if (this.lightmapTexture) {
  874. this.lightmapTexture.dispose();
  875. }
  876. if (this.refractionTexture) {
  877. this.refractionTexture.dispose();
  878. }
  879. _super.prototype.dispose.call(this, forceDisposeEffect);
  880. };
  881. PBRMaterial.prototype.clone = function (name) {
  882. var _this = this;
  883. return BABYLON.SerializationHelper.Clone(function () { return new PBRMaterial(name, _this.getScene()); }, this);
  884. };
  885. PBRMaterial.prototype.serialize = function () {
  886. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  887. serializationObject.customType = "BABYLON.PBRMaterial";
  888. return serializationObject;
  889. };
  890. // Statics
  891. PBRMaterial.Parse = function (source, scene, rootUrl) {
  892. return BABYLON.SerializationHelper.Parse(function () { return new PBRMaterial(source.name, scene); }, source, scene, rootUrl);
  893. };
  894. PBRMaterial._scaledAlbedo = new BABYLON.Color3();
  895. PBRMaterial._scaledReflectivity = new BABYLON.Color3();
  896. PBRMaterial._scaledEmissive = new BABYLON.Color3();
  897. PBRMaterial._scaledReflection = new BABYLON.Color3();
  898. PBRMaterial._lightRadiuses = [1, 1, 1, 1];
  899. __decorate([
  900. BABYLON.serialize()
  901. ], PBRMaterial.prototype, "directIntensity");
  902. __decorate([
  903. BABYLON.serialize()
  904. ], PBRMaterial.prototype, "emissiveIntensity");
  905. __decorate([
  906. BABYLON.serialize()
  907. ], PBRMaterial.prototype, "environmentIntensity");
  908. __decorate([
  909. BABYLON.serialize()
  910. ], PBRMaterial.prototype, "specularIntensity");
  911. __decorate([
  912. BABYLON.serialize()
  913. ], PBRMaterial.prototype, "overloadedShadowIntensity");
  914. __decorate([
  915. BABYLON.serialize()
  916. ], PBRMaterial.prototype, "overloadedShadeIntensity");
  917. __decorate([
  918. BABYLON.serialize()
  919. ], PBRMaterial.prototype, "cameraExposure");
  920. __decorate([
  921. BABYLON.serialize()
  922. ], PBRMaterial.prototype, "cameraContrast");
  923. __decorate([
  924. BABYLON.serialize()
  925. ], PBRMaterial.prototype, "overloadedAmbientIntensity");
  926. __decorate([
  927. BABYLON.serialize()
  928. ], PBRMaterial.prototype, "overloadedAlbedoIntensity");
  929. __decorate([
  930. BABYLON.serialize()
  931. ], PBRMaterial.prototype, "overloadedReflectivityIntensity");
  932. __decorate([
  933. BABYLON.serialize()
  934. ], PBRMaterial.prototype, "overloadedEmissiveIntensity");
  935. __decorate([
  936. BABYLON.serializeAsColor3()
  937. ], PBRMaterial.prototype, "overloadedAmbient");
  938. __decorate([
  939. BABYLON.serializeAsColor3()
  940. ], PBRMaterial.prototype, "overloadedAlbedo");
  941. __decorate([
  942. BABYLON.serializeAsColor3()
  943. ], PBRMaterial.prototype, "overloadedReflectivity");
  944. __decorate([
  945. BABYLON.serializeAsColor3()
  946. ], PBRMaterial.prototype, "overloadedEmissive");
  947. __decorate([
  948. BABYLON.serializeAsColor3()
  949. ], PBRMaterial.prototype, "overloadedReflection");
  950. __decorate([
  951. BABYLON.serialize()
  952. ], PBRMaterial.prototype, "overloadedMicroSurface");
  953. __decorate([
  954. BABYLON.serialize()
  955. ], PBRMaterial.prototype, "overloadedMicroSurfaceIntensity");
  956. __decorate([
  957. BABYLON.serialize()
  958. ], PBRMaterial.prototype, "overloadedReflectionIntensity");
  959. __decorate([
  960. BABYLON.serialize()
  961. ], PBRMaterial.prototype, "disableBumpMap");
  962. __decorate([
  963. BABYLON.serializeAsTexture()
  964. ], PBRMaterial.prototype, "albedoTexture");
  965. __decorate([
  966. BABYLON.serializeAsTexture()
  967. ], PBRMaterial.prototype, "ambientTexture");
  968. __decorate([
  969. BABYLON.serializeAsTexture()
  970. ], PBRMaterial.prototype, "opacityTexture");
  971. __decorate([
  972. BABYLON.serializeAsTexture()
  973. ], PBRMaterial.prototype, "reflectionTexture");
  974. __decorate([
  975. BABYLON.serializeAsTexture()
  976. ], PBRMaterial.prototype, "emissiveTexture");
  977. __decorate([
  978. BABYLON.serializeAsTexture()
  979. ], PBRMaterial.prototype, "reflectivityTexture");
  980. __decorate([
  981. BABYLON.serializeAsTexture()
  982. ], PBRMaterial.prototype, "bumpTexture");
  983. __decorate([
  984. BABYLON.serializeAsTexture()
  985. ], PBRMaterial.prototype, "lightmapTexture");
  986. __decorate([
  987. BABYLON.serializeAsTexture()
  988. ], PBRMaterial.prototype, "refractionTexture");
  989. __decorate([
  990. BABYLON.serializeAsColor3("ambient")
  991. ], PBRMaterial.prototype, "ambientColor");
  992. __decorate([
  993. BABYLON.serializeAsColor3("albedo")
  994. ], PBRMaterial.prototype, "albedoColor");
  995. __decorate([
  996. BABYLON.serializeAsColor3("reflectivity")
  997. ], PBRMaterial.prototype, "reflectivityColor");
  998. __decorate([
  999. BABYLON.serializeAsColor3("reflection")
  1000. ], PBRMaterial.prototype, "reflectionColor");
  1001. __decorate([
  1002. BABYLON.serializeAsColor3("emissivie")
  1003. ], PBRMaterial.prototype, "emissiveColor");
  1004. __decorate([
  1005. BABYLON.serialize()
  1006. ], PBRMaterial.prototype, "microSurface");
  1007. __decorate([
  1008. BABYLON.serialize()
  1009. ], PBRMaterial.prototype, "indexOfRefraction");
  1010. __decorate([
  1011. BABYLON.serialize()
  1012. ], PBRMaterial.prototype, "invertRefractionY");
  1013. __decorate([
  1014. BABYLON.serializeAsFresnelParameters()
  1015. ], PBRMaterial.prototype, "opacityFresnelParameters");
  1016. __decorate([
  1017. BABYLON.serializeAsFresnelParameters()
  1018. ], PBRMaterial.prototype, "emissiveFresnelParameters");
  1019. __decorate([
  1020. BABYLON.serialize()
  1021. ], PBRMaterial.prototype, "linkRefractionWithTransparency");
  1022. __decorate([
  1023. BABYLON.serialize()
  1024. ], PBRMaterial.prototype, "linkEmissiveWithAlbedo");
  1025. __decorate([
  1026. BABYLON.serialize()
  1027. ], PBRMaterial.prototype, "useLightmapAsShadowmap");
  1028. __decorate([
  1029. BABYLON.serialize()
  1030. ], PBRMaterial.prototype, "useEmissiveAsIllumination");
  1031. __decorate([
  1032. BABYLON.serialize()
  1033. ], PBRMaterial.prototype, "useAlphaFromAlbedoTexture");
  1034. __decorate([
  1035. BABYLON.serialize()
  1036. ], PBRMaterial.prototype, "useSpecularOverAlpha");
  1037. __decorate([
  1038. BABYLON.serialize()
  1039. ], PBRMaterial.prototype, "useMicroSurfaceFromReflectivityMapAlpha");
  1040. __decorate([
  1041. BABYLON.serialize()
  1042. ], PBRMaterial.prototype, "useAutoMicroSurfaceFromReflectivityMap");
  1043. __decorate([
  1044. BABYLON.serialize()
  1045. ], PBRMaterial.prototype, "useScalarInLinearSpace");
  1046. __decorate([
  1047. BABYLON.serialize()
  1048. ], PBRMaterial.prototype, "usePhysicalLightFalloff");
  1049. __decorate([
  1050. BABYLON.serialize()
  1051. ], PBRMaterial.prototype, "useRadianceOverAlpha");
  1052. __decorate([
  1053. BABYLON.serialize()
  1054. ], PBRMaterial.prototype, "useParallax");
  1055. __decorate([
  1056. BABYLON.serialize()
  1057. ], PBRMaterial.prototype, "useParallaxOcclusion");
  1058. __decorate([
  1059. BABYLON.serialize()
  1060. ], PBRMaterial.prototype, "parallaxScaleBias");
  1061. __decorate([
  1062. BABYLON.serialize()
  1063. ], PBRMaterial.prototype, "disableLighting");
  1064. Object.defineProperty(PBRMaterial.prototype, "useLogarithmicDepth",
  1065. __decorate([
  1066. BABYLON.serialize()
  1067. ], PBRMaterial.prototype, "useLogarithmicDepth", Object.getOwnPropertyDescriptor(PBRMaterial.prototype, "useLogarithmicDepth")));
  1068. return PBRMaterial;
  1069. })(BABYLON.Material);
  1070. BABYLON.PBRMaterial = PBRMaterial;
  1071. })(BABYLON || (BABYLON = {}));
  1072. BABYLON.Effect.ShadersStore['pbrVertexShader'] = "precision highp float;\n\nattribute vec3 position;\n#ifdef NORMAL\nattribute vec3 normal;\n#endif\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\n#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform mat4 lightmapMatrix;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n#ifdef BUMP\nvarying vec2 vBumpUV;\nuniform vec2 vBumpInfos;\nuniform mat4 bumpMatrix;\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<shadowsVertexDeclaration>\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#include<logDepthDeclaration>\nvoid main(void) {\n#ifdef REFLECTIONMAP_SKYBOX\nvPositionUVW=position;\n#endif \n#include<instancesVertex>\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\n#ifdef NORMAL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvDirectionW=normalize(vec3(finalWorld*vec4(position,0.0)));\n#endif\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef ALBEDO\nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef LIGHTMAP\nif (vLightmapInfos.x == 0.)\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvLightmapUV=vec2(lightmapMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY)\nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef BUMP\nif (vBumpInfos.x == 0.)\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvBumpUV=vec2(bumpMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n\n#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n\n#include<logDepthVertex>\n}";
  1073. BABYLON.Effect.ShadersStore['pbrPixelShader'] = "#ifdef BUMP\n#extension GL_OES_standard_derivatives : enable\n#endif\n#ifdef LODBASEDMICROSFURACE\n#extension GL_EXT_shader_texture_lod : enable\n#endif\n#ifdef LOGARITHMICDEPTH\n#extension GL_EXT_frag_depth : enable\n#endif\nprecision highp float;\n\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec3 vReflectionColor;\nuniform vec4 vAlbedoColor;\nuniform vec4 vLightRadiuses;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vCameraInfos;\n#ifdef OVERLOADEDVALUES\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nuniform vec4 vOverloadedShadowIntensity;\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\nuniform vec3 vSphericalX;\nuniform vec3 vSphericalY;\nuniform vec3 vSphericalZ;\nuniform vec3 vSphericalXX;\nuniform vec3 vSphericalYY;\nuniform vec3 vSphericalZZ;\nuniform vec3 vSphericalXY;\nuniform vec3 vSphericalYZ;\nuniform vec3 vSphericalZX;\nvec3 EnvironmentIrradiance(vec3 normal)\n{\n\n\n\nvec3 result =\nvSphericalX*normal.x +\nvSphericalY*normal.y +\nvSphericalZ*normal.z +\nvSphericalXX*normal.x*normal.x +\nvSphericalYY*normal.y*normal.y +\nvSphericalZZ*normal.z*normal.z +\nvSphericalYZ*normal.y*normal.z +\nvSphericalZX*normal.z*normal.x +\nvSphericalXY*normal.x*normal.y;\nreturn result.rgb;\n}\n#endif\n#if defined(REFLECTION) || defined(REFRACTION)\nuniform vec2 vMicrosurfaceTextureLods;\n#endif\n\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\n\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=Square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat getMipMapIndexFromAverageSlope(float maxMipLevel,float alpha)\n{\n\n\n\n\n\n\n\nfloat mip=kRougnhessToAlphaOffset+maxMipLevel+(maxMipLevel*kRougnhessToAlphaScale*log2(alpha));\nreturn clamp(mip,0.,maxMipLevel);\n}\nfloat getMipMapIndexFromAverageSlopeWithPMREM(float maxMipLevel,float alphaG)\n{\nfloat specularPower=clamp(2./alphaG-2.,0.000001,2048.);\n\nreturn clamp(- 0.5*log2(specularPower)+5.5,0.,maxMipLevel);\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=Square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(kPi*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 FresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 specularColor)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nvec3 fresnel=fresnelSchlickGGX(VdotH,specularColor,vec3(1.,1.,1.));\nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nreturn fresnel*specTerm*kPi; \n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat diffuseFresnelTerm =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn diffuseFresnelTerm*NdotL;\n\n\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nfloat kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn vec3(pow(color.r,2.2),pow(color.g,2.2),pow(color.b,2.2));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn vec3(pow(color.r,1.0/2.2),pow(color.g,1.0/2.2),pow(color.b,1.0/2.2));\n}\nfloat computeLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\nreturn lightDistanceFalloff;\n#else\nfloat lightFalloff=max(0.,1.0-length(lightOffset)/range);\nreturn lightFalloff;\n#endif\n}\n#ifdef CAMERATONEMAP\nvec3 toneMaps(vec3 color)\n{\ncolor=max(color,0.0);\n\ncolor.rgb=color.rgb*vCameraInfos.x;\nfloat tuning=1.5; \n\n\nvec3 tonemapped=1.0-exp2(-color.rgb*tuning); \ncolor.rgb=mix(color.rgb,tonemapped,1.0);\nreturn color;\n}\n#endif\n#ifdef CAMERACONTRAST\nvec4 contrasts(vec4 color)\n{\ncolor=clamp(color,0.0,1.0);\nvec3 resultHighContrast=color.rgb*color.rgb*(3.0-2.0*color.rgb);\nfloat contrast=vCameraInfos.y;\nif (contrast<1.0)\n{\n\ncolor.rgb=mix(vec3(0.5,0.5,0.5),color.rgb,contrast);\n}\nelse\n{\n\ncolor.rgb=mix(color.rgb,resultHighContrast,contrast-1.0);\n}\nreturn color;\n}\n#endif\n\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform sampler2D reflectivitySampler;\n#endif\n\n#include<fresnelFunction>\n#ifdef OPACITYFRESNEL\nuniform vec4 opacityParts;\n#endif\n#ifdef EMISSIVEFRESNEL\nuniform vec4 emissiveLeftColor;\nuniform vec4 emissiveRightColor;\n#endif\n\n#if defined(REFLECTIONMAP_SPHERICAL) || defined(REFLECTIONMAP_PROJECTION) || defined(REFRACTION)\nuniform mat4 view;\n#endif\n\n#ifdef REFRACTION\nuniform vec4 vRefractionInfos;\n#ifdef REFRACTIONMAP_3D\nuniform samplerCube refractionCubeSampler;\n#else\nuniform sampler2D refraction2DSampler;\nuniform mat4 refractionMatrix;\n#endif\n#endif\n\n#ifdef REFLECTION\nuniform vec2 vReflectionInfos;\n#ifdef REFLECTIONMAP_3D\nuniform samplerCube reflectionCubeSampler;\n#else\nuniform sampler2D reflection2DSampler;\n#endif\n#ifdef REFLECTIONMAP_SKYBOX\nvarying vec3 vPositionUVW;\n#else\n#ifdef REFLECTIONMAP_EQUIRECTANGULAR_FIXED\nvarying vec3 vDirectionW;\n#endif\n#if defined(REFLECTIONMAP_PLANAR) || defined(REFLECTIONMAP_CUBIC) || defined(REFLECTIONMAP_PROJECTION)\nuniform mat4 reflectionMatrix;\n#endif\n#endif\n#include<reflectionFunction>\n#endif\n\n#ifdef SHADOWS\nfloat unpack(vec4 color)\n{\nconst vec4 bit_shift=vec4(1.0/(255.0*255.0*255.0),1.0/(255.0*255.0),1.0/255.0,1.0);\nreturn dot(color,bit_shift);\n}\n#if defined(POINTLIGHT0) || defined(POINTLIGHT1) || defined(POINTLIGHT2) || defined(POINTLIGHT3)\nuniform vec2 depthValues;\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float bias)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y =-directionToLight.y;\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight))+bias;\nif (depth>shadow)\n{\n#ifdef OVERLOADEDSHADOWVALUES\nreturn mix(1.0,darkness,vOverloadedShadowIntensity.x);\n#else\nreturn darkness;\n#endif\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=(depth-depthValues.x)/(depthValues.y-depthValues.x);\ndepth=clamp(depth,0.,1.0);\ndirectionToLight=normalize(directionToLight);\ndirectionToLight.y=-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-1.0,1.0,-1.0);\npoissonDisk[1]=vec3(1.0,-1.0,-1.0);\npoissonDisk[2]=vec3(-1.0,-1.0,-1.0);\npoissonDisk[3]=vec3(1.0,-1.0,1.0);\n\nfloat biasedDepth=depth-bias;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,visibility+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,visibility+darkness);\n#endif\n}\n#endif\n#if defined(SPOTLIGHT0) || defined(SPOTLIGHT1) || defined(SPOTLIGHT2) || defined(SPOTLIGHT3) || defined(DIRLIGHT0) || defined(DIRLIGHT1) || defined(DIRLIGHT2) || defined(DIRLIGHT3)\nfloat computeShadow(vec4 vPositionFromLight,sampler2D shadowSampler,float darkness,float bias)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat shadow=unpack(texture2D(shadowSampler,uv))+bias;\nif (depth.z>shadow)\n{\n#ifdef OVERLOADEDSHADOWVALUES\nreturn mix(1.0,darkness,vOverloadedShadowIntensity.x);\n#else\nreturn darkness;\n#endif\n}\nreturn 1.;\n}\nfloat computeShadowWithPCF(vec4 vPositionFromLight,sampler2D shadowSampler,float mapSize,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0)\n{\nreturn 1.0;\n}\nfloat visibility=1.;\nvec2 poissonDisk[4];\npoissonDisk[0]=vec2(-0.94201624,-0.39906216);\npoissonDisk[1]=vec2(0.94558609,-0.76890725);\npoissonDisk[2]=vec2(-0.094184101,-0.92938870);\npoissonDisk[3]=vec2(0.34495938,0.29387760);\n\nfloat biasedDepth=depth.z-bias;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[0]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[1]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[2]*mapSize))<biasedDepth) visibility-=0.25;\nif (unpack(texture2D(shadowSampler,uv+poissonDisk[3]*mapSize))<biasedDepth) visibility-=0.25;\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,visibility+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,visibility+darkness);\n#endif\n}\n\nfloat unpackHalf(vec2 color)\n{\nreturn color.x+(color.y/255.0);\n}\nfloat linstep(float low,float high,float v) {\nreturn clamp((v-low)/(high-low),0.0,1.0);\n}\nfloat ChebychevInequality(vec2 moments,float compare,float bias)\n{\nfloat p=smoothstep(compare-bias,compare,moments.x);\nfloat variance=max(moments.y-moments.x*moments.x,0.02);\nfloat d=compare-moments.x;\nfloat p_max=linstep(0.2,1.0,variance/(variance+d*d));\nreturn clamp(max(p,p_max),0.0,1.0);\n}\nfloat computeShadowWithVSM(vec4 vPositionFromLight,sampler2D shadowSampler,float bias,float darkness)\n{\nvec3 depth=vPositionFromLight.xyz/vPositionFromLight.w;\ndepth=0.5*depth+vec3(0.5);\nvec2 uv=depth.xy;\nif (uv.x<0. || uv.x>1.0 || uv.y<0. || uv.y>1.0 || depth.z>=1.0)\n{\nreturn 1.0;\n}\nvec4 texel=texture2D(shadowSampler,uv);\nvec2 moments=vec2(unpackHalf(texel.xy),unpackHalf(texel.zw));\n#ifdef OVERLOADEDSHADOWVALUES\nreturn min(1.0,mix(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness,vOverloadedShadowIntensity.x));\n#else\nreturn min(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness);\n#endif\n}\n#endif\n#endif\n#include<bumpFragmentFunctions>\n#include<clipPlaneFragmentDeclaration>\n#include<logDepthDeclaration>\n\n#include<fogFragmentDeclaration>\n\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightDirection;\nfloat attenuation=1.0;\nfloat lightDistance;\n\nif (lightData.w == 0.)\n{\nvec3 lightOffset=lightData.xyz-vPositionW;\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nattenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=max(0.00000000001,dot(vNormal,lightDirection));\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(lightOffset);\n\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection.xyz,lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\n\nattenuation*=cosAngle;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW-lightDirection.xyz);\nNdotL=max(0.00000000001,dot(vNormal,-lightDirection.xyz));\nfloat VdotH=clamp(dot(viewDirectionW,H),0.00000000001,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nNdotL=max(0.00000000001,NdotL);\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm;\n#endif\nreturn result;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifndef LINKREFRACTIONTOTRANSPARENCY\n#ifdef ALPHATEST\nif (surfaceAlbedo.a<0.4)\ndiscard;\n#endif\n#endif\n#ifdef ALPHAFROMALBEDO\nalpha*=surfaceAlbedo.a;\n#endif\nsurfaceAlbedo.rgb*=vAlbedoInfos.y;\n#else\n\nsurfaceAlbedo.rgb=surfaceAlbedoContribution;\nsurfaceAlbedoContribution=vec3(1.,1.,1.);\n#endif\n#ifdef VERTEXCOLOR\nsurfaceAlbedo.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#include<bumpFragment>\n\nvec3 ambientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nambientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#ifdef OVERLOADEDVALUES\nambientColor.rgb=mix(ambientColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor.rgb=mix(surfaceReflectivityColor.rgb,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nmicroSurface=mix(microSurface,vOverloadedMicroSurface.x,vOverloadedMicroSurface.y);\n#endif\n\nfloat NdotV=max(0.00000000001,dot(normalW,viewDirectionW));\n\nmicroSurface=clamp(microSurface,0.,1.)*0.98;\n\nfloat roughness=clamp(1.-microSurface,0.000001,1.0);\n\nvec3 lightDiffuseContribution=vec3(0.,0.,0.);\n#ifdef OVERLOADEDSHADOWVALUES\nvec3 shadowedOnlyLightDiffuseContribution=vec3(1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nvec3 lightSpecularContribution= vec3(0.,0.,0.);\n#endif\nfloat notShadowLevel=1.; \nfloat NdotL=-1.;\n#ifdef LIGHT0\n#ifndef SPECULARTERM\nvec3 vLightSpecular0=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT0\nlightingInfo info=computeSpotLighting(viewDirectionW,normalW,vLightData0,vLightDirection0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#ifdef HEMILIGHT0\nlightingInfo info=computeHemisphericLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightGround0,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\nlightingInfo info=computeLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight0,shadowSampler0,shadowsInfo0.z,shadowsInfo0.x);\n#else\n#ifdef SHADOWPCF0\n#if defined(POINTLIGHT0)\nnotShadowLevel=computeShadowWithPCFCube(vLightData0.xyz,shadowSampler0,shadowsInfo0.y,shadowsInfo0.z,shadowsInfo0.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight0,shadowSampler0,shadowsInfo0.y,shadowsInfo0.z,shadowsInfo0.x);\n#endif\n#else\n#if defined(POINTLIGHT0)\nnotShadowLevel=computeShadowCube(vLightData0.xyz,shadowSampler0,shadowsInfo0.x,shadowsInfo0.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight0,shadowSampler0,shadowsInfo0.x,shadowsInfo0.z);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef LIGHT1\n#ifndef SPECULARTERM\nvec3 vLightSpecular1=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT1\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData1,vLightDirection1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#ifdef HEMILIGHT1\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightGround1,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\ninfo=computeLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight1,shadowSampler1,shadowsInfo1.z,shadowsInfo1.x);\n#else\n#ifdef SHADOWPCF1\n#if defined(POINTLIGHT1)\nnotShadowLevel=computeShadowWithPCFCube(vLightData1.xyz,shadowSampler1,shadowsInfo1.y,shadowsInfo1.z,shadowsInfo1.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight1,shadowSampler1,shadowsInfo1.y,shadowsInfo1.z,shadowsInfo1.x);\n#endif\n#else\n#if defined(POINTLIGHT1)\nnotShadowLevel=computeShadowCube(vLightData1.xyz,shadowSampler1,shadowsInfo1.x,shadowsInfo1.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight1,shadowSampler1,shadowsInfo1.x,shadowsInfo1.z);\n#endif\n#endif\n#endif\n#else\nnotShadowLevel=1.;\n#endif\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef LIGHT2\n#ifndef SPECULARTERM\nvec3 vLightSpecular2=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT2\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData2,vLightDirection2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#ifdef HEMILIGHT2\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightGround2,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\ninfo=computeLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight2,shadowSampler2,shadowsInfo2.z,shadowsInfo2.x);\n#else\n#ifdef SHADOWPCF2\n#if defined(POINTLIGHT2)\nnotShadowLevel=computeShadowWithPCFCube(vLightData2.xyz,shadowSampler2,shadowsInfo2.y,shadowsInfo2.z,shadowsInfo2.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight2,shadowSampler2,shadowsInfo2.y,shadowsInfo2.z,shadowsInfo2.x);\n#endif\n#else\n#if defined(POINTLIGHT2)\nnotShadowLevel=computeShadowCube(vLightData2.xyz,shadowSampler2,shadowsInfo2.x,shadowsInfo2.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight2,shadowSampler2,shadowsInfo2.x,shadowsInfo2.z);\n#endif\n#endif \n#endif \n#else\nnotShadowLevel=1.;\n#endif\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef LIGHT3\n#ifndef SPECULARTERM\nvec3 vLightSpecular3=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT3\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData3,vLightDirection3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#ifdef HEMILIGHT3\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightGround3,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\ninfo=computeLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\nnotShadowLevel=computeShadowWithVSM(vPositionFromLight3,shadowSampler3,shadowsInfo3.z,shadowsInfo3.x);\n#else\n#ifdef SHADOWPCF3\n#if defined(POINTLIGHT3)\nnotShadowLevel=computeShadowWithPCFCube(vLightData3.xyz,shadowSampler3,shadowsInfo3.y,shadowsInfo3.z,shadowsInfo3.x);\n#else\nnotShadowLevel=computeShadowWithPCF(vPositionFromLight3,shadowSampler3,shadowsInfo3.y,shadowsInfo3.z,shadowsInfo3.x);\n#endif\n#else\n#if defined(POINTLIGHT3)\nnotShadowLevel=computeShadowCube(vLightData3.xyz,shadowSampler3,shadowsInfo3.x,shadowsInfo3.z);\n#else\nnotShadowLevel=computeShadow(vPositionFromLight3,shadowSampler3,shadowsInfo3.x,shadowsInfo3.z);\n#endif\n#endif \n#endif \n#else\nnotShadowLevel=1.;\n#endif\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n#ifdef OPACITYFRESNEL\nfloat opacityFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,opacityParts.z,opacityParts.w);\nalpha+=opacityParts.x*(1.0-opacityFresnelTerm)+opacityFresnelTerm*opacityParts.y;\n#endif\n\nvec3 surfaceRefractionColor=vec3(0.,0.,0.);\n\n#ifdef LODBASEDMICROSFURACE\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\n#endif\n#ifdef REFRACTION\nvec3 refractionVector=refract(-viewDirectionW,normalW,vRefractionInfos.y);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\nfloat lodRefraction=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.y,alphaG);\n#else\nfloat lodRefraction=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.y,alphaG);\n#endif\n#else\nfloat biasRefraction=(vMicrosurfaceTextureLods.y+2.)*(1.0-microSurface);\n#endif\n#ifdef REFRACTIONMAP_3D\nrefractionVector.y=refractionVector.y*vRefractionInfos.w;\nif (dot(refractionVector,viewDirectionW)<1.0)\n{\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFRACTION\n\nif (microSurface>0.5)\n{\n\nfloat scaleRefraction=1.-exp2(lodRefraction)/exp2(vMicrosurfaceTextureLods.y); \nfloat maxRefraction=max(max(abs(refractionVector.x),abs(refractionVector.y)),abs(refractionVector.z));\nif (abs(refractionVector.x) != maxRefraction) refractionVector.x*=scaleRefraction;\nif (abs(refractionVector.y) != maxRefraction) refractionVector.y*=scaleRefraction;\nif (abs(refractionVector.z) != maxRefraction) refractionVector.z*=scaleRefraction;\n}\n#endif\nsurfaceRefractionColor=textureCubeLodEXT(refractionCubeSampler,refractionVector,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=textureCube(refractionCubeSampler,refractionVector,biasRefraction).rgb*vRefractionInfos.x;\n#endif\n}\n#ifndef REFRACTIONMAPINLINEARSPACE\nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb); \n#endif\n#else\nvec3 vRefractionUVW=vec3(refractionMatrix*(view*vec4(vPositionW+refractionVector*vRefractionInfos.z,1.0)));\nvec2 refractionCoords=vRefractionUVW.xy/vRefractionUVW.z;\nrefractionCoords.y=1.0-refractionCoords.y;\n#ifdef LODBASEDMICROSFURACE\nsurfaceRefractionColor=texture2DLodEXT(refraction2DSampler,refractionCoords,lodRefraction).rgb*vRefractionInfos.x;\n#else\nsurfaceRefractionColor=texture2D(refraction2DSampler,refractionCoords,biasRefraction).rgb*vRefractionInfos.x;\n#endif \nsurfaceRefractionColor=toLinearSpace(surfaceRefractionColor.rgb); \n#endif\n#endif\n\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\n#ifdef REFLECTION\nvec3 vReflectionUVW=computeReflectionCoords(vec4(vPositionW,1.0),normalW);\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\nfloat lodReflection=getMipMapIndexFromAverageSlopeWithPMREM(vMicrosurfaceTextureLods.x,alphaG);\n#else\nfloat lodReflection=getMipMapIndexFromAverageSlope(vMicrosurfaceTextureLods.x,alphaG);\n#endif\n#else\nfloat biasReflection=(vMicrosurfaceTextureLods.x+2.)*(1.0-microSurface);\n#endif\n#ifdef REFLECTIONMAP_3D\n#ifdef LODBASEDMICROSFURACE\n#ifdef USEPMREMREFLECTION\n\nif (microSurface>0.5)\n{\n\nfloat scaleReflection=1.-exp2(lodReflection)/exp2(vMicrosurfaceTextureLods.x); \nfloat maxReflection=max(max(abs(vReflectionUVW.x),abs(vReflectionUVW.y)),abs(vReflectionUVW.z));\nif (abs(vReflectionUVW.x) != maxReflection) vReflectionUVW.x*=scaleReflection;\nif (abs(vReflectionUVW.y) != maxReflection) vReflectionUVW.y*=scaleReflection;\nif (abs(vReflectionUVW.z) != maxReflection) vReflectionUVW.z*=scaleReflection;\n}\n#endif\nenvironmentRadiance=textureCubeLodEXT(reflectionCubeSampler,vReflectionUVW,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=textureCube(reflectionCubeSampler,vReflectionUVW,biasReflection).rgb*vReflectionInfos.x;\n#endif\n#ifdef USESPHERICALFROMREFLECTIONMAP\n#ifndef REFLECTIONMAP_SKYBOX\nvec3 normalEnvironmentSpace=(reflectionMatrix*vec4(normalW,1)).xyz;\nenvironmentIrradiance=EnvironmentIrradiance(normalEnvironmentSpace);\n#endif\n#else\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=textureCube(reflectionCubeSampler,normalW,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\nenvironmentIrradiance*=0.2; \n#endif\n#else\nvec2 coords=vReflectionUVW.xy;\n#ifdef REFLECTIONMAP_PROJECTION\ncoords/=vReflectionUVW.z;\n#endif\ncoords.y=1.0-coords.y;\n#ifdef LODBASEDMICROSFURACE\nenvironmentRadiance=texture2DLodEXT(reflection2DSampler,coords,lodReflection).rgb*vReflectionInfos.x;\n#else\nenvironmentRadiance=texture2D(reflection2DSampler,coords,biasReflection).rgb*vReflectionInfos.x;\n#endif\nenvironmentRadiance=toLinearSpace(environmentRadiance.rgb);\nenvironmentIrradiance=texture2D(reflection2DSampler,coords,20.).rgb*vReflectionInfos.x;\nenvironmentIrradiance=toLinearSpace(environmentIrradiance.rgb);\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nenvironmentIrradiance=mix(environmentIrradiance,vOverloadedReflection,vOverloadedMicroSurface.z);\nenvironmentRadiance=mix(environmentRadiance,vOverloadedReflection,vOverloadedMicroSurface.z);\n#endif\nenvironmentRadiance*=vLightingIntensity.z;\nenvironmentIrradiance*=vLightingIntensity.z;\n\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nvec3 refractance=vec3(0.0 ,0.0,0.0);\n#ifdef REFRACTION\nvec3 transmission=vec3(1.0 ,1.0,1.0);\n#ifdef LINKREFRACTIONTOTRANSPARENCY\n\ntransmission*=(1.0-alpha);\n\n\nvec3 mixedAlbedo=surfaceAlbedoContribution.rgb*surfaceAlbedo.rgb;\nfloat maxChannel=max(max(mixedAlbedo.r,mixedAlbedo.g),mixedAlbedo.b);\nvec3 tint=clamp(maxChannel*mixedAlbedo,0.0,1.0);\n\nsurfaceAlbedoContribution*=alpha;\n\nenvironmentIrradiance*=alpha;\n\nsurfaceRefractionColor*=tint;\n\nalpha=1.0;\n#endif\n\nvec3 bounceSpecularEnvironmentReflectance=(2.0*specularEnvironmentReflectance)/(1.0+specularEnvironmentReflectance);\nspecularEnvironmentReflectance=mix(bounceSpecularEnvironmentReflectance,specularEnvironmentReflectance,alpha);\n\ntransmission*=1.0-specularEnvironmentReflectance;\n\nrefractance=surfaceRefractionColor*transmission;\n#endif\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nrefractance*=vLightingIntensity.z;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n#ifdef EMISSIVEFRESNEL\nfloat emissiveFresnelTerm=computeFresnelTerm(viewDirectionW,normalW,emissiveRightColor.a,emissiveLeftColor.a);\nsurfaceEmissiveColor*=emissiveLeftColor.rgb*(1.0-emissiveFresnelTerm)+emissiveFresnelTerm*emissiveRightColor.rgb;\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=max((lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max((shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+surfaceEmissiveColor*vLightingIntensity.y+refractance,alpha);\n#else\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+refractance,alpha);\n#endif\n#ifdef LIGHTMAP\nvec3 lightmapColor=texture2D(lightmapSampler,vLightmapUV).rgb*vLightmapInfos.y;\n#ifdef USELIGHTMAPASSHADOWMAP\nfinalColor.rgb*=lightmapColor;\n#else\nfinalColor.rgb+=lightmapColor;\n#endif\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n#include<logDepthFragment>\n#include<fogFragment>(color,finalColor)\ngl_FragColor=finalColor;\n}";
  1074. BABYLON.Effect.ShadersStore['legacypbrVertexShader'] = "precision mediump float;\n\nattribute vec3 position;\nattribute vec3 normal;\n#ifdef UV1\nattribute vec2 uv;\n#endif\n#ifdef UV2\nattribute vec2 uv2;\n#endif\n#ifdef VERTEXCOLOR\nattribute vec4 color;\n#endif\n#include<bonesDeclaration>\n\nuniform mat4 world;\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform mat4 albedoMatrix;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform mat4 ambientMatrix;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY\nvarying vec2 vOpacityUV;\nuniform mat4 opacityMatrix;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform mat4 emissiveMatrix;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform mat4 reflectivityMatrix;\n#endif\n\nvarying vec3 vPositionW;\nvarying vec3 vNormalW;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#include<clipPlaneVertexDeclaration>\nvoid main(void) {\nmat4 finalWorld=world;\n#include<bonesVertex>\ngl_Position=viewProjection*finalWorld*vec4(position,1.0);\nvec4 worldPos=finalWorld*vec4(position,1.0);\nvPositionW=vec3(worldPos);\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef ALBEDO\nif (vAlbedoInfos.x == 0.)\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAlbedoUV=vec2(albedoMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef AMBIENT\nif (vAmbientInfos.x == 0.)\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvAmbientUV=vec2(ambientMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef OPACITY\nif (vOpacityInfos.x == 0.)\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvOpacityUV=vec2(opacityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#ifdef EMISSIVE\nif (vEmissiveInfos.x == 0.)\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvEmissiveUV=vec2(emissiveMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#if defined(REFLECTIVITY)\nif (vReflectivityInfos.x == 0.)\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvReflectivityUV=vec2(reflectivityMatrix*vec4(uv2,1.0,0.0));\n}\n#endif\n#include<clipPlaneVertex>\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n}";
  1075. BABYLON.Effect.ShadersStore['legacypbrPixelShader'] = "precision mediump float;\n\n#define RECIPROCAL_PI2 0.15915494\n#define FRESNEL_MAXIMUM_ON_ROUGH 0.25\nuniform vec3 vEyePosition;\nuniform vec3 vAmbientColor;\nuniform vec4 vAlbedoColor;\nuniform vec3 vReflectionColor;\nuniform vec4 vLightRadiuses;\n\nuniform vec4 vLightingIntensity;\nuniform vec4 vCameraInfos;\n#ifdef OVERLOADEDVALUES\nuniform vec4 vOverloadedIntensity;\nuniform vec3 vOverloadedAmbient;\nuniform vec3 vOverloadedAlbedo;\nuniform vec3 vOverloadedReflectivity;\nuniform vec3 vOverloadedEmissive;\nuniform vec3 vOverloadedReflection;\nuniform vec3 vOverloadedMicroSurface;\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nuniform vec4 vOverloadedShadowIntensity;\n#endif\n\nconst float kPi=3.1415926535897932384626433832795;\nconst float kRougnhessToAlphaScale=0.1;\nconst float kRougnhessToAlphaOffset=0.29248125;\n\nfloat Square(float value)\n{\nreturn value*value;\n}\nfloat getLuminance(vec3 color)\n{\nreturn clamp(dot(color,vec3(0.2126,0.7152,0.0722)),0.,1.);\n}\nfloat convertRoughnessToAverageSlope(float roughness)\n{\n\nconst float kMinimumVariance=0.0005;\nfloat alphaG=Square(roughness)+kMinimumVariance;\nreturn alphaG;\n}\n\nfloat getMipMapIndexFromAverageSlope(float maxMipLevel,float alpha)\n{\n\n\n\n\n\n\n\nfloat mip=kRougnhessToAlphaOffset+maxMipLevel+(maxMipLevel*kRougnhessToAlphaScale*log2(alpha));\nreturn clamp(mip,0.,maxMipLevel);\n}\nfloat getMipMapIndexFromAverageSlopeWithPMREM(float maxMipLevel,float alphaG)\n{\nfloat specularPower=clamp(2./alphaG-2.,0.000001,2048.);\n\nreturn clamp(- 0.5*log2(specularPower)+5.5,0.,maxMipLevel);\n}\n\nfloat smithVisibilityG1_TrowbridgeReitzGGX(float dot,float alphaG)\n{\nfloat tanSquared=(1.0-dot*dot)/(dot*dot);\nreturn 2.0/(1.0+sqrt(1.0+alphaG*alphaG*tanSquared));\n}\nfloat smithVisibilityG_TrowbridgeReitzGGX_Walter(float NdotL,float NdotV,float alphaG)\n{\nreturn smithVisibilityG1_TrowbridgeReitzGGX(NdotL,alphaG)*smithVisibilityG1_TrowbridgeReitzGGX(NdotV,alphaG);\n}\n\n\nfloat normalDistributionFunction_TrowbridgeReitzGGX(float NdotH,float alphaG)\n{\n\n\n\nfloat a2=Square(alphaG);\nfloat d=NdotH*NdotH*(a2-1.0)+1.0;\nreturn a2/(kPi*d*d);\n}\nvec3 fresnelSchlickGGX(float VdotH,vec3 reflectance0,vec3 reflectance90)\n{\nreturn reflectance0+(reflectance90-reflectance0)*pow(clamp(1.0-VdotH,0.,1.),5.0);\n}\nvec3 FresnelSchlickEnvironmentGGX(float VdotN,vec3 reflectance0,vec3 reflectance90,float smoothness)\n{\n\nfloat weight=mix(FRESNEL_MAXIMUM_ON_ROUGH,1.0,smoothness);\nreturn reflectance0+weight*(reflectance90-reflectance0)*pow(clamp(1.0-VdotN,0.,1.),5.0);\n}\n\nvec3 computeSpecularTerm(float NdotH,float NdotL,float NdotV,float VdotH,float roughness,vec3 specularColor)\n{\nfloat alphaG=convertRoughnessToAverageSlope(roughness);\nfloat distribution=normalDistributionFunction_TrowbridgeReitzGGX(NdotH,alphaG);\nfloat visibility=smithVisibilityG_TrowbridgeReitzGGX_Walter(NdotL,NdotV,alphaG);\nvisibility/=(4.0*NdotL*NdotV); \nvec3 fresnel=fresnelSchlickGGX(VdotH,specularColor,vec3(1.,1.,1.));\nfloat specTerm=max(0.,visibility*distribution)*NdotL;\nreturn fresnel*specTerm*kPi; \n}\nfloat computeDiffuseTerm(float NdotL,float NdotV,float VdotH,float roughness)\n{\n\n\nfloat diffuseFresnelNV=pow(clamp(1.0-NdotL,0.000001,1.),5.0);\nfloat diffuseFresnelNL=pow(clamp(1.0-NdotV,0.000001,1.),5.0);\nfloat diffuseFresnel90=0.5+2.0*VdotH*VdotH*roughness;\nfloat diffuseFresnelTerm =\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNL) *\n(1.0+(diffuseFresnel90-1.0)*diffuseFresnelNV);\nreturn diffuseFresnelTerm*NdotL;\n\n\n}\nfloat adjustRoughnessFromLightProperties(float roughness,float lightRadius,float lightDistance)\n{\n\nfloat lightRoughness=lightRadius/lightDistance;\n\nfloat totalRoughness=clamp(lightRoughness+roughness,0.,1.);\nreturn totalRoughness;\n}\nfloat computeDefaultMicroSurface(float microSurface,vec3 reflectivityColor)\n{\nfloat kReflectivityNoAlphaWorkflow_SmoothnessMax=0.95;\nfloat reflectivityLuminance=getLuminance(reflectivityColor);\nfloat reflectivityLuma=sqrt(reflectivityLuminance);\nmicroSurface=reflectivityLuma*kReflectivityNoAlphaWorkflow_SmoothnessMax;\nreturn microSurface;\n}\nvec3 toLinearSpace(vec3 color)\n{\nreturn vec3(pow(color.r,2.2),pow(color.g,2.2),pow(color.b,2.2));\n}\nvec3 toGammaSpace(vec3 color)\n{\nreturn vec3(pow(color.r,1.0/2.2),pow(color.g,1.0/2.2),pow(color.b,1.0/2.2));\n}\nfloat computeLightFalloff(vec3 lightOffset,float lightDistanceSquared,float range)\n{\n#ifdef USEPHYSICALLIGHTFALLOFF\nfloat lightDistanceFalloff=1.0/((lightDistanceSquared+0.0001));\nreturn lightDistanceFalloff;\n#else\nfloat lightFalloff=max(0.,1.0-length(lightOffset)/range);\nreturn lightFalloff;\n#endif\n}\n#ifdef CAMERATONEMAP\nvec3 toneMaps(vec3 color)\n{\ncolor=max(color,0.0);\n\ncolor.rgb=color.rgb*vCameraInfos.x;\nfloat tuning=1.5; \n\n\nvec3 tonemapped=1.0-exp2(-color.rgb*tuning); \ncolor.rgb=mix(color.rgb,tonemapped,1.0);\nreturn color;\n}\n#endif\n#ifdef CAMERACONTRAST\nvec4 contrasts(vec4 color)\n{\ncolor=clamp(color,0.0,1.0);\nvec3 resultHighContrast=color.rgb*color.rgb*(3.0-2.0*color.rgb);\nfloat contrast=vCameraInfos.y;\nif (contrast<1.0)\n{\n\ncolor.rgb=mix(vec3(0.5,0.5,0.5),color.rgb,contrast);\n}\nelse\n{\n\ncolor.rgb=mix(color.rgb,resultHighContrast,contrast-1.0);\n}\nreturn color;\n}\n#endif\n\nuniform vec4 vReflectivityColor;\nuniform vec3 vEmissiveColor;\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#include<lightFragmentDeclaration>[0]\n#include<lightFragmentDeclaration>[1]\n#include<lightFragmentDeclaration>[2]\n#include<lightFragmentDeclaration>[3]\n\n#ifdef ALBEDO\nvarying vec2 vAlbedoUV;\nuniform sampler2D albedoSampler;\nuniform vec2 vAlbedoInfos;\n#endif\n#ifdef AMBIENT\nvarying vec2 vAmbientUV;\nuniform sampler2D ambientSampler;\nuniform vec2 vAmbientInfos;\n#endif\n#ifdef OPACITY \nvarying vec2 vOpacityUV;\nuniform sampler2D opacitySampler;\nuniform vec2 vOpacityInfos;\n#endif\n#ifdef EMISSIVE\nvarying vec2 vEmissiveUV;\nuniform vec2 vEmissiveInfos;\nuniform sampler2D emissiveSampler;\n#endif\n#ifdef LIGHTMAP\nvarying vec2 vLightmapUV;\nuniform vec2 vLightmapInfos;\nuniform sampler2D lightmapSampler;\n#endif\n#if defined(REFLECTIVITY)\nvarying vec2 vReflectivityUV;\nuniform vec2 vReflectivityInfos;\nuniform sampler2D reflectivitySampler;\n#endif\n#include<clipPlaneFragmentDeclaration>\n\nstruct lightingInfo\n{\nvec3 diffuse;\n#ifdef SPECULARTERM\nvec3 specular;\n#endif\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightDirection;\nfloat attenuation=1.0;\nfloat lightDistance;\n\nif (lightData.w == 0.)\n{\nvec3 lightOffset=lightData.xyz-vPositionW;\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nattenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\nlightDistance=sqrt(lightDistanceSquared);\nlightDirection=normalize(lightOffset);\n}\n\nelse\n{\nlightDistance=length(-lightData.xyz);\nlightDirection=normalize(-lightData.xyz);\n}\n\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW+lightDirection);\nNdotL=max(0.00000000001,dot(vNormal,lightDirection));\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,vec3 specularColor,float range,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\nvec3 lightOffset=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(lightOffset);\n\nfloat cosAngle=max(0.000000000000001,dot(-lightDirection.xyz,lightVectorW));\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\n\nfloat lightDistanceSquared=dot(lightOffset,lightOffset);\nfloat attenuation=computeLightFalloff(lightOffset,lightDistanceSquared,range);\n\nattenuation*=cosAngle;\n\nfloat lightDistance=sqrt(lightDistanceSquared);\nroughness=adjustRoughnessFromLightProperties(roughness,lightRadius,lightDistance);\n\nvec3 H=normalize(viewDirectionW-lightDirection.xyz);\nNdotL=max(0.00000000001,dot(vNormal,-lightDirection.xyz));\nfloat VdotH=clamp(dot(viewDirectionW,H),0.00000000001,1.0);\nfloat diffuseTerm=computeDiffuseTerm(NdotL,NdotV,VdotH,roughness);\nresult.diffuse=diffuseTerm*diffuseColor*attenuation;\n#ifdef SPECULARTERM\n\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm*attenuation;\n#endif\nreturn result;\n}\nresult.diffuse=vec3(0.);\n#ifdef SPECULARTERM\nresult.specular=vec3(0.);\n#endif\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 specularColor,vec3 groundColor,float roughness,float NdotV,float lightRadius,out float NdotL) {\nlightingInfo result;\n\n\n\nNdotL=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,NdotL);\n#ifdef SPECULARTERM\n\nvec3 lightVectorW=normalize(lightData.xyz);\nvec3 H=normalize(viewDirectionW+lightVectorW);\nfloat NdotH=max(0.00000000001,dot(vNormal,H));\nNdotL=max(0.00000000001,NdotL);\nfloat VdotH=clamp(0.00000000001,1.0,dot(viewDirectionW,H));\nvec3 specTerm=computeSpecularTerm(NdotH,NdotL,NdotV,VdotH,roughness,specularColor);\nresult.specular=specTerm;\n#endif\nreturn result;\n}\nvoid main(void) {\n#include<clipPlaneFragment>\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 surfaceAlbedo=vec4(1.,1.,1.,1.);\nvec3 surfaceAlbedoContribution=vAlbedoColor.rgb;\n\nfloat alpha=vAlbedoColor.a;\n#ifdef ALBEDO\nsurfaceAlbedo=texture2D(albedoSampler,vAlbedoUV);\nsurfaceAlbedo=vec4(toLinearSpace(surfaceAlbedo.rgb),surfaceAlbedo.a);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\n#ifdef ALPHAFROMALBEDO\nalpha*=surfaceAlbedo.a;\n#endif\nsurfaceAlbedo.rgb*=vAlbedoInfos.y;\n#else\n\nsurfaceAlbedo.rgb=surfaceAlbedoContribution;\nsurfaceAlbedoContribution=vec3(1.,1.,1.);\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceAlbedo.rgb=mix(surfaceAlbedo.rgb,vOverloadedAlbedo,vOverloadedIntensity.y);\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n\nvec3 ambientColor=vec3(1.,1.,1.);\n#ifdef AMBIENT\nambientColor=texture2D(ambientSampler,vAmbientUV).rgb*vAmbientInfos.y;\n#ifdef OVERLOADEDVALUES\nambientColor.rgb=mix(ambientColor.rgb,vOverloadedAmbient,vOverloadedIntensity.x);\n#endif\n#endif\n\nfloat microSurface=vReflectivityColor.a;\nvec3 surfaceReflectivityColor=vReflectivityColor.rgb;\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor.rgb=mix(surfaceReflectivityColor.rgb,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef REFLECTIVITY\nvec4 surfaceReflectivityColorMap=texture2D(reflectivitySampler,vReflectivityUV);\nsurfaceReflectivityColor=surfaceReflectivityColorMap.rgb;\nsurfaceReflectivityColor=toLinearSpace(surfaceReflectivityColor);\n#ifdef OVERLOADEDVALUES\nsurfaceReflectivityColor=mix(surfaceReflectivityColor,vOverloadedReflectivity,vOverloadedIntensity.z);\n#endif\n#ifdef MICROSURFACEFROMREFLECTIVITYMAP\nmicroSurface=surfaceReflectivityColorMap.a;\n#else\n#ifdef MICROSURFACEAUTOMATIC\nmicroSurface=computeDefaultMicroSurface(microSurface,surfaceReflectivityColor);\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDVALUES\nmicroSurface=mix(microSurface,vOverloadedMicroSurface.x,vOverloadedMicroSurface.y);\n#endif\n\nfloat NdotV=max(0.00000000001,dot(normalW,viewDirectionW));\n\nmicroSurface=clamp(microSurface,0.,1.)*0.98;\n\nfloat roughness=clamp(1.-microSurface,0.000001,1.0);\n\nvec3 lightDiffuseContribution=vec3(0.,0.,0.);\n#ifdef OVERLOADEDSHADOWVALUES\nvec3 shadowedOnlyLightDiffuseContribution=vec3(1.,1.,1.);\n#endif\n#ifdef SPECULARTERM\nvec3 lightSpecularContribution= vec3(0.,0.,0.);\n#endif\nfloat notShadowLevel=1.; \nfloat NdotL=-1.;\n#ifdef LIGHT0\n#ifndef SPECULARTERM\nvec3 vLightSpecular0=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT0\nlightingInfo info=computeSpotLighting(viewDirectionW,normalW,vLightData0,vLightDirection0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#ifdef HEMILIGHT0\nlightingInfo info=computeHemisphericLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightGround0,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\nlightingInfo info=computeLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightSpecular0,vLightDiffuse0.a,roughness,NdotV,vLightRadiuses[0],NdotL);\n#endif\nnotShadowLevel=1.;\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef LIGHT1\n#ifndef SPECULARTERM\nvec3 vLightSpecular1=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT1\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData1,vLightDirection1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#ifdef HEMILIGHT1\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightGround1,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\ninfo=computeLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightSpecular1,vLightDiffuse1.a,roughness,NdotV,vLightRadiuses[1],NdotL);\n#endif\nnotShadowLevel=1.;\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef LIGHT2\n#ifndef SPECULARTERM\nvec3 vLightSpecular2=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT2\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData2,vLightDirection2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#ifdef HEMILIGHT2\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightGround2,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\ninfo=computeLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightSpecular2,vLightDiffuse2.a,roughness,NdotV,vLightRadiuses[2],NdotL);\n#endif\nnotShadowLevel=1.;\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef LIGHT3\n#ifndef SPECULARTERM\nvec3 vLightSpecular3=vec3(0.0);\n#endif\n#ifdef SPOTLIGHT3\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData3,vLightDirection3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#ifdef HEMILIGHT3\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightGround3,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\ninfo=computeLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightSpecular3,vLightDiffuse3.a,roughness,NdotV,vLightRadiuses[3],NdotL);\n#endif\nnotShadowLevel=1.;\nlightDiffuseContribution+=info.diffuse*notShadowLevel;\n#ifdef OVERLOADEDSHADOWVALUES\nif (NdotL<0.000000000011)\n{\nnotShadowLevel=1.;\n}\nshadowedOnlyLightDiffuseContribution*=notShadowLevel;\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution+=info.specular*notShadowLevel;\n#endif\n#endif\n#ifdef SPECULARTERM\nlightSpecularContribution*=vLightingIntensity.w;\n#endif\n#ifdef OPACITY\nvec4 opacityMap=texture2D(opacitySampler,vOpacityUV);\n#ifdef OPACITYRGB\nopacityMap.rgb=opacityMap.rgb*vec3(0.3,0.59,0.11);\nalpha*=(opacityMap.x+opacityMap.y+opacityMap.z)* vOpacityInfos.y;\n#else\nalpha*=opacityMap.a*vOpacityInfos.y;\n#endif\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\n\nvec3 environmentRadiance=vReflectionColor.rgb;\nvec3 environmentIrradiance=vReflectionColor.rgb;\n#ifdef OVERLOADEDVALUES\nenvironmentIrradiance=mix(environmentIrradiance,vOverloadedReflection,vOverloadedMicroSurface.z);\nenvironmentRadiance=mix(environmentRadiance,vOverloadedReflection,vOverloadedMicroSurface.z);\n#endif\nenvironmentRadiance*=vLightingIntensity.z;\nenvironmentIrradiance*=vLightingIntensity.z;\n\nvec3 specularEnvironmentR0=surfaceReflectivityColor.rgb;\nvec3 specularEnvironmentR90=vec3(1.0,1.0,1.0);\nvec3 specularEnvironmentReflectance=FresnelSchlickEnvironmentGGX(clamp(NdotV,0.,1.),specularEnvironmentR0,specularEnvironmentR90,sqrt(microSurface));\n\nfloat reflectance=max(max(surfaceReflectivityColor.r,surfaceReflectivityColor.g),surfaceReflectivityColor.b);\nsurfaceAlbedo.rgb=(1.-reflectance)*surfaceAlbedo.rgb;\nenvironmentRadiance*=specularEnvironmentReflectance;\n\nvec3 surfaceEmissiveColor=vEmissiveColor;\n#ifdef EMISSIVE\nvec3 emissiveColorTex=texture2D(emissiveSampler,vEmissiveUV).rgb;\nsurfaceEmissiveColor=toLinearSpace(emissiveColorTex.rgb)*surfaceEmissiveColor*vEmissiveInfos.y;\n#endif\n#ifdef OVERLOADEDVALUES\nsurfaceEmissiveColor=mix(surfaceEmissiveColor,vOverloadedEmissive,vOverloadedIntensity.w);\n#endif\n\n#ifdef EMISSIVEASILLUMINATION\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\n#ifdef LINKEMISSIVEWITHALBEDO\nvec3 finalDiffuse=max((lightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max((shadowedOnlyLightDiffuseContribution+surfaceEmissiveColor)*surfaceAlbedoContribution+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#else\nvec3 finalDiffuse=max(lightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#ifdef OVERLOADEDSHADOWVALUES\nshadowedOnlyLightDiffuseContribution=max(shadowedOnlyLightDiffuseContribution*surfaceAlbedoContribution+surfaceEmissiveColor+vAmbientColor,0.0)*surfaceAlbedo.rgb;\n#endif\n#endif\n#endif\n#ifdef OVERLOADEDSHADOWVALUES\nfinalDiffuse=mix(finalDiffuse,shadowedOnlyLightDiffuseContribution,(1.0-vOverloadedShadowIntensity.y));\n#endif\n#ifdef SPECULARTERM\nvec3 finalSpecular=lightSpecularContribution*surfaceReflectivityColor;\n#else\nvec3 finalSpecular=vec3(0.0);\n#endif\n#ifdef SPECULAROVERALPHA\nalpha=clamp(alpha+getLuminance(finalSpecular),0.,1.);\n#endif\n#ifdef RADIANCEOVERALPHA\nalpha=clamp(alpha+getLuminance(environmentRadiance),0.,1.);\n#endif\n\n\n#ifdef EMISSIVEASILLUMINATION\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance+surfaceEmissiveColor*vLightingIntensity.y,alpha);\n#else\nvec4 finalColor=vec4(finalDiffuse*ambientColor*vLightingIntensity.x+surfaceAlbedo.rgb*environmentIrradiance+finalSpecular*vLightingIntensity.x+environmentRadiance,alpha);\n#endif\nfinalColor=max(finalColor,0.0);\n#ifdef CAMERATONEMAP\nfinalColor.rgb=toneMaps(finalColor.rgb);\n#endif\nfinalColor.rgb=toGammaSpace(finalColor.rgb);\n#ifdef CAMERACONTRAST\nfinalColor=contrasts(finalColor);\n#endif\ngl_FragColor=finalColor;\n}";