// Copyright (c) 2017-2020 Xiamen Yaji Software Co., Ltd. CCEffect %{ techniques: - passes: - vert: sprite-vs:vert frag: sprite-fs:frag depthStencilState: depthTest: false depthWrite: false blendState: targets: - blend: true blendSrc: src_alpha blendDst: one_minus_src_alpha blendDstAlpha: one_minus_src_alpha rasterizerState: cullMode: none properties: alphaThreshold: { value: 0.5 } }% CCProgram sprite-vs %{ precision highp float; #include #if USE_LOCAL #include #endif #if SAMPLE_FROM_RT #include #endif in vec3 a_position; in vec2 a_texCoord; in vec4 a_color; out vec4 color; out vec3 uv0; vec4 vert () { vec4 pos = vec4(a_position, 1); #if USE_LOCAL pos = cc_matWorld * pos; #endif #if USE_PIXEL_ALIGNMENT pos = cc_matView * pos; pos.xyz = floor(pos.xyz); pos = cc_matProj * pos; #else pos = cc_matViewProj * pos; #endif color = a_color; uv0.xy = a_texCoord; uv0.z = mod(color.r,10.0); color.r = ( color.r - uv0.z)*0.000001; #if SAMPLE_FROM_RT CC_HANDLE_RT_SAMPLE_FLIP(uv0.xy); #endif return pos; } }% CCProgram sprite-fs %{ precision highp float; #include #include in vec4 color; #if USE_TEXTURE in vec3 uv0; uniform sampler2D texture0; uniform sampler2D texture1; uniform sampler2D texture2; uniform sampler2D texture3; uniform sampler2D texture4; uniform sampler2D texture5; uniform sampler2D texture6; uniform sampler2D texture7; #endif vec4 ONE = vec4(1.0, 1.0, 1.0, 1.0); vec4 HALF = vec4(0.5, 0.5, 0.5, 0.5); vec4 ZERO = vec4(0.0, 0.0, 0.0, 0.0); vec4 frag () { vec4 o = vec4(1, 1, 1, 1); #if USE_TEXTURE vec4 p0 = vec4(uv0.z) - vec4(0.0, 1.0, 2.0, 3.0); vec4 p1 = vec4(uv0.z) - vec4(4.0, 5.0, 6.0, 7.0); vec4 w0 = step(p0*p0,HALF); vec4 w1 = step(p1*p1,HALF); vec4 sampledColor = ZERO; if(uv0.z < 1.5){ sampledColor += w0.x * CCSampleWithAlphaSeparated(texture0, uv0.xy*w0.x); sampledColor += w0.y * CCSampleWithAlphaSeparated(texture1, uv0.xy*w0.y); }else if(uv0.z < 3.5){ sampledColor += w0.z * CCSampleWithAlphaSeparated(texture2, uv0.xy*w0.z); sampledColor += w0.w * CCSampleWithAlphaSeparated(texture3, uv0.xy*w0.w); }else if(uv0.z < 5.5){ sampledColor += w1.x * CCSampleWithAlphaSeparated(texture4, uv0.xy*w1.x); sampledColor += w1.y * CCSampleWithAlphaSeparated(texture5, uv0.xy*w1.y); }else{ sampledColor += w1.z * CCSampleWithAlphaSeparated(texture6, uv0.xy*w1.z); sampledColor += w1.w * CCSampleWithAlphaSeparated(texture7, uv0.xy*w1.w); } o*=sampledColor; #if IS_GRAY float gray = 0.2126 * o.r + 0.7152 * o.g + 0.0722 * o.b; o.r = o.g = o.b = gray; #endif #endif o *= color; ALPHA_TEST(o); return o; } }%