在COCOS2DX 里实现FLASH里的颜色滤镜效果。

首先看下是啥意思:
color-effect

然后学习下颜色矩阵的格式
http://www.graficaobscura.com/matrix/

最后看具体实现代码:

//_self是一个cc.Sprite;
if(_self.shader==null){
_self.shader = new cc.GLProgram("res/shader/E12_ColorMatrix.vsh", "res/shader/E12_ColorMatrix.fsh");
_self.shader.retain();
_self.shader.link();
_self.shader.updateUniforms();
}

var glProgram_state = cc.GLProgramState.getOrCreateWithGLProgram(_self.shader);
var u_ColorMatrix=[
1,0,0,0,
0,1,0,0,
0,0,1,0,
0,0,0,1
];

u_ColorMatrix=[
1,0,0,0,
0,0,0,0,
0,0,0,0,
-0.5,0,0,1
];

glProgram_state.setUniformMat4("u_ColorMatrix", u_ColorMatrix);
_self.setGLProgramState(glProgram_state);

这里是shader:
shader

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *