104 lines
3.5 KiB
JavaScript
104 lines
3.5 KiB
JavaScript
const renderEngine = cc.renderer.renderEngine;
|
|
const renderer = renderEngine.renderer;
|
|
let ShaderMaterial = require('ShaderMaterial');
|
|
|
|
const shader = {
|
|
name: 'FluxaySpine',
|
|
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.r,params.g,params.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:ShaderMaterial.spinevert,
|
|
|
|
frag:
|
|
`uniform sampler2D texture;
|
|
uniform float time;
|
|
uniform float offset;
|
|
uniform float linewidth;
|
|
varying vec2 uv0;
|
|
|
|
uniform vec3 linecolor;
|
|
uniform float dtime;
|
|
uniform int ymode;
|
|
|
|
void main()
|
|
{
|
|
|
|
|
|
if(gl_FragCoord.y<130.0){
|
|
gl_FragColor = texture2D(texture, uv0);
|
|
return;
|
|
}
|
|
|
|
vec2 onePixel = vec2(0.001, 0.001);
|
|
|
|
vec4 color = texture2D(texture, uv0);
|
|
vec4 colorRight = texture2D(texture, uv0.xy + vec2(0,onePixel.t));
|
|
vec4 colorBottom = texture2D(texture, uv0.xy + vec2(onePixel.s,0));
|
|
|
|
color.r = 3.0* sqrt( (color.r - colorRight.r) * (color.r - colorRight.r) + (color.r - colorBottom.r) * (color.r - colorBottom.r) );
|
|
color.g = 3.0* sqrt( (color.g - colorRight.g) * (color.g - colorRight.g) + (color.g - colorBottom.g) * (color.g - colorBottom.g) );
|
|
color.b = 3.0* sqrt( (color.b - colorRight.b) * (color.b - colorRight.b) + (color.b - colorBottom.b) * (color.b - colorBottom.b) );
|
|
|
|
if(color.r +color.g + color.b <0.5){
|
|
discard;
|
|
}
|
|
|
|
gl_FragColor = vec4(0.0,1.0,0.0, 1.0);
|
|
|
|
|
|
|
|
// if(color.r >1.0||color.g >1.0|| color.b >1.0){
|
|
|
|
// discard;
|
|
// }
|
|
// color.r = color.r >1.0 ? 1.0 : color.r;
|
|
// color.g = color.g >1.0 ? 1.0 : color.g;
|
|
// color.b = color.b >1.0 ? 1.0 : color.b;
|
|
|
|
|
|
// float start = tan(time/dtime);
|
|
// float strength = 0.7;
|
|
// float min = (start - offset * uv0.y - linewidth);
|
|
// float max = (start - offset * uv0.y);
|
|
// float bili =(uv0.x-min)/ (max-min);
|
|
// strength = strength*bili;
|
|
|
|
|
|
// if(uv0.x < max && uv0.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); |