找了蛮久没找到, 照着引擎的材质照着写了一个,亲测可用。
置灰:
cc.loader.loadRes(“material/spinegray”, cc.Material, function(error, grayres){
let newgray = cc.Material.getInstantiatedMaterial(grayres, spine);
newgray.define(’_USE_MODEL’, true);
spine.setMaterial(0, newgray);
});
恢复:
spine.setMaterial(0, cc.Material.getInstantiatedBuiltinMaterial(‘2d-spine’,spine));
随便新建一个effect和材质, 把fs里面的main函数换成:
void main () {
vec4 texColor = texture2D(texture, v_uv0);
float gray = 0.2126texColor.r + 0.7152texColor.g + 0.0722*texColor.b;
gl_FragColor = vec4(gray, gray, gray, texColor.a);
}