Custom Shader Attributes (new, shared and limitations)

I’m trying to use the same simple custom shader on two different entities but with different UV values.

varying vec2 vUv1;

uniform sampler2D uDiffuseMap;

void main(void)
{
    vec4 color = texture2D(uDiffuseMap, vUv1);
    gl_FragColor = color;
}
  1. but it seems that the same set of UVs (aUv1: pc.SEMANTIC_TEXCOORD1) is shared between the shaders, using the same value
  2. I’ve tried creating a second identical shader that uses aUv2: pc.SEMANTIC_TEXCOORD2 and tried using mesh.setUvs(2, textureCoords); to set it. But when I check the vertex buffer, it seems that the new attribute isn’t being added.

A minimal test is here https://playcanvas.com/editor/scene/1757000.

  1. Is it possible to re-use the same shader but with different attribute values?
  2. How can I add and use new attributes?

are you calling mesh.update() after mesh.setUvs? Check its parameters too.

Like this?

mesh.setUvs(2, textureCoords);   
mesh.update();

Also,

let shaderDefinition = {
    attributes: {
        aPosition: pc.SEMANTIC_POSITION,
        aUv2: pc.SEMANTIC_TEXCOORD2
    },
    vshader: vertexShader,
    fshader: fragmentShader
};