关于shader从2.*版本中copy的代码,如何运行在3.*中

CCEffect %{
techniques:

  • name: opaque
    passes:
    • vert: legacy/main-functions/general-vs:vert # builtin header
      frag: fs
      blendState:
      targets:
      • blend: true
        blendSrc: src_alpha
        blendDst: one_minus_src_alpha
        blendSrcAlpha: src_alpha
        blendDstAlpha: one_minus_src_alpha
        rasterizerState:
        cullMode: none
        properties:
        texture: { value: white }
        alphaThreshold: { value: 0.5 }
        radius: {
        value: 0.5,
        tooltip: “半径”
        }
        progress: {
        value: 0.5
        }
        texture2: { value: white }
        }%

CCProgram vs %{
precision highp float;

#include <builtin/uniforms/cc-global>
#include <legacy/output>
#include <legacy/fog-fs>

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
#include

in vec4 v_color;

#define PI 3.1415926

#if USE_TEXTURE
in vec2 v_uv0;
uniform sampler2D texture;
#endif

uniform Custom {
float radius;
float progress;
};
uniform sampler2D texture2;

vec4 frag () {
vec4 o = vec4(1.0, 1.0, 1.0, 1.0);

float primeter = 2.0 * PI * radius;              // 周长
float x = v_uv0.x;
float outLen = 1.0 - progress;                   // 超出的部分
float range = 3.0 / 4.0;
vec2 c_uv0 = v_uv0;

float realX = v_uv0.x;
float offset = x-progress;

bool draw = true;
bool useTexture2 = false;
if(x > progress) {    // 两种情况
  if(outLen <= primeter * 0.25) {
    if(offset > sin(outLen / radius) * radius) {
      draw = false;
    }else {
      realX = asin(offset / radius) * radius + progress;
    }
  }else {
    if(outLen < primeter * 0.5 && offset < cos((outLen - primeter * 0.25) / radius) * radius) {
      realX = asin(offset / radius) * radius + progress;
    }else if(offset >= radius) {
      draw = false;
    }else {
      realX = acos(offset / radius) * radius + progress + primeter * .25;
      useTexture2 = true;
    }
  }
}else if(outLen > primeter * 0.5) {
  if(outLen < primeter * 0.75) {
    outLen = outLen - primeter * 0.5;
    if(offset < -sin(outLen / radius) * radius) {
      realX = realX;
    }else {
      realX = asin(-offset / radius) * radius + progress + primeter * 0.5;
      useTexture2 = true;
    }
  }else {
    if(offset < -radius) {
      realX = realX;
    }else {
      realX = asin(-offset / radius) * radius + progress + primeter * 0.5;
      useTexture2 = true;
    }      
  }
}else {
  
}


if(draw) {
  c_uv0.x = realX;
  if(useTexture2) {
    texture(texture2, c_uv0, o);
  }else {
    texture(texture, c_uv0, o);
  }
  
}else {
  o.a = 0.0;
}


o *= v_color;

gl_FragColor = o;
ALPHA_TEST(o);
CC_APPLY_FOG(col, v_position);
return CCFragOutput(col);

}
}%