多图层节点分离红蓝效果，怎么与背景混合？

akidsuki
Tue, 14 Apr 2026 09:50:00 +0000

这是我的着色器代码

CCProgram sprite-fs %{
precision highp float;
#include <builtin/internal/embedded-alpha>
#include <builtin/internal/alpha-test>

in vec4 color;

in vec2 uv0;
#pragma builtin(local)
layout(set = 2, binding = 12)uniform sampler2D cc_spriteTexture;

uniform MyBuffer {
  float u_offset;
  float u_leftIntensity;
  float u_rightIntensity;
};

vec4 frag() {
  vec4 o = vec4(1, 1, 1, 1);

  // o *= CCSampleWithAlphaSeparated(cc_spriteTexture, uv0);
  vec4 leftCol = CCSampleWithAlphaSeparated(cc_spriteTexture, uv0 + vec2(u_offset * 0.001, 0));
  vec4 rightCol = CCSampleWithAlphaSeparated(cc_spriteTexture, uv0 - vec2(u_offset * 0.001, 0));
  leftCol.gb = vec2(0.0, 0.0);
  rightCol.r = 0.0;
  vec4 col;
  col.rgb = leftCol.rgb * u_leftIntensity + rightCol.rgb * u_leftIntensity;
  col.a = leftCol.a* rightCol.a;
  o *= col;
  ALPHA_TEST(o);
  return o;
}
}%

阅读整个主题