cocos creator3.8 箭头的uv 流动shader

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:

mainTexture: { value: white }

tiling: { value: [1.0, 1.0] }

flowSpeed: { value: 5.0 }

}%

CCProgram sprite-vs %{

precision highp float;

#include <builtin/uniforms/cc-global>

#if USE_LOCAL

#include <builtin/uniforms/cc-local>

#endif

in vec3 a_position;

in vec2 a_texCoord;

in vec4 a_color;

out vec4 v_color;

out vec2 uv0;

vec4 vert() {

vec4 pos = vec4(a_position, 1);

#if USE_LOCAL

pos = cc_matWorld * pos;

#endif

pos = cc_matViewProj * pos;

uv0 = a_texCoord;

v_color = a_color;

return pos;

}

}%

CCProgram sprite-fs %{

precision highp float;

#include <builtin/uniforms/cc-global>

#include <builtin/internal/embedded-alpha>

in vec4 v_color;

in vec2 uv0;

uniform sampler2D mainTexture;

uniform Properties {

vec2 tiling;

float flowSpeed;

};

vec4 frag() {

// 计算流动的UV坐标

float t = cc_time.x; // 引擎内置时间(秒)

vec2 uv = vec2(uv0.x * tiling.x, fract(uv0.y * tiling.y + t * flowSpeed)); // y轴方向反向流动,随高度重复

// 采样纹理

vec4 texColor = texture(mainTexture, uv);

// 直接返回纹理颜色乘以顶点颜色

vec4 o = v_color * texColor;

return o;

}

}%

将箭头图片拖到场景中,修改图片的材质,该一下箭头图片node节点的高度 ,同时修改一下材质上 tile 的y值,直接运行,类似如图

相关推荐
TTGGGFF7 小时前
UV详解:替代pip、conda的下一代Python包与环境管理工具
conda·pip·uv
pearbing2 天前
天猫UV量提高实用指南:找准方向,稳步突破流量瓶颈
大数据·uv·天猫uv量提高·天猫uv量·uv量提高·天猫提高uv量
萧鼎2 天前
Python 包管理的“超音速”革命:全面上手 uv 工具链
开发语言·python·uv
coloma20126 天前
COCOS代码动态增加刚体和碰撞体的方法
前端·uv
没事儿写两篇7 天前
Python 包管理工具-uv
python·uv·开源包管理工具
lambert.wang10 天前
当使用 uv 下载 Python 解释器时出现异常,通常是因为网络连接问题导致无法从 GitHub 下载安装包
python·github·uv
叼奶嘴的超人10 天前
Fastapi之UV安装方式与使用方式
fastapi·uv
lambert.wang11 天前
uv安装配置
uv
永霖光电_UVLED12 天前
连续波 UV-B 激光二极管问世,实现全球首次
大数据·人工智能·uv
要站在顶端12 天前
uv 工具核心操作总结文档
uv