cocos shader消失

go 复制代码
// Effect Syntax Guide: https://docs.cocos.com/creator/manual/zh/shader/index.html

// Effect Syntax Guide: https://docs.cocos.com/creator/manual/zh/shader/index.html

// Effect Syntax Guide: https://docs.cocos.com/creator/manual/zh/shader/index.html

CCEffect %{
  techniques:
  - name: glow
    passes:
    - vert: vs:vert

      frag: fs:frag
      blendState:

        targets:
        - blend: true

          blendSrc: src_alpha

          blendDst: one_minus_src_alpha
      depthStencilState:      
          depthTest: false  
          depthWrite: false 

      rasterizerState:
        cullMode: none
      properties:
        rowsCount: { value: 8.0, editor: { slide: true, range: [2, 100] } } 
        
        o: { value: -1, editor: { slide: true, range: [0, 100] } } 
        
}%

CCProgram vs %{
  precision highp float;
#include <cc-global>
#if USE_LOCAL



  #include <builtin/uniforms/cc-local>
#endif
in vec3 a_position;

in vec2 a_texCoord;   
out vec2 uv;

#if USE_LOCAL
  in vec4 a_color; 

  out vec4 v_color; 
#endif


vec4 vert() {

  vec4 pos = vec4(a_position, 1);

  #if USE_LOCAL
    pos = cc_matWorld * pos; 

    v_color = a_color;
  #endif

  pos = cc_matViewProj * pos;
  uv = a_texCoord;
  
  return  pos;
}

}%

CCProgram fs %{
  precision highp float;
  #include <sprite-texture>
  #include <cc-global> // 添加cc_time支持
  in vec2 uv;

  uniform sampler2D mainTexture;
  uniform UBO {


    float rowsCount;   // 切成几行
    float o;    // 整排下落到底部所需时间
  };

// 随机数函数,用于决定方块消失顺序
  float random(vec2 st) {
    return fract(sin(dot(st, vec2(12.9898, 78.233))) * 43768.5453123);
  }

  vec4 frag () {
    // 切成方块
    vec2 gridPos = floor(uv * vec2(rowsCount));
    vec2 blockCoord = (gridPos + 0.5) / vec2(rowsCount);
    
    vec4 color = texture(cc_spriteTexture, blockCoord);
    
    // ===== 消散动画 =====
    float time = cc_time.x * o / 2.0;
    float dissolve = fract(time); // 循环消散
    
    // 方法1:从中心向外消散
    vec2 centerDist = abs(blockCoord - 0.5) * 2.0; // 0=中心,1=边缘
    float distanceFromCenter = length(centerDist);
    
    // 距离中心越远,消散越早
    float appearThreshold = dissolve * 2.0 - distanceFromCenter;
    if (appearThreshold < 0.0) {
      color = vec4(0.0);
    }
    
    // 方法2:向上消散
    // float fadeStart = 0.5 - blockCoord.y * 0.5; // 底部先消散
    // if (dissolve > fadeStart) {
    //   color = vec4(0.0);
    // }
    
    return color;
  

  }

}%
相关推荐
VT LI1 天前
Cocos2d-x 引擎架构全面深度解析:从底层渲染到上层交互的系统性技术全景
游戏引擎·cocos·引擎架构
song_hui_xiang5 天前
Bingo 可玩广告构建工具
cocos·creator·playable·可玩
weixin_4093831210 天前
cocos 3d粒子 让粒子能换成黑色不透明 复制默认材质后改blend state deepseek告诉我的
3d·材质·cocos
mxwin11 天前
unity shader中 ddx ddy是什么
unity·游戏引擎·shader
mxwin12 天前
Unity SetPassCall和DrawCall的区别是什么
unity·游戏引擎·shader
mxwin15 天前
在unity shader中,通过pass产生阴影,通过主pass的光照 接收阴影!那么问题来了,是先产生阴影吗?还是先接收阴影,执行顺序是啥呢
数码相机·unity·游戏引擎·shader
小贺儿开发15 天前
《唐朝诡事录之长安》——盛世马球
人工智能·unity·ai·shader·绘画·影视·互动
mxwin22 天前
Unity Shader 半透明物体为什么不能写入深度缓冲?
unity·游戏引擎·shader
mxwin22 天前
Unity Shader 手写基于 PBR 的 URP Lit Shader 核心光照计算
unity·游戏引擎·shader
mxwin22 天前
Unity GPU Shader 性能优化指南
unity·游戏引擎·shader