babylon.woodProceduralTexture.min.js 2.6 KB

1
  1. var __extends=this&&this.__extends||(function(){var e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,o){e.__proto__=o}||function(e,o){for(var t in o)o.hasOwnProperty(t)&&(e[t]=o[t])};return function(o,t){function r(){this.constructor=o}e(o,t),o.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}})(),__decorate=this&&this.__decorate||function(e,o,t,r){var n,a=arguments.length,i=a<3?o:null===r?r=Object.getOwnPropertyDescriptor(o,t):r;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,o,t,r);else for(var c=e.length-1;c>=0;c--)(n=e[c])&&(i=(a<3?n(i):a>3?n(o,t,i):n(o,t))||i);return a>3&&i&&Object.defineProperty(o,t,i),i},BABYLON;!(function(e){var o=(function(o){function t(t,r,n,a,i){var c=o.call(this,t,r,"woodProceduralTexture",n,a,i)||this;return c._ampScale=100,c._woodColor=new e.Color3(.32,.17,.09),c.updateShaderUniforms(),c}return __extends(t,o),t.prototype.updateShaderUniforms=function(){this.setFloat("ampScale",this._ampScale),this.setColor3("woodColor",this._woodColor)},Object.defineProperty(t.prototype,"ampScale",{get:function(){return this._ampScale},set:function(e){this._ampScale=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),Object.defineProperty(t.prototype,"woodColor",{get:function(){return this._woodColor},set:function(e){this._woodColor=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),t.prototype.serialize=function(){var t=e.SerializationHelper.Serialize(this,o.prototype.serialize.call(this));return t.customType="BABYLON.WoodProceduralTexture",t},t.Parse=function(o,r,n){return e.SerializationHelper.Parse((function(){return new t(o.name,o._size,r,void 0,o._generateMipMaps)}),o,r,n)},__decorate([e.serialize()],t.prototype,"ampScale",null),__decorate([e.serializeAsColor3()],t.prototype,"woodColor",null),t})(e.ProceduralTexture);e.WoodProceduralTexture=o})(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.woodProceduralTexturePixelShader="precision highp float;\nvarying vec2 vPosition;\nvarying vec2 vUV;\nuniform float ampScale;\nuniform vec3 woodColor;\nfloat rand(vec2 n) {\nreturn fract(cos(dot(n,vec2(12.9898,4.1414)))*43758.5453);\n}\nfloat noise(vec2 n) {\nconst vec2 d=vec2(0.0,1.0);\nvec2 b=floor(n),f=smoothstep(vec2(0.0),vec2(1.0),fract(n));\nreturn mix(mix(rand(b),rand(b+d.yx),f.x),mix(rand(b+d.xy),rand(b+d.yy),f.x),f.y);\n}\nfloat fbm(vec2 n) {\nfloat total=0.0,amplitude=1.0;\nfor (int i=0; i<4; i++) {\ntotal+=noise(n)*amplitude;\nn+=n;\namplitude*=0.5;\n}\nreturn total;\n}\nvoid main(void) {\nfloat ratioy=mod(vUV.x*ampScale,2.0+fbm(vUV*0.8));\nvec3 wood=woodColor*ratioy;\ngl_FragColor=vec4(wood,1.0);\n}";