egret_自定义Shader

var img = new egret.Bitmap();

 img.x = 0 ; img.y = 0 ; 

 img.width =750; 

 img.height = 1280; 

var texture = RES.getRes("egret_icon_png");

 img.texture = texture;

  //混合模式 

//img.blendMode = egret.BlendMode.ERASE; this.sceneManger.mainstage.addChild(img); 

 //滤镜 const colorMatrix = [ 0.3, 0.6, 0, 0, 0, 0, 0.6, 0, 0, 0, 0.3, 0.6, 0, 0, 0, 0, 0, 0, 1, 0 ]; 

const colorFlilter = new egret.ColorMatrixFilter(colorMatrix); 

//img.filters = [colorFlilter]; 

 const blurFliter = new egret.BlurFilter(1,1); 

//img.filters = [blurFliter]; 

let vertexSrc = "attribute vec2 aVertexPosition;\n" + "attribute vec2 aTextureCoord;\n" + "attribute vec2 aColor;\n" + "uniform vec2 projectionVector;\n" + "varying vec2 vTextureCoord;\n" + "const vec2 center = vec2(-1.0, 1.0);\n" + "void main(void) {\n" + " gl_Position = vec4( (aVertexPosition / projectionVector) + center , 0.0, 1.0);\n" + " vTextureCoord = aTextureCoord;\n" + "}"; 

 let fragmentSrc = "precision lowp float;\n" + "varying vec2 vTextureCoord;\n" + "uniform float width;\n" + "uniform float height;\n" + "void main(void) {\n" + "vec4 fg;\n" + "if(mod(floor(vTextureCoord.x / width) + floor(vTextureCoord.y / height), 2.0) == 0.0) {" + "fg = vec4(1,1,1,1);" + "}" + "else {" + "fg = vec4(0,0,0,1);" + "}" + "gl_FragColor = fg;\n" + "}"; 

 let size = 50; 

let filter = new egret.CustomFilter(vertexSrc, fragmentSrc, { width: size / 750, height: size / 1280}); 

//img.filters = [filter]; 

img.tint = 0x4169E1;

你可能感兴趣的:(egret_自定义Shader)