babylon.furMaterial.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486
  1. /// <reference path="../../../dist/preview release/babylon.d.ts"/>
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. }
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
  16. var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
  17. if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
  18. else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
  19. return c > 3 && r && Object.defineProperty(target, key, r), r;
  20. };
  21. var BABYLON;
  22. (function (BABYLON) {
  23. var FurMaterialDefines = /** @class */ (function (_super) {
  24. __extends(FurMaterialDefines, _super);
  25. function FurMaterialDefines() {
  26. var _this = _super.call(this) || this;
  27. _this.DIFFUSE = false;
  28. _this.HEIGHTMAP = false;
  29. _this.CLIPPLANE = false;
  30. _this.CLIPPLANE2 = false;
  31. _this.CLIPPLANE3 = false;
  32. _this.CLIPPLANE4 = false;
  33. _this.ALPHATEST = false;
  34. _this.DEPTHPREPASS = false;
  35. _this.POINTSIZE = false;
  36. _this.FOG = false;
  37. _this.NORMAL = false;
  38. _this.UV1 = false;
  39. _this.UV2 = false;
  40. _this.VERTEXCOLOR = false;
  41. _this.VERTEXALPHA = false;
  42. _this.NUM_BONE_INFLUENCERS = 0;
  43. _this.BonesPerMesh = 0;
  44. _this.INSTANCES = false;
  45. _this.HIGHLEVEL = false;
  46. _this.rebuild();
  47. return _this;
  48. }
  49. return FurMaterialDefines;
  50. }(BABYLON.MaterialDefines));
  51. var FurMaterial = /** @class */ (function (_super) {
  52. __extends(FurMaterial, _super);
  53. function FurMaterial(name, scene) {
  54. var _this = _super.call(this, name, scene) || this;
  55. _this.diffuseColor = new BABYLON.Color3(1, 1, 1);
  56. _this.furLength = 1;
  57. _this.furAngle = 0;
  58. _this.furColor = new BABYLON.Color3(0.44, 0.21, 0.02);
  59. _this.furOffset = 0.0;
  60. _this.furSpacing = 12;
  61. _this.furGravity = new BABYLON.Vector3(0, 0, 0);
  62. _this.furSpeed = 100;
  63. _this.furDensity = 20;
  64. _this.furOcclusion = 0.0;
  65. _this._disableLighting = false;
  66. _this._maxSimultaneousLights = 4;
  67. _this.highLevelFur = true;
  68. _this._furTime = 0;
  69. return _this;
  70. }
  71. Object.defineProperty(FurMaterial.prototype, "furTime", {
  72. get: function () {
  73. return this._furTime;
  74. },
  75. set: function (furTime) {
  76. this._furTime = furTime;
  77. },
  78. enumerable: true,
  79. configurable: true
  80. });
  81. FurMaterial.prototype.needAlphaBlending = function () {
  82. return (this.alpha < 1.0);
  83. };
  84. FurMaterial.prototype.needAlphaTesting = function () {
  85. return false;
  86. };
  87. FurMaterial.prototype.getAlphaTestTexture = function () {
  88. return null;
  89. };
  90. FurMaterial.prototype.updateFur = function () {
  91. for (var i = 1; i < this._meshes.length; i++) {
  92. var offsetFur = this._meshes[i].material;
  93. offsetFur.furLength = this.furLength;
  94. offsetFur.furAngle = this.furAngle;
  95. offsetFur.furGravity = this.furGravity;
  96. offsetFur.furSpacing = this.furSpacing;
  97. offsetFur.furSpeed = this.furSpeed;
  98. offsetFur.furColor = this.furColor;
  99. offsetFur.diffuseTexture = this.diffuseTexture;
  100. offsetFur.furTexture = this.furTexture;
  101. offsetFur.highLevelFur = this.highLevelFur;
  102. offsetFur.furTime = this.furTime;
  103. offsetFur.furDensity = this.furDensity;
  104. }
  105. };
  106. // Methods
  107. FurMaterial.prototype.isReadyForSubMesh = function (mesh, subMesh, useInstances) {
  108. if (this.isFrozen) {
  109. if (this._wasPreviouslyReady && subMesh.effect) {
  110. return true;
  111. }
  112. }
  113. if (!subMesh._materialDefines) {
  114. subMesh._materialDefines = new FurMaterialDefines();
  115. }
  116. var defines = subMesh._materialDefines;
  117. var scene = this.getScene();
  118. if (!this.checkReadyOnEveryCall && subMesh.effect) {
  119. if (this._renderId === scene.getRenderId()) {
  120. return true;
  121. }
  122. }
  123. var engine = scene.getEngine();
  124. // Textures
  125. if (defines._areTexturesDirty) {
  126. if (scene.texturesEnabled) {
  127. if (this.diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  128. if (!this.diffuseTexture.isReady()) {
  129. return false;
  130. }
  131. else {
  132. defines._needUVs = true;
  133. defines.DIFFUSE = true;
  134. }
  135. }
  136. if (this.heightTexture && engine.getCaps().maxVertexTextureImageUnits) {
  137. if (!this.heightTexture.isReady()) {
  138. return false;
  139. }
  140. else {
  141. defines._needUVs = true;
  142. defines.HEIGHTMAP = true;
  143. }
  144. }
  145. }
  146. }
  147. // High level
  148. if (this.highLevelFur !== defines.HIGHLEVEL) {
  149. defines.HIGHLEVEL = true;
  150. defines.markAsUnprocessed();
  151. }
  152. // Misc.
  153. BABYLON.MaterialHelper.PrepareDefinesForMisc(mesh, scene, false, this.pointsCloud, this.fogEnabled, this._shouldTurnAlphaTestOn(mesh), defines);
  154. // Lights
  155. defines._needNormals = BABYLON.MaterialHelper.PrepareDefinesForLights(scene, mesh, defines, false, this._maxSimultaneousLights, this._disableLighting);
  156. // Values that need to be evaluated on every frame
  157. BABYLON.MaterialHelper.PrepareDefinesForFrameBoundValues(scene, engine, defines, useInstances ? true : false);
  158. // Attribs
  159. BABYLON.MaterialHelper.PrepareDefinesForAttributes(mesh, defines, true, true);
  160. // Get correct effect
  161. if (defines.isDirty) {
  162. defines.markAsProcessed();
  163. scene.resetCachedMaterial();
  164. // Fallbacks
  165. var fallbacks = new BABYLON.EffectFallbacks();
  166. if (defines.FOG) {
  167. fallbacks.addFallback(1, "FOG");
  168. }
  169. BABYLON.MaterialHelper.HandleFallbacksForShadows(defines, fallbacks, this.maxSimultaneousLights);
  170. if (defines.NUM_BONE_INFLUENCERS > 0) {
  171. fallbacks.addCPUSkinningFallback(0, mesh);
  172. }
  173. //Attributes
  174. var attribs = [BABYLON.VertexBuffer.PositionKind];
  175. if (defines.NORMAL) {
  176. attribs.push(BABYLON.VertexBuffer.NormalKind);
  177. }
  178. if (defines.UV1) {
  179. attribs.push(BABYLON.VertexBuffer.UVKind);
  180. }
  181. if (defines.UV2) {
  182. attribs.push(BABYLON.VertexBuffer.UV2Kind);
  183. }
  184. if (defines.VERTEXCOLOR) {
  185. attribs.push(BABYLON.VertexBuffer.ColorKind);
  186. }
  187. BABYLON.MaterialHelper.PrepareAttributesForBones(attribs, mesh, defines, fallbacks);
  188. BABYLON.MaterialHelper.PrepareAttributesForInstances(attribs, defines);
  189. // Legacy browser patch
  190. var shaderName = "fur";
  191. var join = defines.toString();
  192. var uniforms = ["world", "view", "viewProjection", "vEyePosition", "vLightsType", "vDiffuseColor",
  193. "vFogInfos", "vFogColor", "pointSize",
  194. "vDiffuseInfos",
  195. "mBones",
  196. "vClipPlane", "vClipPlane2", "vClipPlane3", "vClipPlane4", "diffuseMatrix",
  197. "furLength", "furAngle", "furColor", "furOffset", "furGravity", "furTime", "furSpacing", "furDensity", "furOcclusion"
  198. ];
  199. var samplers = ["diffuseSampler",
  200. "heightTexture", "furTexture"
  201. ];
  202. var uniformBuffers = new Array();
  203. BABYLON.MaterialHelper.PrepareUniformsAndSamplersList({
  204. uniformsNames: uniforms,
  205. uniformBuffersNames: uniformBuffers,
  206. samplers: samplers,
  207. defines: defines,
  208. maxSimultaneousLights: this.maxSimultaneousLights
  209. });
  210. subMesh.setEffect(scene.getEngine().createEffect(shaderName, {
  211. attributes: attribs,
  212. uniformsNames: uniforms,
  213. uniformBuffersNames: uniformBuffers,
  214. samplers: samplers,
  215. defines: join,
  216. fallbacks: fallbacks,
  217. onCompiled: this.onCompiled,
  218. onError: this.onError,
  219. indexParameters: { maxSimultaneousLights: this.maxSimultaneousLights }
  220. }, engine), defines);
  221. }
  222. if (!subMesh.effect || !subMesh.effect.isReady()) {
  223. return false;
  224. }
  225. this._renderId = scene.getRenderId();
  226. this._wasPreviouslyReady = true;
  227. return true;
  228. };
  229. FurMaterial.prototype.bindForSubMesh = function (world, mesh, subMesh) {
  230. var scene = this.getScene();
  231. var defines = subMesh._materialDefines;
  232. if (!defines) {
  233. return;
  234. }
  235. var effect = subMesh.effect;
  236. if (!effect) {
  237. return;
  238. }
  239. this._activeEffect = effect;
  240. // Matrices
  241. this.bindOnlyWorldMatrix(world);
  242. this._activeEffect.setMatrix("viewProjection", scene.getTransformMatrix());
  243. // Bones
  244. BABYLON.MaterialHelper.BindBonesParameters(mesh, this._activeEffect);
  245. if (scene.getCachedMaterial() !== this) {
  246. // Textures
  247. if (this._diffuseTexture && BABYLON.StandardMaterial.DiffuseTextureEnabled) {
  248. this._activeEffect.setTexture("diffuseSampler", this._diffuseTexture);
  249. this._activeEffect.setFloat2("vDiffuseInfos", this._diffuseTexture.coordinatesIndex, this._diffuseTexture.level);
  250. this._activeEffect.setMatrix("diffuseMatrix", this._diffuseTexture.getTextureMatrix());
  251. }
  252. if (this._heightTexture) {
  253. this._activeEffect.setTexture("heightTexture", this._heightTexture);
  254. }
  255. // Clip plane
  256. BABYLON.MaterialHelper.BindClipPlane(this._activeEffect, scene);
  257. // Point size
  258. if (this.pointsCloud) {
  259. this._activeEffect.setFloat("pointSize", this.pointSize);
  260. }
  261. BABYLON.MaterialHelper.BindEyePosition(effect, scene);
  262. }
  263. this._activeEffect.setColor4("vDiffuseColor", this.diffuseColor, this.alpha * mesh.visibility);
  264. if (scene.lightsEnabled && !this.disableLighting) {
  265. BABYLON.MaterialHelper.BindLights(scene, mesh, this._activeEffect, defines, this.maxSimultaneousLights);
  266. }
  267. // View
  268. if (scene.fogEnabled && mesh.applyFog && scene.fogMode !== BABYLON.Scene.FOGMODE_NONE) {
  269. this._activeEffect.setMatrix("view", scene.getViewMatrix());
  270. }
  271. // Fog
  272. BABYLON.MaterialHelper.BindFogParameters(scene, mesh, this._activeEffect);
  273. this._activeEffect.setFloat("furLength", this.furLength);
  274. this._activeEffect.setFloat("furAngle", this.furAngle);
  275. this._activeEffect.setColor4("furColor", this.furColor, 1.0);
  276. if (this.highLevelFur) {
  277. this._activeEffect.setVector3("furGravity", this.furGravity);
  278. this._activeEffect.setFloat("furOffset", this.furOffset);
  279. this._activeEffect.setFloat("furSpacing", this.furSpacing);
  280. this._activeEffect.setFloat("furDensity", this.furDensity);
  281. this._activeEffect.setFloat("furOcclusion", this.furOcclusion);
  282. this._furTime += this.getScene().getEngine().getDeltaTime() / this.furSpeed;
  283. this._activeEffect.setFloat("furTime", this._furTime);
  284. this._activeEffect.setTexture("furTexture", this.furTexture);
  285. }
  286. this._afterBind(mesh, this._activeEffect);
  287. };
  288. FurMaterial.prototype.getAnimatables = function () {
  289. var results = [];
  290. if (this.diffuseTexture && this.diffuseTexture.animations && this.diffuseTexture.animations.length > 0) {
  291. results.push(this.diffuseTexture);
  292. }
  293. if (this.heightTexture && this.heightTexture.animations && this.heightTexture.animations.length > 0) {
  294. results.push(this.heightTexture);
  295. }
  296. return results;
  297. };
  298. FurMaterial.prototype.getActiveTextures = function () {
  299. var activeTextures = _super.prototype.getActiveTextures.call(this);
  300. if (this._diffuseTexture) {
  301. activeTextures.push(this._diffuseTexture);
  302. }
  303. if (this._heightTexture) {
  304. activeTextures.push(this._heightTexture);
  305. }
  306. return activeTextures;
  307. };
  308. FurMaterial.prototype.hasTexture = function (texture) {
  309. if (_super.prototype.hasTexture.call(this, texture)) {
  310. return true;
  311. }
  312. if (this.diffuseTexture === texture) {
  313. return true;
  314. }
  315. if (this._heightTexture === texture) {
  316. return true;
  317. }
  318. return false;
  319. };
  320. FurMaterial.prototype.dispose = function (forceDisposeEffect) {
  321. if (this.diffuseTexture) {
  322. this.diffuseTexture.dispose();
  323. }
  324. if (this._meshes) {
  325. for (var i = 1; i < this._meshes.length; i++) {
  326. var mat = this._meshes[i].material;
  327. if (mat) {
  328. mat.dispose(forceDisposeEffect);
  329. }
  330. this._meshes[i].dispose();
  331. }
  332. }
  333. _super.prototype.dispose.call(this, forceDisposeEffect);
  334. };
  335. FurMaterial.prototype.clone = function (name) {
  336. var _this = this;
  337. return BABYLON.SerializationHelper.Clone(function () { return new FurMaterial(name, _this.getScene()); }, this);
  338. };
  339. FurMaterial.prototype.serialize = function () {
  340. var serializationObject = BABYLON.SerializationHelper.Serialize(this);
  341. serializationObject.customType = "BABYLON.FurMaterial";
  342. if (this._meshes) {
  343. serializationObject.sourceMeshName = this._meshes[0].name;
  344. serializationObject.quality = this._meshes.length;
  345. }
  346. return serializationObject;
  347. };
  348. FurMaterial.prototype.getClassName = function () {
  349. return "FurMaterial";
  350. };
  351. // Statics
  352. FurMaterial.Parse = function (source, scene, rootUrl) {
  353. var material = BABYLON.SerializationHelper.Parse(function () { return new FurMaterial(source.name, scene); }, source, scene, rootUrl);
  354. if (source.sourceMeshName && material.highLevelFur) {
  355. scene.executeWhenReady(function () {
  356. var sourceMesh = scene.getMeshByName(source.sourceMeshName);
  357. if (sourceMesh) {
  358. var furTexture = FurMaterial.GenerateTexture("Fur Texture", scene);
  359. material.furTexture = furTexture;
  360. FurMaterial.FurifyMesh(sourceMesh, source.quality);
  361. }
  362. });
  363. }
  364. return material;
  365. };
  366. FurMaterial.GenerateTexture = function (name, scene) {
  367. // Generate fur textures
  368. var texture = new BABYLON.DynamicTexture("FurTexture " + name, 256, scene, true);
  369. var context = texture.getContext();
  370. for (var i = 0; i < 20000; ++i) {
  371. context.fillStyle = "rgba(255, " + Math.floor(Math.random() * 255) + ", " + Math.floor(Math.random() * 255) + ", 1)";
  372. context.fillRect((Math.random() * texture.getSize().width), (Math.random() * texture.getSize().height), 2, 2);
  373. }
  374. texture.update(false);
  375. texture.wrapU = BABYLON.Texture.WRAP_ADDRESSMODE;
  376. texture.wrapV = BABYLON.Texture.WRAP_ADDRESSMODE;
  377. return texture;
  378. };
  379. // Creates and returns an array of meshes used as shells for the Fur Material
  380. // that can be disposed later in your code
  381. // The quality is in interval [0, 100]
  382. FurMaterial.FurifyMesh = function (sourceMesh, quality) {
  383. var meshes = [sourceMesh];
  384. var mat = sourceMesh.material;
  385. var i;
  386. if (!(mat instanceof FurMaterial)) {
  387. throw "The material of the source mesh must be a Fur Material";
  388. }
  389. for (i = 1; i < quality; i++) {
  390. var offsetFur = new BABYLON.FurMaterial(mat.name + i, sourceMesh.getScene());
  391. sourceMesh.getScene().materials.pop();
  392. BABYLON.Tags.EnableFor(offsetFur);
  393. BABYLON.Tags.AddTagsTo(offsetFur, "furShellMaterial");
  394. offsetFur.furLength = mat.furLength;
  395. offsetFur.furAngle = mat.furAngle;
  396. offsetFur.furGravity = mat.furGravity;
  397. offsetFur.furSpacing = mat.furSpacing;
  398. offsetFur.furSpeed = mat.furSpeed;
  399. offsetFur.furColor = mat.furColor;
  400. offsetFur.diffuseTexture = mat.diffuseTexture;
  401. offsetFur.furOffset = i / quality;
  402. offsetFur.furTexture = mat.furTexture;
  403. offsetFur.highLevelFur = mat.highLevelFur;
  404. offsetFur.furTime = mat.furTime;
  405. offsetFur.furDensity = mat.furDensity;
  406. var offsetMesh = sourceMesh.clone(sourceMesh.name + i);
  407. offsetMesh.material = offsetFur;
  408. offsetMesh.skeleton = sourceMesh.skeleton;
  409. offsetMesh.position = BABYLON.Vector3.Zero();
  410. meshes.push(offsetMesh);
  411. }
  412. for (i = 1; i < meshes.length; i++) {
  413. meshes[i].parent = sourceMesh;
  414. }
  415. sourceMesh.material._meshes = meshes;
  416. return meshes;
  417. };
  418. __decorate([
  419. BABYLON.serializeAsTexture("diffuseTexture")
  420. ], FurMaterial.prototype, "_diffuseTexture", void 0);
  421. __decorate([
  422. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  423. ], FurMaterial.prototype, "diffuseTexture", void 0);
  424. __decorate([
  425. BABYLON.serializeAsTexture("heightTexture")
  426. ], FurMaterial.prototype, "_heightTexture", void 0);
  427. __decorate([
  428. BABYLON.expandToProperty("_markAllSubMeshesAsTexturesDirty")
  429. ], FurMaterial.prototype, "heightTexture", void 0);
  430. __decorate([
  431. BABYLON.serializeAsColor3()
  432. ], FurMaterial.prototype, "diffuseColor", void 0);
  433. __decorate([
  434. BABYLON.serialize()
  435. ], FurMaterial.prototype, "furLength", void 0);
  436. __decorate([
  437. BABYLON.serialize()
  438. ], FurMaterial.prototype, "furAngle", void 0);
  439. __decorate([
  440. BABYLON.serializeAsColor3()
  441. ], FurMaterial.prototype, "furColor", void 0);
  442. __decorate([
  443. BABYLON.serialize()
  444. ], FurMaterial.prototype, "furOffset", void 0);
  445. __decorate([
  446. BABYLON.serialize()
  447. ], FurMaterial.prototype, "furSpacing", void 0);
  448. __decorate([
  449. BABYLON.serializeAsVector3()
  450. ], FurMaterial.prototype, "furGravity", void 0);
  451. __decorate([
  452. BABYLON.serialize()
  453. ], FurMaterial.prototype, "furSpeed", void 0);
  454. __decorate([
  455. BABYLON.serialize()
  456. ], FurMaterial.prototype, "furDensity", void 0);
  457. __decorate([
  458. BABYLON.serialize()
  459. ], FurMaterial.prototype, "furOcclusion", void 0);
  460. __decorate([
  461. BABYLON.serialize("disableLighting")
  462. ], FurMaterial.prototype, "_disableLighting", void 0);
  463. __decorate([
  464. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  465. ], FurMaterial.prototype, "disableLighting", void 0);
  466. __decorate([
  467. BABYLON.serialize("maxSimultaneousLights")
  468. ], FurMaterial.prototype, "_maxSimultaneousLights", void 0);
  469. __decorate([
  470. BABYLON.expandToProperty("_markAllSubMeshesAsLightsDirty")
  471. ], FurMaterial.prototype, "maxSimultaneousLights", void 0);
  472. __decorate([
  473. BABYLON.serialize()
  474. ], FurMaterial.prototype, "highLevelFur", void 0);
  475. __decorate([
  476. BABYLON.serialize()
  477. ], FurMaterial.prototype, "furTime", null);
  478. return FurMaterial;
  479. }(BABYLON.PushMaterial));
  480. BABYLON.FurMaterial = FurMaterial;
  481. })(BABYLON || (BABYLON = {}));
  482. //# sourceMappingURL=babylon.furMaterial.js.map
  483. 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#include<bonesDeclaration>\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#include<instancesDeclaration>\nuniform mat4 view;\nuniform mat4 viewProjection;\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform mat4 diffuseMatrix;\nuniform vec2 vDiffuseInfos;\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#include<clipPlaneVertexDeclaration>\n#include<fogVertexDeclaration>\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\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#include<instancesVertex>\n#include<bonesVertex>\n\nfloat r=Rand(position);\n#ifdef HEIGHTMAP\n#if __VERSION__>100\nvfur_length=furLength*texture(heightTexture,uv).x;\n#else\nvfur_length=furLength*texture2D(heightTexture,uv).r;\n#endif\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\nvNormalW=normalize(vec3(finalWorld*vec4(normal,0.0)));\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#include<clipPlaneVertex>\n\n#include<fogVertex>\n\n#include<shadowsVertex>[0..maxSimultaneousLights]\n\n#ifdef VERTEXCOLOR\nvColor=color;\n#endif\n\n#ifdef POINTSIZE\ngl_PointSize=pointSize;\n#endif\n}\n";
  484. BABYLON.Effect.ShadersStore['furPixelShader'] = "precision highp float;\n\nuniform vec3 vEyePosition;\nuniform vec4 vDiffuseColor;\n\nuniform vec4 furColor;\nuniform float furLength;\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#include<helperFunctions>\n\n#include<__decl__lightFragment>[0..maxSimultaneousLights]\n\n#ifdef DIFFUSE\nvarying vec2 vDiffuseUV;\nuniform sampler2D diffuseSampler;\nuniform vec2 vDiffuseInfos;\n#endif\n\n#ifdef HIGHLEVEL\nuniform float furOffset;\nuniform float furOcclusion;\nuniform sampler2D furTexture;\nvarying vec2 vFurUV;\n#endif\n#include<lightsFragmentFunctions>\n#include<shadowsFragmentFunctions>\n#include<fogFragmentDeclaration>\n#include<clipPlaneFragmentDeclaration>\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#include<clipPlaneFragment>\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\n#include<depthPrePass>\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*max(occlusion,furOcclusion),1.1-furOffset);\n#endif\n\nvec3 diffuseBase=vec3(0.,0.,0.);\nlightingInfo info;\nfloat shadow=1.;\nfloat glossiness=0.;\n#ifdef SPECULARTERM\nvec3 specularBase=vec3(0.,0.,0.);\n#endif\n#include<lightFragment>[0..maxSimultaneousLights]\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/furLength*0.5;\nvec4 color=vec4(finalDiffuse*(0.5+r),alpha);\n#endif\n#include<fogFragment>\ngl_FragColor=color;\n}";