babylon.furMaterial.js 26 KB

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