babylon.furMaterial.js 26 KB

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