babylon.furMaterial.js 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577
  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 FurMaterialDefines = (function (_super) {
  14. __extends(FurMaterialDefines, _super);
  15. function FurMaterialDefines() {
  16. _super.call(this);
  17. this.DIFFUSE = false;
  18. this.HEIGHTMAP = false;
  19. this.CLIPPLANE = false;
  20. this.ALPHATEST = false;
  21. this.POINTSIZE = false;
  22. this.FOG = false;
  23. this.LIGHT0 = false;
  24. this.LIGHT1 = false;
  25. this.LIGHT2 = false;
  26. this.LIGHT3 = false;
  27. this.SPOTLIGHT0 = false;
  28. this.SPOTLIGHT1 = false;
  29. this.SPOTLIGHT2 = false;
  30. this.SPOTLIGHT3 = false;
  31. this.HEMILIGHT0 = false;
  32. this.HEMILIGHT1 = false;
  33. this.HEMILIGHT2 = false;
  34. this.HEMILIGHT3 = false;
  35. this.DIRLIGHT0 = false;
  36. this.DIRLIGHT1 = false;
  37. this.DIRLIGHT2 = false;
  38. this.DIRLIGHT3 = false;
  39. this.POINTLIGHT0 = false;
  40. this.POINTLIGHT1 = false;
  41. this.POINTLIGHT2 = false;
  42. this.POINTLIGHT3 = false;
  43. this.SHADOW0 = false;
  44. this.SHADOW1 = false;
  45. this.SHADOW2 = false;
  46. this.SHADOW3 = false;
  47. this.SHADOWS = false;
  48. this.SHADOWVSM0 = false;
  49. this.SHADOWVSM1 = false;
  50. this.SHADOWVSM2 = false;
  51. this.SHADOWVSM3 = false;
  52. this.SHADOWPCF0 = false;
  53. this.SHADOWPCF1 = false;
  54. this.SHADOWPCF2 = false;
  55. this.SHADOWPCF3 = false;
  56. this.NORMAL = false;
  57. this.UV1 = false;
  58. this.UV2 = false;
  59. this.VERTEXCOLOR = false;
  60. this.VERTEXALPHA = false;
  61. this.BONES = false;
  62. this.BONES4 = false;
  63. this.BonesPerMesh = 0;
  64. this.INSTANCES = false;
  65. this.HIGHLEVEL = false;
  66. this._keys = Object.keys(this);
  67. }
  68. return FurMaterialDefines;
  69. })(BABYLON.MaterialDefines);
  70. var FurMaterial = (function (_super) {
  71. __extends(FurMaterial, _super);
  72. function FurMaterial(name, scene) {
  73. _super.call(this, name, scene);
  74. this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  75. this.furLength = 1;
  76. this.furAngle = 0;
  77. this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  78. this.furOffset = 0.0;
  79. this.furSpacing = 12;
  80. this.furGravity = new BABYLON.Vector3(0, 0, 0);
  81. this.furSpeed = 100;
  82. this.furDensity = 20;
  83. this.disableLighting = false;
  84. this.highLevelFur = true;
  85. this._worldViewProjectionMatrix = BABYLON.Matrix.Zero();
  86. this._scaledDiffuse = new BABYLON.Color3(1., 1., 1.);
  87. this._furTime = 0;
  88. this._defines = new FurMaterialDefines();
  89. this._cachedDefines = new FurMaterialDefines();
  90. this._cachedDefines.BonesPerMesh = -1;
  91. }
  92. Object.defineProperty(FurMaterial.prototype, "furTime", {
  93. get: function () {
  94. return this._furTime;
  95. },
  96. set: function (furTime) {
  97. this._furTime = furTime;
  98. },
  99. enumerable: true,
  100. configurable: true
  101. });
  102. FurMaterial.prototype.needAlphaBlending = function () {
  103. return (this.alpha < 1.0);
  104. };
  105. FurMaterial.prototype.needAlphaTesting = function () {
  106. return false;
  107. };
  108. FurMaterial.prototype.getAlphaTestTexture = function () {
  109. return null;
  110. };
  111. // Methods
  112. FurMaterial.prototype._checkCache = function (scene, mesh, useInstances) {
  113. if (!mesh) {
  114. return true;
  115. }
  116. if (this._defines.INSTANCES !== useInstances) {
  117. return false;
  118. }
  119. if (mesh._materialDefines && mesh._materialDefines.isEqual(this._defines)) {
  120. return true;
  121. }
  122. return false;
  123. };
  124. FurMaterial.prototype.isReady = function (mesh, useInstances) {
  125. if (this.checkReadyOnlyOnce) {
  126. if (this._wasPreviouslyReady) {
  127. return true;
  128. }
  129. }
  130. var scene = this.getScene();
  131. if (!this.checkReadyOnEveryCall) {
  132. if (this._renderId === scene.getRenderId()) {
  133. if (this._checkCache(scene, mesh, useInstances)) {
  134. return true;
  135. }
  136. }
  137. }
  138. var engine = scene.getEngine();
  139. var needNormals = false;
  140. var needUVs = false;
  141. this._defines.reset();
  142. // Textures
  143. if (scene.texturesEnabled) {
  144. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  145. if (!this.diffuseTexture.isReady()) {
  146. return false;
  147. }
  148. else {
  149. needUVs = true;
  150. this._defines.DIFFUSE = true;
  151. }
  152. }
  153. if (this.heightTexture) {
  154. if (!this.heightTexture.isReady()) {
  155. return false;
  156. }
  157. else {
  158. needUVs = true;
  159. this._defines.HEIGHTMAP = true;
  160. }
  161. }
  162. }
  163. // Effect
  164. if (scene.clipPlane) {
  165. this._defines.CLIPPLANE = true;
  166. }
  167. if (engine.getAlphaTesting()) {
  168. this._defines.ALPHATEST = true;
  169. }
  170. // Point size
  171. if (this.pointsCloud || scene.forcePointsCloud) {
  172. this._defines.POINTSIZE = true;
  173. }
  174. // Fog
  175. if (scene.fogEnabled && mesh && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE && this.fogEnabled) {
  176. this._defines.FOG = true;
  177. }
  178. // High level
  179. if (this.highLevelFur) {
  180. this._defines.HIGHLEVEL = true;
  181. }
  182. var lightIndex = 0;
  183. if (scene.lightsEnabled && !this.disableLighting) {
  184. for (var index = 0; index < scene.lights.length; index++) {
  185. var light = scene.lights[index];
  186. if (!light.isEnabled()) {
  187. continue;
  188. }
  189. // Excluded check
  190. if (light._excludedMeshesIds.length > 0) {
  191. for (var excludedIndex = 0; excludedIndex < light._excludedMeshesIds.length; excludedIndex++) {
  192. var excludedMesh = scene.getMeshByID(light._excludedMeshesIds[excludedIndex]);
  193. if (excludedMesh) {
  194. light.excludedMeshes.push(excludedMesh);
  195. }
  196. }
  197. light._excludedMeshesIds = [];
  198. }
  199. // Included check
  200. if (light._includedOnlyMeshesIds.length > 0) {
  201. for (var includedOnlyIndex = 0; includedOnlyIndex < light._includedOnlyMeshesIds.length; includedOnlyIndex++) {
  202. var includedOnlyMesh = scene.getMeshByID(light._includedOnlyMeshesIds[includedOnlyIndex]);
  203. if (includedOnlyMesh) {
  204. light.includedOnlyMeshes.push(includedOnlyMesh);
  205. }
  206. }
  207. light._includedOnlyMeshesIds = [];
  208. }
  209. if (!light.canAffectMesh(mesh)) {
  210. continue;
  211. }
  212. needNormals = true;
  213. this._defines["LIGHT" + lightIndex] = true;
  214. var type;
  215. if (light instanceof BABYLON.SpotLight) {
  216. type = "SPOTLIGHT" + lightIndex;
  217. }
  218. else if (light instanceof BABYLON.HemisphericLight) {
  219. type = "HEMILIGHT" + lightIndex;
  220. }
  221. else if (light instanceof BABYLON.PointLight) {
  222. type = "POINTLIGHT" + lightIndex;
  223. }
  224. else {
  225. type = "DIRLIGHT" + lightIndex;
  226. }
  227. this._defines[type] = true;
  228. // Shadows
  229. if (scene.shadowsEnabled) {
  230. var shadowGenerator = light.getShadowGenerator();
  231. if (mesh && mesh.receiveShadows && shadowGenerator) {
  232. this._defines["SHADOW" + lightIndex] = true;
  233. this._defines.SHADOWS = true;
  234. if (shadowGenerator.useVarianceShadowMap || shadowGenerator.useBlurVarianceShadowMap) {
  235. this._defines["SHADOWVSM" + lightIndex] = true;
  236. }
  237. if (shadowGenerator.usePoissonSampling) {
  238. this._defines["SHADOWPCF" + lightIndex] = true;
  239. }
  240. }
  241. }
  242. lightIndex++;
  243. if (lightIndex === maxSimultaneousLights)
  244. break;
  245. }
  246. }
  247. // Attribs
  248. if (mesh) {
  249. if (needNormals && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.NormalKind)) {
  250. this._defines.NORMAL = true;
  251. }
  252. if (needUVs) {
  253. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UVKind)) {
  254. this._defines.UV1 = true;
  255. }
  256. if (mesh.isVerticesDataPresent(BABYLON.VertexBuffer.UV2Kind)) {
  257. this._defines.UV2 = true;
  258. }
  259. }
  260. if (mesh.useVertexColors && mesh.isVerticesDataPresent(BABYLON.VertexBuffer.ColorKind)) {
  261. this._defines.VERTEXCOLOR = true;
  262. if (mesh.hasVertexAlpha) {
  263. this._defines.VERTEXALPHA = true;
  264. }
  265. }
  266. if (mesh.useBones && mesh.computeBonesUsingShaders) {
  267. this._defines.BONES = true;
  268. this._defines.BonesPerMesh = (mesh.skeleton.bones.length + 1);
  269. this._defines.BONES4 = true;
  270. }
  271. // Instances
  272. if (useInstances) {
  273. this._defines.INSTANCES = true;
  274. }
  275. }
  276. // Get correct effect
  277. if (!this._defines.isEqual(this._cachedDefines)) {
  278. this._defines.cloneTo(this._cachedDefines);
  279. scene.resetCachedMaterial();
  280. // Fallbacks
  281. var fallbacks = new BABYLON.EffectFallbacks();
  282. if (this._defines.FOG) {
  283. fallbacks.addFallback(1, "FOG");
  284. }
  285. for (lightIndex = 0; lightIndex < maxSimultaneousLights; lightIndex++) {
  286. if (!this._defines["LIGHT" + lightIndex]) {
  287. continue;
  288. }
  289. if (lightIndex > 0) {
  290. fallbacks.addFallback(lightIndex, "LIGHT" + lightIndex);
  291. }
  292. if (this._defines["SHADOW" + lightIndex]) {
  293. fallbacks.addFallback(0, "SHADOW" + lightIndex);
  294. }
  295. if (this._defines["SHADOWPCF" + lightIndex]) {
  296. fallbacks.addFallback(0, "SHADOWPCF" + lightIndex);
  297. }
  298. if (this._defines["SHADOWVSM" + lightIndex]) {
  299. fallbacks.addFallback(0, "SHADOWVSM" + lightIndex);
  300. }
  301. }
  302. if (this._defines.BONES4) {
  303. fallbacks.addFallback(0, "BONES4");
  304. }
  305. //Attributes
  306. var attribs = [BABYLON.VertexBuffer.PositionKind];
  307. if (this._defines.NORMAL) {
  308. attribs.push(BABYLON.VertexBuffer.NormalKind);
  309. }
  310. if (this._defines.UV1) {
  311. attribs.push(BABYLON.VertexBuffer.UVKind);
  312. }
  313. if (this._defines.UV2) {
  314. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  315. }
  316. if (this._defines.VERTEXCOLOR) {
  317. attribs.push(BABYLON.VertexBuffer.ColorKind);
  318. }
  319. if (this._defines.BONES) {
  320. attribs.push(BABYLON.VertexBuffer.MatricesIndicesKind);
  321. attribs.push(BABYLON.VertexBuffer.MatricesWeightsKind);
  322. }
  323. if (this._defines.INSTANCES) {
  324. attribs.push("world0");
  325. attribs.push("world1");
  326. attribs.push("world2");
  327. attribs.push("world3");
  328. }
  329. // Legacy browser patch
  330. var shaderName = "fur";
  331. var join = this._defines.toString();
  332. this._effect = scene.getEngine().createEffect(shaderName, attribs, ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  333. "vLightData0", "vLightDiffuse0", "vLightSpecular0", "vLightDirection0", "vLightGround0", "lightMatrix0",
  334. "vLightData1", "vLightDiffuse1", "vLightSpecular1", "vLightDirection1", "vLightGround1", "lightMatrix1",
  335. "vLightData2", "vLightDiffuse2", "vLightSpecular2", "vLightDirection2", "vLightGround2", "lightMatrix2",
  336. "vLightData3", "vLightDiffuse3", "vLightSpecular3", "vLightDirection3", "vLightGround3", "lightMatrix3",
  337. "vFogInfos", "vFogColor", "pointSize",
  338. "vDiffuseInfos",
  339. "mBones",
  340. "vClipPlane", "diffuseMatrix",
  341. "shadowsInfo0", "shadowsInfo1", "shadowsInfo2", "shadowsInfo3",
  342. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity"
  343. ], ["diffuseSampler",
  344. "shadowSampler0", "shadowSampler1", "shadowSampler2", "shadowSampler3",
  345. "heightTexture", "furTexture"
  346. ], join, fallbacks, this.onCompiled, this.onError);
  347. }
  348. if (!this._effect.isReady()) {
  349. return false;
  350. }
  351. this._renderId = scene.getRenderId();
  352. this._wasPreviouslyReady = true;
  353. if (mesh) {
  354. if (!mesh._materialDefines) {
  355. mesh._materialDefines = new FurMaterialDefines();
  356. }
  357. this._defines.cloneTo(mesh._materialDefines);
  358. }
  359. return true;
  360. };
  361. FurMaterial.prototype.bindOnlyWorldMatrix = function (world) {
  362. this._effect.setMatrix("world", world);
  363. };
  364. FurMaterial.prototype.bind = function (world, mesh) {
  365. var scene = this.getScene();
  366. // Matrices
  367. this.bindOnlyWorldMatrix(world);
  368. this._effect.setMatrix("viewProjection", scene.getTransformMatrix());
  369. // Bones
  370. if (mesh && mesh.useBones && mesh.computeBonesUsingShaders) {
  371. this._effect.setMatrices("mBones", mesh.skeleton.getTransformMatrices(mesh));
  372. }
  373. if (scene.getCachedMaterial() !== this) {
  374. // Textures
  375. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  376. this._effect.setTexture("diffuseSampler", this.diffuseTexture);
  377. this._effect.setFloat2("vDiffuseInfos", this.diffuseTexture.coordinatesIndex, this.diffuseTexture.level);
  378. this._effect.setMatrix("diffuseMatrix", this.diffuseTexture.getTextureMatrix());
  379. }
  380. if (this.heightTexture) {
  381. this._effect.setTexture("heightTexture", this.heightTexture);
  382. }
  383. // Clip plane
  384. if (scene.clipPlane) {
  385. var clipPlane = scene.clipPlane;
  386. this._effect.setFloat4("vClipPlane", clipPlane.normal.x, clipPlane.normal.y, clipPlane.normal.z, clipPlane.d);
  387. }
  388. // Point size
  389. if (this.pointsCloud) {
  390. this._effect.setFloat("pointSize", this.pointSize);
  391. }
  392. this._effect.setVector3("vEyePosition", scene._mirroredCameraPosition ? scene._mirroredCameraPosition : scene.activeCamera.position);
  393. }
  394. this._effect.setColor4("vDiffuseColor", this._scaledDiffuse, this.alpha * mesh.visibility);
  395. if (scene.lightsEnabled && !this.disableLighting) {
  396. var lightIndex = 0;
  397. for (var index = 0; index < scene.lights.length; index++) {
  398. var light = scene.lights[index];
  399. if (!light.isEnabled()) {
  400. continue;
  401. }
  402. if (!light.canAffectMesh(mesh)) {
  403. continue;
  404. }
  405. if (light instanceof BABYLON.PointLight) {
  406. // Point Light
  407. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  408. }
  409. else if (light instanceof BABYLON.DirectionalLight) {
  410. // Directional Light
  411. light.transferToEffect(this._effect, "vLightData" + lightIndex);
  412. }
  413. else if (light instanceof BABYLON.SpotLight) {
  414. // Spot Light
  415. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightDirection" + lightIndex);
  416. }
  417. else if (light instanceof BABYLON.HemisphericLight) {
  418. // Hemispheric Light
  419. light.transferToEffect(this._effect, "vLightData" + lightIndex, "vLightGround" + lightIndex);
  420. }
  421. light.diffuse.scaleToRef(light.intensity, this._scaledDiffuse);
  422. this._effect.setColor4("vLightDiffuse" + lightIndex, this._scaledDiffuse, light.range);
  423. // Shadows
  424. if (scene.shadowsEnabled) {
  425. var shadowGenerator = light.getShadowGenerator();
  426. if (mesh.receiveShadows && shadowGenerator) {
  427. this._effect.setMatrix("lightMatrix" + lightIndex, shadowGenerator.getTransformMatrix());
  428. this._effect.setTexture("shadowSampler" + lightIndex, shadowGenerator.getShadowMapForRendering());
  429. this._effect.setFloat3("shadowsInfo" + lightIndex, shadowGenerator.getDarkness(), shadowGenerator.getShadowMap().getSize().width, shadowGenerator.bias);
  430. }
  431. }
  432. lightIndex++;
  433. if (lightIndex === maxSimultaneousLights)
  434. break;
  435. }
  436. }
  437. // View
  438. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  439. this._effect.setMatrix("view", scene.getViewMatrix());
  440. }
  441. // Fog
  442. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  443. this._effect.setFloat4("vFogInfos", scene.fogMode, scene.fogStart, scene.fogEnd, scene.fogDensity);
  444. this._effect.setColor3("vFogColor", scene.fogColor);
  445. }
  446. this._effect.setFloat("furLength", this.furLength);
  447. this._effect.setFloat("furAngle", this.furAngle);
  448. this._effect.setColor4("furColor", this.furColor, 1.0);
  449. if (this.highLevelFur) {
  450. this._effect.setVector3("furGravity", this.furGravity);
  451. this._effect.setFloat("furOffset", this.furOffset);
  452. this._effect.setFloat("furSpacing", this.furSpacing);
  453. this._effect.setFloat("furDensity", this.furDensity);
  454. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  455. this._effect.setFloat("furTime", this._furTime);
  456. this._effect.setTexture("furTexture", this.furTexture);
  457. }
  458. _super.prototype.bind.call(this, world, mesh);
  459. };
  460. FurMaterial.prototype.getAnimatables = function () {
  461. var results = [];
  462. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  463. results.push(this.diffuseTexture);
  464. }
  465. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  466. results.push(this.heightTexture);
  467. }
  468. return results;
  469. };
  470. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  471. if (this.diffuseTexture) {
  472. this.diffuseTexture.dispose();
  473. }
  474. _super.prototype.dispose.call(this, forceDisposeEffect);
  475. };
  476. FurMaterial.prototype.clone = function (name) {
  477. var _this = this;
  478. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  479. };
  480. FurMaterial.prototype.serialize = function () {
  481. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  482. serializationObject.customType = "BABYLON.FurMaterial";
  483. return serializationObject;
  484. };
  485. // Statics
  486. FurMaterial.Parse = function (source, scene, rootUrl) {
  487. return BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  488. };
  489. FurMaterial.GenerateTexture = function (name, scene) {
  490. // Generate fur textures
  491. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  492. var context = texture.getContext();
  493. for (var i = 0; i < 20000; ++i) {
  494. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  495. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  496. }
  497. texture.update(false);
  498. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  499. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  500. return texture;
  501. };
  502. // Creates and returns an array of meshes used as shells for the Fur Material
  503. // that can be disposed later in your code
  504. // The quality is in interval [0, 100]
  505. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  506. var meshes = [sourceMesh];
  507. var mat = sourceMesh.material;
  508. if (!(mat instanceof FurMaterial)) {
  509. throw "The material of the source mesh must be a Fur Material";
  510. }
  511. for (var i = 1; i < quality; i++) {
  512. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  513. offsetFur.furLength = mat.furLength;
  514. offsetFur.furAngle = mat.furAngle;
  515. offsetFur.furGravity = mat.furGravity;
  516. offsetFur.furSpacing = mat.furSpacing;
  517. offsetFur.furSpeed = mat.furSpeed;
  518. offsetFur.furColor = mat.furColor;
  519. offsetFur.diffuseTexture = mat.diffuseTexture;
  520. offsetFur.furOffset = i / quality;
  521. offsetFur.furTexture = mat.furTexture;
  522. offsetFur.highLevelFur = mat.highLevelFur;
  523. offsetFur.furTime = mat.furTime;
  524. offsetFur.furDensity = mat.furDensity;
  525. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  526. offsetMesh.material = offsetFur;
  527. offsetMesh.skeleton = sourceMesh.skeleton;
  528. offsetMesh.parent = sourceMesh;
  529. meshes.push(offsetMesh);
  530. }
  531. return meshes;
  532. };
  533. __decorate([
  534. BABYLON.serialize()
  535. ], FurMaterial.prototype, "furLength");
  536. __decorate([
  537. BABYLON.serialize()
  538. ], FurMaterial.prototype, "furAngle");
  539. __decorate([
  540. BABYLON.serializeAsColor3()
  541. ], FurMaterial.prototype, "furColor");
  542. __decorate([
  543. BABYLON.serialize()
  544. ], FurMaterial.prototype, "furOffset");
  545. __decorate([
  546. BABYLON.serialize()
  547. ], FurMaterial.prototype, "furSpacing");
  548. __decorate([
  549. BABYLON.serializeAsVector3()
  550. ], FurMaterial.prototype, "furGravity");
  551. __decorate([
  552. BABYLON.serialize()
  553. ], FurMaterial.prototype, "furSpeed");
  554. __decorate([
  555. BABYLON.serialize()
  556. ], FurMaterial.prototype, "furDensity");
  557. __decorate([
  558. BABYLON.serializeAsTexture()
  559. ], FurMaterial.prototype, "furTexture");
  560. __decorate([
  561. BABYLON.serialize()
  562. ], FurMaterial.prototype, "disableLighting");
  563. __decorate([
  564. BABYLON.serialize()
  565. ], FurMaterial.prototype, "highLevelFur");
  566. Object.defineProperty(FurMaterial.prototype, "furTime",
  567. __decorate([
  568. BABYLON.serialize()
  569. ], FurMaterial.prototype, "furTime", Object.getOwnPropertyDescriptor(FurMaterial.prototype, "furTime")));
  570. return FurMaterial;
  571. })(BABYLON.Material);
  572. BABYLON.FurMaterial = FurMaterial;
  573. })(BABYLON || (BABYLON = {}));
  574. BABYLON.Effect.ShadersStore['furVertexShader'] = "precision highp 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#ifdef BONES\nattribute vec4 matricesIndices;\nattribute vec4 matricesWeights;\n#endif\n\nuniform float furLength;\nuniform float furAngle;\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform vec3 furGravity;\nuniform float furTime;\nuniform float furSpacing;\nuniform float furDensity;\n#endif\n#ifdef HEIGHTMAP\nuniform sampler2D heightTexture;\n#endif\n#ifdef HIGHLEVEL\nvarying vec2 vFurUV;\n#endif\n#ifdef INSTANCES\nattribute vec4 world0;\nattribute vec4 world1;\nattribute vec4 world2;\nattribute vec4 world3;\n#else\nuniform mat4 world;\n#endif\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\n#endif\n#ifdef BONES\nuniform mat4 mBones[BonesPerMesh];\n#endif\n#ifdef POINTSIZE\nuniform float pointSize;\n#endif\n\nvarying vec3 vPositionW;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\nvarying float vfur_length;\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n#ifdef CLIPPLANE\nuniform vec4 vClipPlane;\nvarying float fClipDistance;\n#endif\n#ifdef FOG\nvarying float fFogDistance;\n#endif\n#ifdef SHADOWS\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\nuniform mat4 lightMatrix0;\nvarying vec4 vPositionFromLight0;\n#endif\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\nuniform mat4 lightMatrix1;\nvarying vec4 vPositionFromLight1;\n#endif\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\nuniform mat4 lightMatrix2;\nvarying vec4 vPositionFromLight2;\n#endif\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\nuniform mat4 lightMatrix3;\nvarying vec4 vPositionFromLight3;\n#endif\n#endif\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\nmat4 finalWorld;\n#ifdef INSTANCES\nfinalWorld=mat4(world0,world1,world2,world3);\n#else\nfinalWorld=world;\n#endif\n#ifdef BONES\nmat4 m0=mBones[int(matricesIndices.x)]*matricesWeights.x;\nmat4 m1=mBones[int(matricesIndices.y)]*matricesWeights.y;\nmat4 m2=mBones[int(matricesIndices.z)]*matricesWeights.z;\n#ifdef BONES4\nmat4 m3=mBones[int(matricesIndices.w)]*matricesWeights.w;\nfinalWorld=finalWorld*(m0+m1+m2+m3);\n#else\nfinalWorld=finalWorld*(m0+m1+m2);\n#endif \n#endif\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP \nvfur_length=furLength*texture2D(heightTexture,uv).rgb.x;\n#else \nvfur_length=(furLength*r);\n#endif\nvec3 tangent1=vec3(normal.y,-normal.x,0);\nvec3 tangent2=vec3(-normal.z,0,normal.x);\nr=Rand(tangent1*r);\nfloat J=(2.0+4.0*r);\nr=Rand(tangent2*r);\nfloat K=(2.0+2.0*r);\ntangent1=tangent1*J+tangent2*K;\ntangent1=normalize(tangent1);\nvec3 newPosition=position+normal*vfur_length*cos(furAngle)+tangent1*vfur_length*sin(furAngle);\n#ifdef HIGHLEVEL\n\nvec3 forceDirection=vec3(0.0,0.0,0.0);\nforceDirection.x=sin(furTime+position.x*0.05)*0.2;\nforceDirection.y=cos(furTime*0.7+position.y*0.04)*0.2;\nforceDirection.z=sin(furTime*0.7+position.z*0.04)*0.2;\nvec3 displacement=vec3(0.0,0.0,0.0);\ndisplacement=furGravity+forceDirection;\nfloat displacementFactor=pow(furOffset,3.0);\nvec3 aNormal=normal;\naNormal.xyz+=displacement*displacementFactor;\nnewPosition=vec3(newPosition.x,newPosition.y,newPosition.z)+(normalize(aNormal)*furOffset*furSpacing);\n#endif\n#ifdef NORMAL\n#ifdef HIGHLEVEL\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0))*aNormal);\n#else\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\n#endif\n#endif\n\ngl_Position=viewProjection*finalWorld*vec4(newPosition,1.0);\nvec4 worldPos=finalWorld*vec4(newPosition,1.0);\nvPositionW=vec3(worldPos);\n\n#ifndef UV1\nvec2 uv=vec2(0.,0.);\n#endif\n#ifndef UV2\nvec2 uv2=vec2(0.,0.);\n#endif\n#ifdef DIFFUSE\nif (vDiffuseInfos.x == 0.)\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv,1.0,0.0));\n}\nelse\n{\nvDiffuseUV=vec2(diffuseMatrix*vec4(uv2,1.0,0.0));\n}\n#ifdef HIGHLEVEL\nvFurUV=vDiffuseUV*furDensity;\n#endif\n#else\n#ifdef HIGHLEVEL\nvFurUV=uv*furDensity;\n#endif\n#endif\n\n#ifdef CLIPPLANE\nfClipDistance=dot(worldPos,vClipPlane);\n#endif\n\n#ifdef FOG\nfFogDistance=(view*worldPos).z;\n#endif\n\n#ifdef SHADOWS\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\nvPositionFromLight0=lightMatrix0*worldPos;\n#endif\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\nvPositionFromLight1=lightMatrix1*worldPos;\n#endif\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\nvPositionFromLight2=lightMatrix2*worldPos;\n#endif\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\nvPositionFromLight3=lightMatrix3*worldPos;\n#endif\n#endif\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  575. BABYLON.Effect.ShadersStore['furPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nvarying vec3 vPositionW;\nvarying float vfur_length;\n#ifdef NORMAL\nvarying vec3 vNormalW;\n#endif\n#ifdef VERTEXCOLOR\nvarying vec4 vColor;\n#endif\n\n#ifdef LIGHT0\nuniform vec4 vLightData0;\nuniform vec4 vLightDiffuse0;\n#ifdef SHADOW0\n#if defined(SPOTLIGHT0) || defined(DIRLIGHT0)\nvarying vec4 vPositionFromLight0;\nuniform sampler2D shadowSampler0;\n#else\nuniform samplerCube shadowSampler0;\n#endif\nuniform vec3 shadowsInfo0;\n#endif\n#ifdef SPOTLIGHT0\nuniform vec4 vLightDirection0;\n#endif\n#ifdef HEMILIGHT0\nuniform vec3 vLightGround0;\n#endif\n#endif\n#ifdef LIGHT1\nuniform vec4 vLightData1;\nuniform vec4 vLightDiffuse1;\n#ifdef SHADOW1\n#if defined(SPOTLIGHT1) || defined(DIRLIGHT1)\nvarying vec4 vPositionFromLight1;\nuniform sampler2D shadowSampler1;\n#else\nuniform samplerCube shadowSampler1;\n#endif\nuniform vec3 shadowsInfo1;\n#endif\n#ifdef SPOTLIGHT1\nuniform vec4 vLightDirection1;\n#endif\n#ifdef HEMILIGHT1\nuniform vec3 vLightGround1;\n#endif\n#endif\n#ifdef LIGHT2\nuniform vec4 vLightData2;\nuniform vec4 vLightDiffuse2;\n#ifdef SHADOW2\n#if defined(SPOTLIGHT2) || defined(DIRLIGHT2)\nvarying vec4 vPositionFromLight2;\nuniform sampler2D shadowSampler2;\n#else\nuniform samplerCube shadowSampler2;\n#endif\nuniform vec3 shadowsInfo2;\n#endif\n#ifdef SPOTLIGHT2\nuniform vec4 vLightDirection2;\n#endif\n#ifdef HEMILIGHT2\nuniform vec3 vLightGround2;\n#endif\n#endif\n#ifdef LIGHT3\nuniform vec4 vLightData3;\nuniform vec4 vLightDiffuse3;\n#ifdef SHADOW3\n#if defined(SPOTLIGHT3) || defined(DIRLIGHT3)\nvarying vec4 vPositionFromLight3;\nuniform sampler2D shadowSampler3;\n#else\nuniform samplerCube shadowSampler3;\n#endif\nuniform vec3 shadowsInfo3;\n#endif\n#ifdef SPOTLIGHT3\nuniform vec4 vLightDirection3;\n#endif\n#ifdef HEMILIGHT3\nuniform vec3 vLightGround3;\n#endif\n#endif\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\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)\nfloat computeShadowCube(vec3 lightPosition,samplerCube shadowSampler,float darkness,float bias)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=clamp(depth,0.,1.);\ndirectionToLight.y=1.0-directionToLight.y;\nfloat shadow=unpack(textureCube(shadowSampler,directionToLight))+bias;\nif (depth>shadow)\n{\nreturn darkness;\n}\nreturn 1.0;\n}\nfloat computeShadowWithPCFCube(vec3 lightPosition,samplerCube shadowSampler,float bias,float darkness)\n{\nvec3 directionToLight=vPositionW-lightPosition;\nfloat depth=length(directionToLight);\ndepth=clamp(depth,0.,1.);\ndirectionToLight.y=1.0-directionToLight.y;\nfloat visibility=1.;\nvec3 poissonDisk[4];\npoissonDisk[0]=vec3(-0.094201624,0.04,-0.039906216);\npoissonDisk[1]=vec3(0.094558609,-0.04,-0.076890725);\npoissonDisk[2]=vec3(-0.094184101,0.01,-0.092938870);\npoissonDisk[3]=vec3(0.034495938,-0.01,0.029387760);\n\nfloat biasedDepth=depth-bias;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[0]))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[1]))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[2]))<biasedDepth) visibility-=0.25;\nif (unpack(textureCube(shadowSampler,directionToLight+poissonDisk[3]))<biasedDepth) visibility-=0.25;\nreturn min(1.0,visibility+darkness);\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{\nreturn darkness;\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;\nreturn min(1.0,visibility+darkness);\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));\nreturn min(1.0,1.0-ChebychevInequality(moments,depth.z,bias)+darkness);\n}\n#endif\n#endif\n#ifdef CLIPPLANE\nvarying float fClipDistance;\n#endif\n\n#ifdef FOG\n#define FOGMODE_NONE 0.\n#define FOGMODE_EXP 1.\n#define FOGMODE_EXP2 2.\n#define FOGMODE_LINEAR 3.\n#define E 2.71828\nuniform vec4 vFogInfos;\nuniform vec3 vFogColor;\nvarying float fFogDistance;\nfloat CalcFogFactor()\n{\nfloat fogCoeff=1.0;\nfloat fogStart=vFogInfos.y;\nfloat fogEnd=vFogInfos.z;\nfloat fogDensity=vFogInfos.w;\nif (FOGMODE_LINEAR == vFogInfos.x)\n{\nfogCoeff=(fogEnd-fFogDistance)/(fogEnd-fogStart);\n}\nelse if (FOGMODE_EXP == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fFogDistance*fogDensity);\n}\nelse if (FOGMODE_EXP2 == vFogInfos.x)\n{\nfogCoeff=1.0/pow(E,fFogDistance*fFogDistance*fogDensity*fogDensity);\n}\nreturn clamp(fogCoeff,0.0,1.0);\n}\n#endif\n\nstruct lightingInfo\n{\nvec3 diffuse;\n};\nlightingInfo computeLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,float range) {\nlightingInfo result;\nvec3 lightVectorW;\nfloat attenuation=1.0;\nif (lightData.w == 0.)\n{\nvec3 direction=lightData.xyz-vPositionW;\nattenuation=max(0.,1.0-length(direction)/range);\nlightVectorW=normalize(direction);\n}\nelse\n{\nlightVectorW=normalize(-lightData.xyz);\n}\n\nfloat ndl=max(0.,dot(vNormal,lightVectorW));\nresult.diffuse=ndl*diffuseColor*attenuation;\nreturn result;\n}\nlightingInfo computeSpotLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec4 lightDirection,vec3 diffuseColor,float range) {\nlightingInfo result;\nvec3 direction=lightData.xyz-vPositionW;\nvec3 lightVectorW=normalize(direction);\nfloat attenuation=max(0.,1.0-length(direction)/range);\n\nfloat cosAngle=max(0.,dot(-lightDirection.xyz,lightVectorW));\nfloat spotAtten=0.0;\nif (cosAngle>=lightDirection.w)\n{\ncosAngle=max(0.,pow(cosAngle,lightData.w));\nspotAtten=clamp((cosAngle-lightDirection.w)/(1.-cosAngle),0.0,1.0);\n\nfloat ndl=max(0.,dot(vNormal,-lightDirection.xyz));\nresult.diffuse=ndl*spotAtten*diffuseColor*attenuation;\nreturn result;\n}\nresult.diffuse=vec3(0.);\nreturn result;\n}\nlightingInfo computeHemisphericLighting(vec3 viewDirectionW,vec3 vNormal,vec4 lightData,vec3 diffuseColor,vec3 groundColor) {\nlightingInfo result;\n\nfloat ndl=dot(vNormal,lightData.xyz)*0.5+0.5;\nresult.diffuse=mix(groundColor,diffuseColor,ndl);\nreturn result;\n}\nfloat Rand(vec3 rv) {\nfloat x=dot(rv,vec3(12.9898,78.233,24.65487));\nreturn fract(sin(x)*43758.5453);\n}\nvoid main(void) {\n\n#ifdef CLIPPLANE\nif (fClipDistance>0.0)\ndiscard;\n#endif\nvec3 viewDirectionW=normalize(vEyePosition-vPositionW);\n\nvec4 baseColor=furColor;\nvec3 diffuseColor=vDiffuseColor.rgb;\n\nfloat alpha=vDiffuseColor.a;\n#ifdef DIFFUSE\nbaseColor*=texture2D(diffuseSampler,vDiffuseUV);\n#ifdef ALPHATEST\nif (baseColor.a<0.4)\ndiscard;\n#endif\nbaseColor.rgb*=vDiffuseInfos.y;\n#endif\n#ifdef VERTEXCOLOR\nbaseColor.rgb*=vColor.rgb;\n#endif\n\n#ifdef NORMAL\nvec3 normalW=normalize(vNormalW);\n#else\nvec3 normalW=vec3(1.0,1.0,1.0);\n#endif\n#ifdef HIGHLEVEL\n\nvec4 furTextureColor=texture2D(furTexture,vec2(vFurUV.x,vFurUV.y));\nif (furTextureColor.a<=0.0 || furTextureColor.g<furOffset) {\ndiscard;\n}\nfloat occlusion=mix(0.0,furTextureColor.b*1.2,furOffset);\nbaseColor=vec4(baseColor.xyz*occlusion,1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nfloat shadow=1.;\n#ifdef LIGHT0\n#ifdef SPOTLIGHT0\nlightingInfo info=computeSpotLighting(viewDirectionW,normalW,vLightData0,vLightDirection0,vLightDiffuse0.rgb,vLightDiffuse0.a);\n#endif\n#ifdef HEMILIGHT0\nlightingInfo info=computeHemisphericLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightGround0);\n#endif\n#if defined(POINTLIGHT0) || defined(DIRLIGHT0)\nlightingInfo info=computeLighting(viewDirectionW,normalW,vLightData0,vLightDiffuse0.rgb,vLightDiffuse0.a);\n#endif\n#ifdef SHADOW0\n#ifdef SHADOWVSM0\nshadow=computeShadowWithVSM(vPositionFromLight0,shadowSampler0,shadowsInfo0.z,shadowsInfo0.x);\n#else\n#ifdef SHADOWPCF0\n#if defined(POINTLIGHT0)\nshadow=computeShadowWithPCFCube(vLightData0.xyz,shadowSampler0,shadowsInfo0.z,shadowsInfo0.x);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight0,shadowSampler0,shadowsInfo0.y,shadowsInfo0.z,shadowsInfo0.x);\n#endif\n#else\n#if defined(POINTLIGHT0)\nshadow=computeShadowCube(vLightData0.xyz,shadowSampler0,shadowsInfo0.x,shadowsInfo0.z);\n#else\nshadow=computeShadow(vPositionFromLight0,shadowSampler0,shadowsInfo0.x,shadowsInfo0.z);\n#endif\n#endif\n#endif\n#else\nshadow=1.;\n#endif\ndiffuseBase+=info.diffuse*shadow;\n#endif\n#ifdef LIGHT1\n#ifdef SPOTLIGHT1\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData1,vLightDirection1,vLightDiffuse1.rgb,vLightDiffuse1.a);\n#endif\n#ifdef HEMILIGHT1\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightGround1.a);\n#endif\n#if defined(POINTLIGHT1) || defined(DIRLIGHT1)\ninfo=computeLighting(viewDirectionW,normalW,vLightData1,vLightDiffuse1.rgb,vLightDiffuse1.a);\n#endif\n#ifdef SHADOW1\n#ifdef SHADOWVSM1\nshadow=computeShadowWithVSM(vPositionFromLight1,shadowSampler1,shadowsInfo1.z,shadowsInfo1.x);\n#else\n#ifdef SHADOWPCF1\n#if defined(POINTLIGHT1)\nshadow=computeShadowWithPCFCube(vLightData1.xyz,shadowSampler1,shadowsInfo1.z,shadowsInfo1.x);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight1,shadowSampler1,shadowsInfo1.y,shadowsInfo1.z,shadowsInfo1.x);\n#endif\n#else\n#if defined(POINTLIGHT1)\nshadow=computeShadowCube(vLightData1.xyz,shadowSampler1,shadowsInfo1.x,shadowsInfo1.z);\n#else\nshadow=computeShadow(vPositionFromLight1,shadowSampler1,shadowsInfo1.x,shadowsInfo1.z);\n#endif\n#endif\n#endif\n#else\nshadow=1.;\n#endif\ndiffuseBase+=info.diffuse*shadow;\n#endif\n#ifdef LIGHT2\n#ifdef SPOTLIGHT2\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData2,vLightDirection2,vLightDiffuse2.rgb,vLightDiffuse2.a);\n#endif\n#ifdef HEMILIGHT2\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightGround2);\n#endif\n#if defined(POINTLIGHT2) || defined(DIRLIGHT2)\ninfo=computeLighting(viewDirectionW,normalW,vLightData2,vLightDiffuse2.rgb,vLightDiffuse2.a);\n#endif\n#ifdef SHADOW2\n#ifdef SHADOWVSM2\nshadow=computeShadowWithVSM(vPositionFromLight2,shadowSampler2,shadowsInfo2.z,shadowsInfo2.x);\n#else\n#ifdef SHADOWPCF2\n#if defined(POINTLIGHT2)\nshadow=computeShadowWithPCFCube(vLightData2.xyz,shadowSampler2,shadowsInfo2.z,shadowsInfo2.x);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight2,shadowSampler2,shadowsInfo2.y,shadowsInfo2.z,shadowsInfo2.x);\n#endif\n#else\n#if defined(POINTLIGHT2)\nshadow=computeShadowCube(vLightData2.xyz,shadowSampler2,shadowsInfo2.x,shadowsInfo2.z);\n#else\nshadow=computeShadow(vPositionFromLight2,shadowSampler2,shadowsInfo2.x,shadowsInfo2.z);\n#endif\n#endif \n#endif \n#else\nshadow=1.;\n#endif\ndiffuseBase+=info.diffuse*shadow;\n#endif\n#ifdef LIGHT3\n#ifdef SPOTLIGHT3\ninfo=computeSpotLighting(viewDirectionW,normalW,vLightData3,vLightDirection3,vLightDiffuse3.rgb,vLightDiffuse3.a);\n#endif\n#ifdef HEMILIGHT3\ninfo=computeHemisphericLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightGround3);\n#endif\n#if defined(POINTLIGHT3) || defined(DIRLIGHT3)\ninfo=computeLighting(viewDirectionW,normalW,vLightData3,vLightDiffuse3.rgb,vLightDiffuse3.a);\n#endif\n#ifdef SHADOW3\n#ifdef SHADOWVSM3\nshadow=computeShadowWithVSM(vPositionFromLight3,shadowSampler3,shadowsInfo3.z,shadowsInfo3.x);\n#else\n#ifdef SHADOWPCF3\n#if defined(POINTLIGHT3)\nshadow=computeShadowWithPCFCube(vLightData3.xyz,shadowSampler3,shadowsInfo3.z,shadowsInfo3.x);\n#else\nshadow=computeShadowWithPCF(vPositionFromLight3,shadowSampler3,shadowsInfo3.y,shadowsInfo3.z,shadowsInfo3.x);\n#endif\n#else\n#if defined(POINTLIGHT3)\nshadow=computeShadowCube(vLightData3.xyz,shadowSampler3,shadowsInfo3.x,shadowsInfo3.z);\n#else\nshadow=computeShadow(vPositionFromLight3,shadowSampler3,shadowsInfo3.x,shadowsInfo3.z);\n#endif\n#endif \n#endif \n#else\nshadow=1.;\n#endif\ndiffuseBase+=info.diffuse*shadow;\n#endif\n#ifdef VERTEXALPHA\nalpha*=vColor.a;\n#endif\nvec3 finalDiffuse=clamp(diffuseBase.rgb*baseColor.rgb,0.0,1.0);\n\n#ifdef HIGHLEVEL\nvec4 color=vec4(finalDiffuse,alpha);\n#else\nfloat r=vfur_length*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#ifdef FOG\nfloat fog=CalcFogFactor();\ncolor.rgb=fog*color.rgb+(1.0-fog)*vFogColor;\n#endif\ngl_FragColor=color;\n}";