1 |
- var BABYLON,__extends=this&&this.__extends||(function(){var r=function(e,t){return(r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var i in t)t.hasOwnProperty(i)&&(e[i]=t[i])})(e,t)};return function(e,t){function i(){this.constructor=e}r(e,t),e.prototype=null===t?Object.create(t):(i.prototype=t.prototype,new i)}})(),__decorate=this&&this.__decorate||function(e,t,i,r){var n,f=arguments.length,o=f<3?t:null===r?r=Object.getOwnPropertyDescriptor(t,i):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,i,r);else for(var a=e.length-1;0<=a;a--)(n=e[a])&&(o=(f<3?n(o):3<f?n(t,i,o):n(t,i))||o);return 3<f&&o&&Object.defineProperty(t,i,o),o};!(function(h){var d=(function(t){function e(){var e=t.call(this)||this;return e.DIFFUSE=!1,e.HEIGHTMAP=!1,e.CLIPPLANE=!1,e.CLIPPLANE2=!1,e.CLIPPLANE3=!1,e.CLIPPLANE4=!1,e.ALPHATEST=!1,e.DEPTHPREPASS=!1,e.POINTSIZE=!1,e.FOG=!1,e.NORMAL=!1,e.UV1=!1,e.UV2=!1,e.VERTEXCOLOR=!1,e.VERTEXALPHA=!1,e.NUM_BONE_INFLUENCERS=0,e.BonesPerMesh=0,e.INSTANCES=!1,e.HIGHLEVEL=!1,e.rebuild(),e}return __extends(e,t),e})(h.MaterialDefines),e=(function(r){function a(e,t){var i=r.call(this,e,t)||this;return i.diffuseColor=new h.Color3(1,1,1),i.furLength=1,i.furAngle=0,i.furColor=new h.Color3(.44,.21,.02),i.furOffset=0,i.furSpacing=12,i.furGravity=new h.Vector3(0,0,0),i.furSpeed=100,i.furDensity=20,i.furOcclusion=0,i._disableLighting=!1,i._maxSimultaneousLights=4,i.highLevelFur=!0,i._furTime=0,i}return __extends(a,r),Object.defineProperty(a.prototype,"furTime",{get:function(){return this._furTime},set:function(e){this._furTime=e},enumerable:!0,configurable:!0}),a.prototype.needAlphaBlending=function(){return this.alpha<1},a.prototype.needAlphaTesting=function(){return!1},a.prototype.getAlphaTestTexture=function(){return null},a.prototype.updateFur=function(){for(var e=1;e<this._meshes.length;e++){var t=this._meshes[e].material;t.furLength=this.furLength,t.furAngle=this.furAngle,t.furGravity=this.furGravity,t.furSpacing=this.furSpacing,t.furSpeed=this.furSpeed,t.furColor=this.furColor,t.diffuseTexture=this.diffuseTexture,t.furTexture=this.furTexture,t.highLevelFur=this.highLevelFur,t.furTime=this.furTime,t.furDensity=this.furDensity}},a.prototype.isReadyForSubMesh=function(e,t,i){if(this.isFrozen&&this._wasPreviouslyReady&&t.effect)return!0;t._materialDefines||(t._materialDefines=new d);var r=t._materialDefines,n=this.getScene();if(!this.checkReadyOnEveryCall&&t.effect&&this._renderId===n.getRenderId())return!0;var f=n.getEngine();if(r._areTexturesDirty&&n.texturesEnabled){if(this.diffuseTexture&&h.StandardMaterial.DiffuseTextureEnabled){if(!this.diffuseTexture.isReady())return!1;r._needUVs=!0,r.DIFFUSE=!0}if(this.heightTexture&&f.getCaps().maxVertexTextureImageUnits){if(!this.heightTexture.isReady())return!1;r._needUVs=!0,r.HEIGHTMAP=!0}}if(this.highLevelFur!==r.HIGHLEVEL&&(r.HIGHLEVEL=!0,r.markAsUnprocessed()),h.MaterialHelper.PrepareDefinesForMisc(e,n,!1,this.pointsCloud,this.fogEnabled,this._shouldTurnAlphaTestOn(e),r),r._needNormals=h.MaterialHelper.PrepareDefinesForLights(n,e,r,!1,this._maxSimultaneousLights,this._disableLighting),h.MaterialHelper.PrepareDefinesForFrameBoundValues(n,f,r,!!i),h.MaterialHelper.PrepareDefinesForAttributes(e,r,!0,!0),r.isDirty){r.markAsProcessed(),n.resetCachedMaterial();var o=new h.EffectFallbacks;r.FOG&&o.addFallback(1,"FOG"),h.MaterialHelper.HandleFallbacksForShadows(r,o,this.maxSimultaneousLights),0<r.NUM_BONE_INFLUENCERS&&o.addCPUSkinningFallback(0,e);var a=[h.VertexBuffer.PositionKind];r.NORMAL&&a.push(h.VertexBuffer.NormalKind),r.UV1&&a.push(h.VertexBuffer.UVKind),r.UV2&&a.push(h.VertexBuffer.UV2Kind),r.VERTEXCOLOR&&a.push(h.VertexBuffer.ColorKind),h.MaterialHelper.PrepareAttributesForBones(a,e,r,o),h.MaterialHelper.PrepareAttributesForInstances(a,r);var s=r.toString(),u=["world","view","viewProjection","vEyePosition","vLightsType","vDiffuseColor","vFogInfos","vFogColor","pointSize","vDiffuseInfos","mBones","vClipPlane","vClipPlane2","vClipPlane3","vClipPlane4","diffuseMatrix","furLength","furAngle","furColor","furOffset","furGravity","furTime","furSpacing","furDensity","furOcclusion"],l=["diffuseSampler","heightTexture","furTexture"],c=new Array;h.MaterialHelper.PrepareUniformsAndSamplersList({uniformsNames:u,uniformBuffersNames:c,samplers:l,defines:r,maxSimultaneousLights:this.maxSimultaneousLights}),t.setEffect(n.getEngine().createEffect("fur",{attributes:a,uniformsNames:u,uniformBuffersNames:c,samplers:l,defines:s,fallbacks:o,onCompiled:this.onCompiled,onError:this.onError,indexParameters:{maxSimultaneousLights:this.maxSimultaneousLights}},f),r)}return!(!t.effect||!t.effect.isReady())&&(this._renderId=n.getRenderId(),this._wasPreviouslyReady=!0)},a.prototype.bindForSubMesh=function(e,t,i){var r=this.getScene(),n=i._materialDefines;if(n){var f=i.effect;f&&(this._activeEffect=f,this.bindOnlyWorldMatrix(e),this._activeEffect.setMatrix("viewProjection",r.getTransformMatrix()),h.MaterialHelper.BindBonesParameters(t,this._activeEffect),r.getCachedMaterial()!==this&&(this._diffuseTexture&&h.StandardMaterial.DiffuseTextureEnabled&&(this._activeEffect.setTexture("diffuseSampler",this._diffuseTexture),this._activeEffect.setFloat2("vDiffuseInfos",this._diffuseTexture.coordinatesIndex,this._diffuseTexture.level),this._activeEffect.setMatrix("diffuseMatrix",this._diffuseTexture.getTextureMatrix())),this._heightTexture&&this._activeEffect.setTexture("heightTexture",this._heightTexture),h.MaterialHelper.BindClipPlane(this._activeEffect,r),this.pointsCloud&&this._activeEffect.setFloat("pointSize",this.pointSize),h.MaterialHelper.BindEyePosition(f,r)),this._activeEffect.setColor4("vDiffuseColor",this.diffuseColor,this.alpha*t.visibility),r.lightsEnabled&&!this.disableLighting&&h.MaterialHelper.BindLights(r,t,this._activeEffect,n,this.maxSimultaneousLights),r.fogEnabled&&t.applyFog&&r.fogMode!==h.Scene.FOGMODE_NONE&&this._activeEffect.setMatrix("view",r.getViewMatrix()),h.MaterialHelper.BindFogParameters(r,t,this._activeEffect),this._activeEffect.setFloat("furLength",this.furLength),this._activeEffect.setFloat("furAngle",this.furAngle),this._activeEffect.setColor4("furColor",this.furColor,1),this.highLevelFur&&(this._activeEffect.setVector3("furGravity",this.furGravity),this._activeEffect.setFloat("furOffset",this.furOffset),this._activeEffect.setFloat("furSpacing",this.furSpacing),this._activeEffect.setFloat("furDensity",this.furDensity),this._activeEffect.setFloat("furOcclusion",this.furOcclusion),this._furTime+=this.getScene().getEngine().getDeltaTime()/this.furSpeed,this._activeEffect.setFloat("furTime",this._furTime),this._activeEffect.setTexture("furTexture",this.furTexture)),this._afterBind(t,this._activeEffect))}},a.prototype.getAnimatables=function(){var e=[];return this.diffuseTexture&&this.diffuseTexture.animations&&0<this.diffuseTexture.animations.length&&e.push(this.diffuseTexture),this.heightTexture&&this.heightTexture.animations&&0<this.heightTexture.animations.length&&e.push(this.heightTexture),e},a.prototype.getActiveTextures=function(){var e=r.prototype.getActiveTextures.call(this);return this._diffuseTexture&&e.push(this._diffuseTexture),this._heightTexture&&e.push(this._heightTexture),e},a.prototype.hasTexture=function(e){return!!r.prototype.hasTexture.call(this,e)||(this.diffuseTexture===e||this._heightTexture===e)},a.prototype.dispose=function(e){if(this.diffuseTexture&&this.diffuseTexture.dispose(),this._meshes)for(var t=1;t<this._meshes.length;t++){var i=this._meshes[t].material;i&&i.dispose(e),this._meshes[t].dispose()}r.prototype.dispose.call(this,e)},a.prototype.clone=function(e){var t=this;return h.SerializationHelper.Clone((function(){return new a(e,t.getScene())}),this)},a.prototype.serialize=function(){var e=h.SerializationHelper.Serialize(this);return e.customType="BABYLON.FurMaterial",this._meshes&&(e.sourceMeshName=this._meshes[0].name,e.quality=this._meshes.length),e},a.prototype.getClassName=function(){return"FurMaterial"},a.Parse=function(i,r,e){var n=h.SerializationHelper.Parse((function(){return new a(i.name,r)}),i,r,e);return i.sourceMeshName&&n.highLevelFur&&r.executeWhenReady((function(){var e=r.getMeshByName(i.sourceMeshName);if(e){var t=a.GenerateTexture("Fur Texture",r);n.furTexture=t,a.FurifyMesh(e,i.quality)}})),n},a.GenerateTexture=function(e,t){for(var i=new h.DynamicTexture("FurTexture "+e,256,t,!0),r=i.getContext(),n=0;n<2e4;++n)r.fillStyle="rgba(255, "+Math.floor(255*Math.random())+", "+Math.floor(255*Math.random())+", 1)",r.fillRect(Math.random()*i.getSize().width,Math.random()*i.getSize().height,2,2);return i.update(!1),i.wrapU=h.Texture.WRAP_ADDRESSMODE,i.wrapV=h.Texture.WRAP_ADDRESSMODE,i},a.FurifyMesh=function(e,t){var i,r=[e],n=e.material;if(!(n instanceof a))throw"The material of the source mesh must be a Fur Material";for(i=1;i<t;i++){var f=new h.FurMaterial(n.name+i,e.getScene());e.getScene().materials.pop(),h.Tags.EnableFor(f),h.Tags.AddTagsTo(f,"furShellMaterial"),f.furLength=n.furLength,f.furAngle=n.furAngle,f.furGravity=n.furGravity,f.furSpacing=n.furSpacing,f.furSpeed=n.furSpeed,f.furColor=n.furColor,f.diffuseTexture=n.diffuseTexture,f.furOffset=i/t,f.furTexture=n.furTexture,f.highLevelFur=n.highLevelFur,f.furTime=n.furTime,f.furDensity=n.furDensity;var o=e.clone(e.name+i);o.material=f,o.skeleton=e.skeleton,o.position=h.Vector3.Zero(),r.push(o)}for(i=1;i<r.length;i++)r[i].parent=e;return e.material._meshes=r},__decorate([h.serializeAsTexture("diffuseTexture")],a.prototype,"_diffuseTexture",void 0),__decorate([h.expandToProperty("_markAllSubMeshesAsTexturesDirty")],a.prototype,"diffuseTexture",void 0),__decorate([h.serializeAsTexture("heightTexture")],a.prototype,"_heightTexture",void 0),__decorate([h.expandToProperty("_markAllSubMeshesAsTexturesDirty")],a.prototype,"heightTexture",void 0),__decorate([h.serializeAsColor3()],a.prototype,"diffuseColor",void 0),__decorate([h.serialize()],a.prototype,"furLength",void 0),__decorate([h.serialize()],a.prototype,"furAngle",void 0),__decorate([h.serializeAsColor3()],a.prototype,"furColor",void 0),__decorate([h.serialize()],a.prototype,"furOffset",void 0),__decorate([h.serialize()],a.prototype,"furSpacing",void 0),__decorate([h.serializeAsVector3()],a.prototype,"furGravity",void 0),__decorate([h.serialize()],a.prototype,"furSpeed",void 0),__decorate([h.serialize()],a.prototype,"furDensity",void 0),__decorate([h.serialize()],a.prototype,"furOcclusion",void 0),__decorate([h.serialize("disableLighting")],a.prototype,"_disableLighting",void 0),__decorate([h.expandToProperty("_markAllSubMeshesAsLightsDirty")],a.prototype,"disableLighting",void 0),__decorate([h.serialize("maxSimultaneousLights")],a.prototype,"_maxSimultaneousLights",void 0),__decorate([h.expandToProperty("_markAllSubMeshesAsLightsDirty")],a.prototype,"maxSimultaneousLights",void 0),__decorate([h.serialize()],a.prototype,"highLevelFur",void 0),__decorate([h.serialize()],a.prototype,"furTime",null),a})(h.PushMaterial);h.FurMaterial=e})(BABYLON||(BABYLON={})),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",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}";
|