CCEffect %{ techniques: - passes: - vert: vs frag: fs blendState: targets: - blend: true rasterizerState: cullMode: none properties: texture: { value: white } alphaThreshold: { value: 0.5 } u_lerp: { value: 0, editor: { range:[0, 1, 0.01], slide: true, tooltip: '变形' } } flashColorRed: { value: 0, editor: { range: [0, 1, 0.01], slide: true, tooltip: 'Flash Red Color' } } flashColorGreen: { value: 0, editor: { range: [0, 1, 0.01], slide: true, tooltip: 'Flash Green Color' } } flashColorBlue: { value: 0, editor: { range: [0, 1, 0.01], slide: true, tooltip: 'Flash Blue Color' } } }% CCProgram vs %{ precision highp float; #include #include in vec3 a_position; in vec4 a_color; #if USE_TINT in vec4 a_color0; #endif in vec2 a_uv0; out vec2 v_uv0; out vec4 v_light; #if USE_TINT out vec4 v_dark; #endif void main () { mat4 mvp; #if CC_USE_MODEL mvp = cc_matViewProj * cc_matWorld; #else mvp = cc_matViewProj; #endif v_uv0 = a_uv0; v_light = a_color; #if USE_TINT v_dark = a_color0; #endif gl_Position = mvp * vec4(a_position, 1); } }% CCProgram fs %{ precision highp float; uniform sampler2D texture; uniform u_lerp{ float u_lerp;// 变形量[0, 1]; }; uniform flashColorRed{ float flashColorRed;// 变形量[0, 1]; }; uniform flashColorGreen{ float flashColorGreen;// 变形量[0, 1]; }; uniform flashColorBlue{ float flashColorBlue;// 变形量[0, 1]; }; in vec2 v_uv0; in vec4 v_light; #if USE_TINT in vec4 v_dark; #endif #include #include void main () { vec4 texColor = vec4(1.0); CCTexture(texture, v_uv0, texColor); vec4 finalColor; #if USE_TINT finalColor.a = v_light.a * texColor.a; finalColor.rgb = ((texColor.a - 1.0) * v_dark.a + 1.0 - texColor.rgb) * v_dark.rgb + texColor.rgb * v_light.rgb; #else finalColor = texColor * v_light; #endif if (finalColor.a <= 0.0) discard; vec3 flashColor = vec3(flashColorRed, flashColorGreen, flashColorBlue); vec3 result = mix(finalColor.rgb, flashColor, u_lerp); finalColor = vec4(result.rgb, finalColor.a); ALPHA_TEST(finalColor); gl_FragColor = finalColor; } }%