Getting no uniforms even when set in onBeforeCompile


I´m expanding MeshStandardMaterial by using onBeforeCompile. Im adding some
uniforms like

    this.shaderUniforms = {
      time: {value: 0,0},

    myMaterial.onBeforeCompile = shader => {
        shader.uniforms.time = this.shaderUniforms.time;
        shader.vertexShader = `
                        uniform float time;

      ` + shader.vertexShader;
        return shader;

    this.powder = new THREE.Mesh( powderGeometry, powderMaterial );

But when console.log checking for mesh.material.uniforms → it seems my onBeforeCompile mods didn´t work as I do not have uniforms in there…


Please demonstrate the issue with a live example. Having a time uniform seems to work fine in the following fiddle:

Hmmm… your example is using userData.shader to store the scope… I thought if I use onBeforeCompile and add uniforms, they would be kind of the modified “material”. No?

No since built-in materials have no uniforms property.

1 Like