fragmenshader里面
vec4 texColor = texture2D(CC_Texture0,v_texCoord);
float distance = abs(v_texCoord[0] + v_texCoord[1] - offset) / 1.414;distance = 1 - (1 / width)*distance;
distance = max(distance,0);
vec4 sample = vec4(0.0,0.0,0.0);
sample[0] = color[0] * distance;
sample[1] = color[1] * distance;
sample[2] = color[2] * distance;
sample[3] = distance;
float alpha = sample[3] * texColor[3];
texColor[0] = texColor[0] + sample[0] * alpha*factor;
texColor[1] = texColor[1] + sample[1] * alpha*factor;
texColor[2] = texColor[2] + sample[2] * alpha*factor;
gl_FragColor = v_fragmentColor * texColor;
offset是传入的参数0-2变化的控制的是光线位移 width就是线的宽度。factor是光线透明度。
原文链接:https://www.f2er.com/cocos2dx/345402.html