- Creator 版本:creator2.3.3
- 目标平台: windows模拟器
- 重现方式:必现
用shader写了一个label在其部分区域循环滚动的功能,在浏览器上运行没有问题,可以正常滚动,但用windows模拟器上运行则不动,有没有大佬知道原因呀。
shader代码:
CCEffect %{
techniques:
- passes:
- vert: vs
frag: fs
blendState:
targets:
- blend: true
rasterizerState:
cullMode: none
properties:
texture: { value: white }
moveSpeed: {value: 0.2}
anchorX: {value: 0.5}
showWidth: {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>
#include <texture>
#include <cc-global>
#include <cc-local>
in vec4 v_color;
#if USE_TEXTURE
in vec2 v_uv0;
uniform sampler2D texture;
#endif
#if USE_DYNAMIC
uniform global{
float moveSpeed;
float anchorX;
float showWidth;
};
#endif
void main () {
vec4 o = vec4(1, 1, 1, 1);
vec4 a_color = v_color;
#if USE_TEXTURE
vec2 uv = v_uv0;
#if USE_DYNAMIC
if (showWidth < 1.0) {
//左侧显示起始位置
float showPosL = (1.0-showWidth) * anchorX;
//右侧显示结束位置
float showPosR = showPosL + showWidth;
//偏移位置(初始位置向后偏移0.1)
float fixOff = 0.1;
float offset = mod(cc_time.x * 0.2 / moveSpeed , 1.0) - (showPosL + fixOff);
uv.x = uv.x + offset;
if (uv.x < showPosL + offset || uv.x > showPosR + offset || uv.x > 1.0 || uv.x < 0.0) {
a_color.a = 0.0;
}
}
//
#endif
o*=texture(texture,uv);
#endif
o *= a_color;
ALPHA_TEST(o);
gl_FragColor = o;
}
}%
使用方式为:
let resUrl = 'shader/materials/XXXX';
cc.loader.loadRes(resUrl, cc.Material, (error, res) => {
if (error) {
return;
}
if (txtLabel && txtLabel.isValid) {
let variant1 = txtLabel.setMaterial(0, res);
if (variant1) {
variant1.setProperty('anchorX', this.node.anchorX);
variant1.setProperty('showWidth', this.maxWidth / this.node.width);
variant1.setProperty('moveSpeed', Math.max(1.0, (this.node.width - this.maxWidth) / 100));
}
}
})