babylon.normalMapProceduralTexture.min.js 2.5 KB

1
  1. var BABYLON,__extends=this&&this.__extends||(function(){var o=function(e,t){return(o=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,t){e.__proto__=t}||function(e,t){for(var r in t)t.hasOwnProperty(r)&&(e[r]=t[r])})(e,t)};return function(e,t){function r(){this.constructor=e}o(e,t),e.prototype=null===t?Object.create(t):(r.prototype=t.prototype,new r)}})(),__decorate=this&&this.__decorate||function(e,t,r,o){var n,a=arguments.length,i=a<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)i=Reflect.decorate(e,t,r,o);else for(var u=e.length-1;0<=u;u--)(n=e[u])&&(i=(a<3?n(i):3<a?n(t,r,i):n(t,r))||i);return 3<a&&i&&Object.defineProperty(t,r,i),i};!(function(n){var e=(function(i){function o(e,t,r,o,n){var a=i.call(this,e,t,"normalMapProceduralTexture",r,o,n)||this;return a.updateShaderUniforms(),a}return __extends(o,i),o.prototype.updateShaderUniforms=function(){this.setTexture("baseSampler",this._baseTexture),this.setFloat("size",this.getRenderSize())},o.prototype.render=function(e){i.prototype.render.call(this,e)},o.prototype.resize=function(e,t){i.prototype.resize.call(this,e,t),this.updateShaderUniforms()},Object.defineProperty(o.prototype,"baseTexture",{get:function(){return this._baseTexture},set:function(e){this._baseTexture=e,this.updateShaderUniforms()},enumerable:!0,configurable:!0}),o.prototype.serialize=function(){var e=n.SerializationHelper.Serialize(this,i.prototype.serialize.call(this));return e.customType="BABYLON.NormalMapProceduralTexture",e},o.Parse=function(e,t,r){return n.SerializationHelper.Parse((function(){return new o(e.name,e._size,t,void 0,e._generateMipMaps)}),e,t,r)},__decorate([n.serializeAsTexture()],o.prototype,"baseTexture",null),o})(n.ProceduralTexture);n.NormalMapProceduralTexture=e})(BABYLON||(BABYLON={})),BABYLON.Effect.ShadersStore.normalMapProceduralTexturePixelShader="precision highp float;\n\nuniform sampler2D baseSampler;\nuniform float size;\n\nvarying vec2 vUV;\n\nconst vec3 LUMA_COEFFICIENT=vec3(0.2126,0.7152,0.0722);\nfloat lumaAtCoord(vec2 coord)\n{\nvec3 pixel=texture2D(baseSampler,coord).rgb;\nfloat luma=dot(pixel,LUMA_COEFFICIENT);\nreturn luma;\n}\nvoid main()\n{\nfloat lumaU0=lumaAtCoord(vUV+vec2(-1.0,0.0)/size);\nfloat lumaU1=lumaAtCoord(vUV+vec2( 1.0,0.0)/size);\nfloat lumaV0=lumaAtCoord(vUV+vec2( 0.0,-1.0)/size);\nfloat lumaV1=lumaAtCoord(vUV+vec2( 0.0,1.0)/size);\nvec2 slope=(vec2(lumaU0-lumaU1,lumaV0-lumaV1)+1.0)*0.5;\ngl_FragColor=vec4(slope,1.0,1.0);\n}\n";