babylon.furMaterial.js 27 KB

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