whoami7 - Manager
:
/
home
/
dataiclx
/
public_html
/
wp-content
/
themes
/
woodmart
/
js
/
scripts
/
shaders
/
Upload File:
files >> /home/dataiclx/public_html/wp-content/themes/woodmart/js/scripts/shaders/shaderX.min.js
function ShaderX(a){var b={container:null,sizeContainer:null,autoPlay:!0,vertexShader:"",fragmentShader:"",width:0,height:0,mouseMove:!1,distImage:!1};this.options=jQuery.extend({},b,a),this.container=this.options.container,this.pixelRatio=window.devicePixelRatio,this.uniforms={},this.time=0,this.progress=0,this.empty=!0,this.images={},this.texture1=null,this.texture2=null,this.resizing=!1,this.resizingTimeout=0,this.border=0,this.scale=1,this.drawn=!1,this.runned=!1,this.mouseX=0,this.mouseY=0,this.loadedTextures={},this.options.autoPlay&&this.init()}ShaderX.prototype={init:function(){var a=this;window.addEventListener("resize",function(){a.resize()}),this.options.autoPlay&&(this.runned=!0,this.render(),this.raf())},render:function(){this.container.hasClass("wd-with-webgl")||(this.createCanvas(),this.container.append(this.canvas),this.container.addClass("wd-with-webgl")),this.gl&&(this.progress>0&&this.progress<1||!this.drawn)&&(this.renderCanvas(),this.drawn=!0)},createCanvas:function(){if(this.canvas=document.createElement("CANVAS"),this.gl=this.canvas.getContext("webgl"),!this.gl)return void console.log("WebGL is not supported");this.canvas.width=this.options.width*this.pixelRatio,this.canvas.height=this.options.height*this.pixelRatio;var a=this.createShader(this.gl.VERTEX_SHADER,this.options.vertexShader),b=this.createShader(this.gl.FRAGMENT_SHADER,this.options.fragmentShader);this.program=this.createProgram(a,b);var c=this.gl.getAttribLocation(this.program,"a_position"),d=this.gl.createBuffer();this.gl.bindBuffer(this.gl.ARRAY_BUFFER,d);var e=0,f=this.options.width*this.pixelRatio,g=0,h=this.options.height*this.pixelRatio,i=[e,g,f,g,e,h,e,h,f,g,f,h];this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array(i),this.gl.STATIC_DRAW),this.gl.viewport(0,0,this.gl.canvas.width,this.gl.canvas.height),this.gl.clearColor(0,0,0,0),this.gl.clear(this.gl.COLOR_BUFFER_BIT),this.gl.useProgram(this.program);var j=[2/this.gl.canvas.width,0,0,0,-2/this.gl.canvas.height,0,-1,1,1];this.addUniform("3fv","u_matrix",j),this.addUniform("1f","u_flipY",1),this.addUniform("1f","u_time",0),this.addUniform("2f","u_pixels",[this.options.width*this.pixelRatio,this.options.height*this.pixelRatio]),this.addUniform("1f","u_progress",0),this.addUniform("2f","u_resolution",[this.gl.canvas.width,this.gl.canvas.height]),this.addUniform("2f","u_uvRate",[1,1]),this.addUniform("1f","u_scale",this.scale),this.options.mouseMove&&this.addUniform("2f","u_mouse",[.5,0]),this.gl.enableVertexAttribArray(c);var k=this.gl.FLOAT;this.gl.vertexAttribPointer(c,2,k,!1,0,0);var l=this.gl.getAttribLocation(this.program,"a_texCoord"),m=this.gl.createBuffer();if(this.gl.bindBuffer(this.gl.ARRAY_BUFFER,m),this.gl.bufferData(this.gl.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),this.gl.STATIC_DRAW),this.gl.enableVertexAttribArray(l),this.gl.vertexAttribPointer(l,2,this.gl.FLOAT,!1,0,0),this.texture1&&this.loadImageTexture(this.texture1,0),this.options.distImage){var n=new Image;this.requestCORSIfNotSameOrigin(n,this.options.distImage),n.src=this.options.distImage;var o=this;n.onload=function(){o.loadImageTexture(n,2)}}},raf:function(){function a(){if(b.time+=.03,b.updateUniform("u_time",b.time),b.options.mouseMove){var c=b.getUniform("u_mouse"),d=c[0],e=c[1],f=d?d+.05*(b.mouseX-d):b.mouseX,g=e?e+.05*(b.mouseY-e):b.mouseY;b.updateUniform("u_mouse",[f,g])}b.progress<0&&(b.progress=0),b.progress>1&&(b.progress=1),b.updateUniform("u_progress",b.progress),b.updateUniform("u_scale",b.scale),b.render(),b.requestID=window.requestAnimationFrame(a)}if(this.canvas){var b=this;a()}},resize:function(){var a=this;clearTimeout(this.resizingTimeout),this.resizingTimeout=setTimeout(function(){if(a.canvas){var b=Math.floor(a.options.sizeContainer.outerWidth()*a.pixelRatio),c=Math.floor(a.options.sizeContainer.outerHeight()*a.pixelRatio);a.gl.canvas.width===b&&a.gl.canvas.height===c||(a.gl.canvas.width=b,a.gl.canvas.height=c),a.updateUniform("u_resolution",[b,c]),a.updateUniform("u_pixels",[b,c]),a.updateUniform("u_uvRate",[1,c/b]),a.gl.viewport(0,0,b,c),a.drawn=!1}},500)},run:function(){this.runned||(this.runned=!0,this.render(),this.raf())},stop:function(){this.runned&&(window.cancelAnimationFrame(this.requestID),this.destroyCanvas(),this.container.find("canvas").remove(),this.container.removeClass("wd-with-webgl"),this.runned=!1)},renderCanvas:function(){if(this.empty)return!1;this.gl.drawArrays(this.gl.TRIANGLES,0,6)},destroyCanvas:function(){this.gl&&(this.canvas=null,this.gl.getExtension("WEBGL_lose_context").loseContext(),this.gl=null)},createShader:function(a,b){var c=this.gl.createShader(a);if(this.gl.shaderSource(c,b),this.gl.compileShader(c),this.gl.getShaderParameter(c,this.gl.COMPILE_STATUS))return c;console.log(this.gl.getShaderInfoLog(c)),this.gl.deleteShader(c)},createProgram:function(a,b){var c=this.gl.createProgram();if(this.gl.attachShader(c,a),this.gl.attachShader(c,b),this.gl.linkProgram(c),this.gl.getProgramParameter(c,this.gl.LINK_STATUS))return c;console.log(this.gl.getProgramInfoLog(c)),this.gl.deleteProgram(c)},addUniform:function(a,b,c){var d=this.gl.getUniformLocation(this.program,b);this.uniforms[b]={location:d,type:a},!1!==c&&this.updateUniform(b,c)},updateUniform:function(a,b){if(this.gl){var c=this.uniforms[a];switch(c.type){case"1f":this.gl.uniform1f(c.location,b);break;case"2f":this.gl.uniform2f(c.location,b[0],b[1]);break;case"1i":this.gl.uniform1i(c.location,b);break;case"3fv":this.gl.uniformMatrix3fv(c.location,!1,b)}}},getUniform:function(a,b){if(this.gl){var c=this.uniforms[a];return this.gl.getUniform(this.program,c.location)}},getImageId:function(a){var b=a.split("/");return b[b.length-3]+"-"+b[b.length-2]+"-"+b[b.length-1]},loadImage:function(a,b,c,d){var e,f=this.getImageId(a);if(this.images[f]){if(e=this.images[f],d)return;return 0===b?this.texture1=e:1===b&&(this.texture2=e),this.loadImageTexture(e,b),this.empty=!1,this.drawn=!1,void(c&&c())}e=new Image,this.requestCORSIfNotSameOrigin(e,a),e.src=a;var g=this;e.onload=function(){g.images[f]=e,d||(0===b?g.texture1=e:g.texture2=e,g.loadImageTexture(e,b),g.empty=!1,g.drawn=!1,c&&c())}},requestCORSIfNotSameOrigin:function(a,b){new URL(b,window.location.href).origin!==window.location.origin&&(a.crossOrigin="")},loadImageTexture:function(a,b){if(this.gl){var c;if(this.loadedTextures[b]){c=this.loadedTextures[b];var d=this.gl.TEXTURE0+b;this.gl.activeTexture(d),this.gl.bindTexture(this.gl.TEXTURE_2D,c),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,a),this.addUniform("1i","u_image"+b,b),this.addUniform("2f","u_image"+b+"_size",[a.width,a.height])}else{c=this.gl.createTexture();var d=this.gl.TEXTURE0+b;this.gl.activeTexture(d),this.gl.bindTexture(this.gl.TEXTURE_2D,c),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_S,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_WRAP_T,this.gl.CLAMP_TO_EDGE),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MIN_FILTER,this.gl.LINEAR),this.gl.texParameteri(this.gl.TEXTURE_2D,this.gl.TEXTURE_MAG_FILTER,this.gl.LINEAR),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,this.gl.RGBA,this.gl.UNSIGNED_BYTE,a),this.addUniform("1i","u_image"+b,b),this.addUniform("2f","u_image"+b+"_size",[a.width,a.height]),this.updateUniform("u_flipY",-1)}}},replaceImage:function(a){var b=this;this.getImageId(a);this.texture2&&(b.loadImageTexture(this.texture2,0),b.loadImageTexture(this.texture2,1));var c=function(a){return a*(2-a)};this.loadImage(a,1,function(){function a(){if(j+=i,b.progress=c(j),b.progress>=1)return void window.cancelAnimationFrame(d);d=window.requestAnimationFrame(a)}var d,e=1300,f=60,g=1e3/f,h=e/g,i=1/h,j=0;b.progress=0,a()})}};
Copyright ©2021 || Defacer Indonesia