const renderEngine = cc.renderer.renderEngine; const renderer = renderEngine.renderer; let ShaderMaterial = require('ShaderMaterial'); const shader = { name: 'Fluxay', params: [ { name: 'time', type: renderer.PARAM_FLOAT }, { name: 'dtime', type: renderer.PARAM_FLOAT }, { name: 'offset', type: renderer.PARAM_FLOAT }, { name: 'linewidth', type: renderer.PARAM_FLOAT }, { name: 'linecolor', type: renderer.PARAM_FLOAT3 }, { name: 'ymode', type: renderer.PARAM_INT }, ], start(material,params) { material.cusparmas = {} material.cusparmas._start = 0; material.setParamValue('offset', params.offset||0); material.setParamValue('linewidth', params.linewidth||0.2); material.setParamValue('linecolor', cc.v3(params.linecolor.r,params.linecolor.g,params.linecolor.b)); material.setParamValue('dtime', params.dtime||1.414); material.setParamValue('ymode', params.ymode||0); }, update(material,dt) { // const now = Date.now(); // let time = ((now - material.cusparmas._start) / 1000); material.cusparmas._start+=dt material.setParamValue('time', material.cusparmas._start); }, defines:[], // vert: ` // uniform mat4 viewProj; // attribute vec3 a_position; // attribute vec2 a_uv0; // varying vec2 uv0; // void main () { // vec4 pos = viewProj * vec4(a_position, 1); // gl_Position = pos; // uv0 = a_uv0; // }`, frag: `uniform sampler2D texture; uniform vec4 color; uniform float time; uniform float offset; uniform float linewidth; varying vec2 uv0; uniform vec4 UVoffset; uniform vec3 linecolor; uniform float rotated; uniform float dtime; uniform int ymode; void main() { vec2 UVnormalize; if(ymode == 0){ UVnormalize.x = (uv0.x-UVoffset.x)/(UVoffset.z-UVoffset.x); UVnormalize.y = (uv0.y-UVoffset.y)/(UVoffset.w-UVoffset.y); }else{ UVnormalize.y = (uv0.x-UVoffset.x)/(UVoffset.z-UVoffset.x); UVnormalize.x = (uv0.y-UVoffset.y)/(UVoffset.w-UVoffset.y); } if(rotated > 0.5) { float temp = UVnormalize.x; UVnormalize.x = UVnormalize.y; UVnormalize.y = 1.0 - temp; } vec4 src_color = texture2D(texture, uv0).rgba; float start = tan(time/dtime); float strength = 0.7; float min = (start - offset * UVnormalize.y - linewidth); float max = (start - offset * UVnormalize.y); float bili =(UVnormalize.x-min)/ (max-min); // if(bili>0.3&&bili<0.7){ // bili = 0.3; // } // if(bili>0.5){ // bili = 1.0-bili; // } strength = strength*bili; if(UVnormalize.x < max && UVnormalize.x > min) { vec3 improve = strength * linecolor; vec3 result = vec3(src_color.r+improve.r, src_color.g+improve.g, src_color.b+improve.b); gl_FragColor = vec4(result, src_color.a); }else{ gl_FragColor = src_color; } }`, }; ShaderMaterial.addShader(shader);