cocos creator 流光特效(参考shadertoy效果)

有兴趣的可以去官网:shadertoy官网 

流光特效代码:

// 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 }
}%


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>

  in vec4 v_color;

  in vec2 v_uv0;
  uniform sampler2D texture;

  #define ANGLE 60.0
  float startX = 0.0;
  float thresholdX = 0.08;
  float blur = 0.01;
  float posInterval = 0.02;
  uniform ARGS {
    vec2 iResolution;
    float time;
  }
  float colFactor(vec2 uv, float thresholdX, float blur){
      float intervalY = uv.y;
      float tempX = intervalY * cos(radians(ANGLE)) + startX;
      float intervalX = uv.x - tempX;
      // 在0.08 ~ 0.04平滑处理
      return smoothstep(thresholdX, thresholdX - blur, abs(intervalX));
  }
  void mainImage( out vec4 fragColor, in vec2 fragCoord ,vec2 res)
  {
      // Normalized pixel coordinates (from 0 to 1)
      vec2 uv = fragCoord/res.xy;
      startX = tan(time * 3.);
      // factor取值范围为0.04~0.08范围内
      float factor = colFactor(uv, thresholdX, blur);
      vec4 texColor = texture2D(texture,v_uv0);
      // 混合操作等价于 mix函数
      vec4 factorColor = factor * vec4(1.0, 1., 1., 1.0) + texColor * (1.0 - factor);
      fragColor = factorColor;
  }
  void main () {
    vec2 res = vec2(300.,300.);
    mainImage(gl_FragColor,v_uv0.xy * res.xy,res);
  }
}%

 

  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值