creator 3.0 正式版 spine自定义材质动态修改uniform 不生效

问题:
spine组件在编辑器里设置自定义材质,然后通过tween 动态修改uniform 渲染不生效。同样的操作作用于sprite组件是生效的。

操作函数如下(传入spine组件是渲染不生效,但是onupdate函数里打印uniform值是被修改了的。传入sprite组件则正常):
static redblink2(renderComp: Renderable2D): Tween {
return tween(renderComp)
.to(5, {}, {
onStart: (target) => {
let mat = (target as Renderable2D).material
if (mat) {
const pass = mat.passes[0]
if (pass) {
const hThreshold = pass.getHandle(‘coverColor’);
pass.setUniform(hThreshold, new Vec4(1, 0, 0, 0.5)); // now, albedoScale.w = 0.5
}
}
},
onUpdate: (target, ratio) => {
if (ratio) {
let mat = (target as Renderable2D).material
if (mat) {
const pass = mat.passes[0]
if (pass) {
const hThreshold = pass.getHandle(‘coverColor’);
let out = new Vec4(0, 0, 0, 0)
pass.getUniform(hThreshold, out)
console.log(out.w)
pass.setUniform(hThreshold, new Vec4(1, 0, 0, 0.5 * (1 - ratio)));
}
}
}
},
})
.start()
}

同问,后面有解决吗

10月13日了,在最新的creator3.3.1中发现了同样的问题,将uniform对接到properties中配置到材质上是生效的,通过代码赋值看数值生效,但实际效果还是按材质上配置的走。求解决方案。

mat: Material = null!
initMaterial(){
this.mat = new Material();
this.mat.initialize({
effectAsset: effectAsset,
defines: { USE_RGBE_CUBEMAP: true }
});
this.getComponent(sp.Skeleton)!.customMaterial = this.mat
}

/** 动态修改uniform /
updateUniform(){
let pass = this.mat .passes[0]
pass.setUniform(pass.getHandle(‘要修改的uniform:ucolor’), color(255, 255,
255, 140))
/
* 修改后在赋值给customMaterial */
this.getComponent(sp.Skeleton)!.customMaterial = this.mat
}
我是这样弄的

动态修改预制体加载的带着shader的spine的属性有两种情况。
一是spine加载时的同一帧中,需要在下一帧修改属性
let matCaches1 = node.getComponent(sp.Skeleton)[’_materialCache’];
node.getComponent(sp.Skeleton).scheduleOnce(() => {
for (let x in matCaches1) {
let m = matCaches1[x];
m.setProperty(“isOtherTeam”, 0);
}
});

二是在其它帧中,直接修改属性

let matCaches = this.body.getComponent(sp.Skeleton)[’_materialCache’];
for (var x in matCaches) {
let m = matCaches[x];
m.setProperty(‘isOtherTeam’, 0);
}

如果是在代码里将shader赋给spine的,在加载时可以不用等下一帧才修改属性,而是当前帧修改属性。
注意:spine不要用setMaterial函数,而是要用customMaterial

该主题在最后一个回复创建后14天后自动关闭。不再允许新的回复。