123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- // Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
- CCEffect %{
- techniques:
- - passes:
- - vert: vs
- frag: fs
- blendState:
- targets:
- - blend: true
- rasterizerState:
- cullMode: none
- properties:
- texture: { value: white }
- alphaThreshold: { value: 0.5 }
- u_fluxayTexture: { value: white }
- }%
- CCProgram vs %{
- precision highp float;
- #include <cc-global>
- #include <cc-local>
- in vec3 a_position;
- in vec4 a_color;
- out vec4 v_color;
- #if USE_TEXTURE
- in vec2 a_uv0;
- out vec2 v_uv0;
- #endif
- void main () {
- vec4 pos = vec4(a_position, 1);
- #if CC_USE_MODEL
- pos = cc_matViewProj * cc_matWorld * pos;
- #else
- pos = cc_matViewProj * pos;
- #endif
- #if USE_TEXTURE
- v_uv0 = a_uv0;
- #endif
- v_color = a_color;
- gl_Position = pos;
- }
- }%
- CCProgram fs %{
- precision highp float;
- #include <alpha-test>
- #include <texture>
- #include <cc-global>
- in vec4 v_color;
- #if USE_TEXTURE
- in vec2 v_uv0;
- uniform sampler2D texture;
- #endif
- uniform sampler2D u_fluxayTexture; //流光纹理
- // 自定义属性
- // 所有非 sampler 的 uniform 都必须以 UBO 形式声明
- // UBO 成员声明类型和顺序有严格的校验机制,以排除 GL 标准下隐式布局对齐带来的内存消耗
- uniform ARGS {
- float u_time;
- };
- void main () {
- vec4 o = vec4(1, 1, 1, 1);
- #if USE_TEXTURE
- CCTexture(texture, v_uv0, o);
- #endif
- o *= v_color;
- #if USE_BGRA
- gl_FragColor = o.bgra;
- #else
- gl_FragColor = o.rgba;
- #endif
- ALPHA_TEST(o);
- // 使用 sin 函数模拟时间变化,周期为 2.0 秒
- float simulatedTime = tan(cc_time.x);
- // 在底图不透明的地方叠加流光纹理的颜色
- vec2 fluxayUV = vec2(v_uv0.x, v_uv0.y);
- // 根据时间控制流光纹理的UV
- fluxayUV.x -= simulatedTime;
- // 获取流光纹理上UV的颜色
- vec4 fluxay = texture2D(u_fluxayTexture, fluxayUV);
- if(o.a<= 0.8 && simulatedTime > -1.0 && simulatedTime < 1.0 && v_uv0.x > 0.1 && v_uv0.x < 0.9 && v_uv0.y > 0.1 && v_uv0.y < 0.9) {
- gl_FragColor = o + fluxay;
- } else {
- gl_FragColor = o;
- }
- }
- }%
|