Does Spine work with USE_INSTANCING?

Hello,

I’m working on a custom material/effect with a USE_INSTANCING branch that works on sprites, but does not work on a spine character. I’ve tried the different animation cache modes, and enable/disable batch.

The effect is a duplicate of builtin-spine, with the instancing branches added and the two_color branch removed. Nothing special, but I’ve attached it below.

I’m wondering if it’s user error, or working as intended. Maybe spine outputs skinned meshes that don’t support instancing?

Either way, thanks for your time!

Cocos version: 3.8.1
Spine version: 3.8.99 Pro

CCProgram vert-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;

  #if USE_INSTANCING
    #pragma format(RGBA8) // normalized unsigned byte
    in vec4 a_instancedCol1;
    #pragma format(RGBA8) // normalized unsigned byte
    in vec4 a_instancedCol2;
    #pragma format(RGBA8) // normalized unsigned byte
    in vec4 a_instancedCol3;

    out vec4 v_instancedCol1;
    out vec4 v_instancedCol2;
    out vec4 v_instancedCol3;
  #endif
  
  out vec4 v_light;
  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_light = a_color;

    return pos;
  }
}%

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

  in vec4 v_light;

  in vec2 uv0;
  #pragma builtin(local)
  layout(set = 2, binding = 12) uniform sampler2D cc_spriteTexture;
  uniform sampler2D maskTex;
  #if USE_INSTANCING
    in vec4 v_instancedCol1;
    in vec4 v_instancedCol2;
    in vec4 v_instancedCol3;
  #endif

  uniform Constant{
    vec4 u_col1;
    vec4 u_col2;
    vec4 u_col3;
  };

  vec4 frag () {

    vec4 o = vec4(1, 1, 1, 1);
    vec4 col1 = vec4(0,0,0,0);
    vec4 col2 = vec4(0,0,0,0);
    vec4 col3 = vec4(0,0,0,0);
    
    #if USE_INSTANCING
    col1 = vec4 (0,1,0,1);//  Using green for debugging macro.  v_instancedCol1;
    col2 = v_instancedCol1;
    col3 = v_instancedCol1;
    #else
    col1 = u_col1;
    col2 = u_col2;
    col3 = u_col3;
    #endif

    o *= texture(cc_spriteTexture, uv0);
    vec4 mask = vec4(texture(maskTex, uv0).rgb, 1);
    o.rgb = mix(o.rgb, col1.rgb, mask.r);
    o *= v_light;

    ALPHA_TEST(o);
    return o;
  }
}%

USE_INSTANCING is only for 3D mesh rendering.

if you want to reduce draw calls for 2d objects(sprites, labels, and spines), it’s better to follow the batching mechanism.

1 Like