1 |
- var __extends=this&&this.__extends||(function(){var t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var r in e)e.hasOwnProperty(r)&&(t[r]=e[r])};return function(e,r){function n(){this.constructor=e}t(e,r),e.prototype=null===r?Object.create(r):(n.prototype=r.prototype,new n)}})(),BABYLON;!(function(t){var e=(function(){function t(){}return t})();t.CustomShaderStructure=e;var r=(function(){function t(){}return t})();t.ShaderSpecialParts=r;var n=(function(e){function n(n,s){var i=e.call(this,n,s)||this;return i.CustomParts=new r,i.customShaderNameResolve=i.Builder,i.FragmentShader=t.Effect.ShadersStore.defaultPixelShader,i.VertexShader=t.Effect.ShadersStore.defaultVertexShader,i}return __extends(n,e),n.prototype.AttachAfterBind=function(t,e){for(var r in this._newUniformInstances){var n=r.toString().split("-");"vec2"==n[0]?e.setVector2(n[1],this._newUniformInstances[r]):"vec3"==n[0]?e.setVector3(n[1],this._newUniformInstances[r]):"vec4"==n[0]?e.setVector4(n[1],this._newUniformInstances[r]):"mat4"==n[0]?e.setMatrix(n[1],this._newUniformInstances[r]):"float"==n[0]&&e.setFloat(n[1],this._newUniformInstances[r])}for(var r in this._newSamplerInstances){var n=r.toString().split("-");"sampler2D"==n[0]&&this._newSamplerInstances[r].isReady&&this._newSamplerInstances[r].isReady()&&e.setTexture(n[1],this._newSamplerInstances[r])}},n.prototype.ReviewUniform=function(t,e){if("uniform"==t)for(var r in this._newUniforms)-1==this._customUniform[r].indexOf("sampler")&&e.push(this._newUniforms[r]);if("sampler"==t)for(var r in this._newUniforms)-1!=this._customUniform[r].indexOf("sampler")&&e.push(this._newUniforms[r]);return e},n.prototype.Builder=function(e,r,s,i,o){var a=this;if(this._isCreatedShader)return this._createdShaderName;this._isCreatedShader=!1,n.ShaderIndexer++;var _="custom_"+n.ShaderIndexer;this.ReviewUniform("uniform",r),this.ReviewUniform("sampler",i);var m=this._afterBind.bind(this);return this._afterBind=function(t,e){if(e){a.AttachAfterBind(t,e);try{m(t,e)}catch(e){}}},t.Effect.ShadersStore[_+"VertexShader"]=this.VertexShader.replace("#define CUSTOM_VERTEX_BEGIN",this.CustomParts.Vertex_Begin?this.CustomParts.Vertex_Begin:"").replace("#define CUSTOM_VERTEX_DEFINITIONS",(this._customUniform?this._customUniform.join("\n"):"")+(this.CustomParts.Vertex_Definitions?this.CustomParts.Vertex_Definitions:"")).replace("#define CUSTOM_VERTEX_MAIN_BEGIN",this.CustomParts.Vertex_MainBegin?this.CustomParts.Vertex_MainBegin:"").replace("#define CUSTOM_VERTEX_UPDATE_POSITION",this.CustomParts.Vertex_Before_PositionUpdated?this.CustomParts.Vertex_Before_PositionUpdated:"").replace("#define CUSTOM_VERTEX_UPDATE_NORMAL",this.CustomParts.Vertex_Before_NormalUpdated?this.CustomParts.Vertex_Before_NormalUpdated:""),t.Effect.ShadersStore[_+"PixelShader"]=this.FragmentShader.replace("#define CUSTOM_FRAGMENT_BEGIN",this.CustomParts.Fragment_Begin?this.CustomParts.Fragment_Begin:"").replace("#define CUSTOM_FRAGMENT_MAIN_BEGIN",this.CustomParts.Fragment_MainBegin?this.CustomParts.Fragment_MainBegin:"").replace("#define CUSTOM_FRAGMENT_DEFINITIONS",(this._customUniform?this._customUniform.join("\n"):"")+(this.CustomParts.Fragment_Definitions?this.CustomParts.Fragment_Definitions:"")).replace("#define CUSTOM_FRAGMENT_UPDATE_DIFFUSE",this.CustomParts.Fragment_Custom_Diffuse?this.CustomParts.Fragment_Custom_Diffuse:"").replace("#define CUSTOM_FRAGMENT_UPDATE_ALPHA",this.CustomParts.Fragment_Custom_Alpha?this.CustomParts.Fragment_Custom_Alpha:"").replace("#define CUSTOM_FRAGMENT_BEFORE_FRAGCOLOR",this.CustomParts.Fragment_Before_FragColor?this.CustomParts.Fragment_Before_FragColor:""),this._isCreatedShader=!0,this._createdShaderName=_,_},n.prototype.AddUniform=function(t,e,r){return this._customUniform||(this._customUniform=new Array,this._newUniforms=new Array,this._newSamplerInstances=new Array,this._newUniformInstances=new Array),r&&(e.indexOf("sampler"),this._newUniformInstances[e+"-"+t]=r),this._customUniform.push("uniform "+e+" "+t+";"),this._newUniforms.push(t),this},n.prototype.Fragment_Begin=function(t){return this.CustomParts.Fragment_Begin=t,this},n.prototype.Fragment_Definitions=function(t){return this.CustomParts.Fragment_Definitions=t,this},n.prototype.Fragment_MainBegin=function(t){return this.CustomParts.Fragment_MainBegin=t,this},n.prototype.Fragment_Custom_Diffuse=function(t){return this.CustomParts.Fragment_Custom_Diffuse=t.replace("result","diffuseColor"),this},n.prototype.Fragment_Custom_Alpha=function(t){return this.CustomParts.Fragment_Custom_Alpha=t.replace("result","alpha"),this},n.prototype.Fragment_Before_FragColor=function(t){return this.CustomParts.Fragment_Before_FragColor=t.replace("result","color"),this},n.prototype.Vertex_Begin=function(t){return this.CustomParts.Vertex_Begin=t,this},n.prototype.Vertex_Definitions=function(t){return this.CustomParts.Vertex_Definitions=t,this},n.prototype.Vertex_MainBegin=function(t){return this.CustomParts.Vertex_MainBegin=t,this},n.prototype.Vertex_Before_PositionUpdated=function(t){return this.CustomParts.Vertex_Before_PositionUpdated=t.replace("result","positionUpdated"),this},n.prototype.Vertex_Before_NormalUpdated=function(t){return this.CustomParts.Vertex_Before_NormalUpdated=t.replace("result","normalUpdated"),this},n.ShaderIndexer=1,n})(t.StandardMaterial);t.CustomMaterial=n})(BABYLON||(BABYLON={}));
|