function __Class:setWaiFaGuang( spr,color)
local vertSource1 = [[
attribute vec4 a_position;
attribute vec2 a_texCoord;
attribute vec4 a_color;
#ifdef GL_ES
varying lowp vec4 v_fragmentColor;
varying mediump vec2 v_texCoord;
#else
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
#endif
void main()
{
gl_Position = CC_PMatrix * a_position;
v_fragmentColor = a_color;
v_texCoord = a_texCoord;
}
]]
local fragSource1 = [[
#ifdef GL_ES
precision mediump float;
#endif
varying vec4 v_fragmentColor;
varying vec2 v_texCoord;
uniform float TouM;
uniform float Add;
uniform vec4 Lightcolor;
void main(void)
{
vec4 o = vec4(1, 1, 1, 1);
vec4 o1 = vec4(1, 1, 1, 1);
vec4 o2 = vec4(1, 1, 1, 1);
vec4 o3 = vec4(1, 1, 1, 1);
vec4 o4 = vec4(1, 1, 1, 1);
float add = Add;
o *= texture2D(CC_Texture0, v_texCoord);
o1 *= texture2D(CC_Texture0, vec2(v_texCoord.x-add, v_texCoord.y));
o2 *= texture2D(CC_Texture0, vec2(v_texCoord.x-add, v_texCoord.y-add));
o3 *= texture2D(CC_Texture0, vec2(v_texCoord.x+add, v_texCoord.y));
o4 *= texture2D(CC_Texture0, vec2(v_texCoord.x-add, v_texCoord.y+add));
float alp = (o.a+o1.a+o3.a+o2.a+o4.a)/5;
float a = alp;
a*=step(alp,TouM);
a*=step(0,alp);
a*=abs(sin(CC_Time[1]));
gl_FragColor = Lightcolor*a;
}
]]
local Add = 1/math.max(spr:getContentSize().width,spr:getContentSize().height)*10
dump(Add)
local pProgram = cc.GLProgram:createWithByteArrays(vertSource1,fragSource1)
local glProgramState = cc.GLProgramState:getOrCreateWithGLProgram(pProgram)
glProgramState:setUniformVec4("Lightcolor",color);
glProgramState:setUniformFloat("TouM", 0.9);
glProgramState:setUniformFloat("Add", Add);
-- local spr = spr:getVirtualRenderer():getSprite();
spr:setGLProgram(pProgram)
spr:setGLProgramState(glProgramState)
end
网友评论