How to define a float array uniform in MaterialPlugin?

In my shader code I have uniform float uPickedInstances[32];.

  1. How to define it in my MaterialPlugin?

    MyMaterialPlugin extends MaterialPluginBase {
      getUniforms() {
        return {
          // Is it right?
          ubo: [{name: 'uPickedInstances', size: 32, type: 'float'}]
        };
      }
    }
    
  2. Actually I disabled UBO usage:

    engine.disableUniformBuffers = true;
    

    Why do I still need to specify size and type?

    MyMaterialPlugin extends MaterialPluginBase {
      getUniforms() {
        return {
          ubo: [{name: 'uPickedInstances', size: 0, type: ''}]
        };
      }
    }
    

    Looking at MaterialPluginManager source code, they are not used if UBO usage disabled.

  3. Is there a way to disable UBO usage for MyMaterialPlugin only?

cc @Evgeni_Popov :slight_smile:

We don’t currently support uniform array in material plugins. This PR will add the support:

Once the PR is merged, this PG will work:

It defines an array of vec3 in the shader and use myColor[1] as the color filter (which I set to be (0,1,0) in bindForSubMesh).

Actually, you need to only specify name if you are sure that ubos won’t be used. We still need name because we need to collect the list of all uniform names, and it’s easier to get them from the ubo array than from the “fragment” string, that we would need to parse to extract those names.

No, it’s not possible, a material can’t have some of the settings managed by a ubo and some others not using the ubo.

1 Like

Thank you!

Actually, you need to only specify name if you are sure that ubos won’t be used. We still need name because we need to collect the list of all uniform names, and it’s easier to get them from the ubo array than from the “fragment” string, that we would need to parse to extract those names.

I think we need to improve ubo property typing:

ubo?: Array<{ name: string; size: number; type: string }> | Array<{ name: string }>

Do you agree?

Agree, I have updated my PR!

2 Likes