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值,直接运行,类似如图

相关推荐
SMF19192 天前
【uv】Python包管理器uv安装和应用
开发语言·python·uv
l1t2 天前
利用uv自带的cpython软件包在离线机器中安装pandas软件
pandas·uv
rannn_1112 天前
【Redis|实战篇7】黑马点评|附近商铺、用户签到、UV签到
java·数据库·redis·后端·uv
belldeep6 天前
python:介绍 UV 安装,如何使用 UV 安装配置 OpenHarness
windows·python·环境变量·uv
深耕AI9 天前
【VS Code 中 Python 虚拟环境降级完整指南(含 uv 工具实战)】
开发语言·python·uv
weixin_4492900110 天前
uv打包Python为exe步骤
开发语言·python·uv
getapi10 天前
Windows 11 安装 uv包括:更新、常用命令、Python 管理、环境切换等,(Astral 的 Python 包/环境工具)完整指南
windows·python·uv
SiYuanFeng10 天前
uv初步介绍及简单的使用方法例子
开发语言·python·uv
mxwin10 天前
Unity Shader UV 坐标与纹理平铺Tiling & Offset 深度解析
unity·游戏引擎·shader·uv
致宏Rex10 天前
uv 教程:安装、常用命令、项目结构与关键文件
python·pip·uv